Fixes for wxPython-4.0.7 (ubuntu22) compatible with wxPython-4.1.x python3
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Wed, 12 Apr 2023 19:28:37 +0200
branchpython3
changeset 3791 c98646b1c981
parent 3790 9ec48ec13b65
child 3792 365f866ee120
Fixes for wxPython-4.0.7 (ubuntu22) compatible with wxPython-4.1.x
IDEFrame.py
editors/TextViewer.py
--- a/IDEFrame.py	Tue Feb 21 12:47:18 2023 +0800
+++ b/IDEFrame.py	Wed Apr 12 19:28:37 2023 +0200
@@ -447,9 +447,10 @@
             self.Bind(wx.EVT_MENU, self.GenerateZoomFunction(idx), new_item)
 
         parent.AppendSeparator()
-        AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE,
-                   kind=wx.ITEM_NORMAL, text=_('Switch perspective') + '\tF12')
-        self.Bind(wx.EVT_MENU, self.SwitchPerspective, id=ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE)
+        if wx.VERSION >= (4, 1, 0):
+            AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE,
+                       kind=wx.ITEM_NORMAL, text=_('Switch perspective') + '\tF12')
+            self.Bind(wx.EVT_MENU, self.SwitchPerspective, id=ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE)
 
         AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENUFULLSCREEN,
                    kind=wx.ITEM_NORMAL, text=_('Full screen') + '\tShift-F12')
@@ -1405,10 +1406,11 @@
         for child in self.TabsOpened.GetChildren():
             if isinstance(child, wx.aui.AuiTabCtrl):
                 auitabctrl.append(child)
-                if child not in self.AuiTabCtrl:
+                if wx.VERSION > (4, 1, 0) and child not in self.AuiTabCtrl:
                     child.Bind(wx.EVT_LEFT_DCLICK, self.GetTabsOpenedDClickFunction(child))
         self.AuiTabCtrl = auitabctrl
-        if self.TabsOpened.GetPageCount() == 0:
+        # on wxPython 4.0.7, AuiManager has no "RestorePane" method...
+        if wx.VERSION > (4, 1, 0) and self.TabsOpened.GetPageCount() == 0:
             pane = self.AUIManager.GetPane(self.TabsOpened)
             # on wxPython 4.1.0, AuiPaneInfo has no "IsMaximized" attribute...
             if (not hasattr(pane, "IsMaximized")) or pane.IsMaximized():
@@ -1498,6 +1500,8 @@
         return OnTabsOpenedDClick
 
     def SwitchPerspective(self, evt):
+        if not hasattr(self.AUIManager, "MaximizePane"):
+            return
         pane = self.AUIManager.GetPane(self.TabsOpened)
         # on wxPython 4.1.0, AuiPaneInfo has no "IsMaximized" attribute...
         IsMaximized = pane.IsMaximized() if hasattr(pane, "IsMaximized") \
--- a/editors/TextViewer.py	Tue Feb 21 12:47:18 2023 +0800
+++ b/editors/TextViewer.py	Wed Apr 12 19:28:37 2023 +0200
@@ -191,8 +191,12 @@
     def Colourise(self, start, end):
         self.Editor.Colourise(start, end)
 
-    def StartStyling(self, pos):
-        self.Editor.StartStyling(pos)
+    if wx.VERSION < (4, 1, 0):
+        def StartStyling(self, pos, mask=0xff):
+            self.Editor.StartStyling(pos, mask)
+    else:
+        def StartStyling(self, pos, *ignored):
+            self.Editor.StartStyling(pos)
 
     INDIC0 = 0
     INDIC1 = 1
@@ -977,6 +981,6 @@
             if highlight_start_pos < end_pos and highlight_end_pos > start_pos:
                 self.StartStyling(highlight_start_pos)
                 self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type)
-                self.StartStyling(highlight_start_pos)
+                self.StartStyling(highlight_start_pos, 0x00)
                 until_end = max(0, len(self.Editor.GetText()) - highlight_end_pos)
                 self.SetStyling(until_end, wx.stc.STC_STYLE_DEFAULT)