I'm using an XRC file to define my controls and layout. In that file I
have some wx.BitmapButton 's defined that I'd like to turn into
GenBitmapToggleButton 's. I'm assuming the best way to do that is to
subclass them, which I did with "toggle_button.ToggleButton;" How do
I transform those bitmap-buttons into toggle-bitmap buttons?
This is what I have so far (which of course does nothing):
# toggle_button.py
···
#-----------------------
import wx
import wx.lib.buttons as lb
class ToggleButton(wx.BitmapButton):
def __init__(self):
pre = wx.PreBitmapButton()
# the Create step is done later by XRC.
self.PostCreate(pre)
self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)
def OnCreate(self, event):
self.Unbind(wx.EVT_WINDOW_CREATE)
# Do all extra initialization here
I'm using an XRC file to define my controls and layout. In that file I
have some wx.BitmapButton 's defined that I'd like to turn into
GenBitmapToggleButton 's. I'm assuming the best way to do that is to
subclass them, which I did with "toggle_button.ToggleButton;" How do
I transform those bitmap-buttons into toggle-bitmap buttons?
This is what I have so far (which of course does nothing):
# toggle_button.py #-----------------------
import wx
import wx.lib.buttons as lb
class ToggleButton(wx.BitmapButton):
def __init__(self):
pre = wx.PreBitmapButton()
# the Create step is done later by XRC.
self.PostCreate(pre)
self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)
def OnCreate(self, event):
self.Unbind(wx.EVT_WINDOW_CREATE)
# Do all extra initialization here
You can't. GenBitmapToggleButton does not derive from wx.BitmapButton. Their common parent in the class hierarchy is wx.Control, so if you were to take a wx.BitmapButton object and fool Python into treating it like a GenBitmapToggleButton I expect you'll just end up shooting yourself in the foot.
OTOH, you can make an XmlResouceHandler that knows how to construct a class you create that is derived from GenBitmapToggleButton, and then use that class type directly in the XRC without needing the subclass attribute. See the demo for an example of doing it with a custom panel class.