Tablelist, bitmaps and embedded windows

Tablelist, bitmaps and embedded windows

Post by Kevin Walz » Sat, 06 Jun 2009 11:13:21


I have found a workaround for displaying bitmaps in Tablelist cells: I
can use the package's embedded window procedure to embed a label with a
bitmap in the cell. However, the label has its own background and does
not "blend in" with the row/cell if they are selected. How can this be
done? The sample code below shows the bitmap/label/embedded window;
assistance in getting the label to change its appearance when the row is
selected would be appreciated.

------
package require tablelist_tile

proc createLabel {tbl row col w} {

label $w -bitmap questhead

}

tablelist::tablelist .t -columns {0 "First Column" 0 "Another column"}
-stretch all -background white -labelcommand tablelist::sortByColumn
-selectforeground white -selectbackground blue
pack .t -fill both -expand yes
.t insert end [list "first row" "another value"]
.t insert end [list "another row" "bla bla"]


.t cellconfigure end,0 -window createLabel

===


--
Kevin Walzer
Code by Kevin
http://www.yqcomputer.com/
 
 
 

Tablelist, bitmaps and embedded windows

Post by jeff_godfr » Sun, 07 Jun 2009 00:08:24


Hi Kevin,

As I mentioned in your other thread, why not just create "image"
versions of the bitmaps you want, and then use them with the "-image"
option of the various widgets? If need be, you could just display,
screenshot, crop, and save each bitmap as a GIF/PNG. From there,
either use the files directly, or base64 encode them and include them
as a library file.

It may be a little extra work, but once you've done it should be
trivial to use. Much easier than fiddling with extra label widgets,
IMO.

Jeff

 
 
 

Tablelist, bitmaps and embedded windows

Post by Kevin Walz » Sun, 07 Jun 2009 00:13:33


Jeff,

Part of the reason is that I'm not really interested in the ugly Tk
bitmaps--I'm interested in using the new tk::mac::iconBitmap command in
Tk-Cocoa (on the Mac) which lets you access native system icons and
images on the fly. Inline data won't work here, and converting to a
standard Tk photo image isn't feasible.

Thanks for the suggestion, however.

--Kevin

--
Kevin Walzer
Code by Kevin
http://www.yqcomputer.com/
 
 
 

Tablelist, bitmaps and embedded windows

Post by Csaba Neme » Sun, 07 Jun 2009 05:04:31

Kevin Walzer schrieb:

You can bind to the <<TablelistSelect>> virtual event, like in the
following modified version of your example:


package require tablelist_tile

proc labelCmd {tbl col} {
tablelist::sortByColumn $tbl $col
updateLabelBg $tbl
}

proc updateLabelBg tbl {
set normalBg [$tbl cget -background]
set selectBg [$tbl cget -selectbackground]
set selRows [$tbl curselection]

set count [$tbl size]
for {set row 0} {$row < $count} {incr row} {
set label [$tbl windowpath $row,0]
if {$label ne ""} {
if {$row in $selRows} {
$label configure -background $selectBg
} else {
$label configure -background $normalBg
}
}
}
}

proc createLabel {tbl row col w} {
label $w -bitmap questhead -background [$tbl cget -background]
}

tablelist::tablelist .t -columns {0 "First Column" 0 "Another column"} \
-stretch all -background white -labelcommand labelCmd \
-selectforeground white -selectbackground blue
pack .t -fill both -expand yes
.t insert end [list "first row" "another value"]
.t insert end [list "another row" "bla bla"]

.t cellconfigure end,0 -window createLabel

bind .t <<TablelistSelect>> [list updateLabelBg %W]


For brevity, the script uses the "in" operator, which requires Tcl 8.5
or higher. It is, however, easy to change it to work for arbitrary Tcl
versions.

Notice that, although this is a fairly general solution (working for any
-selectmode value), it assumes that the tablelist widget has a constant
background color and that the labels displaying the bitmaps are embedded
in the first column. By dropping these assumptions, the script would
become much more complex.

--
Csaba Nemethi http://www.yqcomputer.com/ mailto: XXXX@XXXXX.COM
 
 
 

Tablelist, bitmaps and embedded windows

Post by Kevin Walz » Sun, 07 Jun 2009 09:54:48

Hi Csaba,



<snip>


Thanks! That works beautifully.

--Kevin
--
Kevin Walzer
Code by Kevin
http://www.yqcomputer.com/