From 2c2e00dbe0ee6d2c0555287fc4acb8a92f610d49 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 21 Jan 2017 18:26:12 -0800 Subject: [PATCH] Various fixes and (hopefully temporary) workarounds for using the newest version of sip --- etg/_adv.py | 2 + etg/_glcanvas.py | 2 + etg/_grid.py | 3 + etg/_html.py | 3 + etg/_html2.py | 3 + etg/dcbuffer.py | 6 ++ etg/image.py | 2 +- etg/propgridiface.py | 4 ++ etg/propgridprops.py | 3 + etg/scrolwin.py | 146 ++++++++++++++++++------------------------- src/wxpy_api.h | 19 ++++++ 11 files changed, 106 insertions(+), 87 deletions(-) diff --git a/etg/_adv.py b/etg/_adv.py index cf6aa95d..294b5380 100644 --- a/etg/_adv.py +++ b/etg/_adv.py @@ -78,6 +78,8 @@ def run(): # customizing the generated code and docstrings. module.addHeaderCode('#include ') + module.addHeaderCode('#include ') + module.addImport('_core') module.addPyCode("import wx", order=10) module.addInclude(INCLUDES) diff --git a/etg/_glcanvas.py b/etg/_glcanvas.py index 6de53078..5f99ae61 100644 --- a/etg/_glcanvas.py +++ b/etg/_glcanvas.py @@ -55,6 +55,8 @@ 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 ae35bc19..70d4a853 100644 --- a/etg/_grid.py +++ b/etg/_grid.py @@ -58,6 +58,9 @@ 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 64c06d34..1e9c2a5b 100644 --- a/etg/_html.py +++ b/etg/_html.py @@ -78,6 +78,9 @@ 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 7b18d601..0c38079b 100644 --- a/etg/_html2.py +++ b/etg/_html2.py @@ -60,6 +60,9 @@ 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/dcbuffer.py b/etg/dcbuffer.py index 725c951c..7a854763 100644 --- a/etg/dcbuffer.py +++ b/etg/dcbuffer.py @@ -48,8 +48,14 @@ def run(): c.addPrivateCopyCtor() c.find('wxBufferedPaintDC').findOverload('wxBitmap').find('buffer').keepReference = True + # wxAutoBufferedPaintDC is documented as a class deriving from + # wxBufferedPaintDC, but on some platforms it is just a typedef of + # wxPaintDC. This causes compilation errors when the code tries to + # static_cast<> to one of the buffered DCs, so we'll change the base class + # here to more truly adhere to reality. c = module.find('wxAutoBufferedPaintDC') c.addPrivateCopyCtor() + c.bases = ['wxPaintDC'] module.find('wxAutoBufferedPaintDCFactory').factory = True diff --git a/etg/image.py b/etg/image.py index 00995762..3eaebb06 100644 --- a/etg/image.py +++ b/etg/image.py @@ -547,7 +547,7 @@ def run(): #------------------------------------------------------- c = module.find('wxImageHistogram') - c.bases = ['wxObject'] + c.bases = [] # wxImageHistogramBase doesn't actually exist setParamsPyInt('MakeKey') c.find('FindFirstUnusedColour').type = 'void' c.find('FindFirstUnusedColour.r').pyInt = True diff --git a/etg/propgridiface.py b/etg/propgridiface.py index 847a0e05..afe048c3 100644 --- a/etg/propgridiface.py +++ b/etg/propgridiface.py @@ -49,6 +49,10 @@ def run(): c.find('SetPropertyValue').findOverload('wxULongLong_t value').ignore() c.find('SetPropertyValue').findOverload('wxObject *value').ignore() + # TODO: Fix these + c.find('GetPropertyValueAsLongLong').ignore() + c.find('GetPropertyValueAsULongLong').ignore() + module.addItem( tools.wxArrayPtrWrapperTemplate('wxArrayPGProperty', 'wxPGProperty', module)) diff --git a/etg/propgridprops.py b/etg/propgridprops.py index cd137a7b..0f57f23d 100644 --- a/etg/propgridprops.py +++ b/etg/propgridprops.py @@ -77,6 +77,9 @@ def run(): c.briefDoc = "Basic property with integer value." c.detailedDoc = [] + c.find('DoValidation.value').type = 'long long' + + c = module.find('wxLongStringProperty') c.find('OnButtonClick.value').inOut = True c.find('DisplayEditorDialog.value').inOut = True diff --git a/etg/scrolwin.py b/etg/scrolwin.py index 4849c867..518b33a9 100644 --- a/etg/scrolwin.py +++ b/etg/scrolwin.py @@ -10,7 +10,7 @@ import etgtools import etgtools.tweaker_tools as tools -import copy +from etgtools import TypedefDef, ClassDef, MethodDef, ParamDef PACKAGE = "wx" MODULE = "_core" @@ -53,100 +53,74 @@ def run(): scrolled.find('GetVirtualSize.x').out = True scrolled.find('GetVirtualSize.y').out = True + scrolled.addPrivateCopyCtor() + scrolled.addPrivateAssignOp() + tools.fixWindowClass(scrolled) - if True: - # Now that SIP has the ability to support template classes where the - # base class is the template parameter, then we can use this instead - # of the trickery in the other branch below. + # Add back some virtuals that were removed in fixWindowClass + scrolled.find('OnDraw').isVirtual = True + scrolled.find('GetSizeAvailableForScrollTarget').isVirtual = True + scrolled.find('GetSizeAvailableForScrollTarget').ignore(False) + scrolled.find('SendAutoScrollEvents').isVirtual = True - # Doxygen doesn't declare the base class (the template parameter in - # this case) so we can just add it here. - # FIXED in Dox 1.8.x - #scrolled.bases.append('T') + # 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. + docBase = """\ + The :ref:`{name}` class is a combination of the :ref:`{base}` and + :ref:`Scrolled` classes, and manages scrolling for its client area, + transforming the coordinates according to the scrollbar positions, + 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') - scrolled.addPrivateCopyCtor() - scrolled.addPrivateAssignOp() - tools.fixWindowClass(scrolled) - - # Add back some virtuals that were removed in fixWindowClass - scrolled.find('OnDraw').isVirtual = True - scrolled.find('GetSizeAvailableForScrollTarget').isVirtual = True - 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. - docBase = """\ - The :ref:`{name}` class is a combination of the :ref:`{base}` and - :ref:`Scrolled` classes, and manages scrolling for its client area, - transforming the coordinates according to the scrollbar positions, - 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'] - item.briefDoc = docBase.format(name='ScrolledCanvas', base='Window') - 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." + item = module.find('wxScrolledCanvas') + item.docAsClass = True + item.bases = ['wxWindow', 'wxScrolled'] + item.briefDoc = docBase.format(name='ScrolledCanvas', base='Window') + 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." - else: - # NOTE: We do a tricky tweak here because wxScrolled requires using - # a template parameter as the base class, which SIP doesn't handle - # yet. So instead we'll just copy the current extractor elements for - # wxScrolled and morph it into nodes that will generate wrappers for - # wxScrolledWindow and wxScrolledCanvas as if they were non-template - # classes. + 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. + sw = module.find('wxScrolledWindow') + assert isinstance(sw, TypedefDef) + sw.name = '_ScrolledWindowBase' - # First ignore the existing typedefs - module.find('wxScrolledWindow').ignore() - module.find('wxScrolledCanvas').ignore() + module.insertItemBefore(sw, item) - swDoc = " This class derives from wxPanel so it shares its behavior with regard "\ - "to TAB traversal and focus handling. If you do not want this then use "\ - "wxScrolledCanvas instead." - scDoc = " This scrolled window is not intended to have children so it doesn't "\ - "have special handling for TAB traversal or focus management." - # Make the copies and add them to the module - for name, base, doc in [ ('wxScrolledCanvas', 'wxWindow', scDoc), - ('wxScrolledWindow', 'wxPanel', swDoc), ]: - node = copy.deepcopy(scrolled) - assert isinstance(node, etgtools.ClassDef) - node.name = name - node.templateParams = [] - node.bases = [base] - node.briefDoc = etgtools.flattenNode(node.briefDoc, False) - node.briefDoc = node.briefDoc.replace('wxScrolled', name) - # TODO: replace wxScrolled in the detailedDoc too? - node.briefDoc += doc - for ctor in node.find('wxScrolled').all(): - ctor.name = name + klass = ClassDef( + name='wxScrolledWindow', + bases=['_ScrolledWindowBase'], + ##bases=['wxScrolled'], + 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'), + ]), + ], + ) - node.addPrivateCopyCtor() - node.addPrivateAssignOp() - tools.fixWindowClass(node) - - # Add back some virtuals that were removed in fixWindowClass - node.find('OnDraw').isVirtual = True - node.find('GetSizeAvailableForScrollTarget').isVirtual = True - node.find('GetSizeAvailableForScrollTarget').ignore(False) - node.find('SendAutoScrollEvents').isVirtual = True - - module.insertItemAfter(scrolled, node) - - # Ignore the wxScrolled template class - scrolled.ignore() + module.insertItemAfter(sw, klass) + ##sw.ignore() + module.addHeaderCode('typedef wxScrolled _ScrolledWindowBase;') module.addPyCode("PyScrolledWindow = wx.deprecated(ScrolledWindow, 'Use ScrolledWindow instead.')") diff --git a/src/wxpy_api.h b/src/wxpy_api.h index 666050a0..1d3b256c 100644 --- a/src/wxpy_api.h +++ b/src/wxpy_api.h @@ -40,6 +40,25 @@ #include +//-------------------------------------------------------------------------- +// TODO: find a way to not need to do this. +// It is needed because SIP is putting :: on the front of the type, and when +// it's a macro the compiler complains about "expected unqualified-id". The +// risk is that it may be possible for wxLongLong_t to be a type that is not +// actually fully compatible with "long long", causing problems when passing +// into, or returning from wx APIs. + +// If they are macros then undef them and make some typedefs instead +#ifdef wxLongLong_t +#undef wxLongLong_t +typedef long long wxLongLong_t; +#endif + +#ifdef wxULongLong_t +#undef wxULongLong_t +typedef unsigned long long wxULongLong_t; +#endif + //-------------------------------------------------------------------------- // The API items that can be inline functions or macros. // These are made available simply by #including this header file.