Fix segmentation fault happening when changing POU tab selection
authorlaurent
Tue, 24 Jan 2012 21:43:29 +0100
changeset 631 e4dd5bf1f1db
parent 630 9d7e38e271cb
child 632 3ea55a5db68e
Fix segmentation fault happening when changing POU tab selection
PLCOpenEditor.py
--- a/PLCOpenEditor.py	Tue Jan 24 21:42:21 2012 +0100
+++ b/PLCOpenEditor.py	Tue Jan 24 21:43:29 2012 +0100
@@ -484,6 +484,8 @@
             self.TabsOpened = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORTABSOPENED, 
                   style=wx.aui.AUI_NB_DEFAULT_STYLE|wx.aui.AUI_NB_WINDOWLIST_BUTTON)
             self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGING,
+                    self.OnPouSelectedChanging)
+            self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,
                     self.OnPouSelectedChanged)
             self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE,
                     self.OnPageClose)
@@ -526,9 +528,13 @@
             self.TabsOpened.SetImageList(self.TabsImageList)
             if wx.VERSION >= (2, 6, 0):
                 self.TabsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING,
+                    self.OnPouSelectedChanging, id=ID_PLCOPENEDITORTABSOPENED)
+                self.TabsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
                     self.OnPouSelectedChanged, id=ID_PLCOPENEDITORTABSOPENED)
             else:
                 wx.EVT_NOTEBOOK_PAGE_CHANGING(self.TabsOpened, ID_PLCOPENEDITORTABSOPENED,
+                    self.OnPouSelectedChanging)
+                wx.EVT_NOTEBOOK_PAGE_CHANGED(self.TabsOpened, ID_PLCOPENEDITORTABSOPENED,
                     self.OnPouSelectedChanged)
             
             self.RightNoteBook = wx.Notebook(id=ID_PLCOPENEDITORRIGHTNOTEBOOK,
@@ -1201,13 +1207,16 @@
                     self.AUIManager.RestorePane(pane)
                 self.AUIManager.Update()
     
-    def OnPouSelectedChanged(self, event):
-        old_selected = self.TabsOpened.GetSelection()
-        if old_selected >= 0:
-            window = self.TabsOpened.GetPage(old_selected)
+    def OnPouSelectedChanging(self, event):
+        selected = self.TabsOpened.GetSelection()
+        if selected >= 0:
+            window = self.TabsOpened.GetPage(selected)
             if not window.IsDebugging():
                 window.ResetBuffer()
-        selected = event.GetSelection()
+        event.Skip()
+    
+    def OnPouSelectedChanged(self, event):
+        selected = self.TabsOpened.GetSelection()
         if selected >= 0:
             window = self.TabsOpened.GetPage(selected)
             if not window.IsDebugging():