Fixing bug in Variable Panel when pressing Add,Delete,Up or Down button while a cell editor in variable grid is active
--- a/VariablePanel.py Tue Sep 20 23:58:31 2011 +0200
+++ b/VariablePanel.py Tue Sep 20 23:59:49 2011 +0200
@@ -685,7 +685,13 @@
self.UpButton.Enable(table_length > 0 and row > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"])
self.DownButton.Enable(table_length > 0 and row < table_length - 1 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"])
+ def CloseVariablesGridEditControl(self):
+ row = self.VariablesGrid.GetGridCursorRow()
+ col = self.VariablesGrid.GetGridCursorCol()
+ self.VariablesGrid.SetGridCursor(row, col)
+
def OnAddButton(self, event):
+ self.CloseVariablesGridEditControl()
new_row = self.DefaultValue.copy()
if self.Filter in self.DefaultTypes:
new_row["Class"] = self.DefaultTypes[self.Filter]
@@ -703,19 +709,22 @@
event.Skip()
def OnDeleteButton(self, event):
- row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow())
- self.Values.remove(row)
+ self.CloseVariablesGridEditControl()
+ row_index = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow())
+ self.Values.remove(row_index)
self.SaveValues()
- self.RefreshValues()
+ self.RefreshValues(row_index)
self.RefreshButtons()
event.Skip()
def OnUpButton(self, event):
+ self.CloseVariablesGridEditControl()
self.MoveValue(self.VariablesGrid.GetGridCursorRow(), -1)
self.RefreshButtons()
event.Skip()
def OnDownButton(self, event):
+ self.CloseVariablesGridEditControl()
self.MoveValue(self.VariablesGrid.GetGridCursorRow(), 1)
self.RefreshButtons()
event.Skip()
@@ -880,21 +889,23 @@
self.VariablesGrid.SetGridCursor(new_index, self.VariablesGrid.GetGridCursorCol())
def RefreshValues(self, select=0):
- if len(self.Table.data) > 0:
- self.VariablesGrid.SetGridCursor(0, 1)
data = []
for num, variable in enumerate(self.Values):
if variable["Class"] in self.ClassList:
variable["Number"] = num + 1
data.append(variable)
self.Table.SetData(data)
+ self.Table.ResetView(self.VariablesGrid)
if len(self.Table.data) > 0:
if select == -1:
select = len(self.Table.data) - 1
- self.VariablesGrid.SetGridCursor(select, 1)
- self.VariablesGrid.MakeCellVisible(select, 1)
- self.Table.ResetView(self.VariablesGrid)
-
+ else:
+ select = min(select, len(self.Table.data) - 1)
+ col = max(1, self.VariablesGrid.GetGridCursorCol())
+ self.VariablesGrid.SetGridCursor(select, col)
+ self.VariablesGrid.MakeCellVisible(select, col)
+ self.VariablesGrid.SetFocus()
+
def SaveValues(self, buffer = True):
words = self.TagName.split("::")
if self.ElementType == "config":