author | Laurent Bessard |
Fri, 25 Oct 2013 09:57:36 +0200 | |
changeset 1371 | 3c55c99b10ab |
parent 1361 | 7158aa054226 |
child 1380 | 10ac2b18437b |
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) 2007: 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 |
||
25 |
import os |
|
26 |
import re |
|
27 |
from types import TupleType, StringType, UnicodeType |
|
28 |
||
29 |
import wx |
|
30 |
import wx.grid |
|
31 |
import wx.lib.buttons |
|
32 |
||
33 |
from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS |
|
34 |
from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD, ERROR_HIGHLIGHT |
|
35 |
from dialogs.ArrayTypeDialog import ArrayTypeDialog |
|
36 |
from CustomGrid import CustomGrid |
|
37 |
from CustomTable import CustomTable |
|
38 |
from LocationCellEditor import LocationCellEditor |
|
39 |
from util.BitmapLibrary import GetBitmap |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
40 |
from PLCControler import _VariableInfos |
814 | 41 |
|
42 |
#------------------------------------------------------------------------------- |
|
43 |
# Helpers |
|
44 |
#------------------------------------------------------------------------------- |
|
45 |
||
1184
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
46 |
def AppendMenu(parent, help, id, kind, text): |
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
47 |
if wx.VERSION >= (2, 6, 0): |
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
48 |
parent.Append(help=help, id=id, kind=kind, text=text) |
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
49 |
else: |
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
50 |
parent.Append(helpString=help, id=id, kind=kind, item=text) |
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
51 |
|
814 | 52 |
[TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, |
53 |
POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES |
|
1184
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
54 |
] = range(10) |
814 | 55 |
|
56 |
def GetVariableTableColnames(location): |
|
57 |
_ = lambda x : x |
|
58 |
if location: |
|
59 |
return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Option"), _("Documentation")] |
|
60 |
return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Option"), _("Documentation")] |
|
61 |
||
62 |
def GetOptions(constant=True, retain=True, non_retain=True): |
|
63 |
_ = lambda x : x |
|
64 |
options = [""] |
|
65 |
if constant: |
|
66 |
options.append(_("Constant")) |
|
67 |
if retain: |
|
68 |
options.append(_("Retain")) |
|
69 |
if non_retain: |
|
70 |
options.append(_("Non-Retain")) |
|
71 |
return options |
|
72 |
OPTIONS_DICT = dict([(_(option), option) for option in GetOptions()]) |
|
73 |
||
74 |
def GetFilterChoiceTransfer(): |
|
75 |
_ = lambda x : x |
|
76 |
return {_("All"): _("All"), _("Interface"): _("Interface"), |
|
77 |
_(" Input"): _("Input"), _(" Output"): _("Output"), _(" InOut"): _("InOut"), |
|
78 |
_(" External"): _("External"), _("Variables"): _("Variables"), _(" Local"): _("Local"), |
|
79 |
_(" Temp"): _("Temp"), _("Global"): _("Global")}#, _("Access") : _("Access")} |
|
80 |
VARIABLE_CHOICES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().iterkeys()]) |
|
81 |
VARIABLE_CLASSES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().itervalues()]) |
|
82 |
||
83 |
CheckOptionForClass = {"Local": lambda x: x, |
|
84 |
"Temp": lambda x: "", |
|
85 |
"Input": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""), |
|
86 |
"InOut": lambda x: "", |
|
87 |
"Output": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""), |
|
88 |
"Global": lambda x: {"Constant": "Constant", "Retain": "Retain"}.get(x, ""), |
|
89 |
"External": lambda x: {"Constant": "Constant"}.get(x, "") |
|
90 |
} |
|
91 |
||
92 |
LOCATION_MODEL = re.compile("((?:%[IQM](?:\*|(?:[XBWLD]?[0-9]+(?:\.[0-9]+)*)))?)$") |
|
1122
84de51ab40d2
Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents:
1083
diff
changeset
|
93 |
VARIABLE_NAME_SUFFIX_MODEL = re.compile("([0-9]*)$") |
814 | 94 |
|
95 |
#------------------------------------------------------------------------------- |
|
96 |
# Variables Panel Table |
|
97 |
#------------------------------------------------------------------------------- |
|
98 |
||
99 |
class VariableTable(CustomTable): |
|
100 |
||
101 |
""" |
|
102 |
A custom wx.grid.Grid Table using user supplied data |
|
103 |
""" |
|
104 |
def __init__(self, parent, data, colnames): |
|
105 |
# The base class must be initialized *first* |
|
106 |
CustomTable.__init__(self, parent, data, colnames) |
|
107 |
self.old_value = None |
|
108 |
||
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
109 |
def GetValueByName(self, row, colname): |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
110 |
if row < self.GetNumberRows(): |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
111 |
return getattr(self.data[row], colname) |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
112 |
|
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
113 |
def SetValueByName(self, row, colname, value): |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
114 |
if row < self.GetNumberRows(): |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
115 |
setattr(self.data[row], colname, value) |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
116 |
|
814 | 117 |
def GetValue(self, row, col): |
118 |
if row < self.GetNumberRows(): |
|
119 |
if col == 0: |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
120 |
return self.data[row].Number |
814 | 121 |
colname = self.GetColLabelValue(col, False) |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
122 |
if colname == "Initial Value": |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
123 |
colname = "InitialValue" |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
124 |
value = getattr(self.data[row], colname, "") |
814 | 125 |
if colname == "Type" and isinstance(value, TupleType): |
126 |
if value[0] == "array": |
|
127 |
return "ARRAY [%s] OF %s" % (",".join(map(lambda x : "..".join(x), value[2])), value[1]) |
|
128 |
if not isinstance(value, (StringType, UnicodeType)): |
|
129 |
value = str(value) |
|
130 |
if colname in ["Class", "Option"]: |
|
131 |
return _(value) |
|
132 |
return value |
|
133 |
||
134 |
def SetValue(self, row, col, value): |
|
135 |
if col < len(self.colnames): |
|
136 |
colname = self.GetColLabelValue(col, False) |
|
137 |
if colname == "Name": |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
138 |
self.old_value = getattr(self.data[row], colname) |
814 | 139 |
elif colname == "Class": |
140 |
value = VARIABLE_CLASSES_DICT[value] |
|
141 |
self.SetValueByName(row, "Option", CheckOptionForClass[value](self.GetValueByName(row, "Option"))) |
|
142 |
if value == "External": |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
143 |
self.SetValueByName(row, "InitialValue", "") |
814 | 144 |
elif colname == "Option": |
145 |
value = OPTIONS_DICT[value] |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
146 |
elif colname == "Initial Value": |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
147 |
colname = "InitialValue" |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
148 |
setattr(self.data[row], colname, value) |
814 | 149 |
|
150 |
def GetOldValue(self): |
|
151 |
return self.old_value |
|
152 |
||
153 |
def _updateColAttrs(self, grid): |
|
154 |
""" |
|
155 |
wx.grid.Grid -> update the column attributes to add the |
|
156 |
appropriate renderer given the column name. |
|
157 |
||
158 |
Otherwise default to the default renderer. |
|
159 |
""" |
|
160 |
for row in range(self.GetNumberRows()): |
|
161 |
var_class = self.GetValueByName(row, "Class") |
|
162 |
var_type = self.GetValueByName(row, "Type") |
|
163 |
row_highlights = self.Highlights.get(row, {}) |
|
164 |
for col in range(self.GetNumberCols()): |
|
165 |
editor = None |
|
166 |
renderer = None |
|
167 |
colname = self.GetColLabelValue(col, False) |
|
168 |
if self.Parent.Debug: |
|
169 |
grid.SetReadOnly(row, col, True) |
|
170 |
else: |
|
171 |
if colname == "Option": |
|
172 |
options = GetOptions(constant = var_class in ["Local", "External", "Global"], |
|
173 |
retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"], |
|
174 |
non_retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"]) |
|
175 |
if len(options) > 1: |
|
176 |
editor = wx.grid.GridCellChoiceEditor() |
|
177 |
editor.SetParameters(",".join(map(_, options))) |
|
178 |
else: |
|
179 |
grid.SetReadOnly(row, col, True) |
|
180 |
elif col != 0 and self.GetValueByName(row, "Edit"): |
|
181 |
grid.SetReadOnly(row, col, False) |
|
182 |
if colname == "Name": |
|
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
183 |
editor = wx.grid.GridCellTextEditor() |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
184 |
renderer = wx.grid.GridCellStringRenderer() |
814 | 185 |
elif colname == "Initial Value": |
186 |
if var_class not in ["External", "InOut"]: |
|
187 |
if self.Parent.Controler.IsEnumeratedType(var_type): |
|
188 |
editor = wx.grid.GridCellChoiceEditor() |
|
1308
ad61268dbdb6
Replaced old pou variable list and variable tree generating by xslt stylesheet
Laurent Bessard
parents:
1184
diff
changeset
|
189 |
editor.SetParameters(",".join([""] + self.Parent.Controler.GetEnumeratedDataValues(var_type))) |
814 | 190 |
else: |
191 |
editor = wx.grid.GridCellTextEditor() |
|
192 |
renderer = wx.grid.GridCellStringRenderer() |
|
193 |
else: |
|
194 |
grid.SetReadOnly(row, col, True) |
|
195 |
elif colname == "Location": |
|
196 |
if var_class in ["Local", "Global"] and self.Parent.Controler.IsLocatableType(var_type): |
|
197 |
editor = LocationCellEditor(self, self.Parent.Controler) |
|
198 |
renderer = wx.grid.GridCellStringRenderer() |
|
199 |
else: |
|
200 |
grid.SetReadOnly(row, col, True) |
|
201 |
elif colname == "Class": |
|
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
202 |
if len(self.Parent.ClassList) == 1: |
814 | 203 |
grid.SetReadOnly(row, col, True) |
204 |
else: |
|
205 |
editor = wx.grid.GridCellChoiceEditor() |
|
206 |
excluded = [] |
|
207 |
if self.Parent.IsFunctionBlockType(var_type): |
|
208 |
excluded.extend(["Local","Temp"]) |
|
209 |
editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded])) |
|
210 |
elif colname != "Documentation": |
|
211 |
grid.SetReadOnly(row, col, True) |
|
212 |
||
213 |
grid.SetCellEditor(row, col, editor) |
|
214 |
grid.SetCellRenderer(row, col, renderer) |
|
215 |
||
831
dec885ba1f2b
Adding support for signaling that a task interval isn't well formatted
laurent
parents:
830
diff
changeset
|
216 |
if colname == "Location" and LOCATION_MODEL.match(self.GetValueByName(row, colname)) is None: |
814 | 217 |
highlight_colours = ERROR_HIGHLIGHT |
218 |
else: |
|
219 |
highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] |
|
220 |
grid.SetCellBackgroundColour(row, col, highlight_colours[0]) |
|
221 |
grid.SetCellTextColour(row, col, highlight_colours[1]) |
|
222 |
self.ResizeRow(grid, row) |
|
223 |
||
224 |
#------------------------------------------------------------------------------- |
|
225 |
# Variable Panel Drop Target |
|
226 |
#------------------------------------------------------------------------------- |
|
227 |
||
228 |
class VariableDropTarget(wx.TextDropTarget): |
|
229 |
''' |
|
230 |
This allows dragging a variable location from somewhere to the Location |
|
231 |
column of a variable row. |
|
232 |
||
233 |
The drag source should be a TextDataObject containing a Python tuple like: |
|
234 |
('%ID0.0.0', 'location', 'REAL') |
|
235 |
||
236 |
c_ext/CFileEditor.py has an example of this (you can drag a C extension |
|
237 |
variable to the Location column of the variable panel). |
|
238 |
''' |
|
239 |
def __init__(self, parent): |
|
240 |
wx.TextDropTarget.__init__(self) |
|
241 |
self.ParentWindow = parent |
|
242 |
||
243 |
def OnDropText(self, x, y, data): |
|
244 |
self.ParentWindow.ParentWindow.Select() |
|
245 |
x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y) |
|
246 |
col = self.ParentWindow.VariablesGrid.XToCol(x) |
|
247 |
row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize()) |
|
248 |
message = None |
|
249 |
element_type = self.ParentWindow.ElementType |
|
250 |
try: |
|
251 |
values = eval(data) |
|
252 |
except: |
|
253 |
message = _("Invalid value \"%s\" for variable grid element")%data |
|
254 |
values = None |
|
255 |
if not isinstance(values, TupleType): |
|
256 |
message = _("Invalid value \"%s\" for variable grid element")%data |
|
257 |
values = None |
|
258 |
if values is not None: |
|
259 |
if col != wx.NOT_FOUND and row != wx.NOT_FOUND: |
|
260 |
colname = self.ParentWindow.Table.GetColLabelValue(col, False) |
|
261 |
if colname == "Location" and values[1] == "location": |
|
262 |
if not self.ParentWindow.Table.GetValueByName(row, "Edit"): |
|
263 |
message = _("Can't give a location to a function block instance") |
|
264 |
elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]: |
|
265 |
message = _("Can only give a location to local or global variables") |
|
266 |
else: |
|
267 |
location = values[0] |
|
268 |
variable_type = self.ParentWindow.Table.GetValueByName(row, "Type") |
|
269 |
base_type = self.ParentWindow.Controler.GetBaseType(variable_type) |
|
830
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
270 |
|
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
271 |
if values[2] is not None: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
272 |
base_location_type = self.ParentWindow.Controler.GetBaseType(values[2]) |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
273 |
if values[2] != variable_type and base_type != base_location_type: |
814 | 274 |
message = _("Incompatible data types between \"%s\" and \"%s\"")%(values[2], variable_type) |
830
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
275 |
|
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
276 |
if message is None: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
277 |
if not location.startswith("%"): |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
278 |
if location[0].isdigit() and base_type != "BOOL": |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
279 |
message = _("Incompatible size of data between \"%s\" and \"BOOL\"")%location |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
280 |
elif location[0] not in LOCATIONDATATYPES: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
281 |
message = _("Unrecognized data size \"%s\"")%location[0] |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
282 |
elif base_type not in LOCATIONDATATYPES[location[0]]: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
283 |
message = _("Incompatible size of data between \"%s\" and \"%s\"")%(location, variable_type) |
814 | 284 |
else: |
830
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
285 |
dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow.ParentWindow, |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
286 |
_("Select a variable class:"), _("Variable class"), |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
287 |
["Input", "Output", "Memory"], |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
288 |
wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
289 |
if dialog.ShowModal() == wx.ID_OK: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
290 |
selected = dialog.GetSelection() |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
291 |
else: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
292 |
selected = None |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
293 |
dialog.Destroy() |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
294 |
if selected is None: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
295 |
return |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
296 |
if selected == 0: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
297 |
location = "%I" + location |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
298 |
elif selected == 1: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
299 |
location = "%Q" + location |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
300 |
else: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
301 |
location = "%M" + location |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
302 |
|
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
303 |
if message is None: |
814 | 304 |
self.ParentWindow.Table.SetValue(row, col, location) |
305 |
self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid) |
|
306 |
self.ParentWindow.SaveValues() |
|
307 |
elif colname == "Initial Value" and values[1] == "Constant": |
|
308 |
if not self.ParentWindow.Table.GetValueByName(row, "Edit"): |
|
309 |
message = _("Can't set an initial value to a function block instance") |
|
310 |
else: |
|
311 |
self.ParentWindow.Table.SetValue(row, col, values[0]) |
|
312 |
self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid) |
|
313 |
self.ParentWindow.SaveValues() |
|
1140
80a91fc91595
Fixed bug when drag'n dropping global in function variable panel (not possible according to standard)
Laurent Bessard
parents:
1128
diff
changeset
|
314 |
elif (element_type not in ["config", "resource", "function"] and values[1] == "Global" and |
80a91fc91595
Fixed bug when drag'n dropping global in function variable panel (not possible according to standard)
Laurent Bessard
parents:
1128
diff
changeset
|
315 |
self.ParentWindow.Filter in ["All", "Interface", "External"] or |
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
316 |
element_type != "function" and values[1] == "location"): |
814 | 317 |
if values[1] == "location": |
318 |
var_name = values[3] |
|
319 |
else: |
|
320 |
var_name = values[0] |
|
321 |
tagname = self.ParentWindow.GetTagName() |
|
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
322 |
if var_name.upper() in [name.upper() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
323 |
for name in self.ParentWindow.Controler.\ |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
324 |
GetProjectPouNames(self.ParentWindow.Debug)]: |
814 | 325 |
message = _("\"%s\" pou already exists!")%var_name |
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
326 |
elif not var_name.upper() in [name.upper() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
327 |
for name in self.ParentWindow.Controler.\ |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
328 |
GetEditedElementVariables(tagname, self.ParentWindow.Debug)]: |
814 | 329 |
var_infos = self.ParentWindow.DefaultValue.copy() |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
330 |
var_infos.Name = var_name |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
331 |
var_infos.Type = values[2] |
814 | 332 |
if values[1] == "location": |
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
333 |
location = values[0] |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
334 |
if not location.startswith("%"): |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
335 |
dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow.ParentWindow, |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
336 |
_("Select a variable class:"), _("Variable class"), |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
337 |
["Input", "Output", "Memory"], |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
338 |
wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
339 |
if dialog.ShowModal() == wx.ID_OK: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
340 |
selected = dialog.GetSelection() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
341 |
else: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
342 |
selected = None |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
343 |
dialog.Destroy() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
344 |
if selected is None: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
345 |
return |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
346 |
if selected == 0: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
347 |
location = "%I" + location |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
348 |
elif selected == 1: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
349 |
location = "%Q" + location |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
350 |
else: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
351 |
location = "%M" + location |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
352 |
if element_type == "functionBlock": |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
353 |
configs = self.ParentWindow.Controler.GetProjectConfigNames( |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
354 |
self.ParentWindow.Debug) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
355 |
if len(configs) == 0: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
356 |
return |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
357 |
if not var_name.upper() in [name.upper() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
358 |
for name in self.ParentWindow.Controler.\ |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
359 |
GetConfigurationVariableNames(configs[0])]: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
360 |
self.ParentWindow.Controler.AddConfigurationGlobalVar( |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
361 |
configs[0], values[2], var_name, location, "") |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
362 |
var_infos.Class = "External" |
1083
40af794ecd4b
Added support for adding a variable in program VariablePanel by drap'n dropping located variable like in global VariablePanel
Laurent Bessard
parents:
1016
diff
changeset
|
363 |
else: |
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
364 |
if element_type == "program": |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
365 |
var_infos.Class = "Local" |
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
366 |
else: |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
367 |
var_infos.Class = "Global" |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
368 |
var_infos.Location = location |
814 | 369 |
else: |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
370 |
var_infos.Class = "External" |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
371 |
var_infos.Number = len(self.ParentWindow.Values) |
814 | 372 |
self.ParentWindow.Values.append(var_infos) |
373 |
self.ParentWindow.SaveValues() |
|
374 |
self.ParentWindow.RefreshValues() |
|
375 |
||
376 |
if message is not None: |
|
377 |
wx.CallAfter(self.ShowMessage, message) |
|
378 |
||
379 |
def ShowMessage(self, message): |
|
380 |
message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR) |
|
381 |
message.ShowModal() |
|
382 |
message.Destroy() |
|
383 |
||
384 |
#------------------------------------------------------------------------------- |
|
385 |
# Variable Panel |
|
386 |
#------------------------------------------------------------------------------- |
|
387 |
||
388 |
class VariablePanel(wx.Panel): |
|
389 |
||
390 |
def __init__(self, parent, window, controler, element_type, debug=False): |
|
391 |
wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL) |
|
392 |
||
393 |
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=0) |
|
394 |
self.MainSizer.AddGrowableCol(0) |
|
395 |
self.MainSizer.AddGrowableRow(1) |
|
396 |
||
397 |
controls_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=5) |
|
398 |
controls_sizer.AddGrowableCol(5) |
|
399 |
controls_sizer.AddGrowableRow(0) |
|
400 |
self.MainSizer.AddSizer(controls_sizer, border=5, flag=wx.GROW|wx.ALL) |
|
401 |
||
402 |
self.ReturnTypeLabel = wx.StaticText(self, label=_('Return Type:')) |
|
403 |
controls_sizer.AddWindow(self.ReturnTypeLabel, flag=wx.ALIGN_CENTER_VERTICAL) |
|
404 |
||
405 |
self.ReturnType = wx.ComboBox(self, |
|
406 |
size=wx.Size(145, -1), style=wx.CB_READONLY) |
|
407 |
self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, self.ReturnType) |
|
408 |
controls_sizer.AddWindow(self.ReturnType) |
|
409 |
||
410 |
self.DescriptionLabel = wx.StaticText(self, label=_('Description:')) |
|
411 |
controls_sizer.AddWindow(self.DescriptionLabel, flag=wx.ALIGN_CENTER_VERTICAL) |
|
412 |
||
413 |
self.Description = wx.TextCtrl(self, |
|
414 |
size=wx.Size(250, -1), style=wx.TE_PROCESS_ENTER) |
|
415 |
self.Bind(wx.EVT_TEXT_ENTER, self.OnDescriptionChanged, self.Description) |
|
416 |
self.Description.Bind(wx.EVT_KILL_FOCUS, self.OnDescriptionChanged) |
|
417 |
controls_sizer.AddWindow(self.Description) |
|
418 |
||
419 |
class_filter_label = wx.StaticText(self, label=_('Class Filter:')) |
|
420 |
controls_sizer.AddWindow(class_filter_label, flag=wx.ALIGN_CENTER_VERTICAL) |
|
421 |
||
422 |
self.ClassFilter = wx.ComboBox(self, |
|
423 |
size=wx.Size(145, -1), style=wx.CB_READONLY) |
|
424 |
self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, self.ClassFilter) |
|
425 |
controls_sizer.AddWindow(self.ClassFilter) |
|
426 |
||
427 |
for name, bitmap, help in [ |
|
428 |
("AddButton", "add_element", _("Add variable")), |
|
429 |
("DeleteButton", "remove_element", _("Remove variable")), |
|
430 |
("UpButton", "up", _("Move variable up")), |
|
431 |
("DownButton", "down", _("Move variable down"))]: |
|
432 |
button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), |
|
433 |
size=wx.Size(28, 28), style=wx.NO_BORDER) |
|
434 |
button.SetToolTipString(help) |
|
435 |
setattr(self, name, button) |
|
436 |
controls_sizer.AddWindow(button) |
|
437 |
||
438 |
self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL) |
|
439 |
self.VariablesGrid.SetDropTarget(VariableDropTarget(self)) |
|
440 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, |
|
441 |
self.OnVariablesGridCellChange) |
|
442 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, |
|
443 |
self.OnVariablesGridCellLeftClick) |
|
444 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, |
|
445 |
self.OnVariablesGridEditorShown) |
|
446 |
self.MainSizer.AddWindow(self.VariablesGrid, flag=wx.GROW) |
|
447 |
||
448 |
self.SetSizer(self.MainSizer) |
|
449 |
||
450 |
self.ParentWindow = window |
|
451 |
self.Controler = controler |
|
452 |
self.ElementType = element_type |
|
453 |
self.Debug = debug |
|
454 |
||
455 |
self.RefreshHighlightsTimer = wx.Timer(self, -1) |
|
456 |
self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, |
|
457 |
self.RefreshHighlightsTimer) |
|
458 |
||
459 |
self.Filter = "All" |
|
460 |
self.FilterChoices = [] |
|
461 |
self.FilterChoiceTransfer = GetFilterChoiceTransfer() |
|
462 |
||
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
463 |
self.DefaultValue = _VariableInfos("", "", "", "", "", True, "", "INT", ([], []), 0) |
1342
c17507a10807
Fixed various latency issues removing unnecessary calls
Laurent Bessard
parents:
1325
diff
changeset
|
464 |
|
814 | 465 |
if element_type in ["config", "resource"]: |
466 |
self.DefaultTypes = {"All" : "Global"} |
|
467 |
else: |
|
468 |
self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"} |
|
469 |
||
470 |
if element_type in ["config", "resource"] \ |
|
471 |
or element_type in ["program", "transition", "action"]: |
|
472 |
# this is an element that can have located variables |
|
473 |
self.Table = VariableTable(self, [], GetVariableTableColnames(True)) |
|
474 |
||
475 |
if element_type in ["config", "resource"]: |
|
476 |
self.FilterChoices = ["All", "Global"]#,"Access"] |
|
477 |
else: |
|
478 |
self.FilterChoices = ["All", |
|
479 |
"Interface", " Input", " Output", " InOut", " External", |
|
480 |
"Variables", " Local", " Temp"]#,"Access"] |
|
481 |
||
482 |
# these condense the ColAlignements list |
|
483 |
l = wx.ALIGN_LEFT |
|
484 |
c = wx.ALIGN_CENTER |
|
485 |
||
486 |
# Num Name Class Type Loc Init Option Doc |
|
487 |
self.ColSizes = [40, 80, 70, 80, 80, 80, 100, 80] |
|
488 |
self.ColAlignements = [c, l, l, l, l, l, l, l] |
|
489 |
||
490 |
else: |
|
491 |
# this is an element that cannot have located variables |
|
492 |
self.Table = VariableTable(self, [], GetVariableTableColnames(False)) |
|
493 |
||
494 |
if element_type == "function": |
|
495 |
self.FilterChoices = ["All", |
|
496 |
"Interface", " Input", " Output", " InOut", |
|
497 |
"Variables", " Local"] |
|
498 |
else: |
|
499 |
self.FilterChoices = ["All", |
|
500 |
"Interface", " Input", " Output", " InOut", " External", |
|
501 |
"Variables", " Local", " Temp"] |
|
502 |
||
503 |
# these condense the ColAlignements list |
|
504 |
l = wx.ALIGN_LEFT |
|
505 |
c = wx.ALIGN_CENTER |
|
506 |
||
507 |
# Num Name Class Type Init Option Doc |
|
508 |
self.ColSizes = [40, 80, 70, 80, 80, 100, 160] |
|
509 |
self.ColAlignements = [c, l, l, l, l, l, l] |
|
1342
c17507a10807
Fixed various latency issues removing unnecessary calls
Laurent Bessard
parents:
1325
diff
changeset
|
510 |
|
c17507a10807
Fixed various latency issues removing unnecessary calls
Laurent Bessard
parents:
1325
diff
changeset
|
511 |
self.ElementType = element_type |
c17507a10807
Fixed various latency issues removing unnecessary calls
Laurent Bessard
parents:
1325
diff
changeset
|
512 |
self.BodyType = None |
c17507a10807
Fixed various latency issues removing unnecessary calls
Laurent Bessard
parents:
1325
diff
changeset
|
513 |
|
814 | 514 |
for choice in self.FilterChoices: |
515 |
self.ClassFilter.Append(_(choice)) |
|
516 |
||
517 |
reverse_transfer = {} |
|
518 |
for filter, choice in self.FilterChoiceTransfer.items(): |
|
519 |
reverse_transfer[choice] = filter |
|
520 |
self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter])) |
|
521 |
self.RefreshTypeList() |
|
522 |
||
523 |
self.VariablesGrid.SetTable(self.Table) |
|
524 |
self.VariablesGrid.SetButtons({"Add": self.AddButton, |
|
525 |
"Delete": self.DeleteButton, |
|
526 |
"Up": self.UpButton, |
|
527 |
"Down": self.DownButton}) |
|
528 |
self.VariablesGrid.SetEditable(not self.Debug) |
|
529 |
||
530 |
def _AddVariable(new_row): |
|
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
531 |
if new_row > 0: |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
532 |
row_content = self.Values[new_row - 1].copy() |
1175
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
533 |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
534 |
result = VARIABLE_NAME_SUFFIX_MODEL.search(row_content.Name) |
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
535 |
if result is not None: |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
536 |
name = row_content.Name[:result.start(1)] |
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
537 |
suffix = result.group(1) |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
538 |
if suffix != "": |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
539 |
start_idx = int(suffix) |
1122
84de51ab40d2
Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents:
1083
diff
changeset
|
540 |
else: |
84de51ab40d2
Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents:
1083
diff
changeset
|
541 |
start_idx = 0 |
814 | 542 |
else: |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
543 |
name = row_content.Name |
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
544 |
start_idx = 0 |
1175
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
545 |
else: |
1184
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
546 |
row_content = None |
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
547 |
start_idx = 0 |
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
548 |
name = "LocalVar" |
1175
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
549 |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
550 |
if row_content is not None and row_content.Edit: |
1175
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
551 |
row_content = self.Values[new_row - 1].copy() |
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
552 |
else: |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
553 |
row_content = self.DefaultValue.copy() |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
554 |
if self.Filter in self.DefaultTypes: |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
555 |
row_content.Class = self.DefaultTypes[self.Filter] |
814 | 556 |
else: |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
557 |
row_content.Class = self.Filter |
1175
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
558 |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
559 |
row_content.Name = self.Controler.GenerateNewName( |
1175
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
560 |
self.TagName, None, name + "%d", start_idx) |
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
561 |
|
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
562 |
if self.Filter == "All" and len(self.Values) > 0: |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
563 |
self.Values.insert(new_row, row_content) |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
564 |
else: |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
565 |
self.Values.append(row_content) |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
566 |
new_row = self.Table.GetNumberRows() |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
567 |
self.SaveValues() |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
568 |
self.RefreshValues() |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
569 |
return new_row |
814 | 570 |
setattr(self.VariablesGrid, "_AddRow", _AddVariable) |
571 |
||
572 |
def _DeleteVariable(row): |
|
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
573 |
if self.Table.GetValueByName(row, "Edit"): |
814 | 574 |
self.Values.remove(self.Table.GetRow(row)) |
575 |
self.SaveValues() |
|
1361
7158aa054226
Fixed bugs when editing resource variables and tasks
Laurent Bessard
parents:
1347
diff
changeset
|
576 |
if self.ElementType == "resource": |
7158aa054226
Fixed bugs when editing resource variables and tasks
Laurent Bessard
parents:
1347
diff
changeset
|
577 |
self.ParentWindow.RefreshView(variablepanel = False) |
814 | 578 |
self.RefreshValues() |
579 |
setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable) |
|
580 |
||
581 |
def _MoveVariable(row, move): |
|
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
582 |
if self.Filter == "All": |
814 | 583 |
new_row = max(0, min(row + move, len(self.Values) - 1)) |
584 |
if new_row != row: |
|
585 |
self.Values.insert(new_row, self.Values.pop(row)) |
|
586 |
self.SaveValues() |
|
587 |
self.RefreshValues() |
|
588 |
return new_row |
|
589 |
return row |
|
590 |
setattr(self.VariablesGrid, "_MoveRow", _MoveVariable) |
|
591 |
||
592 |
def _RefreshButtons(): |
|
593 |
if self: |
|
594 |
table_length = len(self.Table.data) |
|
595 |
row_class = None |
|
596 |
row_edit = True |
|
597 |
row = 0 |
|
598 |
if table_length > 0: |
|
599 |
row = self.VariablesGrid.GetGridCursorRow() |
|
600 |
row_edit = self.Table.GetValueByName(row, "Edit") |
|
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
601 |
self.AddButton.Enable(not self.Debug) |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
602 |
self.DeleteButton.Enable(not self.Debug and (table_length > 0 and row_edit)) |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
603 |
self.UpButton.Enable(not self.Debug and (table_length > 0 and row > 0 and self.Filter == "All")) |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
604 |
self.DownButton.Enable(not self.Debug and (table_length > 0 and row < table_length - 1 and self.Filter == "All")) |
814 | 605 |
setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons) |
606 |
||
607 |
self.VariablesGrid.SetRowLabelSize(0) |
|
608 |
for col in range(self.Table.GetNumberCols()): |
|
609 |
attr = wx.grid.GridCellAttr() |
|
610 |
attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
|
611 |
self.VariablesGrid.SetColAttr(col, attr) |
|
612 |
self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col]) |
|
613 |
self.VariablesGrid.AutoSizeColumn(col, False) |
|
614 |
||
615 |
def __del__(self): |
|
616 |
self.RefreshHighlightsTimer.Stop() |
|
617 |
||
618 |
def SetTagName(self, tagname): |
|
619 |
self.TagName = tagname |
|
1342
c17507a10807
Fixed various latency issues removing unnecessary calls
Laurent Bessard
parents:
1325
diff
changeset
|
620 |
self.BodyType = self.Controler.GetEditedElementBodyType(self.TagName) |
814 | 621 |
|
622 |
def GetTagName(self): |
|
623 |
return self.TagName |
|
624 |
||
625 |
def IsFunctionBlockType(self, name): |
|
1342
c17507a10807
Fixed various latency issues removing unnecessary calls
Laurent Bessard
parents:
1325
diff
changeset
|
626 |
if self.ElementType != "function" and self.BodyType in ["ST", "IL"]: |
814 | 627 |
return False |
628 |
else: |
|
1325
76e52d5fcffd
Fixed time consuming function when loading VariablePanel
Laurent Bessard
parents:
1308
diff
changeset
|
629 |
return self.Controler.GetBlockType(name, debug=self.Debug) is not None |
814 | 630 |
|
631 |
def RefreshView(self): |
|
632 |
self.PouNames = self.Controler.GetProjectPouNames(self.Debug) |
|
633 |
returnType = None |
|
634 |
description = None |
|
635 |
||
636 |
words = self.TagName.split("::") |
|
637 |
if self.ElementType == "config": |
|
638 |
self.Values = self.Controler.GetConfigurationGlobalVars(words[1], self.Debug) |
|
639 |
elif self.ElementType == "resource": |
|
640 |
self.Values = self.Controler.GetConfigurationResourceGlobalVars(words[1], words[2], self.Debug) |
|
641 |
else: |
|
642 |
if self.ElementType == "function": |
|
643 |
self.ReturnType.Clear() |
|
853
0f97bddb5a30
Adding datatypes defined in ConfNode as possible function return type
Laurent Bessard
parents:
831
diff
changeset
|
644 |
for data_type in self.Controler.GetDataTypes(self.TagName, debug=self.Debug): |
0f97bddb5a30
Adding datatypes defined in ConfNode as possible function return type
Laurent Bessard
parents:
831
diff
changeset
|
645 |
self.ReturnType.Append(data_type) |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
646 |
returnType = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, debug=self.Debug) |
814 | 647 |
description = self.Controler.GetPouDescription(words[1]) |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
648 |
self.Values = self.Controler.GetEditedElementInterfaceVars(self.TagName, debug=self.Debug) |
814 | 649 |
|
650 |
if returnType is not None: |
|
651 |
self.ReturnType.SetStringSelection(returnType) |
|
652 |
self.ReturnType.Enable(not self.Debug) |
|
653 |
self.ReturnTypeLabel.Show() |
|
654 |
self.ReturnType.Show() |
|
655 |
else: |
|
656 |
self.ReturnType.Enable(False) |
|
657 |
self.ReturnTypeLabel.Hide() |
|
658 |
self.ReturnType.Hide() |
|
659 |
||
660 |
if description is not None: |
|
661 |
self.Description.SetValue(description) |
|
662 |
self.Description.Enable(not self.Debug) |
|
663 |
self.DescriptionLabel.Show() |
|
664 |
self.Description.Show() |
|
665 |
else: |
|
666 |
self.Description.Enable(False) |
|
667 |
self.DescriptionLabel.Hide() |
|
668 |
self.Description.Hide() |
|
669 |
||
670 |
self.RefreshValues() |
|
671 |
self.VariablesGrid.RefreshButtons() |
|
672 |
self.MainSizer.Layout() |
|
673 |
||
674 |
def OnReturnTypeChanged(self, event): |
|
675 |
words = self.TagName.split("::") |
|
676 |
self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection()) |
|
677 |
self.Controler.BufferProject() |
|
678 |
self.ParentWindow.RefreshView(variablepanel = False) |
|
679 |
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
|
680 |
event.Skip() |
|
681 |
||
682 |
def OnDescriptionChanged(self, event): |
|
683 |
words = self.TagName.split("::") |
|
684 |
old_description = self.Controler.GetPouDescription(words[1]) |
|
685 |
new_description = self.Description.GetValue() |
|
686 |
if new_description != old_description: |
|
687 |
self.Controler.SetPouDescription(words[1], new_description) |
|
1009
741fbce41ec2
Fixed bug in VariablePanel when editing project single configuration variables
Laurent Bessard
parents:
894
diff
changeset
|
688 |
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
814 | 689 |
event.Skip() |
690 |
||
691 |
def OnClassFilter(self, event): |
|
692 |
self.Filter = self.FilterChoiceTransfer[VARIABLE_CHOICES_DICT[self.ClassFilter.GetStringSelection()]] |
|
693 |
self.RefreshTypeList() |
|
694 |
self.RefreshValues() |
|
695 |
self.VariablesGrid.RefreshButtons() |
|
696 |
event.Skip() |
|
697 |
||
698 |
def RefreshTypeList(self): |
|
699 |
if self.Filter == "All": |
|
700 |
self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All","Interface","Variables"]] |
|
701 |
elif self.Filter == "Interface": |
|
702 |
self.ClassList = ["Input","Output","InOut","External"] |
|
703 |
elif self.Filter == "Variables": |
|
704 |
self.ClassList = ["Local","Temp"] |
|
705 |
else: |
|
706 |
self.ClassList = [self.Filter] |
|
707 |
||
708 |
def OnVariablesGridCellChange(self, event): |
|
709 |
row, col = event.GetRow(), event.GetCol() |
|
710 |
colname = self.Table.GetColLabelValue(col, False) |
|
711 |
value = self.Table.GetValue(row, col) |
|
712 |
message = None |
|
713 |
||
714 |
if colname == "Name" and value != "": |
|
715 |
if not TestIdentifier(value): |
|
716 |
message = _("\"%s\" is not a valid identifier!") % value |
|
717 |
elif value.upper() in IEC_KEYWORDS: |
|
718 |
message = _("\"%s\" is a keyword. It can't be used!") % value |
|
719 |
elif value.upper() in self.PouNames: |
|
720 |
message = _("A POU named \"%s\" already exists!") % value |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
721 |
elif value.upper() in [var.Name.upper() for var in self.Values if var != self.Table.data[row]]: |
814 | 722 |
message = _("A variable with \"%s\" as name already exists in this pou!") % value |
723 |
else: |
|
724 |
self.SaveValues(False) |
|
725 |
old_value = self.Table.GetOldValue() |
|
726 |
if old_value != "": |
|
727 |
self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value) |
|
728 |
self.Controler.BufferProject() |
|
1184
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
729 |
wx.CallAfter(self.ParentWindow.RefreshView, False) |
1016
3d79c31e4697
Fixed bug with variable panel in project configuration editor
Laurent Bessard
parents:
1009
diff
changeset
|
730 |
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
814 | 731 |
else: |
732 |
self.SaveValues() |
|
733 |
if colname == "Class": |
|
1009
741fbce41ec2
Fixed bug in VariablePanel when editing project single configuration variables
Laurent Bessard
parents:
894
diff
changeset
|
734 |
wx.CallAfter(self.ParentWindow.RefreshView, False) |
814 | 735 |
elif colname == "Location": |
736 |
wx.CallAfter(self.ParentWindow.RefreshView) |
|
737 |
||
738 |
if message is not None: |
|
739 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
|
740 |
dialog.ShowModal() |
|
741 |
dialog.Destroy() |
|
742 |
event.Veto() |
|
743 |
else: |
|
744 |
event.Skip() |
|
745 |
||
746 |
def OnVariablesGridEditorShown(self, event): |
|
747 |
row, col = event.GetRow(), event.GetCol() |
|
748 |
||
749 |
label_value = self.Table.GetColLabelValue(col, False) |
|
750 |
if label_value == "Type": |
|
751 |
type_menu = wx.Menu(title='') # the root menu |
|
752 |
||
753 |
# build a submenu containing standard IEC types |
|
754 |
base_menu = wx.Menu(title='') |
|
755 |
for base_type in self.Controler.GetBaseTypes(): |
|
756 |
new_id = wx.NewId() |
|
757 |
AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type) |
|
758 |
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id) |
|
759 |
||
760 |
type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu) |
|
761 |
||
762 |
# build a submenu containing user-defined types |
|
763 |
datatype_menu = wx.Menu(title='') |
|
863
b1ead41fbd3b
Fix bug in VariablePanel 'Type' cell editor menu entry 'User Data Types' containing ConfNodes data types
Laurent Bessard
parents:
853
diff
changeset
|
764 |
datatypes = self.Controler.GetDataTypes(basetypes = False, confnodetypes = False) |
814 | 765 |
for datatype in datatypes: |
766 |
new_id = wx.NewId() |
|
767 |
AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) |
|
768 |
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id) |
|
769 |
||
770 |
type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu) |
|
771 |
||
772 |
for category in self.Controler.GetConfNodeDataTypes(): |
|
773 |
||
774 |
if len(category["list"]) > 0: |
|
775 |
# build a submenu containing confnode types |
|
776 |
confnode_datatype_menu = wx.Menu(title='') |
|
777 |
for datatype in category["list"]: |
|
778 |
new_id = wx.NewId() |
|
779 |
AppendMenu(confnode_datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) |
|
780 |
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id) |
|
781 |
||
782 |
type_menu.AppendMenu(wx.NewId(), category["name"], confnode_datatype_menu) |
|
783 |
||
784 |
# build a submenu containing function block types |
|
785 |
bodytype = self.Controler.GetEditedElementBodyType(self.TagName) |
|
786 |
pouname, poutype = self.Controler.GetEditedElementType(self.TagName) |
|
787 |
classtype = self.Table.GetValueByName(row, "Class") |
|
788 |
||
789 |
new_id = wx.NewId() |
|
790 |
AppendMenu(type_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Array")) |
|
791 |
self.Bind(wx.EVT_MENU, self.VariableArrayTypeFunction, id=new_id) |
|
792 |
||
793 |
if classtype in ["Input", "Output", "InOut", "External", "Global"] or \ |
|
794 |
poutype != "function" and bodytype in ["ST", "IL"]: |
|
795 |
functionblock_menu = wx.Menu(title='') |
|
796 |
fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName) |
|
797 |
for functionblock_type in fbtypes: |
|
798 |
new_id = wx.NewId() |
|
799 |
AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type) |
|
800 |
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id) |
|
801 |
||
802 |
type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu) |
|
803 |
||
804 |
rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col)) |
|
805 |
corner_x = rect.x + rect.width |
|
806 |
corner_y = rect.y + self.VariablesGrid.GetColLabelSize() |
|
807 |
||
808 |
# pop up this new menu |
|
809 |
self.VariablesGrid.PopupMenuXY(type_menu, corner_x, corner_y) |
|
810 |
type_menu.Destroy() |
|
811 |
event.Veto() |
|
812 |
else: |
|
813 |
event.Skip() |
|
814 |
||
815 |
def GetVariableTypeFunction(self, base_type): |
|
816 |
def VariableTypeFunction(event): |
|
817 |
row = self.VariablesGrid.GetGridCursorRow() |
|
818 |
self.Table.SetValueByName(row, "Type", base_type) |
|
819 |
self.Table.ResetView(self.VariablesGrid) |
|
820 |
self.SaveValues(False) |
|
821 |
self.ParentWindow.RefreshView(variablepanel = False) |
|
822 |
self.Controler.BufferProject() |
|
1009
741fbce41ec2
Fixed bug in VariablePanel when editing project single configuration variables
Laurent Bessard
parents:
894
diff
changeset
|
823 |
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
814 | 824 |
return VariableTypeFunction |
825 |
||
826 |
def VariableArrayTypeFunction(self, event): |
|
827 |
row = self.VariablesGrid.GetGridCursorRow() |
|
828 |
dialog = ArrayTypeDialog(self, |
|
829 |
self.Controler.GetDataTypes(self.TagName), |
|
830 |
self.Table.GetValueByName(row, "Type")) |
|
831 |
if dialog.ShowModal() == wx.ID_OK: |
|
832 |
self.Table.SetValueByName(row, "Type", dialog.GetValue()) |
|
833 |
self.Table.ResetView(self.VariablesGrid) |
|
834 |
self.SaveValues(False) |
|
835 |
self.ParentWindow.RefreshView(variablepanel = False) |
|
836 |
self.Controler.BufferProject() |
|
1009
741fbce41ec2
Fixed bug in VariablePanel when editing project single configuration variables
Laurent Bessard
parents:
894
diff
changeset
|
837 |
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
814 | 838 |
dialog.Destroy() |
839 |
||
840 |
def OnVariablesGridCellLeftClick(self, event): |
|
841 |
row = event.GetRow() |
|
842 |
if not self.Debug and (event.GetCol() == 0 and self.Table.GetValueByName(row, "Edit")): |
|
843 |
var_name = self.Table.GetValueByName(row, "Name") |
|
844 |
var_class = self.Table.GetValueByName(row, "Class") |
|
845 |
var_type = self.Table.GetValueByName(row, "Type") |
|
846 |
data = wx.TextDataObject(str((var_name, var_class, var_type, self.TagName))) |
|
847 |
dragSource = wx.DropSource(self.VariablesGrid) |
|
848 |
dragSource.SetData(data) |
|
849 |
dragSource.DoDragDrop() |
|
850 |
event.Skip() |
|
851 |
||
852 |
def RefreshValues(self): |
|
853 |
data = [] |
|
854 |
for num, variable in enumerate(self.Values): |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
855 |
if variable.Class in self.ClassList: |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1342
diff
changeset
|
856 |
variable.Number = num + 1 |
814 | 857 |
data.append(variable) |
858 |
self.Table.SetData(data) |
|
859 |
self.Table.ResetView(self.VariablesGrid) |
|
860 |
||
861 |
def SaveValues(self, buffer = True): |
|
862 |
words = self.TagName.split("::") |
|
863 |
if self.ElementType == "config": |
|
864 |
self.Controler.SetConfigurationGlobalVars(words[1], self.Values) |
|
865 |
elif self.ElementType == "resource": |
|
866 |
self.Controler.SetConfigurationResourceGlobalVars(words[1], words[2], self.Values) |
|
867 |
else: |
|
868 |
if self.ReturnType.IsEnabled(): |
|
869 |
self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection()) |
|
870 |
self.Controler.SetPouInterfaceVars(words[1], self.Values) |
|
871 |
if buffer: |
|
872 |
self.Controler.BufferProject() |
|
1184
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
873 |
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
814 | 874 |
|
875 |
#------------------------------------------------------------------------------- |
|
876 |
# Highlights showing functions |
|
877 |
#------------------------------------------------------------------------------- |
|
878 |
||
879 |
def OnRefreshHighlightsTimer(self, event): |
|
880 |
self.Table.ResetView(self.VariablesGrid) |
|
881 |
event.Skip() |
|
882 |
||
883 |
def AddVariableHighlight(self, infos, highlight_type): |
|
884 |
if isinstance(infos[0], TupleType): |
|
885 |
for i in xrange(*infos[0]): |
|
886 |
self.Table.AddHighlight((i,) + infos[1:], highlight_type) |
|
887 |
cell_visible = infos[0][0] |
|
888 |
else: |
|
889 |
self.Table.AddHighlight(infos, highlight_type) |
|
890 |
cell_visible = infos[0] |
|
891 |
colnames = [colname.lower() for colname in self.Table.colnames] |
|
892 |
self.VariablesGrid.MakeCellVisible(cell_visible, colnames.index(infos[1])) |
|
893 |
self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
894 |
||
895 |
def RemoveVariableHighlight(self, infos, highlight_type): |
|
896 |
if isinstance(infos[0], TupleType): |
|
897 |
for i in xrange(*infos[0]): |
|
898 |
self.Table.RemoveHighlight((i,) + infos[1:], highlight_type) |
|
899 |
else: |
|
900 |
self.Table.RemoveHighlight(infos, highlight_type) |
|
901 |
self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
902 |
||
903 |
def ClearHighlights(self, highlight_type=None): |
|
904 |
self.Table.ClearHighlights(highlight_type) |
|
905 |
self.Table.ResetView(self.VariablesGrid) |