473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Code without effect (wx demo TreeCtrl.py ImageList)

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.
Jul 18 '05 #1
2 2318
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
Jul 18 '05 #2
"Martin Drautzburg" <ma***************@web.de> wrote in message
news:87************@web.de...
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
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matt | last post by:
Is there a way to execute server code without doing a complete page refresh in .Net? I have an ASP page to convert that uses XMLHTTP and I'm wondering if I should continue to use it in ASPX or do...
1
by: Fred W | last post by:
I have 2 dependent dropdowns and would like to populate the contents of the child dropdown dynamically based on the selected item of the parent. Pretty standard requirement. However, can this...
3
by: Marcel Brekelmans | last post by:
Hi, I was wondering if it's possible to install/uninstall a service from code without using the InstalUtil.exe tool with the /i and /u flags. As far as I can Google everyone is doing it that...
9
by: srinivask | last post by:
hai just tell that how can i protect the java script code without seeing view source it should not the code. i want function to perform
0
by: Zytan | last post by:
With exception to turning auto-format off, in VB .NET, is it possible to paste copied text (say from an online help source) into the code, that spans multiple lines, into the VB .NET code without...
15
by: mistral | last post by:
I want find code for clickable thumbnails, when click on small picture, a big image will popup in new window, sized to fit picture. Same as standard javascript image previewer, but without using...
4
by: Dr J R Stockton | last post by:
<URL:http://www.merlyn.demon.co.uk/js-index.htm>, and js-dates.htm, and some Easter pages, now include <BODY onload="Cuffs()">. function Cuffs() { var ThisPage, ThisSite, J, DLJ, HREF ThisPage =...
2
by: _DD | last post by:
Is there any practical way to protect .NET demo programs from being reverse-engineered? This will be for a one-shot thing, and I'm far from making any money on this, so I'd prefer an economical...
1
by: pbd22 | last post by:
Hi. I have been asked to do a rather odd thing by my employer. I have to add a new feature to an old project that "should not know about the change". This is a bit of an odd request but just assume...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.