[wxPython-users] ColourSelect in XRC

Gre7g Luterman hafeliel at yahoo.com
Tue Sep 4 07:48:47 PDT 2007


--- Robin Dunn <robin at alldunn.com> wrote:

> Take a look at PreMaskedComboBox in
> wx/lib/masked/combobox.py. 
> Basically you need to derive a class from
> ColourSelect that has an 
> __init__ that takes only the self parameter.  In
> that __init__ you need 
> to create an uninitialized instance of BitmapButton,
> call PostCreate, 
> and do any other initialization needed (see
> ColourSelect's __init__ for 
> what the intialization steps it is doing.)  If any
> of those steps 
> require an initialized UI object then you need to
> delay them until after 
> the widget is fully created, such as in the first
> EVT_SIZE event.
> 
> Then in your XRC you can create an object of type
> wxBitmapButton with a 
> subclass attribute of
> "package.module.YourClassName".

Thanks, Robin.  For anyone else who needs to do this,
here's that wrapper:

class ColourSelect(colourselect.ColourSelect):
    "This wrapper for ColourSelect is required to
allow use in XRC."
    def __init__(self):
        self.PostCreate(wx.PreBitmapButton())
        self.SetLabel("")

    def Init(self, Callback=None):
        self.Bind(wx.EVT_BUTTON, self.OnClick)
        self.callback = Callback

Buttons were defined as such:

<object class="wxBitmapButton" name="BUTTON_NAME"
subclass="ColorPref.ColourSelect">
  <bitmap />
</object>

Then, after loading the XRC, I just called Init on
each button.

Gre7g

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 




More information about the wxpython-users mailing list