author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Tue, 06 Jun 2017 13:05:30 +0300 | |
changeset 1688 | 457155545922 |
parent 1658 | ba6a6d6e989c |
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:
1508
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:
1508
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:
1508
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:
1508
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:
1508
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:
1508
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:
1508
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:
1508
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:
1508
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:
1508
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:
1508
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:
1508
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:
1508
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:
1508
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:
1508
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
25 |
import re |
|
864
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
26 |
from types import TupleType |
814 | 27 |
|
28 |
import wx |
|
29 |
import wx.grid |
|
30 |
import wx.lib.buttons |
|
31 |
||
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
32 |
from plcopen.structures import IEC_KEYWORDS, TestIdentifier, DefaultType |
814 | 33 |
from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD |
34 |
from controls import CustomEditableListBox, CustomGrid, CustomTable |
|
864
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
35 |
from dialogs import ArrayTypeDialog |
814 | 36 |
from EditorPanel import EditorPanel |
37 |
from util.BitmapLibrary import GetBitmap |
|
38 |
||
39 |
#------------------------------------------------------------------------------- |
|
40 |
# Helpers |
|
41 |
#------------------------------------------------------------------------------- |
|
42 |
||
43 |
DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$") |
|
44 |
||
45 |
def AppendMenu(parent, help, id, kind, text): |
|
46 |
parent.Append(help=help, id=id, kind=kind, text=text) |
|
47 |
||
48 |
def GetElementsTableColnames(): |
|
49 |
_ = lambda x : x |
|
50 |
return ["#", _("Name"), _("Type"), _("Initial Value")] |
|
51 |
||
52 |
def GetDatatypeTypes(): |
|
53 |
_ = lambda x : x |
|
54 |
return [_("Directly"), _("Subrange"), _("Enumerated"), _("Array"), _("Structure")] |
|
55 |
DATATYPE_TYPES_DICT = dict([(_(datatype), datatype) for datatype in GetDatatypeTypes()]) |
|
56 |
||
57 |
#------------------------------------------------------------------------------- |
|
58 |
# Structure Elements Table |
|
59 |
#------------------------------------------------------------------------------- |
|
60 |
||
61 |
class ElementsTable(CustomTable): |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
62 |
|
814 | 63 |
""" |
64 |
A custom wx.grid.Grid Table using user supplied data |
|
65 |
""" |
|
66 |
def __init__(self, parent, data, colnames): |
|
67 |
# The base class must be initialized *first* |
|
68 |
CustomTable.__init__(self, parent, data, colnames) |
|
69 |
self.old_value = None |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
70 |
|
814 | 71 |
def GetValue(self, row, col): |
72 |
if row < self.GetNumberRows(): |
|
73 |
if col == 0: |
|
74 |
return row + 1 |
|
864
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
75 |
colname = self.GetColLabelValue(col, False) |
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
76 |
value = self.data[row].get(colname, "") |
1508
4c645e6b8c98
fix error if non-latin character was entered in initial value in
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
77 |
|
864
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
78 |
if colname == "Type" and isinstance(value, TupleType): |
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
79 |
if value[0] == "array": |
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
80 |
return "ARRAY [%s] OF %s" % (",".join(map(lambda x : "..".join(x), value[2])), value[1]) |
1508
4c645e6b8c98
fix error if non-latin character was entered in initial value in
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
81 |
return value |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
82 |
|
814 | 83 |
def SetValue(self, row, col, value): |
84 |
if col < len(self.colnames): |
|
85 |
colname = self.GetColLabelValue(col, False) |
|
86 |
if colname == "Name": |
|
87 |
self.old_value = self.data[row][colname] |
|
88 |
self.data[row][colname] = value |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
89 |
|
814 | 90 |
def GetOldValue(self): |
91 |
return self.old_value |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
92 |
|
814 | 93 |
def _updateColAttrs(self, grid): |
94 |
""" |
|
95 |
wx.grid.Grid -> update the column attributes to add the |
|
96 |
appropriate renderer given the column name. |
|
97 |
||
98 |
Otherwise default to the default renderer. |
|
99 |
""" |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
100 |
|
814 | 101 |
for row in range(self.GetNumberRows()): |
102 |
row_highlights = self.Highlights.get(row, {}) |
|
103 |
for col in range(self.GetNumberCols()): |
|
104 |
editor = None |
|
105 |
renderer = None |
|
106 |
colname = self.GetColLabelValue(col, False) |
|
107 |
if col != 0: |
|
108 |
grid.SetReadOnly(row, col, False) |
|
109 |
if colname == "Name": |
|
110 |
editor = wx.grid.GridCellTextEditor() |
|
111 |
renderer = wx.grid.GridCellStringRenderer() |
|
112 |
elif colname == "Initial Value": |
|
113 |
editor = wx.grid.GridCellTextEditor() |
|
114 |
renderer = wx.grid.GridCellStringRenderer() |
|
115 |
elif colname == "Type": |
|
116 |
editor = wx.grid.GridCellTextEditor() |
|
117 |
else: |
|
118 |
grid.SetReadOnly(row, col, True) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
119 |
|
814 | 120 |
grid.SetCellEditor(row, col, editor) |
121 |
grid.SetCellRenderer(row, col, renderer) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
122 |
|
814 | 123 |
highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] |
124 |
grid.SetCellBackgroundColour(row, col, highlight_colours[0]) |
|
125 |
grid.SetCellTextColour(row, col, highlight_colours[1]) |
|
126 |
self.ResizeRow(grid, row) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
127 |
|
814 | 128 |
def AddHighlight(self, infos, highlight_type): |
129 |
row_highlights = self.Highlights.setdefault(infos[0], {}) |
|
130 |
if infos[1] == "initial": |
|
131 |
col_highlights = row_highlights.setdefault("initial value", []) |
|
132 |
else: |
|
133 |
col_highlights = row_highlights.setdefault(infos[1], []) |
|
134 |
col_highlights.append(highlight_type) |
|
135 |
||
136 |
#------------------------------------------------------------------------------- |
|
137 |
# Datatype Editor class |
|
138 |
#------------------------------------------------------------------------------- |
|
139 |
||
140 |
class DataTypeEditor(EditorPanel): |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
141 |
|
814 | 142 |
def _init_Editor(self, parent): |
143 |
self.Editor = wx.Panel(parent, style=wx.SUNKEN_BORDER) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
144 |
|
814 | 145 |
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
146 |
self.MainSizer.AddGrowableCol(0) |
|
147 |
self.MainSizer.AddGrowableRow(1) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
148 |
|
814 | 149 |
top_sizer = wx.BoxSizer(wx.HORIZONTAL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
150 |
self.MainSizer.AddSizer(top_sizer, border=5, |
814 | 151 |
flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
152 |
|
814 | 153 |
derivation_type_label = wx.StaticText(self.Editor, label=_('Derivation Type:')) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
154 |
top_sizer.AddWindow(derivation_type_label, border=5, |
814 | 155 |
flag=wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
156 |
|
814 | 157 |
self.DerivationType = wx.ComboBox(self.Editor, |
158 |
size=wx.Size(200, -1), style=wx.CB_READONLY) |
|
159 |
self.Bind(wx.EVT_COMBOBOX, self.OnDerivationTypeChanged, self.DerivationType) |
|
160 |
top_sizer.AddWindow(self.DerivationType, border=5, flag=wx.GROW|wx.RIGHT) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
161 |
|
814 | 162 |
typeinfos_staticbox = wx.StaticBox(self.Editor, label=_('Type infos:')) |
163 |
typeinfos_sizer = wx.StaticBoxSizer(typeinfos_staticbox, wx.HORIZONTAL) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
164 |
self.MainSizer.AddSizer(typeinfos_sizer, border=5, |
814 | 165 |
flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
166 |
|
814 | 167 |
# Panel for Directly derived data types |
168 |
||
169 |
self.DirectlyPanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL) |
|
170 |
typeinfos_sizer.AddWindow(self.DirectlyPanel, 1) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
171 |
|
814 | 172 |
directly_panel_sizer = wx.BoxSizer(wx.HORIZONTAL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
173 |
|
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
174 |
directly_basetype_label = wx.StaticText(self.DirectlyPanel, |
814 | 175 |
label=_('Base Type:')) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
176 |
directly_panel_sizer.AddWindow(directly_basetype_label, 1, border=5, |
814 | 177 |
flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
178 |
|
814 | 179 |
self.DirectlyBaseType = wx.ComboBox(self.DirectlyPanel, style=wx.CB_READONLY) |
947 | 180 |
self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, self.DirectlyBaseType) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
181 |
directly_panel_sizer.AddWindow(self.DirectlyBaseType, 1, border=5, |
814 | 182 |
flag=wx.GROW|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
183 |
|
814 | 184 |
directly_initialvalue_label = wx.StaticText(self.DirectlyPanel, |
185 |
label=_('Initial Value:')) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
186 |
directly_panel_sizer.AddWindow(directly_initialvalue_label, 1, border=5, |
814 | 187 |
flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
188 |
|
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
189 |
self.DirectlyInitialValue = wx.TextCtrl(self.DirectlyPanel, |
947 | 190 |
style=wx.TE_PROCESS_ENTER|wx.TE_RICH) |
814 | 191 |
self.Bind(wx.EVT_TEXT_ENTER, self.OnReturnKeyPressed, self.DirectlyInitialValue) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
192 |
directly_panel_sizer.AddWindow(self.DirectlyInitialValue, 1, border=5, |
814 | 193 |
flag=wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
194 |
|
814 | 195 |
self.DirectlyPanel.SetSizer(directly_panel_sizer) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
196 |
|
814 | 197 |
# Panel for Subrange data types |
198 |
||
199 |
self.SubrangePanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL) |
|
200 |
typeinfos_sizer.AddWindow(self.SubrangePanel, 1) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
201 |
|
814 | 202 |
subrange_panel_sizer = wx.GridSizer(cols=4, hgap=5, rows=3, vgap=0) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
203 |
|
814 | 204 |
subrange_basetype_label = wx.StaticText(self.SubrangePanel, |
205 |
label=_('Base Type:')) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
206 |
subrange_panel_sizer.AddWindow(subrange_basetype_label, 1, border=5, |
814 | 207 |
flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
208 |
|
814 | 209 |
self.SubrangeBaseType = wx.ComboBox(self.SubrangePanel, style=wx.CB_READONLY) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
210 |
self.Bind(wx.EVT_COMBOBOX, self.OnSubrangeBaseTypeChanged, |
814 | 211 |
self.SubrangeBaseType) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
212 |
subrange_panel_sizer.AddWindow(self.SubrangeBaseType, 1, border=5, |
814 | 213 |
flag=wx.GROW|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
214 |
|
814 | 215 |
subrange_initialvalue_label = wx.StaticText(self.SubrangePanel, |
216 |
label=_('Initial Value:')) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
217 |
subrange_panel_sizer.AddWindow(subrange_initialvalue_label, 1, border=5, |
814 | 218 |
flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
219 |
|
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
220 |
self.SubrangeInitialValue = wx.SpinCtrl(self.SubrangePanel, |
814 | 221 |
style=wx.TAB_TRAVERSAL) |
222 |
self.Bind(wx.EVT_SPINCTRL, self.OnInfosChanged, self.SubrangeInitialValue) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
223 |
subrange_panel_sizer.AddWindow(self.SubrangeInitialValue, 1, border=5, |
814 | 224 |
flag=wx.GROW|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
225 |
|
814 | 226 |
subrange_minimum_label = wx.StaticText(self.SubrangePanel, label=_('Minimum:')) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
227 |
subrange_panel_sizer.AddWindow(subrange_minimum_label, 1, border=5, |
814 | 228 |
flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
229 |
|
814 | 230 |
self.SubrangeMinimum = wx.SpinCtrl(self.SubrangePanel, style=wx.TAB_TRAVERSAL) |
231 |
self.Bind(wx.EVT_SPINCTRL, self.OnSubrangeMinimumChanged, self.SubrangeMinimum) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
232 |
subrange_panel_sizer.AddWindow(self.SubrangeMinimum, 1, border=5, |
814 | 233 |
flag=wx.GROW|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
234 |
|
814 | 235 |
for i in xrange(2): |
236 |
subrange_panel_sizer.AddWindow(wx.Size(0, 0), 1) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
237 |
|
814 | 238 |
subrange_maximum_label = wx.StaticText(self.SubrangePanel, |
239 |
label=_('Maximum:')) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
240 |
subrange_panel_sizer.AddWindow(subrange_maximum_label, 1, border=5, |
814 | 241 |
flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
242 |
|
814 | 243 |
self.SubrangeMaximum = wx.SpinCtrl(self.SubrangePanel, style=wx.TAB_TRAVERSAL) |
244 |
self.Bind(wx.EVT_SPINCTRL, self.OnSubrangeMaximumChanged, self.SubrangeMaximum) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
245 |
|
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
246 |
subrange_panel_sizer.AddWindow(self.SubrangeMaximum, 1, border=5, |
814 | 247 |
flag=wx.GROW|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
248 |
|
814 | 249 |
self.SubrangePanel.SetSizer(subrange_panel_sizer) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
250 |
|
814 | 251 |
# Panel for Enumerated data types |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
252 |
|
814 | 253 |
self.EnumeratedPanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL) |
254 |
typeinfos_sizer.AddWindow(self.EnumeratedPanel, 1) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
255 |
|
814 | 256 |
enumerated_panel_sizer = wx.BoxSizer(wx.HORIZONTAL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
257 |
|
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
258 |
self.EnumeratedValues = CustomEditableListBox(self.EnumeratedPanel, |
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
259 |
label=_("Values:"), style=wx.gizmos.EL_ALLOW_NEW| |
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
260 |
wx.gizmos.EL_ALLOW_EDIT| |
814 | 261 |
wx.gizmos.EL_ALLOW_DELETE) |
262 |
setattr(self.EnumeratedValues, "_OnLabelEndEdit", self.OnEnumeratedValueEndEdit) |
|
263 |
for func in ["_OnAddButton", "_OnDelButton", "_OnUpButton", "_OnDownButton"]: |
|
264 |
setattr(self.EnumeratedValues, func, self.OnEnumeratedValuesChanged) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
265 |
enumerated_panel_sizer.AddWindow(self.EnumeratedValues, 1, border=5, |
814 | 266 |
flag=wx.GROW|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
267 |
|
814 | 268 |
enumerated_panel_rightsizer = wx.BoxSizer(wx.HORIZONTAL) |
269 |
enumerated_panel_sizer.AddSizer(enumerated_panel_rightsizer, 1) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
270 |
|
814 | 271 |
enumerated_initialvalue_label = wx.StaticText(self.EnumeratedPanel, |
272 |
label=_('Initial Value:')) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
273 |
enumerated_panel_rightsizer.AddWindow(enumerated_initialvalue_label, 1, |
814 | 274 |
border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
275 |
|
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
276 |
self.EnumeratedInitialValue = wx.ComboBox(self.EnumeratedPanel, |
814 | 277 |
style=wx.CB_READONLY) |
278 |
self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, self.EnumeratedInitialValue) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
279 |
enumerated_panel_rightsizer.AddWindow(self.EnumeratedInitialValue, 1, |
814 | 280 |
border=5, flag=wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
281 |
|
814 | 282 |
self.EnumeratedPanel.SetSizer(enumerated_panel_sizer) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
283 |
|
814 | 284 |
# Panel for Array data types |
285 |
||
286 |
self.ArrayPanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL) |
|
287 |
typeinfos_sizer.AddWindow(self.ArrayPanel, 1) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
288 |
|
814 | 289 |
array_panel_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=0) |
290 |
array_panel_sizer.AddGrowableCol(0) |
|
291 |
array_panel_sizer.AddGrowableCol(1) |
|
292 |
array_panel_sizer.AddGrowableRow(1) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
293 |
|
814 | 294 |
array_panel_leftSizer = wx.BoxSizer(wx.HORIZONTAL) |
295 |
array_panel_sizer.AddSizer(array_panel_leftSizer, flag=wx.GROW) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
296 |
|
814 | 297 |
array_basetype_label = wx.StaticText(self.ArrayPanel, label=_('Base Type:')) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
298 |
array_panel_leftSizer.AddWindow(array_basetype_label, 1, border=5, |
814 | 299 |
flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
300 |
|
814 | 301 |
self.ArrayBaseType = wx.ComboBox(self.ArrayPanel, style=wx.CB_READONLY) |
302 |
self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, self.ArrayBaseType) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
303 |
array_panel_leftSizer.AddWindow(self.ArrayBaseType, 1, border=5, |
814 | 304 |
flag=wx.GROW|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
305 |
|
814 | 306 |
array_panel_rightsizer = wx.BoxSizer(wx.HORIZONTAL) |
307 |
array_panel_sizer.AddSizer(array_panel_rightsizer, flag=wx.GROW) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
308 |
|
814 | 309 |
array_initialvalue_label = wx.StaticText(self.ArrayPanel, |
310 |
label=_('Initial Value:')) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
311 |
array_panel_rightsizer.AddWindow(array_initialvalue_label, 1, border=5, |
814 | 312 |
flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
313 |
|
814 | 314 |
self.ArrayInitialValue = wx.TextCtrl(self.ArrayPanel, |
947 | 315 |
style=wx.TE_PROCESS_ENTER|wx.TE_RICH) |
814 | 316 |
self.Bind(wx.EVT_TEXT_ENTER, self.OnReturnKeyPressed, self.ArrayInitialValue) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
317 |
array_panel_rightsizer.AddWindow(self.ArrayInitialValue, 1, border=5, |
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
318 |
flag=wx.ALL) |
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
319 |
|
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
320 |
self.ArrayDimensions = CustomEditableListBox(self.ArrayPanel, |
814 | 321 |
label=_("Dimensions:"), style=wx.gizmos.EL_ALLOW_NEW| |
322 |
wx.gizmos.EL_ALLOW_EDIT| |
|
323 |
wx.gizmos.EL_ALLOW_DELETE) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
324 |
for func in ["_OnLabelEndEdit", "_OnAddButton", "_OnDelButton", |
814 | 325 |
"_OnUpButton", "_OnDownButton"]: |
326 |
setattr(self.ArrayDimensions, func, self.OnDimensionsChanged) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
327 |
array_panel_sizer.AddWindow(self.ArrayDimensions, 0, border=5, |
814 | 328 |
flag=wx.GROW|wx.ALL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
329 |
|
814 | 330 |
self.ArrayPanel.SetSizer(array_panel_sizer) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
331 |
|
814 | 332 |
# Panel for Structure data types |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
333 |
|
814 | 334 |
self.StructurePanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL) |
335 |
typeinfos_sizer.AddWindow(self.StructurePanel, 1) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
336 |
|
814 | 337 |
structure_panel_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
338 |
structure_panel_sizer.AddGrowableCol(0) |
|
339 |
structure_panel_sizer.AddGrowableRow(1) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
340 |
|
814 | 341 |
structure_button_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
342 |
structure_button_sizer.AddGrowableCol(0) |
|
343 |
structure_button_sizer.AddGrowableRow(0) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
344 |
structure_panel_sizer.AddSizer(structure_button_sizer, 0, border=5, |
814 | 345 |
flag=wx.ALL|wx.GROW) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
346 |
|
814 | 347 |
structure_elements_label = wx.StaticText(self.StructurePanel, |
348 |
label=_('Elements :')) |
|
349 |
structure_button_sizer.AddWindow(structure_elements_label, flag=wx.ALIGN_BOTTOM) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
350 |
|
814 | 351 |
for name, bitmap, help in [ |
352 |
("StructureAddButton", "add_element", _("Add element")), |
|
353 |
("StructureDeleteButton", "remove_element", _("Remove element")), |
|
354 |
("StructureUpButton", "up", _("Move element up")), |
|
355 |
("StructureDownButton", "down", _("Move element down"))]: |
|
356 |
button = wx.lib.buttons.GenBitmapButton(self.StructurePanel, |
|
357 |
bitmap=GetBitmap(bitmap), size=wx.Size(28, 28), style=wx.NO_BORDER) |
|
358 |
button.SetToolTipString(help) |
|
359 |
setattr(self, name, button) |
|
360 |
structure_button_sizer.AddWindow(button) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
361 |
|
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
362 |
self.StructureElementsGrid = CustomGrid(self.StructurePanel, |
814 | 363 |
size=wx.Size(0, 150), style=wx.VSCROLL) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
364 |
self.StructureElementsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, |
814 | 365 |
self.OnStructureElementsGridCellChange) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
366 |
self.StructureElementsGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, |
814 | 367 |
self.OnStructureElementsGridEditorShown) |
368 |
structure_panel_sizer.AddWindow(self.StructureElementsGrid, flag=wx.GROW) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
369 |
|
814 | 370 |
self.StructurePanel.SetSizer(structure_panel_sizer) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
371 |
|
814 | 372 |
self.Editor.SetSizer(self.MainSizer) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
373 |
|
814 | 374 |
def __init__(self, parent, tagname, window, controler): |
375 |
EditorPanel.__init__(self, parent, tagname, window, controler) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
376 |
|
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
377 |
self.StructureElementDefaultValue = {"Name" : "", "Type" : DefaultType, "Initial Value" : ""} |
814 | 378 |
self.StructureElementsTable = ElementsTable(self, [], GetElementsTableColnames()) |
379 |
self.StructureColSizes = [40, 150, 100, 250] |
|
380 |
self.StructureColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT] |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
381 |
|
814 | 382 |
self.StructureElementsGrid.SetTable(self.StructureElementsTable) |
383 |
self.StructureElementsGrid.SetButtons({"Add": self.StructureAddButton, |
|
384 |
"Delete": self.StructureDeleteButton, |
|
385 |
"Up": self.StructureUpButton, |
|
386 |
"Down": self.StructureDownButton}) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
387 |
|
814 | 388 |
def _AddStructureElement(new_row): |
389 |
self.StructureElementsTable.InsertRow(new_row, self.StructureElementDefaultValue.copy()) |
|
390 |
self.RefreshTypeInfos() |
|
391 |
self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
|
392 |
return new_row |
|
393 |
setattr(self.StructureElementsGrid, "_AddRow", _AddStructureElement) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
394 |
|
814 | 395 |
def _DeleteStructureElement(row): |
396 |
self.StructureElementsTable.RemoveRow(row) |
|
397 |
self.RefreshTypeInfos() |
|
398 |
self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
|
399 |
setattr(self.StructureElementsGrid, "_DeleteRow", _DeleteStructureElement) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
400 |
|
814 | 401 |
def _MoveStructureElement(row, move): |
402 |
new_row = self.StructureElementsTable.MoveRow(row, move) |
|
403 |
if new_row != row: |
|
404 |
self.RefreshTypeInfos() |
|
405 |
self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
|
406 |
return new_row |
|
407 |
setattr(self.StructureElementsGrid, "_MoveRow", _MoveStructureElement) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
408 |
|
814 | 409 |
self.StructureElementsGrid.SetRowLabelSize(0) |
410 |
for col in range(self.StructureElementsTable.GetNumberCols()): |
|
411 |
attr = wx.grid.GridCellAttr() |
|
412 |
attr.SetAlignment(self.StructureColAlignements[col], wx.ALIGN_CENTRE) |
|
413 |
self.StructureElementsGrid.SetColAttr(col, attr) |
|
414 |
self.StructureElementsGrid.SetColMinimalWidth(col, self.StructureColSizes[col]) |
|
415 |
self.StructureElementsGrid.AutoSizeColumn(col, False) |
|
416 |
self.StructureElementsGrid.RefreshButtons() |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
417 |
|
814 | 418 |
for datatype in GetDatatypeTypes(): |
419 |
self.DerivationType.Append(_(datatype)) |
|
420 |
self.SubrangePanel.Hide() |
|
421 |
self.EnumeratedPanel.Hide() |
|
422 |
self.ArrayPanel.Hide() |
|
423 |
self.StructurePanel.Hide() |
|
424 |
self.CurrentPanel = "Directly" |
|
425 |
self.Highlights = [] |
|
426 |
self.Initializing = False |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
427 |
|
814 | 428 |
self.HighlightControls = { |
429 |
("Directly", "base"): self.DirectlyBaseType, |
|
430 |
("Directly", "initial"): self.DirectlyInitialValue, |
|
431 |
("Subrange", "base"): self.SubrangeBaseType, |
|
432 |
("Subrange", "lower"): self.SubrangeMinimum, |
|
433 |
("Subrange", "upper"): self.SubrangeMaximum, |
|
434 |
("Subrange", "initial"): self.SubrangeInitialValue, |
|
435 |
("Enumerated", "value"): self.EnumeratedValues, |
|
436 |
("Enumerated", "initial"): self.EnumeratedInitialValue, |
|
437 |
("Array", "initial"): self.ArrayInitialValue, |
|
438 |
("Array", "base"): self.ArrayBaseType, |
|
439 |
("Array", "range"): self.ArrayDimensions, |
|
440 |
} |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
441 |
|
814 | 442 |
self.RefreshHighlightsTimer = wx.Timer(self, -1) |
443 |
self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
444 |
|
814 | 445 |
def __del__(self): |
446 |
self.RefreshHighlightsTimer.Stop() |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
447 |
|
814 | 448 |
def GetBufferState(self): |
449 |
return self.Controler.GetBufferState() |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
450 |
|
814 | 451 |
def Undo(self): |
452 |
self.Controler.LoadPrevious() |
|
453 |
self.ParentWindow.CloseTabsWithoutModel() |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
454 |
|
814 | 455 |
def Redo(self): |
456 |
self.Controler.LoadNext() |
|
457 |
self.ParentWindow.CloseTabsWithoutModel() |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
458 |
|
814 | 459 |
def HasNoModel(self): |
460 |
return self.Controler.GetEditedElement(self.TagName) is None |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
461 |
|
814 | 462 |
def RefreshView(self): |
463 |
self.Initializing = True |
|
464 |
self.DirectlyBaseType.Clear() |
|
465 |
self.ArrayBaseType.Clear() |
|
466 |
for datatype in self.Controler.GetDataTypes(self.TagName): |
|
467 |
self.DirectlyBaseType.Append(datatype) |
|
468 |
self.ArrayBaseType.Append(datatype) |
|
469 |
self.DirectlyBaseType.SetSelection(0) |
|
470 |
self.SubrangeBaseType.Clear() |
|
471 |
words = self.TagName.split("::") |
|
472 |
for base_type in self.Controler.GetSubrangeBaseTypes(words[1]): |
|
473 |
self.SubrangeBaseType.Append(base_type) |
|
474 |
self.SubrangeBaseType.SetSelection(0) |
|
475 |
self.RefreshBoundsRange() |
|
476 |
type_infos = self.Controler.GetDataTypeInfos(self.TagName) |
|
477 |
if type_infos is not None: |
|
478 |
datatype = type_infos["type"] |
|
479 |
self.DerivationType.SetStringSelection(_(datatype)) |
|
480 |
if type_infos["type"] == "Directly": |
|
481 |
self.DirectlyBaseType.SetStringSelection(type_infos["base_type"]) |
|
482 |
self.DirectlyInitialValue.SetValue(type_infos["initial"]) |
|
483 |
elif type_infos["type"] == "Subrange": |
|
484 |
self.SubrangeBaseType.SetStringSelection(type_infos["base_type"]) |
|
485 |
self.RefreshBoundsRange() |
|
486 |
self.SubrangeMinimum.SetValue(int(type_infos["min"])) |
|
487 |
self.SubrangeMaximum.SetValue(int(type_infos["max"])) |
|
488 |
self.RefreshSubrangeInitialValueRange() |
|
489 |
if type_infos["initial"] != "": |
|
490 |
self.SubrangeInitialValue.SetValue(int(type_infos["initial"])) |
|
491 |
else: |
|
492 |
self.SubrangeInitialValue.SetValue(type_infos["min"]) |
|
493 |
elif type_infos["type"] == "Enumerated": |
|
494 |
self.EnumeratedValues.SetStrings(type_infos["values"]) |
|
495 |
self.RefreshEnumeratedValues() |
|
496 |
self.EnumeratedInitialValue.SetStringSelection(type_infos["initial"]) |
|
497 |
elif type_infos["type"] == "Array": |
|
498 |
self.ArrayBaseType.SetStringSelection(type_infos["base_type"]) |
|
499 |
self.ArrayDimensions.SetStrings(map(lambda x : "..".join(x), type_infos["dimensions"])) |
|
500 |
self.ArrayInitialValue.SetValue(type_infos["initial"]) |
|
501 |
elif type_infos["type"] == "Structure": |
|
502 |
self.StructureElementsTable.SetData(type_infos["elements"]) |
|
503 |
self.RefreshDisplayedInfos() |
|
504 |
self.ShowHighlights() |
|
505 |
self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
|
506 |
self.StructureElementsGrid.RefreshButtons() |
|
507 |
self.Initializing = False |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
508 |
|
814 | 509 |
def OnDerivationTypeChanged(self, event): |
510 |
wx.CallAfter(self.RefreshDisplayedInfos) |
|
511 |
wx.CallAfter(self.RefreshTypeInfos) |
|
512 |
event.Skip() |
|
513 |
||
514 |
def OnReturnKeyPressed(self, event): |
|
515 |
self.RefreshTypeInfos() |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
516 |
|
814 | 517 |
def OnInfosChanged(self, event): |
518 |
self.RefreshTypeInfos() |
|
519 |
event.Skip() |
|
520 |
||
521 |
def OnSubrangeBaseTypeChanged(self, event): |
|
522 |
self.RefreshBoundsRange() |
|
523 |
self.RefreshTypeInfos() |
|
524 |
event.Skip() |
|
525 |
||
526 |
def OnSubrangeMinimumChanged(self, event): |
|
527 |
if not self.Initializing: |
|
528 |
wx.CallAfter(self.SubrangeMinimum.SetValue, min(self.SubrangeMaximum.GetValue(), self.SubrangeMinimum.GetValue())) |
|
529 |
wx.CallAfter(self.RefreshSubrangeInitialValueRange) |
|
530 |
wx.CallAfter(self.RefreshTypeInfos) |
|
531 |
event.Skip() |
|
532 |
||
533 |
def OnSubrangeMaximumChanged(self, event): |
|
534 |
if not self.Initializing: |
|
535 |
wx.CallAfter(self.SubrangeMaximum.SetValue, max(self.SubrangeMinimum.GetValue(), self.SubrangeMaximum.GetValue())) |
|
536 |
wx.CallAfter(self.RefreshSubrangeInitialValueRange) |
|
537 |
wx.CallAfter(self.RefreshTypeInfos) |
|
538 |
event.Skip() |
|
539 |
||
540 |
def OnDimensionsChanged(self, event): |
|
541 |
wx.CallAfter(self.RefreshTypeInfos) |
|
542 |
event.Skip() |
|
543 |
||
544 |
def OnEnumeratedValueEndEdit(self, event): |
|
545 |
text = event.GetText() |
|
546 |
values = self.EnumeratedValues.GetStrings() |
|
547 |
index = event.GetIndex() |
|
548 |
if index >= len(values) or values[index].upper() != text.upper(): |
|
549 |
if text.upper() in [value.upper() for value in values]: |
|
550 |
message = wx.MessageDialog(self, _("\"%s\" value already defined!")%text, _("Error"), wx.OK|wx.ICON_ERROR) |
|
551 |
message.ShowModal() |
|
552 |
message.Destroy() |
|
553 |
event.Veto() |
|
554 |
elif text.upper() in IEC_KEYWORDS: |
|
555 |
message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%text, _("Error"), wx.OK|wx.ICON_ERROR) |
|
556 |
message.ShowModal() |
|
557 |
message.Destroy() |
|
558 |
else: |
|
559 |
initial_selected = None |
|
560 |
if index < len(values) and self.EnumeratedInitialValue.GetStringSelection() == values[index]: |
|
561 |
initial_selected = text |
|
562 |
wx.CallAfter(self.RefreshEnumeratedValues, initial_selected) |
|
563 |
wx.CallAfter(self.RefreshTypeInfos) |
|
564 |
event.Skip() |
|
565 |
else: |
|
566 |
event.Skip() |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
567 |
|
814 | 568 |
def OnEnumeratedValuesChanged(self, event): |
569 |
wx.CallAfter(self.RefreshEnumeratedValues) |
|
570 |
wx.CallAfter(self.RefreshTypeInfos) |
|
571 |
event.Skip() |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
572 |
|
1658
ba6a6d6e989c
fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
573 |
def ShowErrorMessage(self, message): |
ba6a6d6e989c
fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
574 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
ba6a6d6e989c
fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
575 |
dialog.ShowModal() |
ba6a6d6e989c
fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
576 |
dialog.Destroy() |
ba6a6d6e989c
fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
577 |
|
814 | 578 |
def OnStructureElementsGridCellChange(self, event): |
579 |
row, col = event.GetRow(), event.GetCol() |
|
947 | 580 |
colname = self.StructureElementsTable.GetColLabelValue(col, False) |
814 | 581 |
value = self.StructureElementsTable.GetValue(row, col) |
582 |
if colname == "Name": |
|
1658
ba6a6d6e989c
fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
583 |
message = None |
814 | 584 |
if not TestIdentifier(value): |
1658
ba6a6d6e989c
fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
585 |
message = _("\"%s\" is not a valid identifier!")%value |
814 | 586 |
elif value.upper() in IEC_KEYWORDS: |
1658
ba6a6d6e989c
fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
587 |
message = _("\"%s\" is a keyword. It can't be used!")%value |
814 | 588 |
## elif value.upper() in self.PouNames: |
1658
ba6a6d6e989c
fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
589 |
## message = _("A pou with \"%s\" as name exists!")%value |
814 | 590 |
elif value.upper() in [var["Name"].upper() for idx, var in enumerate(self.StructureElementsTable.GetData()) if idx != row]: |
1658
ba6a6d6e989c
fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
591 |
message = _("An element named \"%s\" already exists in this structure!")%value |
814 | 592 |
else: |
593 |
self.RefreshTypeInfos() |
|
594 |
wx.CallAfter(self.StructureElementsTable.ResetView, self.StructureElementsGrid) |
|
595 |
## old_value = self.Table.GetOldValue() |
|
596 |
## if old_value != "": |
|
597 |
## self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value) |
|
598 |
## self.Controler.BufferProject() |
|
599 |
event.Skip() |
|
1658
ba6a6d6e989c
fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
600 |
|
ba6a6d6e989c
fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
601 |
if message is not None: |
ba6a6d6e989c
fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
602 |
event.Veto() |
ba6a6d6e989c
fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
603 |
wx.CallAfter(self.ShowErrorMessage, message) |
814 | 604 |
else: |
605 |
self.RefreshTypeInfos() |
|
606 |
wx.CallAfter(self.StructureElementsTable.ResetView, self.StructureElementsGrid) |
|
607 |
event.Skip() |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
608 |
|
814 | 609 |
def OnStructureElementsGridSelectCell(self, event): |
610 |
wx.CallAfter(self.RefreshStructureButtons) |
|
611 |
event.Skip() |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
612 |
|
814 | 613 |
def OnStructureElementsGridEditorShown(self, event): |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
614 |
row, col = event.GetRow(), event.GetCol() |
947 | 615 |
if self.StructureElementsTable.GetColLabelValue(col, False) == "Type": |
814 | 616 |
type_menu = wx.Menu(title='') |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
617 |
|
814 | 618 |
base_menu = wx.Menu(title='') |
619 |
for base_type in self.Controler.GetBaseTypes(): |
|
620 |
new_id = wx.NewId() |
|
621 |
AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type) |
|
622 |
self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(base_type), id=new_id) |
|
623 |
type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
624 |
|
814 | 625 |
datatype_menu = wx.Menu(title='') |
626 |
for datatype in self.Controler.GetDataTypes(self.TagName, False): |
|
627 |
new_id = wx.NewId() |
|
628 |
AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) |
|
629 |
self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(datatype), id=new_id) |
|
630 |
type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu) |
|
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
631 |
|
864
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
632 |
new_id = wx.NewId() |
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
633 |
AppendMenu(type_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Array")) |
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
634 |
self.Bind(wx.EVT_MENU, self.ElementArrayTypeFunction, id=new_id) |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
635 |
|
814 | 636 |
## functionblock_menu = wx.Menu(title='') |
637 |
## bodytype = self.Controler.GetEditedElementBodyType(self.TagName) |
|
638 |
## pouname, poutype = self.Controler.GetEditedElementType(self.TagName) |
|
639 |
## if classtype in ["Input","Output","InOut","External","Global"] or poutype != "function" and bodytype in ["ST", "IL"]: |
|
640 |
## for functionblock_type in self.Controler.GetFunctionBlockTypes(self.TagName): |
|
641 |
## new_id = wx.NewId() |
|
642 |
## AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type) |
|
643 |
## self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id) |
|
644 |
## type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu) |
|
864
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
645 |
|
814 | 646 |
rect = self.StructureElementsGrid.BlockToDeviceRect((row, col), (row, col)) |
647 |
self.StructureElementsGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.StructureElementsGrid.GetColLabelSize()) |
|
648 |
type_menu.Destroy() |
|
649 |
event.Veto() |
|
650 |
else: |
|
651 |
event.Skip() |
|
652 |
||
653 |
def GetElementTypeFunction(self, base_type): |
|
654 |
def ElementTypeFunction(event): |
|
655 |
row = self.StructureElementsGrid.GetGridCursorRow() |
|
656 |
self.StructureElementsTable.SetValueByName(row, "Type", base_type) |
|
657 |
self.RefreshTypeInfos() |
|
658 |
self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
|
659 |
return ElementTypeFunction |
|
660 |
||
864
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
661 |
def ElementArrayTypeFunction(self, event): |
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
662 |
row = self.StructureElementsGrid.GetGridCursorRow() |
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
663 |
dialog = ArrayTypeDialog(self, |
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
947
diff
changeset
|
664 |
self.Controler.GetDataTypes(self.TagName), |
864
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
665 |
self.StructureElementsTable.GetValueByName(row, "Type")) |
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
666 |
if dialog.ShowModal() == wx.ID_OK: |
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
667 |
self.StructureElementsTable.SetValueByName(row, "Type", dialog.GetValue()) |
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
668 |
self.RefreshTypeInfos() |
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
669 |
self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
670 |
dialog.Destroy() |
bf4f7f0801b9
Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents:
814
diff
changeset
|
671 |
|
814 | 672 |
def RefreshDisplayedInfos(self): |
673 |
selected = DATATYPE_TYPES_DICT[self.DerivationType.GetStringSelection()] |
|
674 |
if selected != self.CurrentPanel: |
|
675 |
if self.CurrentPanel == "Directly": |
|
676 |
self.DirectlyPanel.Hide() |
|
677 |
elif self.CurrentPanel == "Subrange": |
|
678 |
self.SubrangePanel.Hide() |
|
679 |
elif self.CurrentPanel == "Enumerated": |
|
680 |
self.EnumeratedPanel.Hide() |
|
681 |
elif self.CurrentPanel == "Array": |
|
682 |
self.ArrayPanel.Hide() |
|
683 |
elif self.CurrentPanel == "Structure": |
|
684 |
self.StructurePanel.Hide() |
|
685 |
self.CurrentPanel = selected |
|
686 |
if selected == "Directly": |
|
687 |
self.DirectlyPanel.Show() |
|
688 |
elif selected == "Subrange": |
|
689 |
self.SubrangePanel.Show() |
|
690 |
elif selected == "Enumerated": |
|
691 |
self.EnumeratedPanel.Show() |
|
692 |
elif selected == "Array": |
|
693 |
self.ArrayPanel.Show() |
|
694 |
elif selected == "Structure": |
|
695 |
self.StructurePanel.Show() |
|
696 |
self.MainSizer.Layout() |
|
697 |
||
698 |
def RefreshEnumeratedValues(self, initial_selected=None): |
|
699 |
if initial_selected is None: |
|
700 |
initial_selected = self.EnumeratedInitialValue.GetStringSelection() |
|
701 |
self.EnumeratedInitialValue.Clear() |
|
702 |
self.EnumeratedInitialValue.Append("") |
|
703 |
for value in self.EnumeratedValues.GetStrings(): |
|
704 |
self.EnumeratedInitialValue.Append(value) |
|
705 |
self.EnumeratedInitialValue.SetStringSelection(initial_selected) |
|
706 |
||
707 |
def RefreshBoundsRange(self): |
|
708 |
range = self.Controler.GetDataTypeRange(self.SubrangeBaseType.GetStringSelection()) |
|
709 |
if range is not None: |
|
710 |
min_value, max_value = range |
|
711 |
self.SubrangeMinimum.SetRange(min_value, max_value) |
|
712 |
self.SubrangeMinimum.SetValue(min(max(min_value, self.SubrangeMinimum.GetValue()), max_value)) |
|
713 |
self.SubrangeMaximum.SetRange(min_value, max_value) |
|
714 |
self.SubrangeMaximum.SetValue(min(max(min_value, self.SubrangeMaximum.GetValue()), max_value)) |
|
715 |
||
716 |
def RefreshSubrangeInitialValueRange(self): |
|
717 |
self.SubrangeInitialValue.SetRange(self.SubrangeMinimum.GetValue(), self.SubrangeMaximum.GetValue()) |
|
718 |
||
719 |
def RefreshTypeInfos(self): |
|
720 |
selected = DATATYPE_TYPES_DICT[self.DerivationType.GetStringSelection()] |
|
721 |
infos = {"type" : selected} |
|
722 |
if selected == "Directly": |
|
723 |
infos["base_type"] = self.DirectlyBaseType.GetStringSelection() |
|
724 |
infos["initial"] = self.DirectlyInitialValue.GetValue() |
|
725 |
elif selected == "Subrange": |
|
726 |
infos["base_type"] = self.SubrangeBaseType.GetStringSelection() |
|
727 |
infos["min"] = str(self.SubrangeMinimum.GetValue()) |
|
728 |
infos["max"] = str(self.SubrangeMaximum.GetValue()) |
|
729 |
initial_value = self.SubrangeInitialValue.GetValue() |
|
730 |
if initial_value == infos["min"]: |
|
731 |
infos["initial"] = "" |
|
732 |
else: |
|
733 |
infos["initial"] = str(initial_value) |
|
734 |
elif selected == "Enumerated": |
|
735 |
infos["values"] = self.EnumeratedValues.GetStrings() |
|
736 |
infos["initial"] = self.EnumeratedInitialValue.GetStringSelection() |
|
737 |
elif selected == "Array": |
|
738 |
infos["base_type"] = self.ArrayBaseType.GetStringSelection() |
|
739 |
infos["dimensions"] = [] |
|
740 |
for dimensions in self.ArrayDimensions.GetStrings(): |
|
741 |
result = DIMENSION_MODEL.match(dimensions) |
|
742 |
if result is None: |
|
743 |
message = wx.MessageDialog(self, _("\"%s\" value isn't a valid array dimension!")%dimensions, _("Error"), wx.OK|wx.ICON_ERROR) |
|
744 |
message.ShowModal() |
|
745 |
message.Destroy() |
|
746 |
self.RefreshView() |
|
747 |
return |
|
748 |
bounds = result.groups() |
|
749 |
if int(bounds[0]) >= int(bounds[1]): |
|
750 |
message = wx.MessageDialog(self, _("\"%s\" value isn't a valid array dimension!\nRight value must be greater than left value.")%dimensions, _("Error"), wx.OK|wx.ICON_ERROR) |
|
751 |
message.ShowModal() |
|
752 |
message.Destroy() |
|
753 |
self.RefreshView() |
|
754 |
return |
|
755 |
infos["dimensions"].append(bounds) |
|
756 |
infos["initial"] = self.ArrayInitialValue.GetValue() |
|
757 |
elif selected == "Structure": |
|
758 |
infos["elements"] = self.StructureElementsTable.GetData() |
|
759 |
infos["initial"] = "" |
|
760 |
self.Controler.SetDataTypeInfos(self.TagName, infos) |
|
761 |
self.ParentWindow.RefreshTitle() |
|
762 |
self.ParentWindow.RefreshFileMenu() |
|
763 |
self.ParentWindow.RefreshEditMenu() |
|
764 |
||
765 |
#------------------------------------------------------------------------------- |
|
766 |
# Highlights showing functions |
|
767 |
#------------------------------------------------------------------------------- |
|
768 |
||
769 |
def OnRefreshHighlightsTimer(self, event): |
|
770 |
self.RefreshView() |
|
771 |
event.Skip() |
|
772 |
||
773 |
def ClearHighlights(self, highlight_type=None): |
|
774 |
if highlight_type is None: |
|
775 |
self.Highlights = [] |
|
776 |
else: |
|
777 |
self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type] |
|
778 |
for control in self.HighlightControls.itervalues(): |
|
779 |
if isinstance(control, (wx.ComboBox, wx.SpinCtrl)): |
|
780 |
control.SetBackgroundColour(wx.NullColour) |
|
781 |
control.SetForegroundColour(wx.NullColour) |
|
782 |
elif isinstance(control, wx.TextCtrl): |
|
783 |
value = control.GetValue() |
|
784 |
control.SetStyle(0, len(value), wx.TextAttr(wx.NullColour)) |
|
785 |
elif isinstance(control, wx.gizmos.EditableListBox): |
|
786 |
listctrl = control.GetListCtrl() |
|
787 |
for i in xrange(listctrl.GetItemCount()): |
|
788 |
listctrl.SetItemBackgroundColour(i, wx.NullColour) |
|
789 |
listctrl.SetItemTextColour(i, wx.NullColour) |
|
790 |
self.StructureElementsTable.ClearHighlights(highlight_type) |
|
791 |
self.RefreshView() |
|
792 |
||
793 |
def AddHighlight(self, infos, start, end ,highlight_type): |
|
794 |
self.Highlights.append((infos, start, end, highlight_type)) |
|
795 |
self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
796 |
||
797 |
def ShowHighlights(self): |
|
798 |
type_infos = self.Controler.GetDataTypeInfos(self.TagName) |
|
799 |
for infos, start, end, highlight_type in self.Highlights: |
|
800 |
if infos[0] == "struct": |
|
801 |
self.StructureElementsTable.AddHighlight(infos[1:], highlight_type) |
|
802 |
else: |
|
803 |
control = self.HighlightControls.get((type_infos["type"], infos[0]), None) |
|
804 |
if control is not None: |
|
805 |
if isinstance(control, (wx.ComboBox, wx.SpinCtrl)): |
|
806 |
control.SetBackgroundColour(highlight_type[0]) |
|
807 |
control.SetForegroundColour(highlight_type[1]) |
|
808 |
elif isinstance(control, wx.TextCtrl): |
|
809 |
control.SetStyle(start[1], end[1] + 1, wx.TextAttr(highlight_type[1], highlight_type[0])) |
|
810 |
elif isinstance(control, wx.gizmos.EditableListBox): |
|
811 |
listctrl = control.GetListCtrl() |
|
812 |
listctrl.SetItemBackgroundColour(infos[1], highlight_type[0]) |
|
813 |
listctrl.SetItemTextColour(infos[1], highlight_type[1]) |
|
814 |
listctrl.Select(listctrl.FocusedItem, False) |
|
815 |