diff --git a/etg/_core.py b/etg/_core.py index 9b7fdb4d..b59df462 100644 --- a/etg/_core.py +++ b/etg/_core.py @@ -94,25 +94,16 @@ INCLUDES = [ 'defs', 'evtloop', 'apptrait', 'app', - + + # basic windows and stuff 'timer', 'window', 'validate', 'panel', 'menu', 'menuitem', + 'imaglist', - # toplevel and dialogs - 'nonownedwnd', - 'toplevel', - 'dialog', - 'dirdlg', - 'filedlg', - 'frame', - 'msgdlg', - 'progdlg', - 'popupwin', - 'tipwin', # controls 'control', @@ -120,6 +111,7 @@ INCLUDES = [ 'defs', 'statbmp', 'stattext', 'statbox', + 'statusbar', 'choice', 'anybutton', 'button', @@ -127,12 +119,9 @@ INCLUDES = [ 'defs', 'withimage', 'bookctrl', 'notebook', - 'imaglist', 'splitter', 'collpane', 'statline', - 'stdpaths', - 'snglinst', 'textcompleter', 'textentry', 'textctrl', @@ -145,14 +134,30 @@ INCLUDES = [ 'defs', 'srchctrl', 'radiobox', 'radiobut', - 'scrolwin', 'slider', 'spinbutt', 'spinctrl', 'tglbtn', - 'statusbar', - 'vscroll', 'scrolbar', + + # toplevel and dialogs + 'nonownedwnd', + 'toplevel', + 'dialog', + 'dirdlg', + 'filedlg', + 'frame', + 'msgdlg', + 'progdlg', + 'popupwin', + 'tipwin', + + # other window types and stuff + 'stdpaths', + 'snglinst', + 'scrolwin', + 'vscroll', + ] diff --git a/etg/bmpbuttn.py b/etg/bmpbuttn.py index 1badaeb6..0c3887c0 100644 --- a/etg/bmpbuttn.py +++ b/etg/bmpbuttn.py @@ -31,6 +31,8 @@ def run(): # customizing the generated code and docstrings. c = module.find('wxBitmapButton') + assert isinstance(c, etgtools.ClassDef) + c.find('wxBitmapButton.bitmap').default = 'wxNullBitmap' c.find('Create.bitmap').default = 'wxNullBitmap' diff --git a/etg/brush.py b/etg/brush.py index 241d2f72..ee820583 100644 --- a/etg/brush.py +++ b/etg/brush.py @@ -77,6 +77,22 @@ def run(): # it is delay-initialized, see stockgdi.sip module.find('wxTheBrushList').ignore() + + + # Some aliases that should be phased out eventually, (sooner rather than + # later.) They are already gone (or wrapped by an #if) in the C++ code, + # and so are not found in the documentation... + module.addPyCode("""\ + wx.STIPPLE_MASK_OPAQUE = wx.BRUSHSTYLE_STIPPLE_MASK_OPAQUE + wx.STIPPLE_MASK = wx.BRUSHSTYLE_STIPPLE_MASK + wx.STIPPLE = wx.BRUSHSTYLE_STIPPLE + wx.BDIAGONAL_HATCH = wx.BRUSHSTYLE_BDIAGONAL_HATCH + wx.CROSSDIAG_HATCH = wx.BRUSHSTYLE_CROSSDIAG_HATCH + wx.FDIAGONAL_HATCH = wx.BRUSHSTYLE_FDIAGONAL_HATCH + wx.CROSS_HATCH = wx.BRUSHSTYLE_CROSS_HATCH + wx.HORIZONTAL_HATCH = wx.BRUSHSTYLE_HORIZONTAL_HATCH + wx.VERTICAL_HATCH = wx.BRUSHSTYLE_VERTICAL_HATCH + """) #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/button.py b/etg/button.py index 3790d090..d7a0f9fd 100644 --- a/etg/button.py +++ b/etg/button.py @@ -33,6 +33,8 @@ def run(): c = module.find('wxButton') tools.fixWindowClass(c) + module.addGlobalStr('wxButtonNameStr', c) + #----------------------------------------------------------------- tools.doCommonTweaks(module) tools.runGenerators(module) diff --git a/etg/checkbox.py b/etg/checkbox.py index 87dd32db..7c284a87 100644 --- a/etg/checkbox.py +++ b/etg/checkbox.py @@ -35,6 +35,8 @@ def run(): c.find('wxCheckBox.label').default = 'wxEmptyString' c.find('Create.label').default = 'wxEmptyString' + module.addGlobalStr('wxCheckBoxNameStr', c) + # Workaround warning for the property name starting with a digit c.find('Get3StateValue').ignore() c.addAutoProperties() diff --git a/etg/collpane.py b/etg/collpane.py index 64b79b06..0af5242d 100644 --- a/etg/collpane.py +++ b/etg/collpane.py @@ -42,6 +42,8 @@ def run(): c.find('Create.label').default = 'wxEmptyString' tools.fixWindowClass(c) + + module.addGlobalStr('wxCollapsiblePaneNameStr', c) #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/control.py b/etg/control.py index 4a78acf5..156b49e1 100644 --- a/etg/control.py +++ b/etg/control.py @@ -32,7 +32,8 @@ def run(): c = module.find('wxControl') assert isinstance(c, etgtools.ClassDef) - + module.addGlobalStr('wxControlNameStr', c) + tools.fixWindowClass(c) module.addPyCode("PyControl = wx.deprecated(Control)") diff --git a/etg/defs.py b/etg/defs.py index 3e0524f7..2258c1a5 100644 --- a/etg/defs.py +++ b/etg/defs.py @@ -96,44 +96,6 @@ def run(): module.addPyCode("wx.BG_STYLE_CUSTOM = wx.BG_STYLE_PAINT") - # Some aliases that should be phased out eventually, (sooner rather than - # later.) They are already gone (or wrapped by an #if) in the C++ code, - # and so are not found in the documentation... - module.addPyCode("""\ - wx.DEFAULT = wx.FONTFAMILY_DEFAULT - wx.DECORATIVE = wx.FONTFAMILY_DECORATIVE - wx.ROMAN = wx.FONTFAMILY_ROMAN - wx.SCRIPT = wx.FONTFAMILY_SCRIPT - wx.SWISS = wx.FONTFAMILY_SWISS - wx.MODERN = wx.FONTFAMILY_MODERN - wx.TELETYPE = wx.FONTFAMILY_TELETYPE - - wx.NORMAL = wx.FONTWEIGHT_NORMAL - wx.LIGHT = wx.FONTWEIGHT_LIGHT - wx.BOLD = wx.FONTWEIGHT_BOLD - - wx.NORMAL = wx.FONTSTYLE_NORMAL - wx.ITALIC = wx.FONTSTYLE_ITALIC - wx.SLANT = wx.FONTSTYLE_SLANT - - wx.SOLID = wx.PENSTYLE_SOLID - wx.DOT = wx.PENSTYLE_DOT - wx.LONG_DASH = wx.PENSTYLE_LONG_DASH - wx.SHORT_DASH = wx.PENSTYLE_SHORT_DASH - wx.DOT_DASH = wx.PENSTYLE_DOT_DASH - wx.USER_DASH = wx.PENSTYLE_USER_DASH - wx.TRANSPARENT = wx.PENSTYLE_TRANSPARENT - - wx.STIPPLE_MASK_OPAQUE = wx.BRUSHSTYLE_STIPPLE_MASK_OPAQUE - wx.STIPPLE_MASK = wx.BRUSHSTYLE_STIPPLE_MASK - wx.STIPPLE = wx.BRUSHSTYLE_STIPPLE - wx.BDIAGONAL_HATCH = wx.BRUSHSTYLE_BDIAGONAL_HATCH - wx.CROSSDIAG_HATCH = wx.BRUSHSTYLE_CROSSDIAG_HATCH - wx.FDIAGONAL_HATCH = wx.BRUSHSTYLE_FDIAGONAL_HATCH - wx.CROSS_HATCH = wx.BRUSHSTYLE_CROSS_HATCH - wx.HORIZONTAL_HATCH = wx.BRUSHSTYLE_HORIZONTAL_HATCH - wx.VERTICAL_HATCH = wx.BRUSHSTYLE_VERTICAL_HATCH - """) #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/dialog.py b/etg/dialog.py index ff7db1fd..c1c7da53 100644 --- a/etg/dialog.py +++ b/etg/dialog.py @@ -36,6 +36,7 @@ def run(): c = module.find('wxDialog') assert isinstance(c, etgtools.ClassDef) + module.addGlobalStr('wxDialogNameStr', c) c.find('wxDialog.title').default = 'wxEmptyString' c.find('Create.title').default = 'wxEmptyString' diff --git a/etg/dirdlg.py b/etg/dirdlg.py index 65b8ca9f..39794338 100644 --- a/etg/dirdlg.py +++ b/etg/dirdlg.py @@ -31,6 +31,8 @@ def run(): # customizing the generated code and docstrings. c = module.find('wxDirDialog') + module.addGlobalStr('wxDirDialogNameStr', c) + module.addGlobalStr('wxDirSelectorPromptStr', c) tools.fixWindowClass(c) diff --git a/etg/filedlg.py b/etg/filedlg.py index c94edb49..271820fb 100644 --- a/etg/filedlg.py +++ b/etg/filedlg.py @@ -33,6 +33,10 @@ def run(): c = module.find('wxFileDialog') isinstance(c, etgtools.ClassDef) + module.addGlobalStr('wxFileDialogNameStr', c) + module.addGlobalStr('wxFileSelectorPromptStr', c) + module.addGlobalStr('wxFileSelectorDefaultWildcardStr', c) + # TODO: add this back. We'll need a way to pass it a callable that can be # called from a C ExtraControlCreatorFunction function diff --git a/etg/font.py b/etg/font.py index fd0fb6e2..af715cec 100644 --- a/etg/font.py +++ b/etg/font.py @@ -53,6 +53,7 @@ def run(): int flags = wxFONTFLAG_DEFAULT, const wxString& faceName = wxEmptyString, wxFontEncoding encoding = wxFONTENCODING_DEFAULT)""", + pyArgsString="(pointSize, family, flags=FONTFLAG_DEFAULT, faceName=EmptyString, encoding=FONTENCODING_DEFAULT)", body="""\ wxFont* font = wxFont::New(pointSize, family, flags, *faceName, encoding); return font; @@ -105,6 +106,28 @@ def run(): module.find('wxFromString').ignore() module.find('wxToString').ignore() + + # Some aliases that should be phased out eventually, (sooner rather than + # later.) They are already gone (or wrapped by an #if) in the C++ code, + # and so are not found in the documentation... + module.addPyCode("""\ + wx.DEFAULT = wx.FONTFAMILY_DEFAULT + wx.DECORATIVE = wx.FONTFAMILY_DECORATIVE + wx.ROMAN = wx.FONTFAMILY_ROMAN + wx.SCRIPT = wx.FONTFAMILY_SCRIPT + wx.SWISS = wx.FONTFAMILY_SWISS + wx.MODERN = wx.FONTFAMILY_MODERN + wx.TELETYPE = wx.FONTFAMILY_TELETYPE + + wx.NORMAL = wx.FONTWEIGHT_NORMAL + wx.LIGHT = wx.FONTWEIGHT_LIGHT + wx.BOLD = wx.FONTWEIGHT_BOLD + + wx.NORMAL = wx.FONTSTYLE_NORMAL + wx.ITALIC = wx.FONTSTYLE_ITALIC + wx.SLANT = wx.FONTSTYLE_SLANT + """) + #----------------------------------------------------------------- tools.doCommonTweaks(module) tools.runGenerators(module) diff --git a/etg/frame.py b/etg/frame.py index 0d3bc956..af67de45 100644 --- a/etg/frame.py +++ b/etg/frame.py @@ -33,6 +33,10 @@ def run(): c = module.find('wxFrame') assert isinstance(c, etgtools.ClassDef) + # TODO: Remove these when wxToolBar is added to Phoenix + module.addGlobalStr('wxToolBarNameStr', c) + module.insertItemBefore(c, etgtools.GlobalVarDef(type='const int', name='wxTB_HORIZONTAL')) + c.find('wxFrame.title').default = 'wxEmptyString' c.find('Create.title').default = 'wxEmptyString' diff --git a/etg/gauge.py b/etg/gauge.py index 4a8fcdad..c2e48eea 100644 --- a/etg/gauge.py +++ b/etg/gauge.py @@ -34,6 +34,8 @@ def run(): c.find('wxGauge.range').default = '100' c.find('Create.range').default = '100' + module.addGlobalStr('wxGaugeNameStr', c) + tools.fixWindowClass(c) #----------------------------------------------------------------- diff --git a/etg/gdicmn.py b/etg/gdicmn.py index e9d4cad0..a025ee5d 100644 --- a/etg/gdicmn.py +++ b/etg/gdicmn.py @@ -309,7 +309,8 @@ def run(): c.addPyMethod('FindColour', '(self, colour)', 'return self.Find(colour)') module.find('wxTheColourDatabase').ignore() - + + #----------------------------------------------------------------- tools.doCommonTweaks(module) tools.runGenerators(module) diff --git a/etg/image.py b/etg/image.py index a34984e0..33acaf41 100644 --- a/etg/image.py +++ b/etg/image.py @@ -261,6 +261,7 @@ def run(): module.find('wxIMAGE_ALPHA_TRANSPARENT').pyInt = True module.find('wxIMAGE_ALPHA_OPAQUE').pyInt = True + module.find('wxIMAGE_ALPHA_THRESHOLD').pyInt = True # These are defines for string objects, not integers, so we can't # generate code for them the same way as integer values. Since they are diff --git a/etg/msgdlg.py b/etg/msgdlg.py index 0d96c0c0..2b549020 100644 --- a/etg/msgdlg.py +++ b/etg/msgdlg.py @@ -35,6 +35,8 @@ def run(): c = module.find('wxMessageDialog') assert isinstance(c, etgtools.ClassDef) + + module.addGlobalStr('wxMessageBoxCaptionStr', c) # These argument types are actually ButtonLabel, but the class is a private # helper. We will always be passing in strings, and ButtonLabel will implicitly diff --git a/etg/notebook.py b/etg/notebook.py index 432a5372..9b73467a 100644 --- a/etg/notebook.py +++ b/etg/notebook.py @@ -37,6 +37,7 @@ def run(): tools.fixWindowClass(c) + module.addGlobalStr('wxNotebookNameStr', c) #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/pen.py b/etg/pen.py index 8d55e1ed..e3ada7d9 100644 --- a/etg/pen.py +++ b/etg/pen.py @@ -101,6 +101,20 @@ def run(): # it is delay-initialized, see stockgdi.sip module.find('wxThePenList').ignore() + + + # Some aliases that should be phased out eventually, (sooner rather than + # later.) They are already gone (or wrapped by an #if) in the C++ code, + # and so are not found in the documentation... + module.addPyCode("""\ + wx.SOLID = wx.PENSTYLE_SOLID + wx.DOT = wx.PENSTYLE_DOT + wx.LONG_DASH = wx.PENSTYLE_LONG_DASH + wx.SHORT_DASH = wx.PENSTYLE_SHORT_DASH + wx.DOT_DASH = wx.PENSTYLE_DOT_DASH + wx.USER_DASH = wx.PENSTYLE_USER_DASH + wx.TRANSPARENT = wx.PENSTYLE_TRANSPARENT + """) #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/radiobox.py b/etg/radiobox.py index 693e1376..e04dcb7d 100644 --- a/etg/radiobox.py +++ b/etg/radiobox.py @@ -33,6 +33,8 @@ def run(): c = module.find('wxRadioBox') assert isinstance(c, etgtools.ClassDef) + + module.addGlobalStr('wxRadioBoxNameStr', c) c.find('wxRadioBox').findOverload('wxString choices').ignore() c.find('Create').findOverload('wxString choices').ignore() diff --git a/etg/radiobut.py b/etg/radiobut.py index 34c3ce45..fbc7a02a 100644 --- a/etg/radiobut.py +++ b/etg/radiobut.py @@ -35,6 +35,8 @@ def run(): c.find('Create.label').default = 'wxEmptyString' tools.fixWindowClass(c) + module.addGlobalStr('wxRadioButtonNameStr', c) + #----------------------------------------------------------------- tools.doCommonTweaks(module) tools.runGenerators(module) diff --git a/etg/scrolbar.py b/etg/scrolbar.py index 1c947943..b14fdf7d 100644 --- a/etg/scrolbar.py +++ b/etg/scrolbar.py @@ -35,6 +35,7 @@ def run(): assert isinstance(c, etgtools.ClassDef) tools.fixWindowClass(c) + module.addGlobalStr('wxScrollBarNameStr', c) #----------------------------------------------------------------- diff --git a/etg/slider.py b/etg/slider.py index 87a922fe..1ebdb90e 100644 --- a/etg/slider.py +++ b/etg/slider.py @@ -42,6 +42,8 @@ def run(): addDefaults(c.find('wxSlider')) addDefaults(c.find('Create')) + module.addGlobalStr('wxSliderNameStr', c) + c.addPyMethod('GetRange', '(self)', 'return (self.GetMin(), self.GetMax())') tools.fixWindowClass(c) diff --git a/etg/srchctrl.py b/etg/srchctrl.py index be493a88..cf259c2b 100644 --- a/etg/srchctrl.py +++ b/etg/srchctrl.py @@ -35,6 +35,8 @@ def run(): c = module.find('wxSearchCtrl') assert isinstance(c, etgtools.ClassDef) + + module.addGlobalStr('wxSearchCtrlNameStr', c) c.find('SetMenu.menu').transfer = True diff --git a/etg/statbmp.py b/etg/statbmp.py index c708ea36..dc4d8897 100644 --- a/etg/statbmp.py +++ b/etg/statbmp.py @@ -33,8 +33,9 @@ def run(): c = module.find('wxStaticBitmap') c.find('wxStaticBitmap.label').default = 'wxNullBitmap' c.find('Create.label').default = 'wxNullBitmap' - tools.fixWindowClass(c) + + module.addGlobalStr('wxStaticBitmapNameStr', c) #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/statbox.py b/etg/statbox.py index cf1afe6b..f9e1b859 100644 --- a/etg/statbox.py +++ b/etg/statbox.py @@ -37,6 +37,7 @@ def run(): c.find('Create.label').default = 'wxEmptyString' tools.fixWindowClass(c) + module.addGlobalStr('wxStaticBoxNameStr', c) #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/statline.py b/etg/statline.py index 16ab9287..253b5161 100644 --- a/etg/statline.py +++ b/etg/statline.py @@ -29,10 +29,14 @@ def run(): #----------------------------------------------------------------- # Tweak the parsed meta objects in the module object as needed for # customizing the generated code and docstrings. + + module.addHeaderCode("#include ") c = module.find('wxStaticLine') tools.fixWindowClass(c) + module.addGlobalStr('wxStaticLineNameStr', c) + #----------------------------------------------------------------- tools.doCommonTweaks(module) tools.runGenerators(module) diff --git a/etg/stattext.py b/etg/stattext.py index 0234e3af..eaaa06cf 100644 --- a/etg/stattext.py +++ b/etg/stattext.py @@ -35,6 +35,8 @@ def run(): c.find('Create.label').default = 'wxEmptyString' tools.fixWindowClass(c) + module.addGlobalStr('wxStaticTextNameStr', c) + #----------------------------------------------------------------- tools.doCommonTweaks(module) tools.runGenerators(module) diff --git a/etg/statusbar.py b/etg/statusbar.py index 862f2f8a..c22b9001 100644 --- a/etg/statusbar.py +++ b/etg/statusbar.py @@ -32,6 +32,7 @@ def run(): c = module.find('wxStatusBar') tools.fixWindowClass(c) + module.addGlobalStr('wxStatusBarNameStr', c) #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/textctrl.py b/etg/textctrl.py index c2d3db89..4d747763 100644 --- a/etg/textctrl.py +++ b/etg/textctrl.py @@ -37,6 +37,7 @@ def run(): c = module.find('wxTextCtrl') + module.addGlobalStr('wxTextCtrlNameStr', c) # Split the HitTest overloads into separately named methods since once # the output parameters are applied they will have the same function diff --git a/etg/toplevel.py b/etg/toplevel.py index 8c81bfbc..6b08c5ac 100644 --- a/etg/toplevel.py +++ b/etg/toplevel.py @@ -34,6 +34,7 @@ def run(): c = module.find('wxTopLevelWindow') assert isinstance(c, etgtools.ClassDef) + module.addGlobalStr('wxFrameNameStr', c) c.find('wxTopLevelWindow.title').default = 'wxEmptyString' c.find('Create.title').default = 'wxEmptyString' diff --git a/etg/window.py b/etg/window.py index 0f0564f7..0dda04cc 100644 --- a/etg/window.py +++ b/etg/window.py @@ -9,6 +9,7 @@ import etgtools import etgtools.tweaker_tools as tools +from etgtools import ClassDef, MethodDef, ParamDef PACKAGE = "wx" MODULE = "_core" @@ -36,19 +37,19 @@ def run(): c = module.find('wxWindow') assert isinstance(c, etgtools.ClassDef) + module.addGlobalStr('wxPanelNameStr', c) + # First we need to let the wrapper generator know about wxWindowBase since # AddChild and RemoveChild need to use that type in order to be virtualized. - wc = etgtools.WigCode("""\ - class wxWindowBase : wxEvtHandler /Abstract/ - { - public: - virtual void AddChild( wxWindowBase* child ); - virtual void RemoveChild( wxWindowBase* child ); - }; - """) - module.insertItemBefore(c, wc) - + winbase = ClassDef(name='wxWindowBase', bases=['wxEvtHandler'], abstract=True, + items=[MethodDef(name='AddChild', isVirtual=True, type='void', protection='public', + items=[ParamDef(name='child', type='wxWindowBase*')]), + MethodDef(name='RemoveChild', isVirtual=True, type='void', protection='public', + items=[ParamDef(name='child', type='wxWindowBase*')]) + ]) + module.insertItemBefore(c, winbase) + # Now change the base class of wxWindow c.bases = ['wxWindowBase'] @@ -120,7 +121,9 @@ def run(): briefDoc="Is the given widget one of this window's built-in scrollbars? Only applicable on Mac.") - c.addCppMethod('void', 'SetDimensions', '(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO)', """\ + c.addCppMethod('void', 'SetDimensions', '(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO)', + pyArgsString="(x, y, width, height, sizeFlags=SIZE_AUTO)", + body="""\ self->SetSize(x, y, width, height, sizeFlags); """) c.addPyCode("Window.SetDimensions = wx.deprecated(Window.SetDimensions)") diff --git a/etgtools/extractors.py b/etgtools/extractors.py index 4c3c83db..d9318c11 100644 --- a/etgtools/extractors.py +++ b/etgtools/extractors.py @@ -17,7 +17,8 @@ import os import pprint import xml.etree.ElementTree as et -from tweaker_tools import removeWxPrefix, magicMethods +from tweaker_tools import removeWxPrefix, magicMethods, \ + guessTypeInt, guessTypeFloat, guessTypeStr from sphinxtools.utilities import FindDescendants #--------------------------------------------------------------------------- @@ -368,7 +369,9 @@ class FunctionDef(BaseDef): defValueMap = { 'true': 'True', 'false': 'False', - 'NULL': 'None', } + 'NULL': 'None', + 'wxString()': '""', + } if isinstance(self, CppMethodDef): # rip appart the argsString instead of using the (empty) list of parameters lastP = self.argsString.rfind(')') @@ -1209,6 +1212,9 @@ class ModuleDef(BaseDef): for item in self.items: if isinstance(item, (ClassDef, FunctionDef)): two.append(item) + elif isinstance(item, GlobalVarDef) and ( + guessTypeInt(item) or guessTypeFloat(item) or guessTypeStr(item)): + one.append(item) elif isinstance(item, GlobalVarDef): three.append(item) # template instantiations go at the end @@ -1357,6 +1363,15 @@ class ModuleDef(BaseDef): pc = PyCodeDef(code, order) self.items.append(pc) return pc + + + def addGlobalStr(self, name, before=None): + gv = GlobalVarDef(type='const char*', name=name) + if before is None: + self.addItem(gv) + else: + self.insertItemBefore(before, gv) + return gv def includePyCode(self, filename, order=None): diff --git a/etgtools/pi_generator.py b/etgtools/pi_generator.py index 8273d52b..1cf9e069 100644 --- a/etgtools/pi_generator.py +++ b/etgtools/pi_generator.py @@ -20,7 +20,8 @@ import sys, os, re import extractors import generators from generators import nci -from tweaker_tools import removeWxPrefix, magicMethods +from tweaker_tools import removeWxPrefix, magicMethods, \ + guessTypeInt, guessTypeFloat, guessTypeStr from cStringIO import StringIO @@ -167,7 +168,17 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase): assert isinstance(typedef, extractors.TypedefDef) if typedef.ignored: return - # write nothing for this one + # If the typedef is for a template instantiation then write a mock + # class for it that combines the template and class, otherwise write + # nothing. + if '<' in typedef.type and '>' in typedef.type: + t = typedef.type.replace('>', '') + t = t.replace(' ', '') + bases = t.split('<') + bases = [removeWxPrefix(b) for b in bases] + name = removeWxPrefix(typedef.name) + stream.write('class %s(%s):\n pass\n\n' % (name, ', '.join(bases))) + #----------------------------------------------------------------------- def generateWigCode(self, wig, stream, indent=''): @@ -180,7 +191,7 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase): assert isinstance(pc, extractors.PyCodeDef) code = pc.code if hasattr(pc, 'klass'): - code = code.replace(pc.klass.name+'.', '') # TODO: Check this + code = code.replace(pc.klass.pyName+'.', '') stream.write('\n') stream.write(nci(code, len(indent))) @@ -279,12 +290,18 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase): if klass.ignored: return - # class declaration + # check if it's a template with the template parameter as the base class + bases = klass.bases[:] + for tp in klass.templateParams: + if tp in bases: + bases.remove(tp) + + # write class declaration klassName = klass.pyName or klass.name stream.write('\n%sclass %s' % (indent, klassName)) - if klass.bases: + if bases: stream.write('(') - bases = [removeWxPrefix(b) for b in klass.bases] + bases = [removeWxPrefix(b) for b in bases] stream.write(', '.join(bases)) stream.write(')') stream.write(':\n') @@ -300,10 +317,14 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase): self.generateClass(item, stream, indent2) # Split the items into public and protected groups + enums = [i for i in klass if + isinstance(i, extractors.EnumDef) and + i.protection == 'public'] ctors = [i for i in klass if - isinstance(i, extractors.MethodDef) and - i.protection == 'public' and (i.isCtor or i.isDtor)] - public = [i for i in klass if i.protection == 'public' and i not in ctors] + isinstance(i, extractors.MethodDef) and + i.protection == 'public' and (i.isCtor or i.isDtor)] + public = [i for i in klass if i.protection == 'public' and + i not in ctors and i not in enums] protected = [i for i in klass if i.protection == 'protected'] dispatch = { @@ -319,16 +340,23 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase): extractors.WigCode : self.generateWigCode, } + for item in enums: + item.klass = klass + self.generateEnum(item, stream, indent2) + for item in ctors: if item.isCtor: + item.klass = klass self.generateMethod(item, stream, indent2, name='__init__', docstring=klass.pyDocstring) for item in public: + item.klass = klass f = dispatch[item.__class__] f(item, stream, indent2) for item in protected: + item.klass = klass f = dispatch[item.__class__] f(item, stream, indent2) @@ -436,34 +464,4 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase): #--------------------------------------------------------------------------- -# helpers - -def guessTypeInt(v): - if isinstance(v, extractors.EnumValueDef): - return True - if isinstance(v, extractors.DefineDef) and '"' not in v.value: - return True - type = v.type.replace('const', '') - type = type.replace(' ', '') - if type in ['int', 'long', 'byte', 'size_t', 'wxCoord']: - return True - if 'unsigned' in type: - return True - return False - - -def guessTypeFloat(v): - type = v.type.replace('const', '') - type = type.replace(' ', '') - if type in ['float', 'double', 'wxDouble']: - return True - return False - -def guessTypeStr(v): - if hasattr(v, 'value') and '"' in v.value: - return True - if 'wxString' in v.type: - return True - return False - #--------------------------------------------------------------------------- diff --git a/etgtools/tweaker_tools.py b/etgtools/tweaker_tools.py index bfbebd38..265160ab 100644 --- a/etgtools/tweaker_tools.py +++ b/etgtools/tweaker_tools.py @@ -870,3 +870,36 @@ error0: #--------------------------------------------------------------------------- +# type helpers + +def guessTypeInt(v): + if isinstance(v, extractors.EnumValueDef): + return True + if isinstance(v, extractors.DefineDef) and '"' not in v.value: + return True + type = v.type.replace('const', '') + type = type.replace(' ', '') + if type in ['int', 'long', 'byte', 'size_t', 'wxCoord', 'wxEventType']: + return True + if 'unsigned' in type: + return True + return False + + +def guessTypeFloat(v): + type = v.type.replace('const', '') + type = type.replace(' ', '') + if type in ['float', 'double', 'wxDouble']: + return True + return False + + +def guessTypeStr(v): + if hasattr(v, 'value') and '"' in v.value: + return True + for t in ['wxString', 'wxChar', 'char*', 'char *']: + if t in v.type: + return True + return False + +#--------------------------------------------------------------------------- diff --git a/src/core_ex.cpp b/src/core_ex.cpp index 78c4f2c1..1c63e833 100644 --- a/src/core_ex.cpp +++ b/src/core_ex.cpp @@ -42,6 +42,10 @@ void wxPyCoreModuleInject(PyObject* moduleDict) PyExc_AssertionError, NULL); PyDict_SetItemString(moduleDict, "wxAssertionError", wxAssertionError); + // An alias that should be deprecated sometime + PyDict_SetItemString(moduleDict, "PyAssertionError", wxAssertionError); + + // // Create an exception object to use when the app object hasn't been created yet // wxPyNoAppError = PyErr_NewException("wx._core.PyNoAppError", // PyExc_RuntimeError, NULL); diff --git a/src/core_ex.py b/src/core_ex.py index 52f3677e..29aa7931 100644 --- a/src/core_ex.py +++ b/src/core_ex.py @@ -7,20 +7,22 @@ wx = _sys.modules[__name__] # Load version numbers from __version__... Ensure that major and minor # versions are the same for both wxPython and wxWidgets. -from __version__ import * -import _core -__version__ = VERSION_STRING -assert MAJOR_VERSION == _core.MAJOR_VERSION, "wxPython/wxWidgets version mismatch" -assert MINOR_VERSION == _core.MINOR_VERSION, "wxPython/wxWidgets version mismatch" -if RELEASE_NUMBER != _core.RELEASE_NUMBER: - import warnings - warnings.warn("wxPython/wxWidgets release number mismatch") -del _core +if 'wxEVT_NULL' in dir(): + from __version__ import * + import _core + __version__ = VERSION_STRING + assert MAJOR_VERSION == _core.MAJOR_VERSION, "wxPython/wxWidgets version mismatch" + assert MINOR_VERSION == _core.MINOR_VERSION, "wxPython/wxWidgets version mismatch" + if RELEASE_NUMBER != _core.RELEASE_NUMBER: + import warnings + warnings.warn("wxPython/wxWidgets release number mismatch") + del _core import warnings class wxPyDeprecationWarning(DeprecationWarning): pass + warnings.simplefilter('default', wxPyDeprecationWarning) del warnings @@ -86,6 +88,6 @@ def deprecated(item, msg=''): #---------------------------------------------------------------------------- -PyAssertionError = wx.wxAssertionError # an alias for compatibility with Classic +EmptyString = "" #----------------------------------------------------------------------------