Including wx.lib.platebtn in an XRC file?

199 Views Asked by At

do you know of a way to include the wx.lib.platebtn.PlateButton widget in an xrc file?

So far, I have only found a way of including widgets that are common to wxWidgets, too, but I think this one is specific to wxpython (I may be wrong, though).

I tried to understand the demo for the XmlResourceHandler, but that is only done for Panels. I couldn't find good tutorials with this specific case either, yet.

I would be grateful for any advice you guys can offer, or a link to a good tutorial.

Thanks a lot.

2

There are 2 best solutions below

1
On

As I recall, there's a way to define your own widgets in XRC, but I can't quite remember where I read about that. Maybe check out the references at the end of the following article: http://www.blog.pythonlibrary.org/2010/10/28/wxpython-an-xrced-tutorial/

I do know that you can use the XRC editor that comes with wxPython's demo to add an "unknown" control. You may be able to do it that way. See http://wiki.wxpython.org/UsingXmlResources#AttachUnknownControl_and_Control_Size or Robin Dunn's answer here: https://groups.google.com/forum/?fromgroups#!topic/wxPython-users/4VAXC7WldFo

0
On

Ok, folks,

I will answer my own question for completion's sake. Afaik, it is not possible to add a platebutton to the XRC file, but as Mike Driscoll suggested (thanks a bundle, man!), it is possible to insert an "unknown" variable, a placeholder if you want, into the XRC file at the place you want. like shown just below:

<object class="unknown" name="A_Name">
    <variables></variables>
</object>

Afterwards, I went into my code example and entered code, not unlike the one below (obviously made general for your viewing pleasure). It seems to work so far, but I was not able to change any settings made to self.MyBtn and only the flags seemed to have any effect, but that could also be something specific to my sizer settings. If you don't think that is the case, feel free to let me know. I'm always interested in better, more efficient or more elegant solutions.

class MyFrame(wx.Frame):
    def __init__(self, parent):
        self.res = xrc.XmlResource("my_xrc_file.xrc")
        self.frame = self.res.LoadFrame("MyFrame")

        imageFile = "/a/path/to/your/file"
        png = wx.Image(imageFile, wx.BITMAP_TYPE_ANY).ConvertToBitmap()

        self.MyBtn = wx.lib.platebtn.PlateButton(self.frame, bmp=png,
                style=platebtn.PB_STYLE_TOGGLE|platebtn.PB_STYLE_DEFAULT)
        self.PlateBtn = self.res.AttachUnknownControl("MyBtn",
                                        self.MyBtn, self.frame) # this returns a bool

I hope it helps some of you.