author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Fri, 11 Aug 2017 15:18:19 +0300 | |
changeset 1726 | d51af006fa6b |
parent 1657 | 3a98027ff372 |
child 1734 | 750eeb7230a1 |
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:
1423
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:
1423
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:
1423
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:
1423
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:
1423
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:
1423
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:
1423
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:
1423
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:
1423
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:
1423
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:
1423
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:
1423
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:
1423
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:
1423
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:
1423
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
25 |
import wx |
|
26 |
import wx.lib.buttons |
|
27 |
import wx.grid |
|
28 |
||
831
dec885ba1f2b
Adding support for signaling that a task interval isn't well formatted
laurent
parents:
814
diff
changeset
|
29 |
from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD, ERROR_HIGHLIGHT |
814 | 30 |
from controls import CustomGrid, CustomTable, DurationCellEditor |
831
dec885ba1f2b
Adding support for signaling that a task interval isn't well formatted
laurent
parents:
814
diff
changeset
|
31 |
from dialogs.DurationEditorDialog import IEC_TIME_MODEL |
814 | 32 |
from EditorPanel import EditorPanel |
33 |
from util.BitmapLibrary import GetBitmap |
|
1657
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
34 |
from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS, DefaultType |
814 | 35 |
#------------------------------------------------------------------------------- |
36 |
# Configuration Editor class |
|
37 |
#------------------------------------------------------------------------------- |
|
38 |
||
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
39 |
[ID_CONFIGURATIONEDITOR, |
814 | 40 |
] = [wx.NewId() for _init_ctrls in range(1)] |
41 |
||
42 |
class ConfigurationEditor(EditorPanel): |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
43 |
|
814 | 44 |
ID = ID_CONFIGURATIONEDITOR |
45 |
VARIABLE_PANEL_TYPE = "config" |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
46 |
|
814 | 47 |
def GetBufferState(self): |
48 |
return self.Controler.GetBufferState() |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
49 |
|
814 | 50 |
def Undo(self): |
51 |
self.Controler.LoadPrevious() |
|
52 |
self.ParentWindow.CloseTabsWithoutModel() |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
53 |
|
814 | 54 |
def Redo(self): |
55 |
self.Controler.LoadNext() |
|
56 |
self.ParentWindow.CloseTabsWithoutModel() |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
57 |
|
814 | 58 |
def HasNoModel(self): |
59 |
return self.Controler.GetEditedElement(self.TagName) is None |
|
60 |
||
61 |
||
62 |
#------------------------------------------------------------------------------- |
|
63 |
# Resource Editor class |
|
64 |
#------------------------------------------------------------------------------- |
|
65 |
||
66 |
def GetTasksTableColnames(): |
|
67 |
_ = lambda x : x |
|
68 |
return [_("Name"), _("Triggering"), _("Single"), _("Interval"), _("Priority")] |
|
69 |
||
70 |
def GetTaskTriggeringOptions(): |
|
71 |
_ = lambda x : x |
|
72 |
return [_("Interrupt"), _("Cyclic")] |
|
73 |
TASKTRIGGERINGOPTIONS_DICT = dict([(_(option), option) for option in GetTaskTriggeringOptions()]) |
|
74 |
||
1423
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
75 |
SingleCellEditor = lambda *x : wx.grid.GridCellChoiceEditor() |
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
76 |
|
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
77 |
def CheckSingle(single, varlist): |
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
78 |
return single in varlist |
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
79 |
|
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
80 |
|
814 | 81 |
def GetInstancesTableColnames(): |
82 |
_ = lambda x : x |
|
83 |
return [_("Name"), _("Type"), _("Task")] |
|
84 |
||
85 |
class ResourceTable(CustomTable): |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
86 |
|
814 | 87 |
""" |
88 |
A custom wx.grid.Grid Table using user supplied data |
|
89 |
""" |
|
90 |
def __init__(self, parent, data, colnames): |
|
91 |
# The base class must be initialized *first* |
|
92 |
CustomTable.__init__(self, parent, data, colnames) |
|
93 |
self.ColAlignements = [] |
|
94 |
self.ColSizes = [] |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
95 |
|
814 | 96 |
def GetColAlignements(self): |
97 |
return self.ColAlignements |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
98 |
|
814 | 99 |
def SetColAlignements(self, list): |
100 |
self.ColAlignements = list |
|
101 |
||
102 |
def GetColSizes(self): |
|
103 |
return self.ColSizes |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
104 |
|
814 | 105 |
def SetColSizes(self, list): |
106 |
self.ColSizes = list |
|
107 |
||
108 |
def GetValue(self, row, col): |
|
109 |
if row < self.GetNumberRows(): |
|
110 |
colname = self.GetColLabelValue(col, False) |
|
1657
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
111 |
value = self.data[row].get(colname, "") |
814 | 112 |
if colname == "Triggering": |
113 |
return _(value) |
|
114 |
return value |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
115 |
|
814 | 116 |
def SetValue(self, row, col, value): |
117 |
if col < len(self.colnames): |
|
118 |
colname = self.GetColLabelValue(col, False) |
|
119 |
if colname == "Triggering": |
|
120 |
value = TASKTRIGGERINGOPTIONS_DICT[value] |
|
121 |
self.data[row][colname] = value |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
122 |
|
814 | 123 |
def _updateColAttrs(self, grid): |
124 |
""" |
|
125 |
wx.grid.Grid -> update the column attributes to add the |
|
126 |
appropriate renderer given the column name. |
|
127 |
||
128 |
Otherwise default to the default renderer. |
|
129 |
""" |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
130 |
|
814 | 131 |
for col in range(self.GetNumberCols()): |
132 |
attr = wx.grid.GridCellAttr() |
|
133 |
attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
|
134 |
grid.SetColAttr(col, attr) |
|
135 |
grid.SetColSize(col, self.ColSizes[col]) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
136 |
|
814 | 137 |
for row in range(self.GetNumberRows()): |
138 |
row_highlights = self.Highlights.get(row, {}) |
|
139 |
for col in range(self.GetNumberCols()): |
|
140 |
editor = None |
|
141 |
renderer = None |
|
879
55b8a16ead2b
Fix resource task interval error highlighting
Laurent Bessard
parents:
831
diff
changeset
|
142 |
error = False |
814 | 143 |
colname = self.GetColLabelValue(col, False) |
144 |
grid.SetReadOnly(row, col, False) |
|
145 |
if colname == "Name": |
|
146 |
editor = wx.grid.GridCellTextEditor() |
|
147 |
renderer = wx.grid.GridCellStringRenderer() |
|
148 |
elif colname == "Interval": |
|
1275
8d4de18c9f29
Fixed DurationCellEditor to make it reusable
Laurent Bessard
parents:
1026
diff
changeset
|
149 |
editor = DurationCellEditor(self, colname) |
814 | 150 |
renderer = wx.grid.GridCellStringRenderer() |
151 |
if self.GetValueByName(row, "Triggering") != "Cyclic": |
|
152 |
grid.SetReadOnly(row, col, True) |
|
879
55b8a16ead2b
Fix resource task interval error highlighting
Laurent Bessard
parents:
831
diff
changeset
|
153 |
interval = self.GetValueByName(row, colname) |
55b8a16ead2b
Fix resource task interval error highlighting
Laurent Bessard
parents:
831
diff
changeset
|
154 |
if interval != "" and IEC_TIME_MODEL.match(interval.upper()) is None: |
55b8a16ead2b
Fix resource task interval error highlighting
Laurent Bessard
parents:
831
diff
changeset
|
155 |
error = True |
814 | 156 |
elif colname == "Single": |
1423
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
157 |
editor = SingleCellEditor(self,colname) |
814 | 158 |
editor.SetParameters(self.Parent.VariableList) |
159 |
if self.GetValueByName(row, "Triggering") != "Interrupt": |
|
160 |
grid.SetReadOnly(row, col, True) |
|
1423
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
161 |
single = self.GetValueByName(row, colname) |
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
162 |
if single != "" and not CheckSingle(single,self.Parent.VariableList): |
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
163 |
error = True |
814 | 164 |
elif colname == "Triggering": |
165 |
editor = wx.grid.GridCellChoiceEditor() |
|
1026
96a2dc05651a
Fixed Triggering column cell choice editor, removing useless and bugging empty string option
Laurent Bessard
parents:
899
diff
changeset
|
166 |
editor.SetParameters(",".join(map(_, GetTaskTriggeringOptions()))) |
814 | 167 |
elif colname == "Type": |
168 |
editor = wx.grid.GridCellChoiceEditor() |
|
169 |
editor.SetParameters(self.Parent.TypeList) |
|
170 |
elif colname == "Priority": |
|
171 |
editor = wx.grid.GridCellNumberEditor() |
|
172 |
editor.SetParameters("0,65535") |
|
173 |
elif colname == "Task": |
|
174 |
editor = wx.grid.GridCellChoiceEditor() |
|
175 |
editor.SetParameters(self.Parent.TaskList) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
176 |
|
814 | 177 |
grid.SetCellEditor(row, col, editor) |
178 |
grid.SetCellRenderer(row, col, renderer) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
179 |
|
879
55b8a16ead2b
Fix resource task interval error highlighting
Laurent Bessard
parents:
831
diff
changeset
|
180 |
if error: |
831
dec885ba1f2b
Adding support for signaling that a task interval isn't well formatted
laurent
parents:
814
diff
changeset
|
181 |
highlight_colours = ERROR_HIGHLIGHT |
dec885ba1f2b
Adding support for signaling that a task interval isn't well formatted
laurent
parents:
814
diff
changeset
|
182 |
else: |
dec885ba1f2b
Adding support for signaling that a task interval isn't well formatted
laurent
parents:
814
diff
changeset
|
183 |
highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] |
814 | 184 |
grid.SetCellBackgroundColour(row, col, highlight_colours[0]) |
185 |
grid.SetCellTextColour(row, col, highlight_colours[1]) |
|
186 |
self.ResizeRow(grid, row) |
|
187 |
||
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
188 |
|
814 | 189 |
#------------------------------------------------------------------------------- |
190 |
# Highlights showing functions |
|
191 |
#------------------------------------------------------------------------------- |
|
192 |
||
193 |
def AddHighlight(self, infos, highlight_type): |
|
194 |
row_highlights = self.Highlights.setdefault(infos[0], {}) |
|
195 |
col_highlights = row_highlights.setdefault(infos[1], []) |
|
196 |
col_highlights.append(highlight_type) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
197 |
|
814 | 198 |
def ClearHighlights(self, highlight_type=None): |
199 |
if highlight_type is None: |
|
200 |
self.Highlights = {} |
|
201 |
else: |
|
202 |
for row, row_highlights in self.Highlights.iteritems(): |
|
203 |
row_items = row_highlights.items() |
|
204 |
for col, col_highlights in row_items: |
|
205 |
if highlight_type in col_highlights: |
|
206 |
col_highlights.remove(highlight_type) |
|
207 |
if len(col_highlights) == 0: |
|
208 |
row_highlights.pop(col) |
|
209 |
||
210 |
||
211 |
||
212 |
class ResourceEditor(EditorPanel): |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
213 |
|
814 | 214 |
VARIABLE_PANEL_TYPE = "resource" |
215 |
||
216 |
def _init_Editor(self, parent): |
|
217 |
self.Editor = wx.Panel(parent, style=wx.SUNKEN_BORDER|wx.TAB_TRAVERSAL) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
218 |
|
814 | 219 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
220 |
main_sizer.AddGrowableCol(0) |
|
221 |
main_sizer.AddGrowableRow(0) |
|
222 |
main_sizer.AddGrowableRow(1) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
223 |
|
814 | 224 |
tasks_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
225 |
tasks_sizer.AddGrowableCol(0) |
|
226 |
tasks_sizer.AddGrowableRow(1) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
227 |
main_sizer.AddSizer(tasks_sizer, border=5, |
814 | 228 |
flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
229 |
|
814 | 230 |
tasks_buttons_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
231 |
tasks_buttons_sizer.AddGrowableCol(0) |
|
232 |
tasks_buttons_sizer.AddGrowableRow(0) |
|
233 |
tasks_sizer.AddSizer(tasks_buttons_sizer, flag=wx.GROW) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
234 |
|
814 | 235 |
tasks_label = wx.StaticText(self.Editor, label=_(u'Tasks:')) |
236 |
tasks_buttons_sizer.AddWindow(tasks_label, flag=wx.ALIGN_BOTTOM) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
237 |
|
814 | 238 |
for name, bitmap, help in [ |
239 |
("AddTaskButton", "add_element", _("Add task")), |
|
240 |
("DeleteTaskButton", "remove_element", _("Remove task")), |
|
241 |
("UpTaskButton", "up", _("Move task up")), |
|
242 |
("DownTaskButton", "down", _("Move task down"))]: |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
243 |
button = wx.lib.buttons.GenBitmapButton(self.Editor, |
814 | 244 |
bitmap=GetBitmap(bitmap), size=wx.Size(28, 28), style=wx.NO_BORDER) |
245 |
button.SetToolTipString(help) |
|
246 |
setattr(self, name, button) |
|
247 |
tasks_buttons_sizer.AddWindow(button) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
248 |
|
814 | 249 |
self.TasksGrid = CustomGrid(self.Editor, style=wx.VSCROLL) |
250 |
self.TasksGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnTasksGridCellChange) |
|
251 |
tasks_sizer.AddWindow(self.TasksGrid, flag=wx.GROW) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
252 |
|
814 | 253 |
instances_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
254 |
instances_sizer.AddGrowableCol(0) |
|
255 |
instances_sizer.AddGrowableRow(1) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
256 |
main_sizer.AddSizer(instances_sizer, border=5, |
814 | 257 |
flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
258 |
|
814 | 259 |
instances_buttons_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
260 |
instances_buttons_sizer.AddGrowableCol(0) |
|
261 |
instances_buttons_sizer.AddGrowableRow(0) |
|
262 |
instances_sizer.AddSizer(instances_buttons_sizer, flag=wx.GROW) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
263 |
|
814 | 264 |
instances_label = wx.StaticText(self.Editor, label=_(u'Instances:')) |
265 |
instances_buttons_sizer.AddWindow(instances_label, flag=wx.ALIGN_BOTTOM) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
266 |
|
814 | 267 |
for name, bitmap, help in [ |
268 |
("AddInstanceButton", "add_element", _("Add instance")), |
|
269 |
("DeleteInstanceButton", "remove_element", _("Remove instance")), |
|
270 |
("UpInstanceButton", "up", _("Move instance up")), |
|
271 |
("DownInstanceButton", "down", _("Move instance down"))]: |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
272 |
button = wx.lib.buttons.GenBitmapButton(self.Editor, |
814 | 273 |
bitmap=GetBitmap(bitmap), size=wx.Size(28, 28), style=wx.NO_BORDER) |
274 |
button.SetToolTipString(help) |
|
275 |
setattr(self, name, button) |
|
276 |
instances_buttons_sizer.AddWindow(button) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
277 |
|
814 | 278 |
self.InstancesGrid = CustomGrid(self.Editor, style=wx.VSCROLL) |
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
279 |
self.InstancesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, |
814 | 280 |
self.OnInstancesGridCellChange) |
281 |
instances_sizer.AddWindow(self.InstancesGrid, flag=wx.GROW) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
282 |
|
814 | 283 |
self.Editor.SetSizer(main_sizer) |
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
284 |
|
814 | 285 |
def __init__(self, parent, tagname, window, controler): |
286 |
EditorPanel.__init__(self, parent, tagname, window, controler) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
287 |
|
814 | 288 |
self.RefreshHighlightsTimer = wx.Timer(self, -1) |
289 |
self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
290 |
|
814 | 291 |
self.TasksDefaultValue = {"Name" : "", "Triggering" : "", "Single" : "", "Interval" : "", "Priority" : 0} |
292 |
self.TasksTable = ResourceTable(self, [], GetTasksTableColnames()) |
|
293 |
self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT]) |
|
294 |
self.TasksTable.SetColSizes([200, 100, 100, 150, 100]) |
|
295 |
self.TasksGrid.SetTable(self.TasksTable) |
|
296 |
self.TasksGrid.SetButtons({"Add": self.AddTaskButton, |
|
297 |
"Delete": self.DeleteTaskButton, |
|
298 |
"Up": self.UpTaskButton, |
|
299 |
"Down": self.DownTaskButton}) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
300 |
|
814 | 301 |
def _AddTask(new_row): |
302 |
self.TasksTable.InsertRow(new_row, self.TasksDefaultValue.copy()) |
|
303 |
self.RefreshModel() |
|
304 |
self.RefreshView() |
|
305 |
return new_row |
|
306 |
setattr(self.TasksGrid, "_AddRow", _AddTask) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
307 |
|
814 | 308 |
def _DeleteTask(row): |
309 |
self.TasksTable.RemoveRow(row) |
|
310 |
self.RefreshModel() |
|
311 |
self.RefreshView() |
|
312 |
setattr(self.TasksGrid, "_DeleteRow", _DeleteTask) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
313 |
|
814 | 314 |
def _MoveTask(row, move): |
315 |
new_row = self.TasksTable.MoveRow(row, move) |
|
316 |
if new_row != row: |
|
317 |
self.RefreshModel() |
|
318 |
self.RefreshView() |
|
319 |
return new_row |
|
320 |
setattr(self.TasksGrid, "_MoveRow", _MoveTask) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
321 |
|
814 | 322 |
self.TasksGrid.SetRowLabelSize(0) |
323 |
self.TasksTable.ResetView(self.TasksGrid) |
|
324 |
self.TasksGrid.RefreshButtons() |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
325 |
|
814 | 326 |
self.InstancesDefaultValue = {"Name" : "", "Type" : "", "Task" : ""} |
327 |
self.InstancesTable = ResourceTable(self, [], GetInstancesTableColnames()) |
|
328 |
self.InstancesTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]) |
|
329 |
self.InstancesTable.SetColSizes([200, 150, 150]) |
|
330 |
self.InstancesGrid.SetTable(self.InstancesTable) |
|
331 |
self.InstancesGrid.SetButtons({"Add": self.AddInstanceButton, |
|
332 |
"Delete": self.DeleteInstanceButton, |
|
333 |
"Up": self.UpInstanceButton, |
|
334 |
"Down": self.DownInstanceButton}) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
335 |
|
814 | 336 |
def _AddInstance(new_row): |
337 |
self.InstancesTable.InsertRow(new_row, self.InstancesDefaultValue.copy()) |
|
338 |
self.RefreshModel() |
|
339 |
self.RefreshView() |
|
340 |
return new_row |
|
341 |
setattr(self.InstancesGrid, "_AddRow", _AddInstance) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
342 |
|
814 | 343 |
def _DeleteInstance(row): |
344 |
self.InstancesTable.RemoveRow(row) |
|
345 |
self.RefreshModel() |
|
346 |
self.RefreshView() |
|
347 |
setattr(self.InstancesGrid, "_DeleteRow", _DeleteInstance) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
348 |
|
814 | 349 |
def _MoveInstance(row, move): |
350 |
new_row = max(0, min(row + move, self.InstancesTable.GetNumberRows() - 1)) |
|
351 |
if new_row != row: |
|
352 |
if self.InstancesTable.GetValueByName(row, "Task") != self.InstancesTable.GetValueByName(new_row, "Task"): |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
353 |
return row |
814 | 354 |
self.InstancesTable.MoveRow(row, move) |
355 |
self.RefreshModel() |
|
356 |
self.RefreshView() |
|
357 |
return new_row |
|
358 |
setattr(self.InstancesGrid, "_MoveRow", _MoveInstance) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
359 |
|
814 | 360 |
def _RefreshInstanceButtons(): |
361 |
if self: |
|
362 |
rows = self.InstancesTable.GetNumberRows() |
|
363 |
row = self.InstancesGrid.GetGridCursorRow() |
|
364 |
self.DeleteInstanceButton.Enable(rows > 0) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
365 |
self.UpInstanceButton.Enable(row > 0 and |
814 | 366 |
self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row - 1, "Task")) |
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
367 |
self.DownInstanceButton.Enable(0 <= row < rows - 1 and |
814 | 368 |
self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row + 1, "Task")) |
369 |
setattr(self.InstancesGrid, "RefreshButtons", _RefreshInstanceButtons) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
370 |
|
814 | 371 |
self.InstancesGrid.SetRowLabelSize(0) |
372 |
self.InstancesTable.ResetView(self.InstancesGrid) |
|
373 |
self.InstancesGrid.RefreshButtons() |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
374 |
|
814 | 375 |
self.TasksGrid.SetFocus() |
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
376 |
|
814 | 377 |
def __del__(self): |
378 |
self.RefreshHighlightsTimer.Stop() |
|
379 |
||
380 |
def RefreshTypeList(self): |
|
381 |
self.TypeList = "" |
|
382 |
blocktypes = self.Controler.GetBlockResource() |
|
383 |
for blocktype in blocktypes: |
|
384 |
self.TypeList += ",%s"%blocktype |
|
385 |
||
386 |
def RefreshTaskList(self): |
|
387 |
self.TaskList = "" |
|
388 |
for row in xrange(self.TasksTable.GetNumberRows()): |
|
389 |
self.TaskList += ",%s"%self.TasksTable.GetValueByName(row, "Name") |
|
390 |
||
391 |
def RefreshVariableList(self): |
|
392 |
self.VariableList = "" |
|
393 |
for variable in self.Controler.GetEditedResourceVariables(self.TagName): |
|
394 |
self.VariableList += ",%s"%variable |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
395 |
|
814 | 396 |
def RefreshModel(self): |
397 |
self.Controler.SetEditedResourceInfos(self.TagName, self.TasksTable.GetData(), self.InstancesTable.GetData()) |
|
398 |
self.RefreshBuffer() |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
399 |
|
814 | 400 |
# Buffer the last model state |
401 |
def RefreshBuffer(self): |
|
402 |
self.Controler.BufferProject() |
|
403 |
self.ParentWindow.RefreshTitle() |
|
404 |
self.ParentWindow.RefreshFileMenu() |
|
405 |
self.ParentWindow.RefreshEditMenu() |
|
406 |
||
407 |
def GetBufferState(self): |
|
408 |
return self.Controler.GetBufferState() |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
409 |
|
814 | 410 |
def Undo(self): |
411 |
self.Controler.LoadPrevious() |
|
412 |
self.ParentWindow.CloseTabsWithoutModel() |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
413 |
|
814 | 414 |
def Redo(self): |
415 |
self.Controler.LoadNext() |
|
416 |
self.ParentWindow.CloseTabsWithoutModel() |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
417 |
|
814 | 418 |
def HasNoModel(self): |
419 |
return self.Controler.GetEditedElement(self.TagName) is None |
|
420 |
||
421 |
def RefreshView(self, variablepanel=True): |
|
422 |
EditorPanel.RefreshView(self, variablepanel) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
423 |
|
814 | 424 |
tasks, instances = self.Controler.GetEditedResourceInfos(self.TagName) |
425 |
self.TasksTable.SetData(tasks) |
|
426 |
self.InstancesTable.SetData(instances) |
|
427 |
self.RefreshTypeList() |
|
428 |
self.RefreshTaskList() |
|
429 |
self.RefreshVariableList() |
|
430 |
self.TasksTable.ResetView(self.TasksGrid) |
|
431 |
self.InstancesTable.ResetView(self.InstancesGrid) |
|
432 |
self.TasksGrid.RefreshButtons() |
|
433 |
self.InstancesGrid.RefreshButtons() |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
434 |
|
1657
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
435 |
def ShowErrorMessage(self, message): |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
436 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
437 |
dialog.ShowModal() |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
438 |
dialog.Destroy() |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
439 |
|
814 | 440 |
def OnTasksGridCellChange(self, event): |
441 |
row, col = event.GetRow(), event.GetCol() |
|
1604
7f98c091be56
fix issue with task rename if "Name" column label is translated into
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
442 |
if self.TasksTable.GetColLabelValue(col, False) == "Name": |
1657
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
443 |
value = self.TasksTable.GetValue(row, col) |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
444 |
message = None |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
445 |
|
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
446 |
if not TestIdentifier(value): |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
447 |
message = _("\"%s\" is not a valid identifier!") % value |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
448 |
elif value.upper() in IEC_KEYWORDS: |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
449 |
message = _("\"%s\" is a keyword. It can't be used!") % value |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
450 |
elif value.upper() in [var["Name"].upper() for i, var in enumerate(self.TasksTable.data) if i!=row]: |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
451 |
message = _("A task with the same name already exists!") |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
452 |
if message is not None: |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
453 |
event.Veto() |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
454 |
wx.CallAfter(self.ShowErrorMessage, message) |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
455 |
return |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
456 |
|
814 | 457 |
tasklist = [name for name in self.TaskList.split(",") if name != ""] |
458 |
for i in xrange(self.TasksTable.GetNumberRows()): |
|
459 |
task = self.TasksTable.GetValueByName(i, "Name") |
|
460 |
if task in tasklist: |
|
461 |
tasklist.remove(task) |
|
462 |
if len(tasklist) > 0: |
|
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1604
diff
changeset
|
463 |
old_name = tasklist[0].upper() |
814 | 464 |
new_name = self.TasksTable.GetValue(row, col) |
465 |
for i in xrange(self.InstancesTable.GetNumberRows()): |
|
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1604
diff
changeset
|
466 |
name = self.InstancesTable.GetValueByName(i, "Task").upper() |
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1604
diff
changeset
|
467 |
if old_name == name: |
814 | 468 |
self.InstancesTable.SetValueByName(i, "Task", new_name) |
469 |
self.RefreshModel() |
|
470 |
colname = self.TasksTable.GetColLabelValue(col, False) |
|
1423
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
471 |
if colname in ["Triggering", "Name", "Single", "Interval"]: |
814 | 472 |
wx.CallAfter(self.RefreshView, False) |
473 |
event.Skip() |
|
474 |
||
475 |
def OnInstancesGridCellChange(self, event): |
|
1657
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
476 |
row, col = event.GetRow(), event.GetCol() |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
477 |
if self.InstancesTable.GetColLabelValue(col, False) == "Name": |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
478 |
value = self.InstancesTable.GetValue(row, col) |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
479 |
message = None |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
480 |
|
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
481 |
if not TestIdentifier(value): |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
482 |
message = _("\"%s\" is not a valid identifier!") % value |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
483 |
elif value.upper() in IEC_KEYWORDS: |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
484 |
message = _("\"%s\" is a keyword. It can't be used!") % value |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
485 |
elif value.upper() in [var["Name"].upper() for i ,var in enumerate(self.InstancesTable.data) if i!=row]: |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
486 |
message = _("An instance with the same name already exists!") |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
487 |
if message is not None: |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
488 |
event.Veto() |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
489 |
wx.CallAfter(self.ShowErrorMessage, message) |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
490 |
return |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
491 |
|
814 | 492 |
self.RefreshModel() |
493 |
self.ParentWindow.RefreshPouInstanceVariablesPanel() |
|
494 |
self.InstancesGrid.RefreshButtons() |
|
495 |
event.Skip() |
|
496 |
||
497 |
#------------------------------------------------------------------------------- |
|
498 |
# Highlights showing functions |
|
499 |
#------------------------------------------------------------------------------- |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
500 |
|
814 | 501 |
def OnRefreshHighlightsTimer(self, event): |
502 |
self.RefreshView() |
|
503 |
event.Skip() |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
504 |
|
814 | 505 |
def AddHighlight(self, infos, start, end, highlight_type): |
899
64aa66d481c5
Fix bug in resource search result highlighting
Laurent Bessard
parents:
879
diff
changeset
|
506 |
EditorPanel.AddHighlight(self, infos, start, end, highlight_type) |
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
507 |
|
814 | 508 |
if infos[0] == "task": |
509 |
self.TasksTable.AddHighlight(infos[1:], highlight_type) |
|
510 |
elif infos[0] == "instance": |
|
511 |
self.InstancesTable.AddHighlight(infos[1:], highlight_type) |
|
512 |
self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
513 |
||
514 |
def ClearHighlights(self, highlight_type=None): |
|
515 |
EditorPanel.ClearHighlights(self, highlight_type) |
|
1420
71b1545d746f
Enable overloading of task triggerring source cell editor (SINGLE) in resource editor. PLCGenerator now generates MULTI keywork instead of SINGLE when task's activation is surroundes with square brackets
Edouard Tisserant
parents:
1275
diff
changeset
|
516 |
|
814 | 517 |
self.TasksTable.ClearHighlights(highlight_type) |
518 |
self.InstancesTable.ClearHighlights(highlight_type) |
|
519 |
self.TasksTable.ResetView(self.TasksGrid) |
|
520 |
self.InstancesTable.ResetView(self.InstancesGrid) |