author | Laurent Bessard |
Thu, 10 Oct 2013 14:46:03 +0200 | |
changeset 1354 | 241c19ea80da |
parent 1214 | 2ef048b5383c |
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 |
1209 | 164 |
|
165 |
# Check that data is valid regarding DebugVariablePanel |
|
814 | 166 |
try: |
167 |
values = eval(data) |
|
1207 | 168 |
if not isinstance(values, TupleType): |
169 |
raise ValueError |
|
814 | 170 |
except: |
1207 | 171 |
message = _("Invalid value \"%s\" for debug variable") % data |
814 | 172 |
values = None |
909
852af7c6f0ef
Adding support for change DebugVariablePanel 2D graphs layout using drag'n drop
Laurent Bessard
parents:
907
diff
changeset
|
173 |
|
1209 | 174 |
# Display message if data is invalid |
814 | 175 |
if message is not None: |
176 |
wx.CallAfter(self.ShowMessage, message) |
|
1207 | 177 |
|
1209 | 178 |
# Data contain a reference to a variable to debug |
1207 | 179 |
elif values[1] == "debug": |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
180 |
grid = self.ParentWindow.VariablesGrid |
1207 | 181 |
|
182 |
# 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
|
183 |
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
|
184 |
row = grid.YToRow(y - grid.GetColLabelSize()) |
1207 | 185 |
|
186 |
# 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
|
187 |
if row == wx.NOT_FOUND: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
188 |
row = self.ParentWindow.Table.GetNumberRows() |
1207 | 189 |
|
190 |
# Add variable to table |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
191 |
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
|
192 |
|
814 | 193 |
def ShowMessage(self, message): |
1207 | 194 |
""" |
195 |
Show error message in Error Dialog |
|
196 |
@param message: Error message to display |
|
197 |
""" |
|
198 |
dialog = wx.MessageDialog(self.ParentWindow, |
|
199 |
message, |
|
200 |
_("Error"), |
|
201 |
wx.OK|wx.ICON_ERROR) |
|
814 | 202 |
dialog.ShowModal() |
203 |
dialog.Destroy() |
|
1207 | 204 |
|
205 |
||
206 |
#------------------------------------------------------------------------------- |
|
207 |
# Debug Variable Table Panel |
|
208 |
#------------------------------------------------------------------------------- |
|
209 |
||
210 |
""" |
|
211 |
Class that implements a panel displaying debug variable values in a table |
|
212 |
""" |
|
213 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
214 |
class DebugVariableTablePanel(wx.Panel, DebugViewer): |
814 | 215 |
|
902
ffa8ee5ee2fe
Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents:
898
diff
changeset
|
216 |
def __init__(self, parent, producer, window): |
1207 | 217 |
""" |
218 |
Constructor |
|
219 |
@param parent: Reference to the parent wx.Window |
|
220 |
@param producer: Object receiving debug value and dispatching them to |
|
221 |
consumers |
|
222 |
@param window: Reference to Beremiz frame |
|
223 |
""" |
|
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
|
224 |
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
|
225 |
|
1207 | 226 |
# 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
|
227 |
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
|
228 |
|
1207 | 229 |
# Variable storing flag indicating that variable displayed in table |
230 |
# received new value and then table need to be refreshed |
|
814 | 231 |
self.HasNewData = False |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
232 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
233 |
DebugViewer.__init__(self, producer, True) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
234 |
|
1207 | 235 |
# Construction of window layout by creating controls and sizers |
236 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
237 |
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
|
238 |
main_sizer.AddGrowableCol(0) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
239 |
main_sizer.AddGrowableRow(1) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
240 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
241 |
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
|
242 |
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
|
243 |
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
|
244 |
|
1207 | 245 |
# Creation of buttons for navigating in table |
246 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
247 |
for name, bitmap, help in [ |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
248 |
("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
|
249 |
("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
|
250 |
("DownButton", "down", _("Move debug variable down"))]: |
1207 | 251 |
button = wx.lib.buttons.GenBitmapButton(self, |
252 |
bitmap=GetBitmap(bitmap), |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
253 |
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
|
254 |
button.SetToolTipString(help) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
255 |
setattr(self, name, button) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
256 |
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
|
257 |
|
1207 | 258 |
# Creation of grid and associated table |
259 |
||
260 |
self.VariablesGrid = CustomGrid(self, |
|
261 |
size=wx.Size(-1, 150), style=wx.VSCROLL) |
|
262 |
# Define grid drop target |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
263 |
self.VariablesGrid.SetDropTarget(DebugVariableTableDropTarget(self)) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
264 |
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
|
265 |
self.OnVariablesGridCellRightClick) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
266 |
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
|
267 |
self.OnVariablesGridCellLeftClick) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
268 |
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
|
269 |
|
1207 | 270 |
self.Table = DebugVariableTable(self, [], |
271 |
GetDebugVariablesTableColnames()) |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
272 |
self.VariablesGrid.SetTable(self.Table) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
273 |
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
|
274 |
"Up": self.UpButton, |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
275 |
"Down": self.DownButton}) |
1207 | 276 |
|
277 |
# Definition of function associated to navigation buttons |
|
278 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
279 |
def _AddVariable(new_row): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
280 |
return self.VariablesGrid.GetGridCursorRow() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
281 |
setattr(self.VariablesGrid, "_AddRow", _AddVariable) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
282 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
283 |
def _DeleteVariable(row): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
284 |
item = self.Table.GetItem(row) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
285 |
self.RemoveDataConsumer(item) |
1207 | 286 |
self.Table.RemoveItem(item) |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
287 |
self.RefreshView() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
288 |
setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
289 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
290 |
def _MoveVariable(row, move): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
291 |
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
|
292 |
if new_row != row: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
293 |
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
|
294 |
self.RefreshView() |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
295 |
return new_row |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
296 |
setattr(self.VariablesGrid, "_MoveRow", _MoveVariable) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
297 |
|
1207 | 298 |
# Initialization of grid layout |
299 |
||
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
300 |
self.VariablesGrid.SetRowLabelSize(0) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
301 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
302 |
self.GridColSizes = [200, 100] |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
303 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
304 |
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
|
305 |
attr = wx.grid.GridCellAttr() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
306 |
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
|
307 |
self.VariablesGrid.SetColAttr(col, attr) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
308 |
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
|
309 |
|
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
310 |
self.Table.ResetView(self.VariablesGrid) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
311 |
self.VariablesGrid.RefreshButtons() |
1192
d8783c0c7d80
Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents:
1191
diff
changeset
|
312 |
|
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
|
313 |
self.SetSizer(main_sizer) |
1192
d8783c0c7d80
Fixed bugs in DebugVariablePanel with ticktime modifications
Laurent Bessard
parents:
1191
diff
changeset
|
314 |
|
902
ffa8ee5ee2fe
Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents:
898
diff
changeset
|
315 |
def RefreshNewData(self, *args, **kwargs): |
1207 | 316 |
""" |
317 |
Called to refresh Table according to values received by variables |
|
318 |
Can receive any parameters (not used here) |
|
319 |
""" |
|
320 |
# Refresh 'Value' column of table if new data have been received since |
|
321 |
# last refresh |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
322 |
if self.HasNewData: |
814 | 323 |
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
|
324 |
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
|
325 |
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
|
326 |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
327 |
def RefreshView(self, only_values=False): |
1207 | 328 |
""" |
329 |
Function refreshing table layout and values |
|
330 |
@param only_values: True if only 'Value' column need to be updated |
|
331 |
""" |
|
332 |
# 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
|
333 |
self.Freeze() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
334 |
|
1207 | 335 |
# 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
|
336 |
if only_values: |
1207 | 337 |
self.Table.RefreshValues(self.VariablesGrid) |
338 |
||
339 |
# Update complete table layout refreshing table navigation buttons |
|
340 |
# state according to |
|
929
c562031146e4
Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents:
928
diff
changeset
|
341 |
else: |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
342 |
self.Table.ResetView(self.VariablesGrid) |
1207 | 343 |
self.VariablesGrid.RefreshButtons() |
344 |
||
345 |
self.Thaw() |
|
346 |
||
347 |
def ResetView(self): |
|
348 |
""" |
|
349 |
Function removing all variables denugged from table |
|
350 |
@param only_values: True if only 'Value' column need to be updated |
|
351 |
""" |
|
352 |
# Unsubscribe all variables debugged |
|
353 |
self.UnsubscribeAllDataConsumers() |
|
354 |
||
355 |
# Clear table content |
|
356 |
self.Table.Empty() |
|
357 |
||
358 |
# Update table layout |
|
359 |
self.Freeze() |
|
360 |
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
|
361 |
self.VariablesGrid.RefreshButtons() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
362 |
self.Thaw() |
1207 | 363 |
|
364 |
def SubscribeAllDataConsumers(self): |
|
365 |
""" |
|
366 |
Function refreshing table layout and values |
|
367 |
@param only_values: True if only 'Value' column need to be updated |
|
368 |
""" |
|
369 |
DebugViewer.SubscribeAllDataConsumers(self) |
|
370 |
||
371 |
# Navigate through variable displayed in table, removing those that |
|
372 |
# doesn't exist anymore in PLC |
|
373 |
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
|
374 |
iec_path = item.GetVariable() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
375 |
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
|
376 |
self.RemoveDataConsumer(item) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
377 |
self.Table.RemoveItem(idx) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
378 |
else: |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
379 |
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
|
380 |
item.RefreshVariableType() |
1207 | 381 |
|
382 |
# Update table layout |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
383 |
self.Freeze() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
384 |
self.Table.ResetView(self.VariablesGrid) |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
385 |
self.VariablesGrid.RefreshButtons() |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
386 |
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
|
387 |
|
1207 | 388 |
def GetForceVariableMenuFunction(self, item): |
389 |
""" |
|
390 |
Function returning callback function for contextual menu 'Force' item |
|
391 |
@param item: Debug Variable item where contextual menu was opened |
|
392 |
@return: Callback function |
|
393 |
""" |
|
814 | 394 |
def ForceVariableFunction(event): |
1207 | 395 |
# Get variable path and data type |
396 |
iec_path = item.GetVariable() |
|
397 |
iec_type = self.GetDataType(iec_path) |
|
398 |
||
399 |
# Return immediately if not data type found |
|
400 |
if iec_type is None: |
|
401 |
return |
|
402 |
||
403 |
# Open dialog for entering value to force variable |
|
404 |
dialog = ForceVariableDialog(self, iec_type, str(item.GetValue())) |
|
405 |
||
406 |
# If valid value entered, force variable |
|
407 |
if dialog.ShowModal() == wx.ID_OK: |
|
408 |
self.ForceDataValue(iec_path.upper(), dialog.GetValue()) |
|
409 |
||
814 | 410 |
return ForceVariableFunction |
411 |
||
412 |
def GetReleaseVariableMenuFunction(self, iec_path): |
|
1207 | 413 |
""" |
414 |
Function returning callback function for contextual menu 'Release' item |
|
415 |
@param iec_path: Debug Variable path where contextual menu was opened |
|
416 |
@return: Callback function |
|
417 |
""" |
|
814 | 418 |
def ReleaseVariableFunction(event): |
1207 | 419 |
# Release variable |
814 | 420 |
self.ReleaseDataValue(iec_path) |
421 |
return ReleaseVariableFunction |
|
422 |
||
892
771581a6b0be
Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents:
888
diff
changeset
|
423 |
def OnVariablesGridCellLeftClick(self, event): |
1207 | 424 |
""" |
425 |
Called when left mouse button is pressed on a table cell |
|
426 |
@param event: wx.grid.GridEvent |
|
427 |
""" |
|
428 |
# Initiate a drag and drop if the cell clicked was in 'Variable' column |
|
429 |
if self.Table.GetColLabelValue(event.GetCol(), False) == "Variable": |
|
430 |
item = self.Table.GetItem(event.GetRow()) |
|
431 |
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
|
432 |
dragSource = wx.DropSource(self.VariablesGrid) |
771581a6b0be
Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents:
888
diff
changeset
|
433 |
dragSource.SetData(data) |
771581a6b0be
Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents:
888
diff
changeset
|
434 |
dragSource.DoDragDrop() |
1207 | 435 |
|
892
771581a6b0be
Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents:
888
diff
changeset
|
436 |
event.Skip() |
771581a6b0be
Fix bug with representation of string variable value in DebugVariablePanel
Laurent Bessard
parents:
888
diff
changeset
|
437 |
|
814 | 438 |
def OnVariablesGridCellRightClick(self, event): |
1207 | 439 |
""" |
440 |
Called when right mouse button is pressed on a table cell |
|
441 |
@param event: wx.grid.GridEvent |
|
442 |
""" |
|
443 |
# Open a contextual menu if the cell clicked was in 'Value' column |
|
444 |
if self.Table.GetColLabelValue(event.GetCol(), False) == "Value": |
|
445 |
row = event.GetRow() |
|
446 |
||
447 |
# Get variable path |
|
448 |
item = self.Table.GetItem(row) |
|
449 |
iec_path = item.GetVariable().upper() |
|
450 |
||
451 |
# Create contextual menu |
|
814 | 452 |
menu = wx.Menu(title='') |
453 |
||
1207 | 454 |
# Add menu items |
455 |
for text, enable, callback in [ |
|
456 |
(_("Force value"), True, |
|
457 |
self.GetForceVariableMenuFunction(item)), |
|
458 |
# Release menu item is enabled only if variable is forced |
|
459 |
(_("Release value"), self.Table.IsForced(row), |
|
460 |
self.GetReleaseVariableMenuFunction(iec_path))]: |
|
461 |
||
462 |
new_id = wx.NewId() |
|
463 |
menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text) |
|
464 |
menu.Enable(new_id, enable) |
|
465 |
self.Bind(wx.EVT_MENU, callback, id=new_id) |
|
466 |
||
467 |
# Popup contextual menu |
|
814 | 468 |
self.PopupMenu(menu) |
469 |
||
470 |
menu.Destroy() |
|
471 |
event.Skip() |
|
472 |
||
1214
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1209
diff
changeset
|
473 |
def InsertValue(self, iec_path, index=None, force=False, graph=False): |
1207 | 474 |
""" |
475 |
Insert a new variable to debug in table |
|
476 |
@param iec_path: Variable path to debug |
|
477 |
@param index: Row where insert the variable in table (default None, |
|
478 |
insert at last position) |
|
479 |
@param force: Force insertion of variable even if not defined in |
|
480 |
producer side |
|
1214
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1209
diff
changeset
|
481 |
@param graph: Values must be displayed in graph canvas (Do nothing, |
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1209
diff
changeset
|
482 |
here for compatibility with Debug Variable Graphic Panel) |
1207 | 483 |
""" |
484 |
# 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
|
485 |
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
|
486 |
if iec_path == item.GetVariable(): |
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
487 |
return |
1207 | 488 |
|
489 |
# Insert at last position if index not defined |
|
490 |
if index is None: |
|
491 |
index = self.Table.GetNumberRows() |
|
492 |
||
493 |
# Subscribe variable to producer |
|
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
494 |
item = DebugVariableItem(self, iec_path) |
814 | 495 |
result = self.AddDataConsumer(iec_path.upper(), item) |
1207 | 496 |
|
497 |
# Insert variable in table if subscription done or insertion forced |
|
814 | 498 |
if result is not None or force: |
1207 | 499 |
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
|
500 |
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
|
501 |
|
887
d3c6c4ab8b28
Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents:
878
diff
changeset
|
502 |
def ResetGraphicsValues(self): |
1207 | 503 |
""" |
504 |
Called to reset graphics values when PLC is started |
|
505 |
(Nothing to do because no graphic values here. Defined for |
|
506 |
compatibility with Debug Variable Graphic Panel) |
|
507 |
""" |
|
988
30e7571c10d0
Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents:
980
diff
changeset
|
508 |
pass |
1198
8b4e6bd0aa92
Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents:
1194
diff
changeset
|
509 |