# HG changeset patch # User laurent # Date 1323426370 -3600 # Node ID 7db729686416fe6e54739abaedc4be369b7646fc # Parent 4bb7b132e15ddc58a1ef1564db25fc5acf5e411c Making variable panel not editable when showing variables of debugging block diff -r 4bb7b132e15d -r 7db729686416 TextViewer.py --- a/TextViewer.py Fri Dec 09 10:22:26 2011 +0100 +++ b/TextViewer.py Fri Dec 09 11:26:10 2011 +0100 @@ -184,7 +184,7 @@ if tagname != "" and controler is not None: self.VARIABLE_PANEL_TYPE = controler.GetPouType(tagname.split("::")[1]) - EditorPanel.__init__(self, parent, tagname, window, controler) + EditorPanel.__init__(self, parent, tagname, window, controler, debug) self.Keywords = [] self.Variables = {} @@ -196,7 +196,6 @@ self.TextSyntax = None self.CurrentAction = None self.Highlights = [] - self.Debug = debug self.InstancePath = instancepath self.ContextStack = [] self.CallStack = [] diff -r 4bb7b132e15d -r 7db729686416 Viewer.py --- a/Viewer.py Fri Dec 09 10:22:26 2011 +0100 +++ b/Viewer.py Fri Dec 09 11:26:10 2011 +0100 @@ -452,7 +452,7 @@ def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""): self.VARIABLE_PANEL_TYPE = controler.GetPouType(tagname.split("::")[1]) - EditorPanel.__init__(self, parent, tagname, window, controler) + EditorPanel.__init__(self, parent, tagname, window, controler, debug) DebugViewer.__init__(self, controler, debug) self._init_menus() diff -r 4bb7b132e15d -r 7db729686416 controls/CustomGrid.py --- a/controls/CustomGrid.py Fri Dec 09 10:22:26 2011 +0100 +++ b/controls/CustomGrid.py Fri Dec 09 11:26:10 2011 +0100 @@ -37,6 +37,8 @@ def __init__(self, *args, **kwargs): wx.grid.Grid.__init__(self, *args, **kwargs) + self.Editable = True + if wx.VERSION >= (2, 6, 0): self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnSelectCell) else: @@ -46,6 +48,10 @@ def SetDefaultValue(self, default_value): self.DefaultValue = default_value + def SetEditable(self, editable=True): + self.Editable = editable + self.RefreshButtons() + def SetButtons(self, buttons): for name in ["Add", "Delete", "Up", "Down"]: button = buttons.get(name, None) @@ -56,12 +62,14 @@ 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(rows > 0) + self.DeleteButton.Enable(self.Editable and rows > 0) if self.UpButton is not None: - self.UpButton.Enable(row > 0) + self.UpButton.Enable(self.Editable and row > 0) if self.DownButton is not None: - self.DownButton.Enable(0 <= row < rows - 1) + self.DownButton.Enable(self.Editable and 0 <= row < rows - 1) def CloseEditControl(self): self.SetGridCursor(self.GetGridCursorRow(), self.GetGridCursorCol()) @@ -145,16 +153,16 @@ elif row < 0 or col == self.Table.GetNumberCols() - 1: self.Navigate(wx.NavigationKeyEvent.IsForward) key_handled = True - elif keycode in (wx.WXK_ADD, wx.WXK_NUMPAD_ADD): + elif keycode in (wx.WXK_ADD, wx.WXK_NUMPAD_ADD) and self.Editable: self.AddRow() key_handled = True - elif keycode in (wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE): + elif keycode in (wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE) and self.Editable: self.DeleteRow() key_handled = True - elif keycode == wx.WXK_UP and event.ShiftDown(): + elif keycode == wx.WXK_UP and event.ShiftDown() and self.Editable: self.MoveRow(self.GetGridCursorRow(), -1) key_handled = True - elif keycode == wx.WXK_DOWN and event.ShiftDown(): + elif keycode == wx.WXK_DOWN and event.ShiftDown() and self.Editable: self.MoveRow(self.GetGridCursorRow(), 1) key_handled = True if not key_handled: diff -r 4bb7b132e15d -r 7db729686416 controls/EditorPanel.py --- a/controls/EditorPanel.py Fri Dec 09 10:22:26 2011 +0100 +++ b/controls/EditorPanel.py Fri Dec 09 11:26:10 2011 +0100 @@ -50,7 +50,7 @@ self._init_Editor(self) if self.VARIABLE_PANEL_TYPE is not None: - self.VariableEditor = VariablePanel(self, self, self.Controler, self.VARIABLE_PANEL_TYPE) + self.VariableEditor = VariablePanel(self, self, self.Controler, self.VARIABLE_PANEL_TYPE, self.Debug) self.VariableEditor.SetTagName(self.TagName) if self.Editor is not None: @@ -64,11 +64,12 @@ if self.Editor is not None: self.Initialize(self.Editor) - def __init__(self, parent, tagname, window, controler): + def __init__(self, parent, tagname, window, controler, debug=False): self.ParentWindow = window self.Controler = controler self.TagName = tagname self.Icon = None + self.Debug = debug self._init_ctrls(parent) diff -r 4bb7b132e15d -r 7db729686416 controls/VariablePanel.py --- a/controls/VariablePanel.py Fri Dec 09 10:22:26 2011 +0100 +++ b/controls/VariablePanel.py Fri Dec 09 11:26:10 2011 +0100 @@ -207,52 +207,55 @@ editor = None renderer = None colname = self.GetColLabelValue(col, False) - if colname == "Option": - options = GetOptions(constant = var_class in ["Local", "External", "Global"], - retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"], - non_retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"]) - if len(options) > 1: - editor = wx.grid.GridCellChoiceEditor() - editor.SetParameters(",".join(map(_, options))) - else: - grid.SetReadOnly(row, col, True) - elif col != 0 and self.GetValueByName(row, "Edit"): - grid.SetReadOnly(row, col, False) - if colname == "Name": - if self.Parent.PouIsUsed and var_class in ["Input", "Output", "InOut"]: + if self.Parent.Debug: + grid.SetReadOnly(row, col, True) + else: + if colname == "Option": + options = GetOptions(constant = var_class in ["Local", "External", "Global"], + retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"], + non_retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"]) + if len(options) > 1: + editor = wx.grid.GridCellChoiceEditor() + editor.SetParameters(",".join(map(_, options))) + else: grid.SetReadOnly(row, col, True) - else: - editor = wx.grid.GridCellTextEditor() - renderer = wx.grid.GridCellStringRenderer() - elif colname == "Initial Value": - if var_class != "External": - if self.Parent.Controler.IsEnumeratedType(var_type): - editor = wx.grid.GridCellChoiceEditor() - editor.SetParameters(",".join(self.Parent.Controler.GetEnumeratedDataValues(var_type))) + elif col != 0 and self.GetValueByName(row, "Edit"): + grid.SetReadOnly(row, col, False) + if colname == "Name": + if self.Parent.PouIsUsed and var_class in ["Input", "Output", "InOut"]: + grid.SetReadOnly(row, col, True) else: editor = wx.grid.GridCellTextEditor() - renderer = wx.grid.GridCellStringRenderer() - else: - grid.SetReadOnly(row, col, True) - elif colname == "Location": - if var_class in ["Local", "Global"] and self.Parent.Controler.IsLocatableType(var_type): - editor = LocationCellEditor(self, self.Parent.Controler) - renderer = wx.grid.GridCellStringRenderer() - else: - grid.SetReadOnly(row, col, True) - elif colname == "Class": - if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and var_class in ["Input", "Output", "InOut"]: - grid.SetReadOnly(row, col, True) - else: - editor = wx.grid.GridCellChoiceEditor() - excluded = [] - if self.Parent.PouIsUsed: - excluded.extend(["Input","Output","InOut"]) - if self.Parent.IsFunctionBlockType(var_type): - excluded.extend(["Local","Temp"]) - editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded])) - elif colname != "Documentation": - grid.SetReadOnly(row, col, True) + renderer = wx.grid.GridCellStringRenderer() + elif colname == "Initial Value": + if var_class != "External": + if self.Parent.Controler.IsEnumeratedType(var_type): + editor = wx.grid.GridCellChoiceEditor() + editor.SetParameters(",".join(self.Parent.Controler.GetEnumeratedDataValues(var_type))) + else: + editor = wx.grid.GridCellTextEditor() + renderer = wx.grid.GridCellStringRenderer() + else: + grid.SetReadOnly(row, col, True) + elif colname == "Location": + if var_class in ["Local", "Global"] and self.Parent.Controler.IsLocatableType(var_type): + editor = LocationCellEditor(self, self.Parent.Controler) + renderer = wx.grid.GridCellStringRenderer() + else: + grid.SetReadOnly(row, col, True) + elif colname == "Class": + if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and var_class in ["Input", "Output", "InOut"]: + grid.SetReadOnly(row, col, True) + else: + editor = wx.grid.GridCellChoiceEditor() + excluded = [] + if self.Parent.PouIsUsed: + excluded.extend(["Input","Output","InOut"]) + if self.Parent.IsFunctionBlockType(var_type): + excluded.extend(["Local","Temp"]) + editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded])) + elif colname != "Documentation": + grid.SetReadOnly(row, col, True) grid.SetCellEditor(row, col, editor) grid.SetCellRenderer(row, col, renderer) @@ -502,11 +505,12 @@ self._init_sizers() - def __init__(self, parent, window, controler, element_type): + def __init__(self, parent, window, controler, element_type, debug=False): self._init_ctrls(parent) self.ParentWindow = window self.Controler = controler self.ElementType = element_type + self.Debug = debug self.RefreshHighlightsTimer = wx.Timer(self, -1) self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) @@ -580,6 +584,7 @@ "Delete": self.DeleteButton, "Up": self.UpButton, "Down": self.DownButton}) + self.VariablesGrid.SetEditable(not self.Debug) def _AddVariable(new_row): if not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]: @@ -629,10 +634,10 @@ row_edit = self.Table.GetValueByName(row, "Edit") if self.PouIsUsed: row_class = self.Table.GetValueByName(row, "Class") - self.AddButton.Enable(not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]) - self.DeleteButton.Enable(table_length > 0 and row_edit and row_class not in ["Input", "Output", "InOut"]) - 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"]) + 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) @@ -658,31 +663,31 @@ return name in self.Controler.GetFunctionBlockTypes(self.TagName) def RefreshView(self): - self.PouNames = self.Controler.GetProjectPouNames() + self.PouNames = self.Controler.GetProjectPouNames(self.Debug) words = self.TagName.split("::") if self.ElementType == "config": self.PouIsUsed = False returnType = None - self.Values = self.Controler.GetConfigurationGlobalVars(words[1]) + self.Values = self.Controler.GetConfigurationGlobalVars(words[1], self.Debug) elif self.ElementType == "resource": self.PouIsUsed = False returnType = None - self.Values = self.Controler.GetConfigurationResourceGlobalVars(words[1], words[2]) + self.Values = self.Controler.GetConfigurationResourceGlobalVars(words[1], words[2], self.Debug) else: if self.ElementType == "function": self.ReturnType.Clear() - for base_type in self.Controler.GetDataTypes(self.TagName, True): + for base_type in self.Controler.GetDataTypes(self.TagName, True, debug=self.Debug): self.ReturnType.Append(base_type) returnType = self.Controler.GetEditedElementInterfaceReturnType(self.TagName) else: returnType = None self.PouIsUsed = self.Controler.PouIsUsed(words[1]) - self.Values = self.Controler.GetEditedElementInterfaceVars(self.TagName) + self.Values = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug) if returnType is not None: self.ReturnType.SetStringSelection(returnType) - self.ReturnType.Enable(True) + self.ReturnType.Enable(self.Debug) self.staticText1.Show() self.ReturnType.Show() else: @@ -844,7 +849,7 @@ def OnVariablesGridCellLeftClick(self, event): row = event.GetRow() - if event.GetCol() == 0 and self.Table.GetValueByName(row, "Edit"): + if not self.Debug and (event.GetCol() == 0 and self.Table.GetValueByName(row, "Edit")): row = event.GetRow() var_name = self.Table.GetValueByName(row, "Name") var_class = self.Table.GetValueByName(row, "Class")