Fix pywxrc's generation of menu and menubar classes and aldo fix how
it generates attributes for menus, menubars and menuitems comtained in other objects. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@45967 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
		@@ -3,7 +3,7 @@ Recent Changes for wxPython
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
2.8.4.0
 | 
					2.8.4.0
 | 
				
			||||||
-------
 | 
					-------
 | 
				
			||||||
* 
 | 
					* 14-May-2007
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wxGTK: Make wx.NO_BORDER style work with wx.RadioBox (patch 1525406)
 | 
					wxGTK: Make wx.NO_BORDER style work with wx.RadioBox (patch 1525406)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -80,6 +80,9 @@ Updates to MaskedEdit controls from Will Sadkin:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Update to latest FloatCanvas from Chris Barker.
 | 
					Update to latest FloatCanvas from Chris Barker.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The pywxrc tool now properly supports generating classes for menus and
 | 
				
			||||||
 | 
					menubars, and also creating attributes for menus, menubars and menu
 | 
				
			||||||
 | 
					items. 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -70,27 +70,63 @@ class xrc%(windowName)s(wx.%(windowClass)s):
 | 
				
			|||||||
        get_resources().LoadOn%(windowClass)s(pre, parent, "%(windowName)s")
 | 
					        get_resources().LoadOn%(windowClass)s(pre, parent, "%(windowName)s")
 | 
				
			||||||
        self.PostCreate(pre)
 | 
					        self.PostCreate(pre)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Define variables for the controls
 | 
					        # create attributes for the named items in this container
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    CREATE_WIDGET_VAR = """\
 | 
					    CREATE_WIDGET_VAR = """\
 | 
				
			||||||
        self.%(widgetName)s = xrc.XRCCTRL(self, \"%(widgetName)s\")
 | 
					        self.%(widgetName)s = xrc.XRCCTRL(self, \"%(widgetName)s\")
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    FRAME_MENUBAR_VAR = """\
 | 
				
			||||||
 | 
					        self.%(widgetName)s = self.GetMenuBar()
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    FRAME_MENUBAR_MENUITEM_VAR = """\
 | 
				
			||||||
 | 
					        self.%(widgetName)s = self.GetMenuBar().FindItemById(xrc.XRCID(\"%(widgetName)s\"))
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    FRAME_MENUBAR_MENU_VAR = """\
 | 
				
			||||||
 | 
					        idx = self.GetMenuBar().FindMenu(\"%(label)s\")
 | 
				
			||||||
 | 
					        if idx != wx.NOT_FOUND:
 | 
				
			||||||
 | 
					            self.%(widgetName)s = self.GetMenuBar().GetMenu(idx)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            self.%(widgetName)s = self.GetMenuBar().FindItemById(xrc.XRCID(\"%(widgetName)s\")).GetSubMenu()
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    MENUBAR_MENUITEM_VAR = """\
 | 
				
			||||||
 | 
					        self.%(widgetName)s = self.FindItemById(xrc.XRCID(\"%(widgetName)s\"))
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    MENUBAR_MENU_VAR = """\
 | 
				
			||||||
 | 
					        idx = self.FindMenu(\"%(label)s\")
 | 
				
			||||||
 | 
					        if idx != wx.NOT_FOUND:
 | 
				
			||||||
 | 
					            self.%(widgetName)s = self.GetMenu(idx)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            self.%(widgetName)s = self.FindItemById(xrc.XRCID(\"%(widgetName)s\")).GetSubMenu()
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    MENU_MENUITEM_VAR = """\
 | 
				
			||||||
 | 
					        self.%(widgetName)s = self.FindItemById(xrc.XRCID(\"%(widgetName)s\"))
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    MENU_MENU_VAR = """\
 | 
				
			||||||
 | 
					        self.%(widgetName)s = self.FindItemById(xrc.XRCID(\"%(widgetName)s\")).GetSubMenu()
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    MENU_CLASS_HEADER = """\
 | 
					    MENU_CLASS_HEADER = """\
 | 
				
			||||||
class xrc%(windowName)s(wx.%(windowClass)s):
 | 
					class xrc%(windowName)s(wx.%(windowClass)s):
 | 
				
			||||||
    def __init__(self):
 | 
					    def __init__(self):
 | 
				
			||||||
        pre = get_resources().LoadMenu("%(windowName)s")
 | 
					        pre = get_resources().LoadMenu("%(windowName)s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # This is a copy of Robin's PostCreate voodoo magic in wx.Window that
 | 
					        # wx.Menu doesn't have a PostCreate method so duplicate
 | 
				
			||||||
        # relinks the self object with the menu object.
 | 
					        # the important bits of it here.
 | 
				
			||||||
        self.this = pre.this
 | 
					        self.this = pre.this
 | 
				
			||||||
        self.thisown = pre.thisown
 | 
					        self.thisown = pre.thisown
 | 
				
			||||||
        pre.thisown = 0
 | 
					        pre.thisown = 0
 | 
				
			||||||
        if hasattr(self, '_setOORInfo'):
 | 
					 | 
				
			||||||
        self._setOORInfo(self)
 | 
					        self._setOORInfo(self)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Define variables for the menu items
 | 
					        # create attributes for the named menu items
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    MENUBAR_CLASS_HEADER = """\
 | 
					    MENUBAR_CLASS_HEADER = """\
 | 
				
			||||||
@@ -99,7 +135,7 @@ class xrc%(windowName)s(wx.%(windowClass)s):
 | 
				
			|||||||
        pre = get_resources().LoadMenuBar("%(windowName)s")
 | 
					        pre = get_resources().LoadMenuBar("%(windowName)s")
 | 
				
			||||||
        self.PostCreate(pre)
 | 
					        self.PostCreate(pre)
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        # Define variables for the menu items
 | 
					        # create attributes for the named menu items
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    CREATE_MENUITEM_VAR = """\
 | 
					    CREATE_MENUITEM_VAR = """\
 | 
				
			||||||
@@ -235,27 +271,90 @@ class XmlResourceCompiler:
 | 
				
			|||||||
            windowName = topWindow.getAttribute("name")
 | 
					            windowName = topWindow.getAttribute("name")
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            if windowClass in ["MenuBar"]:
 | 
					            if windowClass in ["MenuBar"]:
 | 
				
			||||||
                outputList.append(self.templates.MENUBAR_CLASS_HEADER % locals())
 | 
					                genfunc = self.GenerateMenuBarClass
 | 
				
			||||||
            elif windowClass in ["Menu"]:
 | 
					            elif windowClass in ["Menu"]:
 | 
				
			||||||
                outputList.append(self.templates.MENU_CLASS_HEADER % locals())
 | 
					                genfunc = self.GenerateMenuClass
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                outputList.append(self.templates.CLASS_HEADER % locals())
 | 
					                genfunc = self.GenerateWidgetClass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # Generate a variable for each control, and standard event handlers
 | 
					            outputList += genfunc(windowClass, windowName, topWindow)
 | 
				
			||||||
            # for standard controls.
 | 
					            outputList.append('\n\n')
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					        return "".join(outputList)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def GenerateMenuBarClass(self, windowClass, windowName, topWindow):
 | 
				
			||||||
 | 
					        outputList = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # output the header
 | 
				
			||||||
 | 
					        outputList.append(self.templates.MENUBAR_CLASS_HEADER % locals())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # create an attribute for menus and menu items that have names
 | 
				
			||||||
        for widget in topWindow.getElementsByTagName("object"):
 | 
					        for widget in topWindow.getElementsByTagName("object"):
 | 
				
			||||||
            widgetClass = widget.getAttribute("class")
 | 
					            widgetClass = widget.getAttribute("class")
 | 
				
			||||||
            widgetClass = re.sub("^wx", "", widgetClass)
 | 
					            widgetClass = re.sub("^wx", "", widgetClass)
 | 
				
			||||||
            widgetName = widget.getAttribute("name")
 | 
					            widgetName = widget.getAttribute("name")
 | 
				
			||||||
                if (widgetName != "" and widgetClass != ""):
 | 
					            if widgetName != "" and widgetClass != "":
 | 
				
			||||||
                if widgetClass == "MenuItem":
 | 
					                if widgetClass == "MenuItem":
 | 
				
			||||||
                        outputList.append(self.templates.CREATE_MENUITEM_VAR % locals())
 | 
					                    outputList.append(self.templates.MENUBAR_MENUITEM_VAR % locals())
 | 
				
			||||||
                    elif widgetClass not in \
 | 
					                elif widgetClass == "Menu":
 | 
				
			||||||
                        ['tool', 'unknown', 'notebookpage', 'separator', 'sizeritem']:
 | 
					                    label = widget.getElementsByTagName("label")[0]
 | 
				
			||||||
                        outputList.append(self.templates.CREATE_WIDGET_VAR % locals())
 | 
					                    label = label.childNodes[0].data
 | 
				
			||||||
            outputList.append('\n\n')
 | 
					                    outputList.append(self.templates.MENUBAR_MENU_VAR % locals())
 | 
				
			||||||
 | 
					                else:
 | 
				
			||||||
 | 
					                    raise RuntimeError("Unexpected widgetClass for MenuBar: %s" % widgetClass)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return "".join(outputList)
 | 
					        return outputList
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def GenerateMenuClass(self, windowClass, windowName, topWindow):
 | 
				
			||||||
 | 
					        outputList = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # output the header
 | 
				
			||||||
 | 
					        outputList.append(self.templates.MENU_CLASS_HEADER % locals())
 | 
				
			||||||
 | 
					        for widget in topWindow.getElementsByTagName("object"):
 | 
				
			||||||
 | 
					            widgetClass = widget.getAttribute("class")
 | 
				
			||||||
 | 
					            widgetClass = re.sub("^wx", "", widgetClass)
 | 
				
			||||||
 | 
					            widgetName = widget.getAttribute("name")
 | 
				
			||||||
 | 
					            if widgetName != "" and widgetClass != "":
 | 
				
			||||||
 | 
					                if widgetClass == "MenuItem":
 | 
				
			||||||
 | 
					                    outputList.append(self.templates.MENU_MENUITEM_VAR % locals())
 | 
				
			||||||
 | 
					                elif widgetClass == "Menu":
 | 
				
			||||||
 | 
					                    label = widget.getElementsByTagName("label")[0]
 | 
				
			||||||
 | 
					                    label = label.childNodes[0].data
 | 
				
			||||||
 | 
					                    outputList.append(self.templates.MENU_MENU_VAR % locals())
 | 
				
			||||||
 | 
					                else:
 | 
				
			||||||
 | 
					                    raise RuntimeError("Unexpected widgetClass for Menu: %s" % widgetClass)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return outputList
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def GenerateWidgetClass(self, windowClass, windowName, topWindow):
 | 
				
			||||||
 | 
					        outputList = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # output the header
 | 
				
			||||||
 | 
					        outputList.append(self.templates.CLASS_HEADER % locals())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Generate an attribute for each named item in the container
 | 
				
			||||||
 | 
					        for widget in topWindow.getElementsByTagName("object"):
 | 
				
			||||||
 | 
					            widgetClass = widget.getAttribute("class")
 | 
				
			||||||
 | 
					            widgetClass = re.sub("^wx", "", widgetClass)
 | 
				
			||||||
 | 
					            widgetName = widget.getAttribute("name")
 | 
				
			||||||
 | 
					            if widgetName != "" and widgetClass != "":
 | 
				
			||||||
 | 
					                if widgetClass not in \
 | 
				
			||||||
 | 
					                       ['tool', 'unknown', 'notebookpage', 'separator',
 | 
				
			||||||
 | 
					                        'sizeritem', 'Menu', 'MenuBar', 'MenuItem']:
 | 
				
			||||||
 | 
					                    outputList.append(self.templates.CREATE_WIDGET_VAR % locals())
 | 
				
			||||||
 | 
					                elif widgetClass == "MenuBar":
 | 
				
			||||||
 | 
					                    outputList.append(self.templates.FRAME_MENUBAR_VAR % locals())
 | 
				
			||||||
 | 
					                elif widgetClass == "MenuItem":
 | 
				
			||||||
 | 
					                    outputList.append(self.templates.FRAME_MENUBAR_MENUITEM_VAR % locals())
 | 
				
			||||||
 | 
					                elif widgetClass == "Menu":
 | 
				
			||||||
 | 
					                    label = widget.getElementsByTagName("label")[0]
 | 
				
			||||||
 | 
					                    label = label.childNodes[0].data
 | 
				
			||||||
 | 
					                    outputList.append(self.templates.FRAME_MENUBAR_MENU_VAR % locals())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return outputList
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #-------------------------------------------------------------------
 | 
					    #-------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user