Code without effect (wx demo TreeCtrl.py ImageList)
steve at holdenweb.com
Mon Dec 20 19:03:06 CET 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, isz)
> fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART...
> --> 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
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
More information about the Python-list