[wxPython-users] pywxrc generates wrong python code.

Robin Dunn robin at alldunn.com
Tue May 1 09:59:07 PDT 2007


甜瓜 wrote:
> In wxPython v2.8.3:
> I use xrcedit to create a main menu, and then use pywxrc script to
> generate .py code. As below for menu part:
> ========
> class xrcMAINMENU(wx.MenuBar):
>    def PreCreate(self, pre):
>        """ This function is called during the class's initialization.
> 
>        Override it for custom setup before the window is created usually to
>        set additional window styles using SetWindowStyle() and
> SetExtraStyle()."""
>        pass
> 
>    def __init__(self, parent):
>        # Two stage creation (see
> http://wiki.wxpython.org/index.cgi/TwoStageCreation)
>        pre = wx.PreMenuBar()   #!!!!!!ERROR!!!!!
>        self.PreCreate(pre)
>        get_resources().LoadOnMenuBar(pre, parent, "MAINMENU")
>        self.PostCreate(pre)
> 
>        # Define variables for the controls
>        self.IDM_CONNECT = self.FindItemById(xrc.XRCID("IDM_CONNECT"))
> ========
> But wx module does not have a function named PreMenuBar(). What should
> I do? Is this a bug?

Yes it's a bug.  I expect that pywxrc should probably not generate a 
subclass for menubars like this at all, because there is no need for it 
as there is for container windows.  Instead it should probably just 
generate a function something like this:


def xrcMAINMENU():
	return get_resources().LoadMenuBar("MAINMENU")


and similar for wx.Menus too.  A patch implementing this change would be 
gladly accepted.

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





More information about the wxpython-users mailing list