From 984a036d34017d32069842a52aaf7ea7c07cbc9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Piel?= Date: Wed, 22 Aug 2018 13:50:33 +0200 Subject: [PATCH 1/3] pywxrc: remove old comments It's not using the 2 stages creation anymore. --- wx/tools/pywxrc.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/wx/tools/pywxrc.py b/wx/tools/pywxrc.py index 434ba84b..22e0a779 100644 --- a/wx/tools/pywxrc.py +++ b/wx/tools/pywxrc.py @@ -73,7 +73,6 @@ class xrc%(windowName)s(wx.%(windowClass)s): #!XRCED:end-block:xrc%(windowName)s.PreCreate def __init__(self, parent): - # Two stage creation (see http://wiki.wxpython.org/index.cgi/TwoStageCreation) wx.%(windowClass)s.__init__(self) self.PreCreate() get_resources().Load%(windowClass)s(self, parent, "%(windowName)s") @@ -84,7 +83,6 @@ class xrc%(windowName)s(wx.%(windowClass)s): SUBCLASS_HEADER = """\ class %(subclass)s(wx.%(windowClass)s): def __init__(self): - # Two stage creation (see http://wiki.wxpython.org/index.cgi/TwoStageCreation) wx.%(windowClass)s.__init__(self) self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate) From 96ed353b343e7feac18ef423378531ab24a0ecad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Piel?= Date: Wed, 22 Aug 2018 13:51:16 +0200 Subject: [PATCH 2/3] pywxrc: fix Menu with variable name and label defined after sub-menus If the XRC looked like: The generated code would fail, because it would try to look for a main menu called "Save" instead of looking for "File". => Make the XML parsing more clever to not look for the first "label" tag, but the first _direct_ child with tag "label". --- wx/tools/pywxrc.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/wx/tools/pywxrc.py b/wx/tools/pywxrc.py index 22e0a779..a87740ea 100644 --- a/wx/tools/pywxrc.py +++ b/wx/tools/pywxrc.py @@ -396,7 +396,10 @@ class XmlResourceCompiler: if widgetClass == "MenuItem": outputList.append(self.templates.MENUBAR_MENUITEM_VAR % locals()) elif widgetClass == "Menu": - label = widget.getElementsByTagName("label")[0] + for e in widget.childNodes: + if e.nodeType == e.ELEMENT_NODE and e.tagName == "label": + label = e + break label = label.childNodes[0].data outputList.append(self.templates.MENUBAR_MENU_VAR % locals()) else: @@ -420,7 +423,10 @@ class XmlResourceCompiler: if widgetClass == "MenuItem": outputList.append(self.templates.MENU_MENUITEM_VAR % locals()) elif widgetClass == "Menu": - label = widget.getElementsByTagName("label")[0] + for e in widget.childNodes: + if e.nodeType == e.ELEMENT_NODE and e.tagName == "label": + label = e + break label = label.childNodes[0].data outputList.append(self.templates.MENU_MENU_VAR % locals()) else: @@ -465,22 +471,26 @@ class XmlResourceCompiler: widgetName = widget.getAttribute("name") if widgetName != "" and widgetClass != "": vars.append(widgetName) - if widgetClass not in \ - ['tool', 'unknown', 'notebookpage', 'separator', - 'sizeritem', 'Menu', 'MenuBar', 'MenuItem']: - outputList.append(self.templates.CREATE_WIDGET_VAR % locals()) - elif widgetClass == "MenuBar": + if 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] + # Only look directly under for the "label" + for e in widget.childNodes: + if e.nodeType == e.ELEMENT_NODE and e.tagName == "label": + label = e + break label = label.childNodes[0].data outputList.append(self.templates.FRAME_MENUBAR_MENU_VAR % locals()) - elif widgetClass == "ToolBar": - outputList.append(self.templates.FRAME_TOOLBAR_VAR % locals()) +# elif widgetClass == "ToolBar": +# outputList.append(self.templates.FRAME_TOOLBAR_VAR % locals()) elif widgetClass == "tool": outputList.append(self.templates.FRAME_TOOLBAR_TOOL_VAR % locals()) + elif widgetClass in ('unknown', 'notebookpage', 'separator', 'sizeritem'): + pass + else: + outputList.append(self.templates.CREATE_WIDGET_VAR % locals()) return outputList From 1b46085c9737b64d2083b10f50aaf2b4306b0e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Piel?= Date: Wed, 22 Aug 2018 13:56:01 +0200 Subject: [PATCH 3/3] pywxrc: fix showing the success message at the end When generating a file, it should show a success message like "Resources written to...". However, the print() failed, which made it sound like the whole generation failed. --- wx/tools/pywxrc.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wx/tools/pywxrc.py b/wx/tools/pywxrc.py index a87740ea..117a8f1a 100644 --- a/wx/tools/pywxrc.py +++ b/wx/tools/pywxrc.py @@ -856,7 +856,6 @@ def main(args=None): if not args: args = sys.argv[1:] - resourceFilename = "" outputFilename = None embedResources = False generateGetText = False @@ -931,7 +930,7 @@ def main(args=None): print_("%s." % str(exc), file=sys.stderr) else: if outputFilename != "-": - print_("Resources written to %s." % outputFilename, file=outputFilename) + print_("Resources written to %s." % outputFilename, file=sys.stderr) if __name__ == "__main__": main(sys.argv[1:])