From 9b7c2ad48899b8e41c06798043d2834355d3fcc8 Mon Sep 17 00:00:00 2001 From: Scott Talbert Date: Fri, 10 Jun 2016 22:19:03 -0400 Subject: [PATCH] Fix stc compilation under SIP 4.18 The stc code doesn't compile under SIP 4.18. This appears to be due to changes in the cast_xyz function generation, but it exposed a problem in the Phoenix implementation. The wx interface headers say that wxStyledTextCtrl inherits from wxTextEntry, but it actually inherits from wxTextCtrlIface. This now (probably rightly so) doesn't compile with SIP 4.18. The solution is to essentially copy the methods from wxTextEntry and wxTextCtrl, as is done for wxSearchCtrl and wxRichTextCtrl. --- etg/_stc.py | 29 +++++++++++++++++++++++++++++ unittests/test_stc.py | 21 +++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/etg/_stc.py b/etg/_stc.py index c0544ece..463427cc 100644 --- a/etg/_stc.py +++ b/etg/_stc.py @@ -65,6 +65,7 @@ def run(): c = module.find('wxStyledTextCtrl') assert isinstance(c, etgtools.ClassDef) + c.bases = ['wxControl'] # wxTextCtrlIface is also a base... c.piBases = ['wx.Control', 'wx.TextEntry'] tools.fixWindowClass(c, False) module.addGlobalStr('wxSTCNameStr', c) @@ -128,6 +129,34 @@ def run(): # forcibly mashed into an int in the C code module.find('wxSTC_MASK_FOLDERS').forcedInt = True + + # Make sure that all the methods from wxTextEntry and wxTextCtrl are + # included. This is needed because we are pretending that this class only + # derives from wxControl but the real C++ class also derives from + # wxTextCtrlIface which derives from wxTextEntryBase. + import textentry + mod = textentry.parseAndTweakModule() + klass = mod.find('wxTextEntry') + items = [item for item in klass.items if isinstance(item, etgtools.MethodDef) and + not item.isCtor and + not item.isDtor and + not c.findItem(item.name)] + c.items.extend(items) + + import textctrl + mod = textctrl.parseAndTweakModule() + klass = mod.find('wxTextCtrl') + items = [item for item in klass.items if isinstance(item, etgtools.MethodDef) and + not item.isCtor and + not item.isDtor and + not c.findItem(item.name)] + c.items.extend(items) + + c.find('EmulateKeyPress').ignore() + c.find('IsMultiLine').ignore() + c.find('IsSingleLine').ignore() + + # TODO: Add the UTF8 PyMethods from classic (see _stc_utf8_methods.py) diff --git a/unittests/test_stc.py b/unittests/test_stc.py index 8dc3358a..01a491ad 100644 --- a/unittests/test_stc.py +++ b/unittests/test_stc.py @@ -222,6 +222,27 @@ class stc_Tests(wtc.WidgetTestCase): stc.EVT_STC_INDICATOR_RELEASE stc.EVT_STC_AUTOCOMP_CANCELLED stc.EVT_STC_AUTOCOMP_CHAR_DELETED + + + def test_stcHasTextCtrlMethods(self): + # Just ensure that the common TextCtrl methods are present. This is + # done because the C++ class either derives from wxTextEntryBase + # or from wxTextCtrlIface, but these classes are not part of the API + # (and thus are not wrapped), so we have to kludge things. + # See etg/_stc.py for details. + + t = stc.StyledTextCtrl(self.frame) + t.Cut + t.CanCut + t.DiscardEdits + t.GetDefaultStyle + t.GetNumberOfLines + t.GetStyle + t.IsModified + t.HitTest + t.AppendText + t.WriteText + t.ChangeValue