making an XRC bitmapbutton custom derived class

I am trying to make my own bitmapbutton XRC class. I am using the
standard genbitmapbutton as my basis with the toggle mixin.

Now I am running into something strange. When I look at the images for
label, selected etc in the init, they are all not OK (IsOK() returns
False). However when the OnCreate code is run, the bitmap for the label
is OK but the rest is not.

So what happens between these two moments in time and what do I need to
do to make the other bitmaps OK as well?

Paul

A bit of code might be handy too, see below the text:

Paul Sijben wrote:

I am trying to make my own bitmapbutton XRC class. I am using the
standard genbitmapbutton as my basis with the toggle mixin.

Now I am running into something strange. When I look at the images for
label, selected etc in the init, they are all not OK (IsOK() returns
False). However when the OnCreate code is run, the bitmap for the label
is OK but the rest is not.

So what happens between these two moments in time and what do I need to
do to make the other bitmaps OK as well?

Paul
  
class ToggleGenBitmapButton(wlbuttons.__ToggleMixin,TransGenBitmapButton):
    def __init__(self):
        pre=wx.PreBitmapButton()
        self.labelDelta=0
        self._transparent=0
        self.up = True
        self.hasFocus = False
        self.style= wx.BORDER_NONE| wx. wx.TRANSPARENT
        self.bezelWidth = 0
        self.useFocusInd = False

        self.__pre=pre

        self.PostCreate(pre)
        self.Bind( wx.EVT_WINDOW_CREATE , self.OnCreate)

    def OnCreate(self,evt):
        #print "OnCreate"
        self.Unbind ( wx.EVT_WINDOW_CREATE )
        self.InheritAttributes()
        self.InitColours()

        self.SetBitmapSelected(self.__pre.BitmapSelected)

        #here self.__pre.BitmapSelected.IsOk()==False

        self.SetBitmapFocus(self.__pre.BitmapFocus)
        self.SetBitmapLabel(self.__pre.BitmapLabel)

        #here self.__pre.BitmapLabel.IsOk()==True !?!?!

        self.SetBitmapDisabled(self.__pre.BitmapDisabled)

where:
import wx.lib.buttons as wlbuttons
class TransGenBitmapButton(wlbuttons.GenBitmapButton):
#and then TransGenBitmapButton has some features to make it transparent
on winXP

···

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
  
--
Paul Sijben tel: +31334566488
Eemvalley Technology fax: +31334557523
the Netherlands http://eemvalley.com

Paul Sijben wrote:

A bit of code might be handy too, see below the text:

Paul Sijben wrote:

I am trying to make my own bitmapbutton XRC class. I am using the
standard genbitmapbutton as my basis with the toggle mixin.

Now I am running into something strange. When I look at the images for
label, selected etc in the init, they are all not OK (IsOK() returns
False). However when the OnCreate code is run, the bitmap for the label
is OK but the rest is not.

So what happens between these two moments in time and what do I need to
do to make the other bitmaps OK as well?

Paul
  
class ToggleGenBitmapButton(wlbuttons.__ToggleMixin,TransGenBitmapButton):
    def __init__(self):
        pre=wx.PreBitmapButton()

It's not going to work like this. You are creating a wx.BitmapButton here, but tring to mix it with the generic button classes, which are mostly unrelated and which expect to be used on a class that is derived from wx.PyControl.

Instead make your button class normally by deriving from the wx.lib.buttons classes and implementing your additional features however you need it. Then once that is working you can worry about how to load it from XRC. I suggest making a XmlResourceHandler that knows how to load the required attributes from the XRC object, and then create the button using your class. See the demo for an example of an XmlResourceHandler. If you are using XRCed to edit your XRC file then there is a way to make it aware of your handler class with a bit of plugin code.

···

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