Hello

I am having difficulties displaying a list of images (thumbnails) and
then interacting with them. I have attached the program I am using along
with the thumbnail.

I have googled this problem every way that I can think of and have not
found a solution yet. I do not think that I am ending up with a dangling
reference as suggested in previous threads because all of the
information is allocated in the "main".

I generated the program with wxglade. I did this because I have much
larger application already using lists and trees and image windows and
all kinds of GUI stuff generated with wxglade.

I then added my custom stuff to run as long as it is the "main". Nothing
exciting in any of it. I did try making a ListItem and setting the Image
and then dropping that into the list control as well, but then I just
get text.

So, I am all out of ideas and googling so I thought I would try this
list. Any and all help is very much appreciated.

imageListTest.py (1.34 KB)

myself.png

···

--
Al Niessner

I have never found the companion that was so companionable as solitude.
- From Walden by Henry David Thoreau

The universe is indifferent, and life is brutal; however, it is man's
choice of behavior that makes them malevolent rather than benevolent.

Some will fall in love with life and drink it from a fountain
That is pouring like an avalanche coming down the mountain.
- From the song Pepper by the Butthole Surfers

Al Niessner wrote:

I am having difficulties displaying a list of images (thumbnails) and
then interacting with them. I have attached the program I am using along
with the thumbnail.

I have googled this problem every way that I can think of and have not
found a solution yet. I do not think that I am ending up with a dangling
reference as suggested in previous threads because all of the
information is allocated in the "main".

I generated the program with wxglade. I did this because I have much
larger application already using lists and trees and image windows and
all kinds of GUI stuff generated with wxglade.

I then added my custom stuff to run as long as it is the "main". Nothing
exciting in any of it. I did try making a ListItem and setting the Image
and then dropping that into the list control as well, but then I just
get text.

So, I am all out of ideas and googling so I thought I would try this
list. Any and all help is very much appreciated.

You either need to save a reference to the image list, or use AssignImageList instead of SetImageList so the ListCtrl will take ownership of it. Otherwise the image list will be destroyed when it goes out of scope.

You also need to specify the right size in the image list constructor (120,90, not 120,120)

You've specified the wx.LC_REPORT style for the listctrl, but you've not added any columns.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thank you for your help. I have been playing with the lists all day
yesterday and finally started to get something to work (started with
text). Basically I got rid of LC_REPORT and went to LC_LIST, but all of
my icons stack up in the upper left corner and do not react to mouse
events (text works just fine). I will return to LC_REPORT and add some
columns and see if that works better.

Is ImageList really that sensitive to the constructed size image? In my
real application I have icons that are 120x90 as well as 90x120 so I
went with 120x120 just to cover the full range.

I think that I have all of my scoping right. The ImageList that I create
in my application is held by the class that acts as intermediate between
my data, my view, and my controls. The list changes depending on other
events so I am reluctant to give ownership to the list control. In the
sample I sent, the ImageList is created in the global scope and should
not vanish until the program is exited. So in both cases I think the
scoping is good.

···

On Mon, 2007-10-01 at 12:58 -0700, Robin Dunn wrote:

Al Niessner wrote:
> I am having difficulties displaying a list of images (thumbnails) and
>
then interacting with them. I have attached the program I am using along
> with the thumbnail.
>
> I have googled this problem every way that I can think of and have not
> found a solution yet. I do not think that I am ending up with a dangling
> reference as suggested in previous threads because all of the
> information is allocated in the "main".
>
> I generated the program with wxglade. I did this because I have much
> larger application already using lists and trees and image windows and
> all kinds of GUI stuff generated with wxglade.
>
> I then added my custom stuff to run as long as it is the "main". Nothing
> exciting in any of it. I did try making a ListItem and setting the Image
> and then dropping that into the list control as well, but then I just
> get text.
>
> So, I am all out of ideas and googling so I thought I would try this
> list. Any and all help is very much appreciated.

You either need to save a reference to the image list, or use
AssignImageList instead of SetImageList so the ListCtrl will take
ownership of it. Otherwise the image list will be destroyed when it
goes out of scope.

You also need to specify the right size in the image list constructor
(120,90, not 120,120)

You've specified the wx.LC_REPORT style for the listctrl, but you've not
added any columns.

--
Al Niessner

I have never found the companion that was so companionable as solitude.
- From Walden by Henry David Thoreau

The universe is indifferent, and life is brutal; however, it is man's
choice of behavior that makes them malevolent rather than benevolent.

Some will fall in love with life and drink it from a fountain
That is pouring like an avalanche coming down the mountain.
- From the song Pepper by the Butthole Surfers

Al Niessner wrote:

Is ImageList really that sensitive to the constructed size image? In my
real application I have icons that are 120x90 as well as 90x120 so I
went with 120x120 just to cover the full range.

Yes all the bitmaps are supposed to be the same size. To do what you want you'll need to dynamically create a new bitmap that is 120x120 and draw the real bitmap inside of it.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Well I got it working finally.

for pic in pics:
    input = StringIO.StringIO(pic.getThumb())
    index = self._thumbList.Add (wx.BitmapFromImage (self._pilToImg
(Image.open (input))))
    self.Thumbs.InsertImageItem (index, index)

where
self.Thumbs = wx.ListCtrl(self.window_2_pane_1, -1, style=wx.LC_ICON|
wx.LC_NO_HEADER|wx.SUNKEN_BORDER)
self._thumbList = wx.ImageList(120, 120)
self.Thumbs.SetImageList (self._thumbList, wx.IMAGE_LIST_NORMAL)

It was the creation of Thumbs that I simply had to get right. After I
did, it all worked well.

Some of the thumbs are 120x90 or 120x90, but I use
thumb = Image.open (filename)
thumb.thumbnail ((120,120), Image.BICUBIC)

I am not sure why the thumbs come out different sizes, but it may be a
transparent part or something.

Anyway, thanks for all your help Robin and I am hoping that the history
of this will help others in the future.

···

On Tue, 2007-10-02 at 12:41 -0700, Robin Dunn wrote:

Al Niessner wrote:

>
> Is ImageList really that sensitive to the constructed size image? In my
> real application I have icons that are 120x90 as well as 90x120 so I
> went with 120x120 just to cover the full range.

Yes all the bitmaps are supposed to be the same size. To do what you
want you'll need to dynamically create a new bitmap that is 120x120 and
draw the real bitmap inside of it.

--
Al Niessner

I have never found the companion that was so companionable as solitude.
- From Walden by Henry David Thoreau

The universe is indifferent, and life is brutal; however, it is man's
choice of behavior that makes them malevolent rather than benevolent.

Some will fall in love with life and drink it from a fountain
That is pouring like an avalanche coming down the mountain.
- From the song Pepper by the Butthole Surfers

Al,

I am working on a similar problem. Would you be willing to send me
the final, working code that puts thumbnails in a list control (and/or
anything else you came up with for working with or creating
thumbnails)?

Thanks,

Ryan

···

On Oct 2, 2007 5:23 PM, Al Niessner <Al.Niessner@gmx.net> wrote:

Well I got it working finally.

for pic in pics:
    input = StringIO.StringIO(pic.getThumb())
    index = self._thumbList.Add (wx.BitmapFromImage (self._pilToImg
(Image.open (input))))
    self.Thumbs.InsertImageItem (index, index)

where
self.Thumbs = wx.ListCtrl(self.window_2_pane_1, -1, style=wx.LC_ICON|
wx.LC_NO_HEADER|wx.SUNKEN_BORDER)
self._thumbList = wx.ImageList(120, 120)
self.Thumbs.SetImageList (self._thumbList, wx.IMAGE_LIST_NORMAL)

It was the creation of Thumbs that I simply had to get right. After I
did, it all worked well.

Some of the thumbs are 120x90 or 120x90, but I use
thumb = Image.open (filename)
thumb.thumbnail ((120,120), Image.BICUBIC)

I am not sure why the thumbs come out different sizes, but it may be a
transparent part or something.

Anyway, thanks for all your help Robin and I am hoping that the history
of this will help others in the future.

On Tue, 2007-10-02 at 12:41 -0700, Robin Dunn wrote:
> Al Niessner wrote:
>
> >
> > Is ImageList really that sensitive to the constructed size image? In my
> > real application I have icons that are 120x90 as well as 90x120 so I
> > went with 120x120 just to cover the full range.
>
> Yes all the bitmaps are supposed to be the same size. To do what you
> want you'll need to dynamically create a new bitmap that is 120x120 and
> draw the real bitmap inside of it.
>
>
--
Al Niessner

I have never found the companion that was so companionable as solitude.
- From Walden by Henry David Thoreau

The universe is indifferent, and life is brutal; however, it is man's
choice of behavior that makes them malevolent rather than benevolent.

Some will fall in love with life and drink it from a fountain
That is pouring like an avalanche coming down the mountain.
- From the song Pepper by the Butthole Surfers

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

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