From 066a9fd80f8bdbd46caaa92fe01d99a8db9d2dba Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 23 Jan 2017 14:06:37 -0800 Subject: [PATCH] Fix wxScrolledWindow wrapping, and remove workarounds --- etg/_glcanvas.py | 2 -- etg/_grid.py | 3 --- etg/_html.py | 3 --- etg/_html2.py | 3 --- etg/scrolwin.py | 70 +++++++++++++++++++++++++----------------------- 5 files changed, 37 insertions(+), 44 deletions(-) diff --git a/etg/_glcanvas.py b/etg/_glcanvas.py index 5f99ae61..6de53078 100644 --- a/etg/_glcanvas.py +++ b/etg/_glcanvas.py @@ -55,8 +55,6 @@ def run(): module.addPyCode('import wx', order=10) module.addInclude(INCLUDES) - # TODO: Remove this when wxScrolledWindow inheritance is fixed - module.addHeaderCode('typedef wxScrolled _ScrolledWindowBase;') #----------------------------------------------------------------- diff --git a/etg/_grid.py b/etg/_grid.py index 70d4a853..ae35bc19 100644 --- a/etg/_grid.py +++ b/etg/_grid.py @@ -58,9 +58,6 @@ def run(): module.addImport('_core') module.addPyCode("import wx", order=10) - # TODO: Remove this when wxScrolledWindow inheritance is fixed - module.addHeaderCode('typedef wxScrolled _ScrolledWindowBase;') - module.addInclude(INCLUDES) diff --git a/etg/_html.py b/etg/_html.py index 1e9c2a5b..64c06d34 100644 --- a/etg/_html.py +++ b/etg/_html.py @@ -78,9 +78,6 @@ def run(): module.addPyCode("import wx", order=10) module.addInclude(INCLUDES) - # TODO: Remove this when wxScrolledWindow inheritance is fixed - module.addHeaderCode('typedef wxScrolled _ScrolledWindowBase;') - module.addCppCode("""\ #include #include diff --git a/etg/_html2.py b/etg/_html2.py index 0c38079b..7b18d601 100644 --- a/etg/_html2.py +++ b/etg/_html2.py @@ -60,9 +60,6 @@ def run(): module.addPyCode('import wx', order=10) module.addInclude(INCLUDES) - # TODO: Remove this when wxScrolledWindow inheritance is fixed - module.addHeaderCode('typedef wxScrolled _ScrolledWindowBase;') - #----------------------------------------------------------------- #----------------------------------------------------------------- diff --git a/etg/scrolwin.py b/etg/scrolwin.py index 518b33a9..29df9596 100644 --- a/etg/scrolwin.py +++ b/etg/scrolwin.py @@ -63,10 +63,9 @@ def run(): scrolled.find('GetSizeAvailableForScrollTarget').ignore(False) scrolled.find('SendAutoScrollEvents').isVirtual = True - # The wxScrolledWindow and wxScrolledCanvas typedefs will be output - # normally and SIP will treat them like classes that have a - # wxScrolled mix-in as one of their base classes. Let's add some more - # info to them for the doc generators. + # The wxScrolledCanvas typedef will be output normally and SIP will treat + # it like a class that has a wxScrolled mix-in as one of the base classes. + # Let's add some more info to them for the doc generators. docBase = """\ The :ref:`{name}` class is a combination of the :ref:`{base}` and :ref:`Scrolled` classes, and manages scrolling for its client area, @@ -74,12 +73,6 @@ def run(): and setting the scroll positions, thumb sizes and ranges according to the area in view. """ - item = module.find('wxScrolledWindow') - assert isinstance(item, etgtools.TypedefDef) - item.docAsClass = True - item.bases = ['wxPanel', 'wxScrolled'] - item.briefDoc = docBase.format(name='ScrolledWindow', base='Panel') - item = module.find('wxScrolledCanvas') item.docAsClass = True item.bases = ['wxWindow', 'wxScrolled'] @@ -87,40 +80,51 @@ def run(): item.detailedDoc[0] = "This scrolled window is not intended to have children "\ "so it doesn't have special handling for TAB traversal "\ "or focus management." - - - module.items.remove(item) - # wxScrolledWindow is documented as a typedef but it's actually a class. - # So we need to implement it that way here too in order to keep - # static_casts happy. + # move it ahead of wxScrolledWindow sw = module.find('wxScrolledWindow') - assert isinstance(sw, TypedefDef) - sw.name = '_ScrolledWindowBase' - + module.items.remove(item) module.insertItemBefore(sw, item) + # wxScrolledWindow is documented as a typedef but it's actually a class. + # So we need to implement it that way here too in order to keep + # static_casts and such happy. + assert isinstance(sw, TypedefDef) + + # First, let's add a typedef to serve as the base class of + # wxScrolledWindow, since SIP doesn't yet understand using template + # instantiations as base classes. Setting noTypeName tells SIP to not use + # the typedef name in the actual generated code, but the typedef's type + # instead. + td = TypedefDef(name='_ScrolledWindowBase', + type='wxScrolled', + noTypeName=True, + piIgnored=True) + module.insertItemAfter(sw, td) + module.addHeaderCode('typedef wxScrolled _ScrolledWindowBase;') + sw.ignore() + + # Now implement the class definition klass = ClassDef( name='wxScrolledWindow', bases=['_ScrolledWindowBase'], - ##bases=['wxScrolled'], + piBases=['Window', 'Scrolled'], briefDoc=sw.briefDoc, detailedDoc=sw.detailedDoc, items=[ - MethodDef(name='wxScrolledWindow', isCtor=True, items=[]), - MethodDef(name='wxScrolledWindow', isCtor=True, items=[ - ParamDef(name='parent', type='wxWindow*'), - ParamDef(name='winid', type='wxWindowID', default='wxID_ANY'), - ParamDef(name='pos', type='const wxPoint&', default='wxDefaultPosition'), - ParamDef(name='size', type='const wxSize&', default='wxDefaultSize'), - ParamDef(name='style', type='long', default='wxScrolledWindowStyle'), - ParamDef(name='name', type='const wxString&', default='wxPanelNameStr'), - ]), + MethodDef(name='wxScrolledWindow', isCtor=True, items=[], + overloads=[ + MethodDef(name='wxScrolledWindow', isCtor=True, items=[ + ParamDef(name='parent', type='wxWindow*'), + ParamDef(name='winid', type='wxWindowID', default='wxID_ANY'), + ParamDef(name='pos', type='const wxPoint&', default='wxDefaultPosition'), + ParamDef(name='size', type='const wxSize&', default='wxDefaultSize'), + ParamDef(name='style', type='long', default='wxScrolledWindowStyle'), + ParamDef(name='name', type='const wxString&', default='wxPanelNameStr'), + ]), + ]), ], ) - - module.insertItemAfter(sw, klass) - ##sw.ignore() - module.addHeaderCode('typedef wxScrolled _ScrolledWindowBase;') + module.insertItemAfter(td, klass) module.addPyCode("PyScrolledWindow = wx.deprecated(ScrolledWindow, 'Use ScrolledWindow instead.')")