author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Fri, 05 Mar 2021 09:36:22 +0100 | |
branch | svghmi |
changeset 3179 | 73d26eae5fb1 |
parent 2432 | dbc065a2f7a5 |
child 2737 | 38afed869ff6 |
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 |
|
1853
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
25 |
|
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
26 |
from __future__ import absolute_import |
814 | 27 |
import wx |
28 |
import wx.lib.buttons |
|
29 |
import wx.grid |
|
2432
dbc065a2f7a5
python3 support: pylint, W1613 # (xrange-builtin) xrange built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2301
diff
changeset
|
30 |
from six.moves import xrange |
814 | 31 |
|
831
dec885ba1f2b
Adding support for signaling that a task interval isn't well formatted
laurent
parents:
814
diff
changeset
|
32 |
from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD, ERROR_HIGHLIGHT |
814 | 33 |
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
|
34 |
from dialogs.DurationEditorDialog import IEC_TIME_MODEL |
1853
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
35 |
from editors.EditorPanel import EditorPanel |
814 | 36 |
from util.BitmapLibrary import GetBitmap |
1834
cd42b426028b
fix ungrouped imports from package X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
37 |
from util.TranslationCatalogs import NoTranslate |
1850
614396cbffbf
fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
38 |
from plcopen.structures import TestIdentifier, IEC_KEYWORDS |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
39 |
|
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
40 |
|
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
41 |
# ------------------------------------------------------------------------------- |
814 | 42 |
# Configuration Editor class |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
43 |
# ------------------------------------------------------------------------------- |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
44 |
|
814 | 45 |
|
1773
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
46 |
[ |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
47 |
ID_CONFIGURATIONEDITOR, |
814 | 48 |
] = [wx.NewId() for _init_ctrls in range(1)] |
49 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
50 |
|
814 | 51 |
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
|
52 |
|
814 | 53 |
ID = ID_CONFIGURATIONEDITOR |
54 |
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
|
55 |
|
814 | 56 |
def GetBufferState(self): |
57 |
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
|
58 |
|
814 | 59 |
def Undo(self): |
60 |
self.Controler.LoadPrevious() |
|
61 |
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
|
62 |
|
814 | 63 |
def Redo(self): |
64 |
self.Controler.LoadNext() |
|
65 |
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
|
66 |
|
814 | 67 |
def HasNoModel(self): |
68 |
return self.Controler.GetEditedElement(self.TagName) is None |
|
69 |
||
70 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
71 |
# ------------------------------------------------------------------------------- |
814 | 72 |
# Resource Editor class |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
73 |
# ------------------------------------------------------------------------------- |
814 | 74 |
|
75 |
def GetTasksTableColnames(): |
|
1762
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
76 |
_ = NoTranslate |
814 | 77 |
return [_("Name"), _("Triggering"), _("Single"), _("Interval"), _("Priority")] |
78 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
79 |
|
814 | 80 |
def GetTaskTriggeringOptions(): |
1762
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
81 |
_ = NoTranslate |
814 | 82 |
return [_("Interrupt"), _("Cyclic")] |
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
83 |
|
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
84 |
|
1762
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
85 |
def SingleCellEditor(*x): |
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
86 |
return wx.grid.GridCellChoiceEditor() |
1423
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
87 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
88 |
|
1423
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
89 |
def CheckSingle(single, varlist): |
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
90 |
return single in varlist |
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
91 |
|
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
92 |
|
814 | 93 |
def GetInstancesTableColnames(): |
1762
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
94 |
_ = NoTranslate |
814 | 95 |
return [_("Name"), _("Type"), _("Task")] |
96 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
97 |
|
814 | 98 |
class ResourceTable(CustomTable): |
99 |
""" |
|
100 |
A custom wx.grid.Grid Table using user supplied data |
|
101 |
""" |
|
102 |
def __init__(self, parent, data, colnames): |
|
103 |
# The base class must be initialized *first* |
|
104 |
CustomTable.__init__(self, parent, data, colnames) |
|
105 |
self.ColAlignements = [] |
|
106 |
self.ColSizes = [] |
|
2301
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2232
diff
changeset
|
107 |
self.TASKTRIGGERINGOPTIONS_DICT = dict([(_(option), option) |
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2232
diff
changeset
|
108 |
for option in GetTaskTriggeringOptions()]) |
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
|
109 |
|
814 | 110 |
def GetColAlignements(self): |
111 |
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
|
112 |
|
814 | 113 |
def SetColAlignements(self, list): |
114 |
self.ColAlignements = list |
|
115 |
||
116 |
def GetColSizes(self): |
|
117 |
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
|
118 |
|
814 | 119 |
def SetColSizes(self, list): |
120 |
self.ColSizes = list |
|
121 |
||
122 |
def GetValue(self, row, col): |
|
123 |
if row < self.GetNumberRows(): |
|
124 |
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
|
125 |
value = self.data[row].get(colname, "") |
814 | 126 |
if colname == "Triggering": |
127 |
return _(value) |
|
128 |
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
|
129 |
|
814 | 130 |
def SetValue(self, row, col, value): |
131 |
if col < len(self.colnames): |
|
132 |
colname = self.GetColLabelValue(col, False) |
|
133 |
if colname == "Triggering": |
|
2301
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2232
diff
changeset
|
134 |
value = self.TASKTRIGGERINGOPTIONS_DICT[value] |
814 | 135 |
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
|
136 |
|
814 | 137 |
def _updateColAttrs(self, grid): |
138 |
""" |
|
139 |
wx.grid.Grid -> update the column attributes to add the |
|
140 |
appropriate renderer given the column name. |
|
141 |
||
142 |
Otherwise default to the default renderer. |
|
143 |
""" |
|
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
|
144 |
|
814 | 145 |
for col in range(self.GetNumberCols()): |
146 |
attr = wx.grid.GridCellAttr() |
|
147 |
attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
|
148 |
grid.SetColAttr(col, attr) |
|
149 |
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
|
150 |
|
814 | 151 |
for row in range(self.GetNumberRows()): |
152 |
row_highlights = self.Highlights.get(row, {}) |
|
153 |
for col in range(self.GetNumberCols()): |
|
154 |
editor = None |
|
155 |
renderer = None |
|
879
55b8a16ead2b
Fix resource task interval error highlighting
Laurent Bessard
parents:
831
diff
changeset
|
156 |
error = False |
814 | 157 |
colname = self.GetColLabelValue(col, False) |
158 |
grid.SetReadOnly(row, col, False) |
|
159 |
if colname == "Name": |
|
160 |
editor = wx.grid.GridCellTextEditor() |
|
161 |
renderer = wx.grid.GridCellStringRenderer() |
|
162 |
elif colname == "Interval": |
|
1275
8d4de18c9f29
Fixed DurationCellEditor to make it reusable
Laurent Bessard
parents:
1026
diff
changeset
|
163 |
editor = DurationCellEditor(self, colname) |
814 | 164 |
renderer = wx.grid.GridCellStringRenderer() |
165 |
if self.GetValueByName(row, "Triggering") != "Cyclic": |
|
166 |
grid.SetReadOnly(row, col, True) |
|
879
55b8a16ead2b
Fix resource task interval error highlighting
Laurent Bessard
parents:
831
diff
changeset
|
167 |
interval = self.GetValueByName(row, colname) |
55b8a16ead2b
Fix resource task interval error highlighting
Laurent Bessard
parents:
831
diff
changeset
|
168 |
if interval != "" and IEC_TIME_MODEL.match(interval.upper()) is None: |
55b8a16ead2b
Fix resource task interval error highlighting
Laurent Bessard
parents:
831
diff
changeset
|
169 |
error = True |
814 | 170 |
elif colname == "Single": |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
171 |
editor = SingleCellEditor(self, colname) |
814 | 172 |
editor.SetParameters(self.Parent.VariableList) |
173 |
if self.GetValueByName(row, "Triggering") != "Interrupt": |
|
174 |
grid.SetReadOnly(row, col, True) |
|
1423
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
175 |
single = self.GetValueByName(row, colname) |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
176 |
if single != "" and not CheckSingle(single, self.Parent.VariableList): |
1423
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
177 |
error = True |
814 | 178 |
elif colname == "Triggering": |
179 |
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
|
180 |
editor.SetParameters(",".join(map(_, GetTaskTriggeringOptions()))) |
814 | 181 |
elif colname == "Type": |
182 |
editor = wx.grid.GridCellChoiceEditor() |
|
183 |
editor.SetParameters(self.Parent.TypeList) |
|
184 |
elif colname == "Priority": |
|
185 |
editor = wx.grid.GridCellNumberEditor() |
|
186 |
editor.SetParameters("0,65535") |
|
187 |
elif colname == "Task": |
|
188 |
editor = wx.grid.GridCellChoiceEditor() |
|
189 |
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
|
190 |
|
814 | 191 |
grid.SetCellEditor(row, col, editor) |
192 |
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
|
193 |
|
879
55b8a16ead2b
Fix resource task interval error highlighting
Laurent Bessard
parents:
831
diff
changeset
|
194 |
if error: |
831
dec885ba1f2b
Adding support for signaling that a task interval isn't well formatted
laurent
parents:
814
diff
changeset
|
195 |
highlight_colours = ERROR_HIGHLIGHT |
dec885ba1f2b
Adding support for signaling that a task interval isn't well formatted
laurent
parents:
814
diff
changeset
|
196 |
else: |
dec885ba1f2b
Adding support for signaling that a task interval isn't well formatted
laurent
parents:
814
diff
changeset
|
197 |
highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] |
814 | 198 |
grid.SetCellBackgroundColour(row, col, highlight_colours[0]) |
199 |
grid.SetCellTextColour(row, col, highlight_colours[1]) |
|
200 |
self.ResizeRow(grid, row) |
|
201 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
202 |
# ------------------------------------------------------------------------------- |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
203 |
# Highlights showing functions |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
204 |
# ------------------------------------------------------------------------------- |
814 | 205 |
|
206 |
def AddHighlight(self, infos, highlight_type): |
|
207 |
row_highlights = self.Highlights.setdefault(infos[0], {}) |
|
208 |
col_highlights = row_highlights.setdefault(infos[1], []) |
|
209 |
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
|
210 |
|
814 | 211 |
def ClearHighlights(self, highlight_type=None): |
212 |
if highlight_type is None: |
|
213 |
self.Highlights = {} |
|
214 |
else: |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1834
diff
changeset
|
215 |
for _row, row_highlights in self.Highlights.iteritems(): |
814 | 216 |
row_items = row_highlights.items() |
217 |
for col, col_highlights in row_items: |
|
218 |
if highlight_type in col_highlights: |
|
219 |
col_highlights.remove(highlight_type) |
|
220 |
if len(col_highlights) == 0: |
|
221 |
row_highlights.pop(col) |
|
222 |
||
223 |
||
224 |
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
|
225 |
|
814 | 226 |
VARIABLE_PANEL_TYPE = "resource" |
227 |
||
228 |
def _init_Editor(self, parent): |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
229 |
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
|
230 |
|
814 | 231 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
232 |
main_sizer.AddGrowableCol(0) |
|
233 |
main_sizer.AddGrowableRow(0) |
|
234 |
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
|
235 |
|
814 | 236 |
tasks_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
237 |
tasks_sizer.AddGrowableCol(0) |
|
238 |
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
|
239 |
main_sizer.AddSizer(tasks_sizer, border=5, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
240 |
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
|
241 |
|
814 | 242 |
tasks_buttons_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
243 |
tasks_buttons_sizer.AddGrowableCol(0) |
|
244 |
tasks_buttons_sizer.AddGrowableRow(0) |
|
245 |
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
|
246 |
|
814 | 247 |
tasks_label = wx.StaticText(self.Editor, label=_(u'Tasks:')) |
248 |
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
|
249 |
|
814 | 250 |
for name, bitmap, help in [ |
251 |
("AddTaskButton", "add_element", _("Add task")), |
|
252 |
("DeleteTaskButton", "remove_element", _("Remove task")), |
|
253 |
("UpTaskButton", "up", _("Move task up")), |
|
254 |
("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
|
255 |
button = wx.lib.buttons.GenBitmapButton(self.Editor, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
256 |
bitmap=GetBitmap(bitmap), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
257 |
size=wx.Size(28, 28), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
258 |
style=wx.NO_BORDER) |
814 | 259 |
button.SetToolTipString(help) |
260 |
setattr(self, name, button) |
|
261 |
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
|
262 |
|
814 | 263 |
self.TasksGrid = CustomGrid(self.Editor, style=wx.VSCROLL) |
264 |
self.TasksGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnTasksGridCellChange) |
|
265 |
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
|
266 |
|
814 | 267 |
instances_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
268 |
instances_sizer.AddGrowableCol(0) |
|
269 |
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
|
270 |
main_sizer.AddSizer(instances_sizer, border=5, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
271 |
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
|
272 |
|
814 | 273 |
instances_buttons_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
274 |
instances_buttons_sizer.AddGrowableCol(0) |
|
275 |
instances_buttons_sizer.AddGrowableRow(0) |
|
276 |
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
|
277 |
|
814 | 278 |
instances_label = wx.StaticText(self.Editor, label=_(u'Instances:')) |
279 |
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
|
280 |
|
814 | 281 |
for name, bitmap, help in [ |
282 |
("AddInstanceButton", "add_element", _("Add instance")), |
|
283 |
("DeleteInstanceButton", "remove_element", _("Remove instance")), |
|
284 |
("UpInstanceButton", "up", _("Move instance up")), |
|
285 |
("DownInstanceButton", "down", _("Move instance down"))]: |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
286 |
button = wx.lib.buttons.GenBitmapButton( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
287 |
self.Editor, bitmap=GetBitmap(bitmap), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
288 |
size=wx.Size(28, 28), style=wx.NO_BORDER) |
814 | 289 |
button.SetToolTipString(help) |
290 |
setattr(self, name, button) |
|
291 |
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
|
292 |
|
814 | 293 |
self.InstancesGrid = CustomGrid(self.Editor, style=wx.VSCROLL) |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
294 |
self.InstancesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnInstancesGridCellChange) |
814 | 295 |
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
|
296 |
|
814 | 297 |
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
|
298 |
|
814 | 299 |
def __init__(self, parent, tagname, window, controler): |
300 |
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
|
301 |
|
814 | 302 |
self.RefreshHighlightsTimer = wx.Timer(self, -1) |
303 |
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
|
304 |
|
1968
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
305 |
self.TasksDefaultValue = {"Name": "task0", "Triggering": "Cyclic", |
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
306 |
"Single": "", "Interval": "T#20ms", "Priority": 0} |
814 | 307 |
self.TasksTable = ResourceTable(self, [], GetTasksTableColnames()) |
308 |
self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT]) |
|
309 |
self.TasksTable.SetColSizes([200, 100, 100, 150, 100]) |
|
310 |
self.TasksGrid.SetTable(self.TasksTable) |
|
311 |
self.TasksGrid.SetButtons({"Add": self.AddTaskButton, |
|
312 |
"Delete": self.DeleteTaskButton, |
|
313 |
"Up": self.UpTaskButton, |
|
314 |
"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
|
315 |
|
814 | 316 |
def _AddTask(new_row): |
1968
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
317 |
if new_row > 0: |
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
318 |
row_content = self.TasksTable.data[new_row-1].copy() |
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
319 |
old_name = row_content['Name'] |
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
320 |
row_content['Name'] =\ |
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
321 |
self.Controler.GenerateNewName(self.TagName, old_name, old_name+'%d') |
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
322 |
else: |
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
323 |
row_content = self.TasksDefaultValue.copy() |
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
324 |
|
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
325 |
self.TasksTable.InsertRow(new_row, row_content) |
814 | 326 |
self.RefreshModel() |
327 |
self.RefreshView() |
|
328 |
return new_row |
|
329 |
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
|
330 |
|
814 | 331 |
def _DeleteTask(row): |
332 |
self.TasksTable.RemoveRow(row) |
|
333 |
self.RefreshModel() |
|
334 |
self.RefreshView() |
|
335 |
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
|
336 |
|
814 | 337 |
def _MoveTask(row, move): |
338 |
new_row = self.TasksTable.MoveRow(row, move) |
|
339 |
if new_row != row: |
|
340 |
self.RefreshModel() |
|
341 |
self.RefreshView() |
|
342 |
return new_row |
|
343 |
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
|
344 |
|
814 | 345 |
self.TasksGrid.SetRowLabelSize(0) |
346 |
self.TasksTable.ResetView(self.TasksGrid) |
|
347 |
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
|
348 |
|
1968
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
349 |
self.InstancesDefaultValue = {"Name": "instance0", "Type": "", "Task": ""} |
814 | 350 |
self.InstancesTable = ResourceTable(self, [], GetInstancesTableColnames()) |
351 |
self.InstancesTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]) |
|
352 |
self.InstancesTable.SetColSizes([200, 150, 150]) |
|
353 |
self.InstancesGrid.SetTable(self.InstancesTable) |
|
354 |
self.InstancesGrid.SetButtons({"Add": self.AddInstanceButton, |
|
355 |
"Delete": self.DeleteInstanceButton, |
|
356 |
"Up": self.UpInstanceButton, |
|
357 |
"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
|
358 |
|
814 | 359 |
def _AddInstance(new_row): |
1968
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
360 |
if new_row > 0: |
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
361 |
row_content = self.InstancesTable.data[new_row - 1].copy() |
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
362 |
old_name = row_content['Name'] |
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
363 |
row_content['Name'] =\ |
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
364 |
self.Controler.GenerateNewName(self.TagName, old_name, old_name+'%d') |
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
365 |
else: |
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
366 |
row_content = self.InstancesDefaultValue.copy() |
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
367 |
|
64827679f3f1
add fields autocomplete when adding task or instance in resources
Surkov Sergey <surkovsv93@gmail.com>
parents:
1853
diff
changeset
|
368 |
self.InstancesTable.InsertRow(new_row, row_content) |
814 | 369 |
self.RefreshModel() |
370 |
self.RefreshView() |
|
371 |
return new_row |
|
372 |
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
|
373 |
|
814 | 374 |
def _DeleteInstance(row): |
375 |
self.InstancesTable.RemoveRow(row) |
|
376 |
self.RefreshModel() |
|
377 |
self.RefreshView() |
|
378 |
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
|
379 |
|
814 | 380 |
def _MoveInstance(row, move): |
381 |
new_row = max(0, min(row + move, self.InstancesTable.GetNumberRows() - 1)) |
|
382 |
if new_row != row: |
|
383 |
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
|
384 |
return row |
814 | 385 |
self.InstancesTable.MoveRow(row, move) |
386 |
self.RefreshModel() |
|
387 |
self.RefreshView() |
|
388 |
return new_row |
|
389 |
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
|
390 |
|
814 | 391 |
def _RefreshInstanceButtons(): |
392 |
if self: |
|
393 |
rows = self.InstancesTable.GetNumberRows() |
|
394 |
row = self.InstancesGrid.GetGridCursorRow() |
|
395 |
self.DeleteInstanceButton.Enable(rows > 0) |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
396 |
self.UpInstanceButton.Enable( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
397 |
row > 0 and |
814 | 398 |
self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row - 1, "Task")) |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
399 |
self.DownInstanceButton.Enable( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
400 |
0 <= row < rows - 1 and |
814 | 401 |
self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row + 1, "Task")) |
402 |
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
|
403 |
|
814 | 404 |
self.InstancesGrid.SetRowLabelSize(0) |
405 |
self.InstancesTable.ResetView(self.InstancesGrid) |
|
406 |
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
|
407 |
|
814 | 408 |
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
|
409 |
|
814 | 410 |
def __del__(self): |
411 |
self.RefreshHighlightsTimer.Stop() |
|
412 |
||
413 |
def RefreshTypeList(self): |
|
414 |
self.TypeList = "" |
|
415 |
blocktypes = self.Controler.GetBlockResource() |
|
416 |
for blocktype in blocktypes: |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1657
diff
changeset
|
417 |
self.TypeList += ",%s" % blocktype |
814 | 418 |
|
419 |
def RefreshTaskList(self): |
|
420 |
self.TaskList = "" |
|
421 |
for row in xrange(self.TasksTable.GetNumberRows()): |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1657
diff
changeset
|
422 |
self.TaskList += ",%s" % self.TasksTable.GetValueByName(row, "Name") |
814 | 423 |
|
424 |
def RefreshVariableList(self): |
|
425 |
self.VariableList = "" |
|
426 |
for variable in self.Controler.GetEditedResourceVariables(self.TagName): |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1657
diff
changeset
|
427 |
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
|
428 |
|
814 | 429 |
def RefreshModel(self): |
430 |
self.Controler.SetEditedResourceInfos(self.TagName, self.TasksTable.GetData(), self.InstancesTable.GetData()) |
|
431 |
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
|
432 |
|
814 | 433 |
# Buffer the last model state |
434 |
def RefreshBuffer(self): |
|
435 |
self.Controler.BufferProject() |
|
436 |
self.ParentWindow.RefreshTitle() |
|
437 |
self.ParentWindow.RefreshFileMenu() |
|
438 |
self.ParentWindow.RefreshEditMenu() |
|
439 |
||
440 |
def GetBufferState(self): |
|
441 |
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
|
442 |
|
814 | 443 |
def Undo(self): |
444 |
self.Controler.LoadPrevious() |
|
445 |
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
|
446 |
|
814 | 447 |
def Redo(self): |
448 |
self.Controler.LoadNext() |
|
449 |
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
|
450 |
|
814 | 451 |
def HasNoModel(self): |
452 |
return self.Controler.GetEditedElement(self.TagName) is None |
|
453 |
||
454 |
def RefreshView(self, variablepanel=True): |
|
455 |
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
|
456 |
|
814 | 457 |
tasks, instances = self.Controler.GetEditedResourceInfos(self.TagName) |
458 |
self.TasksTable.SetData(tasks) |
|
459 |
self.InstancesTable.SetData(instances) |
|
460 |
self.RefreshTypeList() |
|
461 |
self.RefreshTaskList() |
|
462 |
self.RefreshVariableList() |
|
463 |
self.TasksTable.ResetView(self.TasksGrid) |
|
464 |
self.InstancesTable.ResetView(self.InstancesGrid) |
|
465 |
self.TasksGrid.RefreshButtons() |
|
466 |
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
|
467 |
|
1657
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
468 |
def ShowErrorMessage(self, message): |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
469 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR) |
1657
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
470 |
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
|
471 |
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
|
472 |
|
814 | 473 |
def OnTasksGridCellChange(self, event): |
474 |
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
|
475 |
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
|
476 |
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
|
477 |
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
|
478 |
|
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
479 |
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
|
480 |
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
|
481 |
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
|
482 |
message = _("\"%s\" is a keyword. It can't be used!") % value |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
483 |
elif value.upper() in [var["Name"].upper() for i, var in enumerate(self.TasksTable.data) if i != row]: |
1657
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 = _("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
|
485 |
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
|
486 |
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
|
487 |
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
|
488 |
return |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
489 |
|
814 | 490 |
tasklist = [name for name in self.TaskList.split(",") if name != ""] |
491 |
for i in xrange(self.TasksTable.GetNumberRows()): |
|
492 |
task = self.TasksTable.GetValueByName(i, "Name") |
|
493 |
if task in tasklist: |
|
494 |
tasklist.remove(task) |
|
495 |
if len(tasklist) > 0: |
|
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1604
diff
changeset
|
496 |
old_name = tasklist[0].upper() |
814 | 497 |
new_name = self.TasksTable.GetValue(row, col) |
498 |
for i in xrange(self.InstancesTable.GetNumberRows()): |
|
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1604
diff
changeset
|
499 |
name = self.InstancesTable.GetValueByName(i, "Task").upper() |
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1604
diff
changeset
|
500 |
if old_name == name: |
814 | 501 |
self.InstancesTable.SetValueByName(i, "Task", new_name) |
2232
3220dd020675
If task type is changed from 'interrupt' to 'cyclic' init interval with T#20ms.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1968
diff
changeset
|
502 |
if self.TasksTable.GetColLabelValue(col, False) == "Triggering": |
3220dd020675
If task type is changed from 'interrupt' to 'cyclic' init interval with T#20ms.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1968
diff
changeset
|
503 |
self.TasksTable.SetValueByName(row, "Interval", "T#20ms") |
814 | 504 |
self.RefreshModel() |
505 |
colname = self.TasksTable.GetColLabelValue(col, False) |
|
1423
4e33f644f7cf
Added highlighting of wrong SINGLE task trigger
Edouard Tisserant
parents:
1420
diff
changeset
|
506 |
if colname in ["Triggering", "Name", "Single", "Interval"]: |
814 | 507 |
wx.CallAfter(self.RefreshView, False) |
508 |
event.Skip() |
|
509 |
||
510 |
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
|
511 |
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
|
512 |
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
|
513 |
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
|
514 |
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
|
515 |
|
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
516 |
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
|
517 |
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
|
518 |
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
|
519 |
message = _("\"%s\" is a keyword. It can't be used!") % value |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
520 |
elif value.upper() in [var["Name"].upper() for i, var in enumerate(self.InstancesTable.data) if i != row]: |
1657
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
521 |
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
|
522 |
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
|
523 |
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
|
524 |
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
|
525 |
return |
3a98027ff372
apply constraints to names for tasks and task instances in resource configuration
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
526 |
|
814 | 527 |
self.RefreshModel() |
528 |
self.ParentWindow.RefreshPouInstanceVariablesPanel() |
|
529 |
self.InstancesGrid.RefreshButtons() |
|
530 |
event.Skip() |
|
531 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
532 |
# ------------------------------------------------------------------------------- |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
533 |
# Highlights showing functions |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
534 |
# ------------------------------------------------------------------------------- |
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
|
535 |
|
814 | 536 |
def OnRefreshHighlightsTimer(self, event): |
537 |
self.RefreshView() |
|
538 |
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
|
539 |
|
814 | 540 |
def AddHighlight(self, infos, start, end, highlight_type): |
899
64aa66d481c5
Fix bug in resource search result highlighting
Laurent Bessard
parents:
879
diff
changeset
|
541 |
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
|
542 |
|
814 | 543 |
if infos[0] == "task": |
544 |
self.TasksTable.AddHighlight(infos[1:], highlight_type) |
|
545 |
elif infos[0] == "instance": |
|
546 |
self.InstancesTable.AddHighlight(infos[1:], highlight_type) |
|
547 |
self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
548 |
||
549 |
def ClearHighlights(self, highlight_type=None): |
|
550 |
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
|
551 |
|
814 | 552 |
self.TasksTable.ClearHighlights(highlight_type) |
553 |
self.InstancesTable.ClearHighlights(highlight_type) |
|
554 |
self.TasksTable.ResetView(self.TasksGrid) |
|
555 |
self.InstancesTable.ResetView(self.InstancesGrid) |