Problems With ColourSelect Box Inside A wxDialog

William Wonneberger wberger at ccil.org
Fri Oct 12 07:53:48 EDT 2001


Hi, Robert;

Again, thank you very much for your time and help.  I really
appreciate it.

>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))
>
>*not*
>
>  ColourSelect(self, wxPoint(200, 46), [0, 0,110], wxSize(55, 20))   
>

The second instantiation does work, as I'm using the updated
ColourSelect control posted by Lorne White.  For the updated
colourselect.py, which also fixes some problems with callbacks, take a
look at
http://www.telusplanet.net/public/lwhite1/pymodules/lib/colourselect.py
(The constructor for this one was different compared to the one with
the build for wxPython 2.3.1 for Python 2.1).  I have since updated to
get the latest version of colourselect.py which included a fix for the
memory leaks as posted by Robin Dunn
(http://cvs.wxwindows.org/cgi-bin/viewcvs.cgi/wxPython/wxPython/lib/colourselect.py#rev1.8).
As you rightfully pointed out, going back to the CVS version with the
fixes for the memory leaks did require the change to the
ColourSelect() constructor as you described.  (A question on the side,
and this may be one for Lorne White, how and or why was there a
difference between the two constructors?  Obviously, this is not as
important, since what I have now with the updated ColourSelect Python
module works).

>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.
>

Thanks for pointing this out.  I left them the same just to make sure
I could get the dialog to come up and display correctly.  I have since
changed them to have different attribute names.

>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? 
>

No, all of the controls in the dialog are solely within the dialog
class.   And again, I'm using the updated colourselect.py module that
Robin posted earlier.

>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.
>

Thanks for pointing this out.  The OnOK event handler has been
removed.

So, to follow-up, here's where I'm at;

The dialog works and the ColourSelect controls now work and display
correctly.

Using the updated colourselect.py module as posted in the CVS tree by
Robin fixes the memory leak.  The source for my updated dialog box is
now as follows;

class wxPlotterSettingsDialog(wxDialog):
    def __init__(self, parent):        
        wxDialog.__init__(self, parent, -1, "wxPlotter Settings",
                          wxDefaultPosition, wxSize(350, 200))
        self.static = wxStaticText(self, -1, "Number of points to
draw: ",
                                   wxPoint(70, 22))
        self.linesSpin = wxSpinCtrl(self, 20, "", wxPoint(200, 20),
                                    wxSize(55, 20))
        self.linesSpin.SetRange(1, 360)
        self.linesSpin.SetValue(parent.lineCount)
        self.static = wxStaticText(self, -1, "Line Color: ",
wxPoint(70, 50))
        self.linecolorselect = ColourSelect(self, -1,
parent.lineColor,
                                            wxPoint(200, 46),
wxSize(55, 20))
        self.static = wxStaticText(self, -1, "Background Color: ",
                                   wxPoint(70, 75))
        self.backgroundcolorselect = ColourSelect(self, -1,
parent.backgroundColor,
                                                  wxPoint(200, 73),
wxSize(55, 20))        
        self.static = wxStaticText(self, -1, "Line Ending: ",
                                   wxPoint(70, 102))
        self.lineEnding1 = wxRadioButton(self, 25, "Rectangle", (140,
100))
        self.lineEnding2 = wxRadioButton(self, 26, "Circle", (215,
100))
        self.lineEnding3 = wxRadioButton(self, 27, "None", (270, 100))
        self.button = wxButton(self, wxID_OK, " OK ",
                               wxPoint(95, 140),
wxDefaultSize).SetDefault()
        self.button = wxButton(self, wxID_CANCEL, " Cancel ",
                               wxPoint(175, 140), wxDefaultSize)
        
    def GetLines(self):
        return self.linesSpin.GetValue()

    def GetLineColor(self):
        return self.linecolorselect.GetColour()

    def GetBackgroundColor(self):
        return self.backgroundcolorselect.GetColour()

    def GetLineEnding(self):
        print "lineEnding1 = ", self.lineEnding1.GetValue()
        print "lineEnding2 = ", self.lineEnding2.GetValue()
        print "lineEnding3 = ", self.lineEnding3.GetValue()
        return 0

Again, thank you very, very much for your time, help, and patience,
and also to Lorne and Robin for their help as well.

Best Regards...

Bill Wonneberger
wberger at ccil.org




More information about the Python-list mailing list