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