# HG changeset patch # User laurent # Date 1260189496 -3600 # Node ID fecd4f6c01ed31e5b20e077d1aa55edcadef1a2a # Parent ea90da16a5e2898c2ab565c00cb6f39f099f790e Adding support for forcing PLC variable in DebugVariablePanel diff -r ea90da16a5e2 -r fecd4f6c01ed PLCOpenEditor.py --- a/PLCOpenEditor.py Mon Dec 07 13:37:27 2009 +0100 +++ b/PLCOpenEditor.py Mon Dec 07 13:38:16 2009 +0100 @@ -1729,6 +1729,8 @@ item, root_cookie = self.InstancesTree.GetNextChild(root, root_cookie) for item in to_delete: self.InstancesTree.Delete(item) + if infos["type"] in [ITEM_CONFIGURATION, ITEM_RESOURCE]: + self.InstancesTree.Expand(root) def OnInstancesTreeBeginDrag(self, event): if self.Controler.DebugAvailable(): @@ -3919,6 +3921,11 @@ elif colname == "Value": self.data[row].SetValue(value) + def IsForced(self, row): + if row < self.GetNumberRows(): + return self.data[row].IsForced() + return False + def ResetView(self, grid): """ (wx.grid.Grid) -> Reset the grid view. Call this to @@ -4071,6 +4078,7 @@ self.VariablesGrid.SetSelectionBackground(wx.WHITE) self.VariablesGrid.SetSelectionForeground(wx.BLACK) self.VariablesGrid.SetDropTarget(DebugVariableDropTarget(self)) + self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.OnVariablesGridRightClick) self.UpButton = wx.Button(id=ID_DEBUGVARIABLEPANELUPBUTTON, label='^', name='UpButton', parent=self, pos=wx.Point(0, 0), @@ -4124,6 +4132,39 @@ self.Table.ResetView(self.VariablesGrid) self.Thaw() + def GetForceVariableMenuFunction(self, iec_path): + iec_type = self.GetDataType(iec_path) + def ForceVariableFunction(event): + if iec_type is not None: + dialog = ForceVariableDialog(self, iec_type) + if dialog.ShowModal() == wx.ID_OK: + self.ForceDataValue(iec_path, dialog.GetValue()) + return ForceVariableFunction + + def GetReleaseVariableMenuFunction(self, iec_path): + def ReleaseVariableFunction(event): + self.ReleaseDataValue(iec_path) + return ReleaseVariableFunction + + def OnVariablesGridRightClick(self, event): + row, col = event.GetRow(), event.GetCol() + if self.Table.GetColLabelValue(col, False) == "Value": + iec_path = self.Table.GetValueByName(row, "Variable").upper() + + menu = wx.Menu(title='') + new_id = wx.NewId() + AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Force value")) + self.Bind(wx.EVT_MENU, self.GetForceVariableMenuFunction(iec_path.upper()), id=new_id) + new_id = wx.NewId() + AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Release value")) + self.Bind(wx.EVT_MENU, self.GetReleaseVariableMenuFunction(iec_path.upper()), id=new_id) + if self.Table.IsForced(row): + menu.Enable(new_id, True) + else: + menu.Enable(new_id, False) + self.PopupMenu(menu) + event.Skip() + def OnDeleteButton(self, event): idx = self.VariablesGrid.GetGridCursorRow() item = self.Table.GetItem(idx)