diff --git a/etg/srchctrl.py b/etg/srchctrl.py index 47a5fdf0..19bafe03 100644 --- a/etg/srchctrl.py +++ b/etg/srchctrl.py @@ -35,7 +35,6 @@ def run(): c = module.find('wxSearchCtrl') assert isinstance(c, etgtools.ClassDef) - module.addGlobalStr('wxSearchCtrlNameStr', c) c.find('SetMenu.menu').transfer = True @@ -62,14 +61,49 @@ def run(): #endif """) - # Not using autoProperties here because some getters use 'Is' - c.addProperty('Menu GetMenu SetMenu') - c.addProperty('SearchButtonVisible IsSearchButtonVisible ShowSearchButton') - c.addProperty('CancelButtonVisible IsCancelButtonVisible ShowCancelButton') - c.addProperty('DescriptiveText GetDescriptiveText SetDescriptiveText') - - tools.fixWindowClass(c) + searchCtrl = c + + # The safest way to reconcile the differences in the class hierachy + # between the native wxSearchCtrl on Mac and the generic one on the other + # platforms is to just say that this class derives directly from + # wxControl (the first common ancestor) instead of wxTextCtrl, and then + # redeclare all the wxTextEntry and/or wxTextCtrlIface methods that we + # are interested in having here. That way the C++ compiler can sort out + # the proper way to call those methods and avoid calling the wrong + # implementations like would happen if try to force it another way... + searchCtrl.bases = ['wxControl'] + + # Instead of duplicating those declarations here, let's use the parser + # and tweakers we already have and then just transplant those MethodDefs + # into this ClassDef. That will then preserve things like the + # documentation and custom tweaks that would be real tedious to duplicate + # and maintain. + import textentry + mod = textentry.parseAndTweakModule() + klass = mod.find('wxTextEntry') + searchCtrl.items.extend(klass.items) + + # Do the same with wxTextCtrl, but also remove things like the + # Constructors and Create methods first. + import textctrl + mod = textctrl.parseAndTweakModule() + klass = mod.find('wxTextCtrl') + # get just the methods that are not ctors, dtor or Create + items = [item for item in klass.items if isinstance(item, etgtools.MethodDef) and + not item.isCtor and + not item.isDtor and + item.name != 'Create'] + searchCtrl.items.extend(items) + + + + # Add some properties that autoProperties would not see because they are + # not using 'Get' and 'Set' + searchCtrl.addProperty('SearchButtonVisible IsSearchButtonVisible ShowSearchButton') + searchCtrl.addProperty('CancelButtonVisible IsCancelButtonVisible ShowCancelButton') + searchCtrl.addAutoProperties() + tools.fixWindowClass(searchCtrl) module.addPyCode("""\ EVT_SEARCHCTRL_CANCEL_BTN = wx.PyEventBinder( wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, 1) diff --git a/etg/textctrl.py b/etg/textctrl.py index 40af8e16..a38bac04 100644 --- a/etg/textctrl.py +++ b/etg/textctrl.py @@ -22,7 +22,7 @@ ITEMS = [ 'wxTextAttr', 'wxTextCtrl', ] #--------------------------------------------------------------------------- -def run(): +def parseAndTweakModule(): # Parse the XML file(s) building a collection of Extractor objects module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING) etgtools.parseDoxyXML(module, ITEMS) @@ -34,9 +34,9 @@ def run(): c = module.find('wxTextAttr') assert isinstance(c, etgtools.ClassDef) c.find('operator=').ignore() - c.find('SetFont').pyArgsString = '(font, flags=TEXT_ATTR_FONT & ~TEXT_ATTR_FONT_PIXEL_SIZE)' + c = module.find('wxTextCtrl') module.addGlobalStr('wxTextCtrlNameStr', c) @@ -58,9 +58,15 @@ def run(): for op in c.findAll('operator<<'): op.ignore() + c.find('OnDropFiles').ignore() + tools.fixWindowClass(c) - - #----------------------------------------------------------------- + return module + + +#----------------------------------------------------------------- +def run(): + module = parseAndTweakModule() tools.doCommonTweaks(module) tools.runGenerators(module) diff --git a/etg/textentry.py b/etg/textentry.py index 5e00ac61..c8213d1c 100644 --- a/etg/textentry.py +++ b/etg/textentry.py @@ -21,7 +21,7 @@ ITEMS = [ "wxTextEntry", ] #--------------------------------------------------------------------------- -def run(): +def parseAndTweakModule(): # Parse the XML file(s) building a collection of Extractor objects module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING, False) etgtools.parseDoxyXML(module, ITEMS) @@ -45,9 +45,12 @@ def run(): c.find('Replace.to').name = 'to_' c.find('SetSelection.from').name = 'from_' c.find('SetSelection.to').name = 'to_' + + return module - - #----------------------------------------------------------------- +#----------------------------------------------------------------- +def run(): + module = parseAndTweakModule() tools.doCommonTweaks(module) tools.runGenerators(module) diff --git a/unittests/test_srchctrl.py b/unittests/test_srchctrl.py index a54409e7..7c94aeaf 100644 --- a/unittests/test_srchctrl.py +++ b/unittests/test_srchctrl.py @@ -36,6 +36,29 @@ class srchctrl_Tests(wtc.WidgetTestCase): t.SetValue('Hello') self.assertEqual(t.GetValue(), 'Hello') self.assertEqual(t.Value, 'Hello') + + + def test_srchctrlHasTextCtrlMethods(self): + # Just ensure that the common TextCtrl methods are present. This is + # done because although the C++ class either derives from wxTextCtrl + # or from wxTextCtrlIface, we have to kludge it up a bit since the + # actual class hierarchies are different between platforms. See + # etg/srchctrl.py for details. + + t = wx.SearchCtrl(self.frame) + t.Cut + t.CanCut + t.DiscardEdits + t.GetDefaultStyle + t.GetNumberOfLines + t.GetStyle + t.IsModified + t.HitTest + t.AppendText + t.WriteText + t.ChangeValue + + #---------------------------------------------------------------------------