Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tablelist cellconfigure displays wrong image

6 views
Skip to first unread message

Kevin Walzer

unread,
Sep 17, 2006, 11:52:40 AM9/17/06
to
I am having problems getting tablelist 4.5 to correctly display images
in a cell when displaying the contents of a directory. My code fetches
the image based on a list of pre-defined images corresponding to file
extension; if a file extension is not found, the image reverts to a
default image.

The problem is that the *first* image displayed always seems to be the
default image. It's as if tablelist can't determine the correct image
type on the first image. Subsequent images are displayed correctly.

My code below uses a directory/folder image as the default, so the
initial displayed image is always a folder--even if it's a file. But the
kind of image doesn't really matter--in other versions of this code, the
default was a generic "document" image, which would display even if the
first file listed was an .html or .pdf file (which I do have correct
images for).

I don't know if this is a bug in tablelist or an issue with how I'm
laying out my code. Any advice is appreciated.

Here's the code to get my image:

proc getImage {filename} {


if {[file isfile $filename] } {

if {[lsearch [image names] [file extension $filename] ]<=0} {
set listphoto "file-generic"
} else {
set listphoto [file extension $filename]
}

} else {
set listphoto folder

}
}


Here's the code to display the directory contents (based on glob
-directory . -nocomplain):

$w.right.list insert end [list $name $type $owner $size $date]
$w.right.list columnconfigure 3 -align right
$w.right.list columnconfigure 4 -align right

# $w.right.list columnconfigure [list 0 1 2 3 4] -align right

foreach col {0 end} {



$w.right.list cellconfigure $col,0 -image [fileicons::getImage $item]
#puts $cellimage
}
}


--
Kevin Walzer
Poetic Code
http://www.kevin-walzer.com

Csaba Nemethi

unread,
Sep 17, 2006, 4:32:14 PM9/17/06
to
Kevin Walzer schrieb:

Take a closer look at the lines

if {[lsearch [image names] [file extension $filename] ]<=0} {
set listphoto "file-generic"

According to this code snippet, listphoto will be set to "file-generic"
not only if [file extension $filename] is not among the elements of
[image names], but also if it is the first element of that list. I
suspect that this was not your intention; to get it right, replace the
"<=0" with "<0".

--
Csaba Nemethi http://www.nemethi.de mailto:csaba....@t-online.de

Jeff Hobbs

unread,
Sep 18, 2006, 12:19:12 AM9/18/06
to
Csaba Nemethi wrote:
> Take a closer look at the lines
>
> if {[lsearch [image names] [file extension $filename] ]<=0} {
> set listphoto "file-generic"
>
> According to this code snippet, listphoto will be set to "file-generic"
> not only if [file extension $filename] is not among the elements of
> [image names], but also if it is the first element of that list. I
> suspect that this was not your intention; to get it right, replace the
> "<=0" with "<0".

And it is cases like this that caused 8.5 to have an 'in' expr operator.
In 8.5, you would write:

if {[file extension $filename] ni [image names]} { ...

(of course, the user code required negation).

--

Jeff Hobbs, The Tcl Guy, http://www.activestate.com/

0 new messages