[wxPython-users] help with ThumbnailCtrl

Brad Allen brad at allendev.com
Wed Mar 21 12:14:22 PDT 2007



At 7:48 AM +0200 3/21/07, Peter Damoc wrote:
>1. Support for certain kinds of image types is provided either by 
>wx.Image or by PIL so... if it is supported by one of these two... 
>it should be easy to add.

This was accomplished in the legacy code, but the same approach using 
the new ThumbnailCtrl from June 2006 causes Python to crash. If there 
is not a great performance gain from updating the ThumbnailCtrl from 
the 2005 to the 2006 version, then maybe I should not spend the 
development effort to make it work.

Below is what what was done in the legacy code to add support for 
group 4 TIFF encoding. The 2005 
ThumbnailCtrl.ScrolledThumbnail.LoadImages was modified as follows:


------------------------
(this is a method of ScrolledThumbnail)


def LoadImages(self, newfile, imagecount):
     """ Methods That Load Images On ThumbnailCtrl. Used Internally. """

     if not self._isrunning:
         thread.exit()
         return
    
     try:
         pil = Image.open(newfile)
     except IOError:
         # on corrupt/unknown images we see IOError "cannot identify image file"
         wx.MessageBox("An image file could not be viewed.",
                          "Bad Image File ",
              wx.OK|wx.CENTRE|wx.ICON_INFORMATION)
         return
        
     originalsize = pil.size
    
     w, h = common.THUMB_SIZES[0]
     try:
         pil.thumbnail((w, h), Image.ANTIALIAS)
     ## In case the TIFF Image uses Group4 Decoder   
     except IOError:
         wx_img = wx.Image(newfile, wx.BITMAP_TYPE_TIF)
         pil = imageToPil(wx_img)
         pil.thumbnail((w, h), Image.ANTIALIAS)

     img = wx.EmptyImage(pil.size[0], pil.size[1])

     img.SetData(pil.convert("RGB").tostring())
    
     try:
         self._items[imagecount]._threadedimage = img
         self._items[imagecount]._originalsize = originalsize
         self._items[imagecount]._bitmap = img
     except:
         return



--------------------------

The call to imageToPil is a module level function that was added to 
ThumbnailCtrl.py:

import Image #this is part of PIL

def imageToPil(image):
     """ Reads a TIFF image compressed using Group4 Decoder and
     converts it into a PIL Image object"""
    
     pil = Image.new('RGB', (image.GetWidth(), image.GetHeight()))
     pil.fromstring(image.GetData())
     return pil








More information about the wxpython-users mailing list