Problems With ColourSelect Box Inside A wxDialog

Robert Amesz reqhye72zux at
Thu Oct 11 21:30:43 CEST 2001

William Wonneberger wrote:
> Ah, a bit too excited in my last posting....
> With the corrected dialog box code in which the ColourSelect controls
> are now being displayed correctly, I do still have the problem in
> which there is a memory leak when the application terminates;
> 17:28:19: There were memory leaks.
> 17:28:19: ----- Memory dump -----
> 17:28:19: wxColour at $1378E58, size 16
> 17:28:19:
> 17:28:19:
> 17:28:19: ----- Memory statistics -----
> 17:28:19: 1 objects of class wxColour, total size 16
> 17:28:19:
> 17:28:19: Number of object items: 1
> 17:28:19: Number of non-object items: 0
> 17:28:19: Total allocated size: 16
> 17:28:19:
> 17:28:19:
> Am I missing something still, or is this something I should post to
> the wxPython bug tracker?

First of all, you're still not instantiating the ColourSelect control 
correctly. It should be:

  ColourSelect(self, -1, [0, 0,110], wxPoint(200, 46), wxSize(55, 20))


  ColourSelect(self, wxPoint(200, 46), [0, 0,110], wxSize(55, 20))   

As it is, you must get some error message.

The second problem is that *both* ColourSelect controls are bound to 
self.colorselect, and that might conceivably cause some trouble with 
keeping wxPython shadow objects properly synchronized with their 
internal wxWindows counterparts.

Having said that, when I try running your dialog code (after fixing the 
ColourSelect instantiation) I get no memory leaks, so the problem might 
be elsewhere. Do you keep any references to those controls anywhere 
except in your dialog-class? 

While I'm at it: there are some minor issues left: for some reason, 
overriding OnOK doesn't work, it obviously isn't being shadowed in 
wxPython. If you're not trying to override that method you'd better not 
use that name, because it might be added in a next version of 
wxPython.[*] As it is, just having buttons with wxID_OK and wxID_CANCEL 
in your dialog is sufficient.

Also, your event handlers will never be called, because the IDs of the 
controls and the EVT_* 'macros' do not match. Personally, I try to 
avoid setting explicit IDs as much as possible, and just use -1 in the 
constructor. When I need that ID when setting up an event handler, I 
use the GetId method.

> Again, thank you very much for your time and help...

You're very welcome.

Robert Amesz
[*] I'm not even sure it's advisable that it could be overridden: that 
would certainly interfere with the calling of validators, unless you're 
very careful[**]. Unfortunately, I've found setting a validator for an 
entire dialog doesn't seem to work. Oh, you can set it allright, but 
only the Clone method ever gets called. I wonder if I should report 
this to Robin Dunn?

[**] In which case you might argue that validators shouldn't be called 
from the OnOK method at all, but perhaps from the EndModal() or Show 
methods, or better still a separate EndDialog method, that being the 
logical counterpart of the InitDialog method.

More information about the Python-list mailing list