Fix bug when closing project and one editor is opened
authorlaurent
Fri, 27 Apr 2012 01:55:45 +0200
changeset 672 d751b1c609b3
parent 671 47b9ad1471cc
child 673 b686f0081e2b
Fix bug when closing project and one editor is opened
RessourceEditor.py
controls/CustomGrid.py
controls/VariablePanel.py
--- a/RessourceEditor.py	Mon Apr 23 11:16:40 2012 +0200
+++ b/RessourceEditor.py	Fri Apr 27 01:55:45 2012 +0200
@@ -406,13 +406,14 @@
         setattr(self.InstancesGrid, "_MoveRow", _MoveInstance)
         
         def _RefreshInstanceButtons():
-            rows = self.InstancesTable.GetNumberRows()
-            row = self.InstancesGrid.GetGridCursorRow()
-            self.DeleteInstanceButton.Enable(rows > 0)
-            self.UpInstanceButton.Enable(row > 0 and 
-                self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row - 1, "Task"))
-            self.DownInstanceButton.Enable(0 <= row < rows - 1 and 
-                self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row + 1, "Task"))
+            if self:
+                rows = self.InstancesTable.GetNumberRows()
+                row = self.InstancesGrid.GetGridCursorRow()
+                self.DeleteInstanceButton.Enable(rows > 0)
+                self.UpInstanceButton.Enable(row > 0 and 
+                    self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row - 1, "Task"))
+                self.DownInstanceButton.Enable(0 <= row < rows - 1 and 
+                    self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row + 1, "Task"))
         setattr(self.InstancesGrid, "RefreshButtons", _RefreshInstanceButtons)
         
         self.InstancesGrid.SetRowLabelSize(0)
--- a/controls/CustomGrid.py	Mon Apr 23 11:16:40 2012 +0200
+++ b/controls/CustomGrid.py	Fri Apr 27 01:55:45 2012 +0200
@@ -72,16 +72,17 @@
                 button.Bind(wx.EVT_BUTTON, getattr(self, "On%sButton" % name))
     
     def RefreshButtons(self):
-        rows = self.Table.GetNumberRows()
-        row = self.GetGridCursorRow()
-        if self.AddButton is not None:
-            self.AddButton.Enable(self.Editable)
-        if self.DeleteButton is not None:
-            self.DeleteButton.Enable(self.Editable and rows > 0)
-        if self.UpButton is not None:
-            self.UpButton.Enable(self.Editable and row > 0)
-        if self.DownButton is not None:
-            self.DownButton.Enable(self.Editable and 0 <= row < rows - 1)
+        if self:
+            rows = self.Table.GetNumberRows()
+            row = self.GetGridCursorRow()
+            if self.AddButton is not None:
+                self.AddButton.Enable(self.Editable)
+            if self.DeleteButton is not None:
+                self.DeleteButton.Enable(self.Editable and rows > 0)
+            if self.UpButton is not None:
+                self.UpButton.Enable(self.Editable and row > 0)
+            if self.DownButton is not None:
+                self.DownButton.Enable(self.Editable and 0 <= row < rows - 1)
     
     def CloseEditControl(self):
         row, col = self.GetGridCursorRow(), self.GetGridCursorCol()
--- a/controls/VariablePanel.py	Mon Apr 23 11:16:40 2012 +0200
+++ b/controls/VariablePanel.py	Fri Apr 27 01:55:45 2012 +0200
@@ -551,19 +551,20 @@
         setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
         
         def _RefreshButtons():
-            table_length = len(self.Table.data)
-            row_class = None
-            row_edit = True
-            row = 0
-            if table_length > 0:
-                row = self.VariablesGrid.GetGridCursorRow()
-                row_edit = self.Table.GetValueByName(row, "Edit")
-                if self.PouIsUsed:
-                    row_class = self.Table.GetValueByName(row, "Class")
-            self.AddButton.Enable(not self.Debug and (not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]))
-            self.DeleteButton.Enable(not self.Debug and (table_length > 0 and row_edit and row_class not in ["Input", "Output", "InOut"]))
-            self.UpButton.Enable(not self.Debug and (table_length > 0 and row > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]))
-            self.DownButton.Enable(not self.Debug and (table_length > 0 and row < table_length - 1 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]))
+            if self:
+                table_length = len(self.Table.data)
+                row_class = None
+                row_edit = True
+                row = 0
+                if table_length > 0:
+                    row = self.VariablesGrid.GetGridCursorRow()
+                    row_edit = self.Table.GetValueByName(row, "Edit")
+                    if self.PouIsUsed:
+                        row_class = self.Table.GetValueByName(row, "Class")
+                self.AddButton.Enable(not self.Debug and (not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]))
+                self.DeleteButton.Enable(not self.Debug and (table_length > 0 and row_edit and row_class not in ["Input", "Output", "InOut"]))
+                self.UpButton.Enable(not self.Debug and (table_length > 0 and row > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]))
+                self.DownButton.Enable(not self.Debug and (table_length > 0 and row < table_length - 1 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]))
         setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons)
         
         self.VariablesGrid.SetRowLabelSize(0)