ImageList and ListCtrl - Dynamic updating?

So, I am starting to really like what I have. I have a dir control
and when I choose a new directory, new thumbnails are dynamically
created and added to the ListCtrl. The only problem is that for a
directory with 50-100 images, it takes 5-15 seconds to generate the
thumbnails and the application appears to just sit there. It would be
awesome if the ListCtrl's display was periodically updated so I could
look at the first few images while it creates the rest. But I don't
know how to do that. Here are the methods for creating a thumbnail
and filling the ListCtrl:

    def OnThumbDirChange(self, event):
        print('OnThumbDirChange event')
        mypath = self.thumbdirctrl.GetPath()
        print('mypath='+mypath)
        pat1 = os.path.join(mypath,'*.jpg')
        pat2 = os.path.join(mypath, '*.JPG')
        myfiles = glob.glob(pat1)
        myfiles2 = glob.glob(pat2)
        myfiles3 = [item for item in myfiles2 if item not in myfiles]
        allfiles = myfiles+myfiles3

        if allfiles:
            self.list.ClearAll()
            il = wx.ImageList(267, 200)
            self.list.AssignImageList(il, wx.IMAGE_LIST_NORMAL)
            for n, curfile in enumerate(allfiles):
                img = self.CreateOneThumb(curfile)
                il.Add(img)
                self.list.InsertImageItem(n, n)

    def CreateOneThumb(self, pathin):
        pilImage = Image.open(pathin)
        size = (tw, th)
        pilImage.thumbnail(size)#, Image.ANTIALIAS)
        image = wx.EmptyImage(pilImage.size[0],pilImage.size[1])
        image.SetData(pilImage.convert("RGB").tostring())
        #image.setAlphaData(pil.convert("RGBA").tostring()[3::4]

        ## use the wx.Image or convert it to wx.Bitmap
        bitmap = wx.BitmapFromImage(image)
        return bitmap

I have never played with threads in wxPython and don't know if there
is an easy way to do what I want. Can someone help me?

Thanks,

Ryan

···

On Feb 10, 2008 9:28 PM, Ryan Krauss <ryanlists@gmail.com> wrote:

So, thanks to Robin, I am making progress. imagelist_icon.py is a
working example, the only problem is that the ListCtrl wraps and seems
to want to scroll horizontally. It would really fit my application
better if it scrolled vertically and was essentially a one column
format. As I understand it, I need to set up my ListCtrl to be in
report mode. imagelist_report.py represents my attempt to do that,
but the thumbnails all end up on top of one another. Here is the
__init__ method:

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.list = wx.ListCtrl(self, -1,
style=wx.LC_ICON|wx.LC_NO_HEADER|wx.SUNKEN_BORDER)

        il = wx.ImageList(267, 200)
        myfiles = glob.glob('IMG*.JPG')
        for n, curfile in enumerate(myfiles):
            img = wx.Image(curfile)
            il.Add(wx.BitmapFromImage(img))
            self.list.InsertImageItem(n, n)

        self.list.AssignImageList(il, wx.IMAGE_LIST_NORMAL)

        self.__set_properties()
        self.__do_layout()

What am I doing wrong?

Thanks,

Ryan

On Feb 8, 2008 4:12 PM, Robin Dunn <robin@alldunn.com> wrote:
>
> Ryan Krauss wrote:
> > I am trying to build on some code submitted to the list a while back.
> > I want to display some thumbnails in a ListCtrl using an ImageList. I
> > can't figure out why the attached code doesn't actually work. I don't
> > get any error messages, but no images are displayed (I just get a
> > white canvas).
>
> You never add any items to your list ctrl.
>
> --
> Robin Dunn
> Software Craftsman
> http://wxPython.org Java give you jitters? Relax with wxPython!
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
>
>

Attached is a screen shot of trying to run the ThumbnailCtrlDemo.py.
As soon as I mouse over the pictures, move the scroll bar or move the
sash, it redraws all the thumbnails correctly.

···

On Feb 11, 2008 3:13 PM, Andrea Gavana <andrea.gavana@gmail.com> wrote:

Hi Ryan,

On Feb 11, 2008 4:28 PM, Ryan Krauss wrote:
> self.SendSizeEvent() did not fix my problem. I will try and create a
> simple example that recreates the problem with ThumbnailCtrl and
> submit it to the list. But it might be few days. This is personal
> programming and I have a grant proposal due at the end of the week.

If you can provide a runnable sample that demonstrates the problem, I
will be more than happy to ty to fix it.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org