ColourSelect in XRC

Gre7g Luterman wrote:

What's the simplest way to put a ColourSelect object
into a dialog that I've created with an XRC file?

If I understand correctly, XRC wants to use two-part
construction instead of one-part construction, and
since ColourSelect was created with one-part
construction, it is unclear to me how to bridge the
gap.

Any suggestions?

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

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

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

···

--- Robin Dunn <robin@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".

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around