Two bugs fixed:
authorlbessard
Mon, 15 Dec 2008 09:45:16 +0100
changeset 294 4a36f2ec8967
parent 293 dbc366959daf
child 295 c6ef6d92ce16
Two bugs fixed:
- Errors on Tab close while removing variable panel
- Error in Cut/Copy/Paste function generating 'maximum recursion exceeded' exception
PLCOpenEditor.py
--- a/PLCOpenEditor.py	Thu Dec 11 09:13:22 2008 +0100
+++ b/PLCOpenEditor.py	Mon Dec 15 09:45:16 2008 +0100
@@ -423,6 +423,8 @@
                 self.TabsOpened = wx.aui.AuiNotebook(self)
                 self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,
                         self.OnPouSelectedChanged)
+                self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE,
+                        self.OnPageClose)
                 self.AUIManager.AddPane(self.TabsOpened, wx.aui.AuiPaneInfo().CentrePane())
             else:
                 self.TabsOpened = wx.Notebook(id=ID_PLCOPENEDITORTABSOPENED,
@@ -470,6 +472,8 @@
                 self.TabsOpened = wx.aui.AuiNotebook(self)
                 self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,
                         self.OnPouSelectedChanged)
+                self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE,
+                        self.OnPageClose)
                 self.AUIManager.AddPane(self.TabsOpened, wx.aui.AuiPaneInfo().CentrePane().MinSize(wx.Size(0, 0)))
             
                 self.LibraryPanel = wx.Panel(id=ID_PLCOPENEDITORLIBRARYPANEL,
@@ -617,15 +621,17 @@
         self.SelectedItem = None
 
     def OnPageClose(self, event):
-        selected = self.TabsOpened.GetSelection()
+        selected = event.GetSelection()
         if selected >= 0:
-            tagname = self.GetPage(selected).GetTagName()
-            self.VariablePanelIndexer.RemoveVariablePanel(tagname)
+            if not self.Debug:
+                tagname = self.TabsOpened.GetPage(selected).GetTagName()
+                self.VariablePanelIndexer.RemoveVariablePanel(tagname)
             if self.TabsOpened.GetPageCount() > 0:
                 new_index = min(selected, self.TabsOpened.GetPageCount() - 1)
-                tagname = self.GetPage(new_index).GetTagName()
                 self.TabsOpened.SetSelection(new_index)
-                self.VariablePanelIndexer.ChangeVariablePanel(tagname)
+                if not self.Debug:
+                    tagname = self.TabsOpened.GetPage(new_index).GetTagName()
+                    self.VariablePanelIndexer.ChangeVariablePanel(tagname)
             self.RefreshTitle()
             self.RefreshFileMenu()
             self.RefreshEditMenu()
@@ -822,10 +828,10 @@
     def OnCloseTabMenu(self, event):
         selected = self.TabsOpened.GetSelection()
         if selected >= 0:
-            self.TabsOpened.DeletePage(selected)
             if not self.Debug:
                 tagname = self.TabsOpened.GetPage(selected).GetTagName()
                 self.VariablePanelIndexer.RemoveVariablePanel(tagname)
+            self.TabsOpened.DeletePage(selected)
             if self.TabsOpened.GetPageCount() > 0:
                 new_index = min(selected, self.TabsOpened.GetPageCount() - 1)
                 self.TabsOpened.SetSelection(new_index)
@@ -1057,25 +1063,25 @@
 
     def OnCutMenu(self, event):
         control = self.FindFocus()
-        if isinstance(control, Viewer):
+        if isinstance(control, (Viewer, TextViewer)):
             control.Cut()
-        else:
+        elif isinstance(control, wx.TextCtrl):
             control.ProcessEvent(event)
         event.Skip()
     
     def OnCopyMenu(self, event):
         control = self.FindFocus()
-        if isinstance(control, Viewer):
+        if isinstance(control, (Viewer, TextViewer)):
             control.Copy()
-        else:
+        elif isinstance(control, wx.TextCtrl):
             control.ProcessEvent(event)
         event.Skip()
     
     def OnPasteMenu(self, event):
         control = self.FindFocus()
-        if isinstance(control, Viewer):
+        if isinstance(control, (Viewer, TextViewer)):
             control.Paste()
-        else:
+        elif isinstance(control, wx.TextCtrl):
             control.ProcessEvent(event)
         event.Skip()
     
@@ -3523,17 +3529,14 @@
     def RemoveVariablePanel(self, tagname):
         if tagname in self.VariablePanelList:
             panel = self.VariablePanelList.pop(tagname)
-            panel.Hide()
             self.MainSizer.Remove(panel)
+            panel.Destroy()
             if self.CurrentPanel == tagname:
                 self.CurrentPanel = None
     
     def RemoveAllPanels(self):
-        if self.CurrentPanel is not None and self.CurrentPanel in self.VariablePanelList:
-            self.VariablePanelList[self.CurrentPanel].Hide()
-        self.VariablePanelList = {}
-        self.MainSizer.Clear()
-        self.CurrentPanel = None
+        for tagname in self.VariablePanelList.keys():
+            self.RemoveVariablePanel(tagname)
     
     def UpdateVariablePanelTagName(self, old_tagname, new_tagname):
         if old_tagname in self.VariablePanelList:
@@ -3939,22 +3942,22 @@
         self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
         
         self.AddButton = wx.Button(id=ID_VARIABLEEDITORPANELADDBUTTON, label='Add',
-              name='AddButton', parent=self, pos=wx.Point(345, 340),
+              name='AddButton', parent=self, pos=wx.Point(0, 0),
               size=wx.Size(72, 32), style=0)
         self.Bind(wx.EVT_BUTTON, self.OnAddButton, id=ID_VARIABLEEDITORPANELADDBUTTON)
 
         self.DeleteButton = wx.Button(id=ID_VARIABLEEDITORPANELDELETEBUTTON, label='Delete',
-              name='DeleteButton', parent=self, pos=wx.Point(425, 340),
+              name='DeleteButton', parent=self, pos=wx.Point(0, 0),
               size=wx.Size(72, 32), style=0)
         self.Bind(wx.EVT_BUTTON, self.OnDeleteButton, id=ID_VARIABLEEDITORPANELDELETEBUTTON)
 
         self.UpButton = wx.Button(id=ID_VARIABLEEDITORPANELUPBUTTON, label='^',
-              name='UpButton', parent=self, pos=wx.Point(505, 340),
+              name='UpButton', parent=self, pos=wx.Point(0, 0),
               size=wx.Size(32, 32), style=0)
         self.Bind(wx.EVT_BUTTON, self.OnUpButton, id=ID_VARIABLEEDITORPANELUPBUTTON)
 
         self.DownButton = wx.Button(id=ID_VARIABLEEDITORPANELDOWNBUTTON, label='v',
-              name='DownButton', parent=self, pos=wx.Point(545, 340),
+              name='DownButton', parent=self, pos=wx.Point(0, 0),
               size=wx.Size(32, 32), style=0)
         self.Bind(wx.EVT_BUTTON, self.OnDownButton, id=ID_VARIABLEEDITORPANELDOWNBUTTON)