I'm trying to implement a thumbnail browser and I run into some problems:
Section A: Real problems:
A1. the selection algorithm seams to be wrong (maybe is my mistake), if I do a lclick followed by a shift+lclick it selects every item in a rectangle between my clicks, now this might be what people want for a drag selection but in my case the selection should be between the item where the first click occured and the item under the second click.
A2. in the file I attached, at lines 34-35 there is a little hack I had to do to be able to add an image to the image list, if I try to add the image directly it throws an error, an internaly caught error, no traceback only a dialog informing me that I cannot add the image. If you wanna test the thing replace lines 34-35 with
self.il.Add(fileToThumb(fullpath, self.tsize))
A3. If I run the script in a folder with lots of big images it takes forever to load...
now I suspected this behavior, is not a surprise and I'm wondering what is the best approach to the problem? The only thing I could think of (and probably try to implement later) is to fill the ImageList with EmptyImages, start a new thread, and replace the empty images with the thumbnails in that thread.
A4. If tried to use the new Bind mechanism for event handling and cut myself on the cutting-edge of 2.5, :D. Is there a way to use Bind and remain compatible with 2.4?
Section B: not so much problems as annoyances:
B1. Why does ListCtrl lacks a GetSelection/SetSelection combo ? sure we have the code in lib.mixins.listctrl for getSelection BUT why isn't it part of ListCtrl?
B2. Why does it have to be a index of an ImageList the only way the virtual list can get the info about the image, why can it be raw image data? maybe an OnGetItemImageData method... this approach combined with a cache mechanism could solve at least my problem 
P.S. in order to test the attached script place it in a directory containing some jpgs or pngs and run it
tb.py (3.29 KB)
···
--
Peter Damoc
Hacker Wannabe
A2. in the file I attached, at lines 34-35 there is a little hack I had to do to be able to add an image to the image list, if I try to add the image directly it throws an error, an internaly caught error, no traceback only a dialog informing me that I cannot add the image. If you wanna test the thing replace lines 34-35 with
self.il.Add(fileToThumb(fullpath, self.tsize))
Works either way here for a folder with only 8 items.
But with a large number of items I see the error message
and not all the images are loaded.
Win2K, Python 2.3, wxPython 2.4.2.4.
A3. If I run the script in a folder with lots of big images it takes forever to load...
now I suspected this behavior, is not a surprise and I'm wondering what is the best approach to the problem? The only thing I could think of (and probably try to implement later) is to fill the ImageList with EmptyImages, start a new thread, and replace the empty images with the thumbnails in that thread.
That's what I'd do: Count the files, insert placeholders
with names, and process the images in a thread. Maybe
use a custom event to tell the main thread when each image
is ready.
- Sam
···
__________________________________________________________
Spinward Stars, LLC Samuel Reynolds
Custom Software and Web Development 303-805-1446
http://SpinwardStars.com/ sam@SpinwardStars.com
thanks for your reply Sam, any ideea as to what I can use for a placeholder?
I tried a wx.EmptyImage but is no good
for i in range(len(self.tlist)):
self.il.Add(wx.EmptyImage(self.tsize[0], self.tsize[1]).ConvertToBitmap())
takes 2.344 seconds for a 164 images, I tried to simplify:
img = wx.EmptyImage(self.tsize[0], self.tsize[1]).ConvertToBitmap()
for i in range(len(self.tlist)):
self.il.Add(img)
and got 2.078 seconds
it takes some 7 seconds afterwards to create the thumbnails (took 10 secs with antialias turned on)
Specs: XP, wxPython 2.4, python 2.3.3, pil 1.1.4 on an Athlon 2400+ with 1gb RAM and a 80Gb 7200 RPM SEAGATE
Is there a way to get to a lower level in ListCtrl and supply the image data myself uppon the event that triggers GetItemImage call?
···
On Sat, 14 Feb 2004 08:09:27 -0700, Samuel Reynolds <sam@SpinwardStars.com> wrote:
A3. If I run the script in a folder with lots of big images it takes forever to load...
now I suspected this behavior, is not a surprise and I'm wondering what is the best approach to the problem? The only thing I could think of (and probably try to implement later) is to fill the ImageList with EmptyImages, start a new thread, and replace the empty images with the thumbnails in that thread.
That's what I'd do: Count the files, insert placeholders
with names, and process the images in a thread. Maybe
use a custom event to tell the main thread when each image
is ready.
- Sam
--
Peter Damoc
Hacker Wannabe
Or just of forgetfullness. You already pointed out (and I
confirmed
) that there's a problem with the direct
assignment, at least with any significant number of items.
Duh!
- Sam
···
At 2004-02-15 12:08 PM -0700, I wrote:
I also noticed, in the original script you posted, that
you Add an EmptyImage, then immediately Replace it with
a loaded image. I replaced the double-call with a single
call to Add the loaded image, and the window opened much
more quickly.
[snip]
... hopefully
I haven't revealed a previously unplumbed level of
ignorance. 
__________________________________________________________
Spinward Stars, LLC Samuel Reynolds
Custom Software and Web Development 303-805-1446
http://SpinwardStars.com/ sam@SpinwardStars.com