author | Laurent Bessard |
Fri, 31 May 2013 18:32:51 +0200 | |
changeset 1207 | fb9799a0c0f7 |
parent 1202 | 3d8c87ab2b5d |
child 1209 | 953a8f14040a |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
7 |
#Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
25 |
from types import TupleType |
814 | 26 |
|
27 |
import wx |
|
28 |
import wx.lib.buttons |
|
888
baf5dbfd28f4
Adding support for disabling 2D and 3D graphics in DebugVariablePanel when matplotlib is not installed
Laurent Bessard
parents:
887
diff
changeset
|
29 |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
30 |
from editors.DebugViewer import DebugViewer |
814 | 31 |
from controls import CustomGrid, CustomTable |
32 |
from dialogs.ForceVariableDialog import ForceVariableDialog |
|
33 |
from util.BitmapLibrary import GetBitmap |
|
34 |
||
1199
fc0e7d80494f
Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents:
1198
diff
changeset
|
35 |
from DebugVariableItem import DebugVariableItem |
fc0e7d80494f
Move GraphButton from DebugVariableGraphicPanel to separate file
Laurent Bessard
parents:
1198
diff
changeset
|
36 |
|
814 | 37 |
def GetDebugVariablesTableColnames(): |
1207 | 38 |
""" |
39 |
Function returning table column header labels |
|
40 |
@return: List of labels [col_label,...] |
|
41 |
""" |
|
814 | 42 |
_ = lambda x : x |
909
852af7c6f0ef
Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents:
907
diff
changeset
|
43 |
return [_("Variable"), _("Value")] |
924
5f2cc382be8c
Added support for displaying string variables variations in a graph and cursor on graphs
Laurent Bessard
parents:
919
diff
changeset
|
44 |
|
1207 | 45 |
#------------------------------------------------------------------------------- |
46 |
# Debug Variable Table Panel |
|
47 |
#------------------------------------------------------------------------------- |
|
48 |
||
49 |
""" |
|
50 |
Class that implements a custom table storing value to display in Debug Variable |
|
51 |
Table Panel grid |
|
52 |
""" |
|
53 |
||
814 | 54 |
class DebugVariableTable(CustomTable): |
55 |
||
56 |
def GetValue(self, row, col): |
|
57 |
if row < self.GetNumberRows(): |
|
58 |
return self.GetValueByName(row, self.GetColLabelValue(col, False)) |
|
59 |
return "" |
|
60 |
||
61 |
def SetValue(self, row, col, value): |
|
62 |
if col < len(self.colnames): |
|
63 |
self.SetValueByName(row, self.GetColLabelValue(col, False), value) |
|
64 |
||
65 |
def GetValueByName(self, row, colname): |
|
66 |
if row < self.GetNumberRows(): |
|
67 |
if colname == "Variable": |
|
68 |
return self.data[row].GetVariable() |
|
69 |
elif colname == "Value": |
|
70 |
return self.data[row].GetValue() |
|
71 |
return "" |
|
72 |
||
73 |
def SetValueByName(self, row, colname, value): |
|
74 |
if row < self.GetNumberRows(): |
|
75 |
if colname == "Variable": |
|
76 |
self.data[row].SetVariable(value) |
|
77 |
elif colname == "Value": |
|
78 |
self.data[row].SetValue(value) |
|
79 |
||
80 |
def IsForced(self, row): |
|
81 |
if row < self.GetNumberRows(): |
|
82 |
return self.data[row].IsForced() |
|
83 |
return False |
|
84 |
||
85 |
def _updateColAttrs(self, grid): |
|
86 |
""" |
|
87 |
wx.grid.Grid -> update the column attributes to add the |
|
88 |
appropriate renderer given the column name. |
|
89 |
||
90 |
Otherwise default to the default renderer. |
|
91 |
""" |
|
92 |
||
93 |
for row in range(self.GetNumberRows()): |
|
94 |
for col in range(self.GetNumberCols()): |
|
887
d3c6c4ab8b28
Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents:
878
diff
changeset
|
95 |
colname = self.GetColLabelValue(col, False) |
909
852af7c6f0ef
Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents:
907
diff
changeset
|
96 |
if colname == "Value": |
852af7c6f0ef
Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents:
907
diff
changeset
|
97 |
if self.IsForced(row): |
852af7c6f0ef
Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents:
907
diff
changeset
|
98 |
grid.SetCellTextColour(row, col, wx.BLUE) |
814 | 99 |
else: |
909
852af7c6f0ef
Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents:
907
diff
changeset
|
100 |
grid.SetCellTextColour(row, col, wx.BLACK) |
852af7c6f0ef
Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents:
907
diff
changeset
|
101 |
grid.SetReadOnly(row, col, True) |
814 | 102 |
self.ResizeRow(grid, row) |
1207 | 103 |
|
104 |
def RefreshValues(self, grid): |
|
105 |
for col in xrange(self.GetNumberCols()): |
|
106 |
colname = self.GetColLabelValue(col, False) |
|
107 |
if colname == "Value": |
|
108 |
for row in xrange(self.GetNumberRows()): |
|
109 |
grid.SetCellValue(row, col, str(self.data[row].GetValue())) |
|
110 |
if self.IsForced(row): |
|
111 |
grid.SetCellTextColour(row, col, wx.BLUE) |
|
112 |
else: |
|
113 |
grid.SetCellTextColour(row, col, wx.BLACK) |
|
114 |
||
115 |
def AppendItem(self, item): |
|
116 |
self.data.append(item) |
|
117 |
||
118 |
def InsertItem(self, idx, item): |
|
119 |
self.data.insert(idx, item) |
|
120 |
||
121 |
def RemoveItem(self, item): |
|
122 |
self.data.remove(item) |
|
814 | 123 |
|
124 |
def MoveItem(self, idx, new_idx): |
|
125 |
self.data.insert(new_idx, self.data.pop(idx)) |
|
126 |
||
127 |
def GetItem(self, idx): |
|
128 |
return self.data[idx] |
|
129 |
||
1207 | 130 |
|
131 |
#------------------------------------------------------------------------------- |
|
132 |
# Debug Variable Table Panel Drop Target |
|
133 |
#------------------------------------------------------------------------------- |
|
134 |
||
135 |
""" |
|
136 |
Class that implements a custom drop target class for Debug Variable Table Panel |
|
137 |
""" |
|
138 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
139 |
class DebugVariableTableDropTarget(wx.TextDropTarget): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
140 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
141 |
def __init__(self, parent): |
1207 | 142 |
""" |
143 |
Constructor |
|
144 |
@param window: Reference to the Debug Variable Panel |
|
145 |
""" |
|
814 | 146 |
wx.TextDropTarget.__init__(self) |
147 |
self.ParentWindow = parent |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
148 |
|
916
697d8b77d716
Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents:
912
diff
changeset
|
149 |
def __del__(self): |
1207 | 150 |
""" |
151 |
Destructor |
|
152 |
""" |
|
153 |
# Remove reference to Debug Variable Panel |
|
916
697d8b77d716
Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents:
912
diff
changeset
|
154 |
self.ParentWindow = None |
928
a94e7fea7051
Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents:
927
diff
changeset
|
155 |
|
814 | 156 |
def OnDropText(self, x, y, data): |
1207 | 157 |
""" |
158 |
Function called when mouse is dragged over Drop Target |
|
159 |
@param x: X coordinate of mouse pointer |
|
160 |
@param y: Y coordinate of mouse pointer |
|
161 |
@param data: Text associated to drag'n drop |
|
162 |
""" |
|
814 | 163 |
message = None |
164 |
try: |
|
165 |
values = eval(data) |
|
1207 | 166 |
if not isinstance(values, TupleType): |
167 |
raise ValueError |
|
814 | 168 |
except: |
1207 | 169 |
message = _("Invalid value \"%s\" for debug variable") % data |
814 | 170 |
values = None |
909
852af7c6f0ef
Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents:
907
diff
changeset
|
171 |
|
814 | 172 |
if message is not None: |
173 |
wx.CallAfter(self.ShowMessage, message) |
|
1207 | 174 |
|
175 |
elif values[1] == "debug": |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
176 |
grid = self.ParentWindow.VariablesGrid |
1207 | 177 |
|
178 |
# Get row where variable was dropped |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
179 |
x, y = grid.CalcUnscrolledPosition(x, y) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
180 |
row = grid.YToRow(y - grid.GetColLabelSize()) |
1207 | 181 |
|
182 |
# If no row found add variable at table end |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
183 |
if row == wx.NOT_FOUND: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
184 |
row = self.ParentWindow.Table.GetNumberRows() |
1207 | 185 |
|
186 |
# Add variable to table |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
187 |
self.ParentWindow.InsertValue(values[0], row, force=True) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
188 |
|
814 | 189 |
def ShowMessage(self, message): |
1207 | 190 |
""" |
191 |
Show error message in Error Dialog |
|
192 |
@param message: Error message to display |
|
193 |
""" |
|
194 |
dialog = wx.MessageDialog(self.ParentWindow, |
|
195 |
message, |
|
196 |
_("Error"), |
|
197 |
wx.OK|wx.ICON_ERROR) |
|
814 | 198 |
dialog.ShowModal() |
199 |
dialog.Destroy() |
|
1207 | 200 |
|
201 |
||
202 |
#------------------------------------------------------------------------------- |
|
203 |
# Debug Variable Table Panel |
|
204 |
#------------------------------------------------------------------------------- |
|
205 |
||
206 |
""" |
|
207 |
Class that implements a panel displaying debug variable values in a table |
|
208 |
""" |
|
209 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
210 |
class DebugVariableTablePanel(wx.Panel, DebugViewer): |
814 | 211 |
|
902
ffa8ee5ee2fe
Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents:
898
diff
changeset
|
212 |
def __init__(self, parent, producer, window): |
1207 | 213 |
""" |
214 |
Constructor |
|
215 |
@param parent: Reference to the parent wx.Window |
|
216 |
@param producer: Object receiving debug value and dispatching them to |
|
217 |
consumers |
|
218 |
@param window: Reference to Beremiz frame |
|
219 |
""" |
|
916
697d8b77d716
Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents:
912
diff
changeset
|
220 |
wx.Panel.__init__(self, parent, style=wx.SP_3D|wx.TAB_TRAVERSAL) |
902
ffa8ee5ee2fe
Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents:
898
diff
changeset
|
221 |
|
1207 | 222 |
# Save Reference to Beremiz frame |
902
ffa8ee5ee2fe
Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents:
898
diff
changeset
|
223 |
self.ParentWindow = window |
ffa8ee5ee2fe
Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents:
898
diff
changeset
|
224 |
|
1207 | 225 |
# Variable storing flag indicating that variable displayed in table |
226 |
# received new value and then table need to be refreshed |
|
814 | 227 |
self.HasNewData = False |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
228 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
229 |
DebugViewer.__init__(self, producer, True) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
230 |
|
1207 | 231 |
# Construction of window layout by creating controls and sizers |
232 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
233 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
234 |
main_sizer.AddGrowableCol(0) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
235 |
main_sizer.AddGrowableRow(1) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
236 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
237 |
button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
238 |
main_sizer.AddSizer(button_sizer, border=5, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
239 |
flag=wx.ALIGN_RIGHT|wx.ALL) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
240 |
|
1207 | 241 |
# Creation of buttons for navigating in table |
242 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
243 |
for name, bitmap, help in [ |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
244 |
("DeleteButton", "remove_element", _("Remove debug variable")), |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
245 |
("UpButton", "up", _("Move debug variable up")), |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
246 |
("DownButton", "down", _("Move debug variable down"))]: |
1207 | 247 |
button = wx.lib.buttons.GenBitmapButton(self, |
248 |
bitmap=GetBitmap(bitmap), |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
249 |
size=wx.Size(28, 28), style=wx.NO_BORDER) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
250 |
button.SetToolTipString(help) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
251 |
setattr(self, name, button) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
252 |
button_sizer.AddWindow(button, border=5, flag=wx.LEFT) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
253 |
|
1207 | 254 |
# Creation of grid and associated table |
255 |
||
256 |
self.VariablesGrid = CustomGrid(self, |
|
257 |
size=wx.Size(-1, 150), style=wx.VSCROLL) |
|
258 |
# Define grid drop target |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
259 |
self.VariablesGrid.SetDropTarget(DebugVariableTableDropTarget(self)) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
260 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
261 |
self.OnVariablesGridCellRightClick) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
262 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
263 |
self.OnVariablesGridCellLeftClick) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
264 |
main_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
265 |
|
1207 | 266 |
self.Table = DebugVariableTable(self, [], |
267 |
GetDebugVariablesTableColnames()) |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
268 |
self.VariablesGrid.SetTable(self.Table) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
269 |
self.VariablesGrid.SetButtons({"Delete": self.DeleteButton, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
270 |
"Up": self.UpButton, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
271 |
"Down": self.DownButton}) |
1207 | 272 |
|
273 |
# Definition of function associated to navigation buttons |
|
274 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
275 |
def _AddVariable(new_row): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
276 |
return self.VariablesGrid.GetGridCursorRow() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
277 |
setattr(self.VariablesGrid, "_AddRow", _AddVariable) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
278 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
279 |
def _DeleteVariable(row): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
280 |
item = self.Table.GetItem(row) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
281 |
self.RemoveDataConsumer(item) |
1207 | 282 |
self.Table.RemoveItem(item) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
283 |
self.RefreshView() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
284 |
setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
285 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
286 |
def _MoveVariable(row, move): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
287 |
new_row = max(0, min(row + move, self.Table.GetNumberRows() - 1)) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
288 |
if new_row != row: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
289 |
self.Table.MoveItem(row, new_row) |
916
697d8b77d716
Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents:
912
diff
changeset
|
290 |
self.RefreshView() |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
291 |
return new_row |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
292 |
setattr(self.VariablesGrid, "_MoveRow", _MoveVariable) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
293 |
|
1207 | 294 |
# Initialization of grid layout |
295 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
296 |
self.VariablesGrid.SetRowLabelSize(0) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
297 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
298 |
self.GridColSizes = [200, 100] |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
299 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
300 |
for col in range(self.Table.GetNumberCols()): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
301 |
attr = wx.grid.GridCellAttr() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
302 |
attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
303 |
self.VariablesGrid.SetColAttr(col, attr) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
304 |
self.VariablesGrid.SetColSize(col, self.GridColSizes[col]) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
305 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
306 |
self.Table.ResetView(self.VariablesGrid) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
307 |
self.VariablesGrid.RefreshButtons() |
1192
d8783c0c7d80
Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents:
1191
diff
changeset
|
308 |
|
916
697d8b77d716
Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents:
912
diff
changeset
|
309 |
self.SetSizer(main_sizer) |
1192
d8783c0c7d80
Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents:
1191
diff
changeset
|
310 |
|
902
ffa8ee5ee2fe
Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents:
898
diff
changeset
|
311 |
def RefreshNewData(self, *args, **kwargs): |
1207 | 312 |
""" |
313 |
Called to refresh Table according to values received by variables |
|
314 |
Can receive any parameters (not used here) |
|
315 |
""" |
|
316 |
# Refresh 'Value' column of table if new data have been received since |
|
317 |
# last refresh |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
318 |
if self.HasNewData: |
814 | 319 |
self.HasNewData = False |
916
697d8b77d716
Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents:
912
diff
changeset
|
320 |
self.RefreshView(only_values=True) |
902
ffa8ee5ee2fe
Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents:
898
diff
changeset
|
321 |
DebugViewer.RefreshNewData(self, *args, **kwargs) |
ffa8ee5ee2fe
Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents:
898
diff
changeset
|
322 |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
323 |
def RefreshView(self, only_values=False): |
1207 | 324 |
""" |
325 |
Function refreshing table layout and values |
|
326 |
@param only_values: True if only 'Value' column need to be updated |
|
327 |
""" |
|
328 |
# Block refresh until table layout and values are completely updated |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
329 |
self.Freeze() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
330 |
|
1207 | 331 |
# Update only 'value' column from table |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
332 |
if only_values: |
1207 | 333 |
self.Table.RefreshValues(self.VariablesGrid) |
334 |
||
335 |
# Update complete table layout refreshing table navigation buttons |
|
336 |
# state according to |
|
929
c562031146e4
Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents:
928
diff
changeset
|
337 |
else: |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
338 |
self.Table.ResetView(self.VariablesGrid) |
1207 | 339 |
self.VariablesGrid.RefreshButtons() |
340 |
||
341 |
self.Thaw() |
|
342 |
||
343 |
def ResetView(self): |
|
344 |
""" |
|
345 |
Function removing all variables denugged from table |
|
346 |
@param only_values: True if only 'Value' column need to be updated |
|
347 |
""" |
|
348 |
# Unsubscribe all variables debugged |
|
349 |
self.UnsubscribeAllDataConsumers() |
|
350 |
||
351 |
# Clear table content |
|
352 |
self.Table.Empty() |
|
353 |
||
354 |
# Update table layout |
|
355 |
self.Freeze() |
|
356 |
self.Table.ResetView(self.VariablesGrid) |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
357 |
self.VariablesGrid.RefreshButtons() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
358 |
self.Thaw() |
1207 | 359 |
|
360 |
def SubscribeAllDataConsumers(self): |
|
361 |
""" |
|
362 |
Function refreshing table layout and values |
|
363 |
@param only_values: True if only 'Value' column need to be updated |
|
364 |
""" |
|
365 |
DebugViewer.SubscribeAllDataConsumers(self) |
|
366 |
||
367 |
# Navigate through variable displayed in table, removing those that |
|
368 |
# doesn't exist anymore in PLC |
|
369 |
for item in self.Table.GetData()[:]: |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
370 |
iec_path = item.GetVariable() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
371 |
if self.GetDataType(iec_path) is None: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
372 |
self.RemoveDataConsumer(item) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
373 |
self.Table.RemoveItem(idx) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
374 |
else: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
375 |
self.AddDataConsumer(iec_path.upper(), item) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
376 |
item.RefreshVariableType() |
1207 | 377 |
|
378 |
# Update table layout |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
379 |
self.Freeze() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
380 |
self.Table.ResetView(self.VariablesGrid) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
381 |
self.VariablesGrid.RefreshButtons() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
382 |
self.Thaw() |
916
697d8b77d716
Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents:
912
diff
changeset
|
383 |
|
1207 | 384 |
def GetForceVariableMenuFunction(self, item): |
385 |
""" |
|
386 |
Function returning callback function for contextual menu 'Force' item |
|
387 |
@param item: Debug Variable item where contextual menu was opened |
|
388 |
@return: Callback function |
|
389 |
""" |
|
814 | 390 |
def ForceVariableFunction(event): |
1207 | 391 |
# Get variable path and data type |
392 |
iec_path = item.GetVariable() |
|
393 |
iec_type = self.GetDataType(iec_path) |
|
394 |
||
395 |
# Return immediately if not data type found |
|
396 |
if iec_type is None: |
|
397 |
return |
|
398 |
||
399 |
# Open dialog for entering value to force variable |
|
400 |
dialog = ForceVariableDialog(self, iec_type, str(item.GetValue())) |
|
401 |
||
402 |
# If valid value entered, force variable |
|
403 |
if dialog.ShowModal() == wx.ID_OK: |
|
404 |
self.ForceDataValue(iec_path.upper(), dialog.GetValue()) |
|
405 |
||
814 | 406 |
return ForceVariableFunction |
407 |
||
408 |
def GetReleaseVariableMenuFunction(self, iec_path): |
|
1207 | 409 |
""" |
410 |
Function returning callback function for contextual menu 'Release' item |
|
411 |
@param iec_path: Debug Variable path where contextual menu was opened |
|
412 |
@return: Callback function |
|
413 |
""" |
|
814 | 414 |
def ReleaseVariableFunction(event): |
1207 | 415 |
# Release variable |
814 | 416 |
self.ReleaseDataValue(iec_path) |
417 |
return ReleaseVariableFunction |
|
418 |
||
892
771581a6b0be
Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents:
888
diff
changeset
|
419 |
def OnVariablesGridCellLeftClick(self, event): |
1207 | 420 |
""" |
421 |
Called when left mouse button is pressed on a table cell |
|
422 |
@param event: wx.grid.GridEvent |
|
423 |
""" |
|
424 |
# Initiate a drag and drop if the cell clicked was in 'Variable' column |
|
425 |
if self.Table.GetColLabelValue(event.GetCol(), False) == "Variable": |
|
426 |
item = self.Table.GetItem(event.GetRow()) |
|
427 |
data = wx.TextDataObject(str((item.GetVariable(), "debug"))) |
|
892
771581a6b0be
Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents:
888
diff
changeset
|
428 |
dragSource = wx.DropSource(self.VariablesGrid) |
771581a6b0be
Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents:
888
diff
changeset
|
429 |
dragSource.SetData(data) |
771581a6b0be
Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents:
888
diff
changeset
|
430 |
dragSource.DoDragDrop() |
1207 | 431 |
|
892
771581a6b0be
Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents:
888
diff
changeset
|
432 |
event.Skip() |
771581a6b0be
Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents:
888
diff
changeset
|
433 |
|
814 | 434 |
def OnVariablesGridCellRightClick(self, event): |
1207 | 435 |
""" |
436 |
Called when right mouse button is pressed on a table cell |
|
437 |
@param event: wx.grid.GridEvent |
|
438 |
""" |
|
439 |
# Open a contextual menu if the cell clicked was in 'Value' column |
|
440 |
if self.Table.GetColLabelValue(event.GetCol(), False) == "Value": |
|
441 |
row = event.GetRow() |
|
442 |
||
443 |
# Get variable path |
|
444 |
item = self.Table.GetItem(row) |
|
445 |
iec_path = item.GetVariable().upper() |
|
446 |
||
447 |
# Create contextual menu |
|
814 | 448 |
menu = wx.Menu(title='') |
449 |
||
1207 | 450 |
# Add menu items |
451 |
for text, enable, callback in [ |
|
452 |
(_("Force value"), True, |
|
453 |
self.GetForceVariableMenuFunction(item)), |
|
454 |
# Release menu item is enabled only if variable is forced |
|
455 |
(_("Release value"), self.Table.IsForced(row), |
|
456 |
self.GetReleaseVariableMenuFunction(iec_path))]: |
|
457 |
||
458 |
new_id = wx.NewId() |
|
459 |
menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text) |
|
460 |
menu.Enable(new_id, enable) |
|
461 |
self.Bind(wx.EVT_MENU, callback, id=new_id) |
|
462 |
||
463 |
# Popup contextual menu |
|
814 | 464 |
self.PopupMenu(menu) |
465 |
||
466 |
menu.Destroy() |
|
467 |
event.Skip() |
|
468 |
||
1207 | 469 |
def InsertValue(self, iec_path, index=None, force=False): |
470 |
""" |
|
471 |
Insert a new variable to debug in table |
|
472 |
@param iec_path: Variable path to debug |
|
473 |
@param index: Row where insert the variable in table (default None, |
|
474 |
insert at last position) |
|
475 |
@param force: Force insertion of variable even if not defined in |
|
476 |
producer side |
|
477 |
""" |
|
478 |
# Return immediately if variable is already debugged |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
479 |
for item in self.Table.GetData(): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
480 |
if iec_path == item.GetVariable(): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
481 |
return |
1207 | 482 |
|
483 |
# Insert at last position if index not defined |
|
484 |
if index is None: |
|
485 |
index = self.Table.GetNumberRows() |
|
486 |
||
487 |
# Subscribe variable to producer |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
488 |
item = DebugVariableItem(self, iec_path) |
814 | 489 |
result = self.AddDataConsumer(iec_path.upper(), item) |
1207 | 490 |
|
491 |
# Insert variable in table if subscription done or insertion forced |
|
814 | 492 |
if result is not None or force: |
1207 | 493 |
self.Table.InsertItem(index, item) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
494 |
self.RefreshView() |
916
697d8b77d716
Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents:
912
diff
changeset
|
495 |
|
887
d3c6c4ab8b28
Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents:
878
diff
changeset
|
496 |
def ResetGraphicsValues(self): |
1207 | 497 |
""" |
498 |
Called to reset graphics values when PLC is started |
|
499 |
(Nothing to do because no graphic values here. Defined for |
|
500 |
compatibility with Debug Variable Graphic Panel) |
|
501 |
""" |
|
988
30e7571c10d0
Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents:
980
diff
changeset
|
502 |
pass |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
503 |