Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Code without effect (wx demo TreeCtrl.py ImageList)

Reply
Thread Tools

Code without effect (wx demo TreeCtrl.py ImageList)

 
 
Martin Drautzburg
Guest
Posts: n/a
 
      12-20-2004
In the wx demoy TreeCtrl.py I find the following code, that should
have no effect but seems to be needed nevertheless.

class TestTreeCtrlPanel(wx.Panel):
def __init__(self, parent, log):
[...}
self.tree = MyTreeCtrl(self, tID, wx.DefaultPosition, ...
isz = (16,16)
il = wx.ImageList(isz[0], isz[1])
fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART...
[...]

self.tree.SetImageList(il)
--> self.il = il

What is the effect of the last statement? self.il is not used
anywhere. I used similar code in my application and it crashes unless
I assign the image list to the parent panel. The name of the attribute
does not seem to matter. I can write self.foo=il just as well, but
without it it crashes.
 
Reply With Quote
 
 
 
 
Steve Holden
Guest
Posts: n/a
 
      12-20-2004
Martin Drautzburg wrote:

> In the wx demoy TreeCtrl.py I find the following code, that should
> have no effect but seems to be needed nevertheless.
>
> class TestTreeCtrlPanel(wx.Panel):
> def __init__(self, parent, log):
> [...}
> self.tree = MyTreeCtrl(self, tID, wx.DefaultPosition, ...
> isz = (16,16)
> il = wx.ImageList(isz[0], isz[1])
> fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART...
> [...]
>
> self.tree.SetImageList(il)
> --> self.il = il
>
> What is the effect of the last statement? self.il is not used
> anywhere. I used similar code in my application and it crashes unless
> I assign the image list to the parent panel. The name of the attribute
> does not seem to matter. I can write self.foo=il just as well, but
> without it it crashes.


You will probably find that without that reference to the image list it
will be garbage-collected while the images are still beign displayed,
leading to results that are at best unpredictable and at worst fatal to
your program.

regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
 
Reply With Quote
 
 
 
 
Paul McGuire
Guest
Posts: n/a
 
      12-20-2004
"Martin Drautzburg" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In the wx demoy TreeCtrl.py I find the following code, that should
> have no effect but seems to be needed nevertheless.
>
> class TestTreeCtrlPanel(wx.Panel):
> def __init__(self, parent, log):
> [...}
> self.tree = MyTreeCtrl(self, tID, wx.DefaultPosition, ...
> isz = (16,16)
> il = wx.ImageList(isz[0], isz[1])
> fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART...
> [...]
>
> self.tree.SetImageList(il)
> --> self.il = il
>
> What is the effect of the last statement? self.il is not used
> anywhere. I used similar code in my application and it crashes unless
> I assign the image list to the parent panel. The name of the attribute
> does not seem to matter. I can write self.foo=il just as well, but
> without it it crashes.


Two possibilities come to mind:
- used by a base class wx.Panel for which you do not have the source
(although if this were the case, I would think the attribute name would be
significant)
- needed to retain a reference handle to the image list, to prevent it from
being garbage collected (kind of far-fetched, but consistent with the "name
it anything you want" behavior)

-- Paul


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding proper functionality to code.Please read comments in code andfirst test it in your browser to see the effect. Mclaren Fan Javascript 2 11-08-2011 05:50 PM
platform-specific overrides of functions and class methods (expandingon imputils demo code) lkcl Python 6 09-14-2009 11:51 PM
Code Effect Daniel Antonson C Programming 24 07-05-2005 05:10 PM
wxPython demo /Process does not open new demo Andy Leszczynski Python 1 02-18-2005 06:03 PM
PyOpenGL demo in wxPython demo crashes F. GEIGER Python 9 05-03-2004 04:43 PM



Advertisments