author | laurent |
Thu, 21 Apr 2011 11:06:17 +0200 | |
changeset 535 | 08f32198e932 |
parent 507 | 42150e041dbe |
child 556 | 69214983dd03 |
permissions | -rw-r--r-- |
125 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
import wx |
|
26 |
import wx.grid |
|
27 |
import wx.gizmos |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
28 |
from plcopen.structures import IEC_KEYWORDS, TestIdentifier |
125 | 29 |
|
207 | 30 |
import re |
31 |
||
32 |
DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$") |
|
33 |
||
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
34 |
def AppendMenu(parent, help, id, kind, text): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
35 |
if wx.VERSION >= (2, 6, 0): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
36 |
parent.Append(help=help, id=id, kind=kind, text=text) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
37 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
38 |
parent.Append(helpString=help, id=id, kind=kind, item=text) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
39 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
40 |
#------------------------------------------------------------------------------- |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
41 |
# Structure Elements Table |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
42 |
#------------------------------------------------------------------------------- |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
43 |
|
391 | 44 |
def GetElementsTableColnames(): |
45 |
_ = lambda x : x |
|
46 |
return ["#", _("Name"), _("Type"), _("Initial Value")] |
|
47 |
||
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
48 |
class ElementsTable(wx.grid.PyGridTableBase): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
49 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
50 |
""" |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
51 |
A custom wx.grid.Grid Table using user supplied data |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
52 |
""" |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
53 |
def __init__(self, parent, data, colnames): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
54 |
# The base class must be initialized *first* |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
55 |
wx.grid.PyGridTableBase.__init__(self) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
56 |
self.data = data |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
57 |
self.old_value = None |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
58 |
self.colnames = colnames |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
59 |
self.Errors = {} |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
60 |
self.Parent = parent |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
61 |
# XXX |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
62 |
# we need to store the row length and collength to |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
63 |
# see if the table has changed size |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
64 |
self._rows = self.GetNumberRows() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
65 |
self._cols = self.GetNumberCols() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
66 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
67 |
def GetNumberCols(self): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
68 |
return len(self.colnames) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
69 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
70 |
def GetNumberRows(self): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
71 |
return len(self.data) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
72 |
|
391 | 73 |
def GetColLabelValue(self, col, translate=True): |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
74 |
if col < len(self.colnames): |
391 | 75 |
if translate: |
76 |
return _(self.colnames[col]) |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
77 |
return self.colnames[col] |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
78 |
|
391 | 79 |
def GetRowLabelValues(self, row, translate=True): |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
80 |
return row |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
81 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
82 |
def GetValue(self, row, col): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
83 |
if row < self.GetNumberRows(): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
84 |
if col == 0: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
85 |
return row + 1 |
391 | 86 |
name = str(self.data[row].get(self.GetColLabelValue(col, False), "")) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
87 |
return name |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
88 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
89 |
def SetValue(self, row, col, value): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
90 |
if col < len(self.colnames): |
391 | 91 |
colname = self.GetColLabelValue(col, False) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
92 |
if colname == "Name": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
93 |
self.old_value = self.data[row][colname] |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
94 |
self.data[row][colname] = value |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
95 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
96 |
def GetValueByName(self, row, colname): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
97 |
if row < self.GetNumberRows(): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
98 |
return self.data[row].get(colname) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
99 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
100 |
def SetValueByName(self, row, colname, value): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
101 |
if row < self.GetNumberRows(): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
102 |
self.data[row][colname] = value |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
103 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
104 |
def GetOldValue(self): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
105 |
return self.old_value |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
106 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
107 |
def ResetView(self, grid): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
108 |
""" |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
109 |
(wx.grid.Grid) -> Reset the grid view. Call this to |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
110 |
update the grid if rows and columns have been added or deleted |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
111 |
""" |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
112 |
grid.BeginBatch() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
113 |
for current, new, delmsg, addmsg in [ |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
114 |
(self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED), |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
115 |
(self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
116 |
]: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
117 |
if new < current: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
118 |
msg = wx.grid.GridTableMessage(self,delmsg,new,current-new) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
119 |
grid.ProcessTableMessage(msg) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
120 |
elif new > current: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
121 |
msg = wx.grid.GridTableMessage(self,addmsg,new-current) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
122 |
grid.ProcessTableMessage(msg) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
123 |
self.UpdateValues(grid) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
124 |
grid.EndBatch() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
125 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
126 |
self._rows = self.GetNumberRows() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
127 |
self._cols = self.GetNumberCols() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
128 |
# update the column rendering scheme |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
129 |
self._updateColAttrs(grid) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
130 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
131 |
# update the scrollbars and the displayed part of the grid |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
132 |
grid.AdjustScrollbars() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
133 |
grid.ForceRefresh() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
134 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
135 |
def UpdateValues(self, grid): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
136 |
"""Update all displayed values""" |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
137 |
# This sends an event to the grid table to update all of the values |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
138 |
msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
139 |
grid.ProcessTableMessage(msg) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
140 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
141 |
def _updateColAttrs(self, grid): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
142 |
""" |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
143 |
wx.grid.Grid -> update the column attributes to add the |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
144 |
appropriate renderer given the column name. |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
145 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
146 |
Otherwise default to the default renderer. |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
147 |
""" |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
148 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
149 |
for row in range(self.GetNumberRows()): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
150 |
for col in range(self.GetNumberCols()): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
151 |
editor = None |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
152 |
renderer = None |
391 | 153 |
colname = self.GetColLabelValue(col, False) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
154 |
if col != 0: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
155 |
grid.SetReadOnly(row, col, False) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
156 |
if colname == "Name": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
157 |
editor = wx.grid.GridCellTextEditor() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
158 |
renderer = wx.grid.GridCellStringRenderer() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
159 |
elif colname == "Initial Value": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
160 |
editor = wx.grid.GridCellTextEditor() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
161 |
renderer = wx.grid.GridCellStringRenderer() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
162 |
elif colname == "Type": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
163 |
editor = wx.grid.GridCellTextEditor() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
164 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
165 |
grid.SetReadOnly(row, col, True) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
166 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
167 |
grid.SetCellEditor(row, col, editor) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
168 |
grid.SetCellRenderer(row, col, renderer) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
169 |
|
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
313
diff
changeset
|
170 |
if self.Errors.has_key(row) and self.Errors[row][0] == colname.lower(): |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
171 |
grid.SetCellBackgroundColour(row, col, wx.Colour(255, 255, 0)) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
172 |
grid.SetCellTextColour(row, col, wx.RED) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
173 |
grid.MakeCellVisible(row, col) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
174 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
175 |
grid.SetCellTextColour(row, col, wx.BLACK) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
176 |
grid.SetCellBackgroundColour(row, col, wx.WHITE) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
177 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
178 |
def SetData(self, data): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
179 |
self.data = data |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
180 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
181 |
def GetData(self): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
182 |
return self.data |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
183 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
184 |
def AppendRow(self, row_content): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
185 |
self.data.append(row_content) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
186 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
187 |
def RemoveRow(self, row_index): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
188 |
self.data.pop(row_index) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
189 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
190 |
def MoveRow(self, idx, move): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
191 |
new_idx = max(0, min(idx + move, len(self.data) - 1)) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
192 |
if new_idx != idx: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
193 |
self.data.insert(new_idx, self.data.pop(idx)) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
194 |
return new_idx |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
195 |
return None |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
196 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
197 |
def GetRow(self, row_index): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
198 |
return self.data[row_index] |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
199 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
200 |
def Empty(self): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
201 |
self.data = [] |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
202 |
self.editors = [] |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
203 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
204 |
def AddError(self, infos): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
205 |
self.Errors[infos[0]] = infos[1:] |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
206 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
207 |
def ClearErrors(self): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
208 |
self.Errors = {} |
125 | 209 |
|
210 |
#------------------------------------------------------------------------------- |
|
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
313
diff
changeset
|
211 |
# Datatype Editor class |
125 | 212 |
#------------------------------------------------------------------------------- |
213 |
||
214 |
[ID_DATATYPEEDITOR, ID_DATATYPEEDITORSTATICBOX, |
|
215 |
ID_DATATYPEEDITORDERIVATIONTYPE, ID_DATATYPEEDITORDIRECTLYPANEL, |
|
216 |
ID_DATATYPEEDITORSUBRANGEPANEL, ID_DATATYPEEDITORDIRECTLYBASETYPE, |
|
217 |
ID_DATATYPEEDITORSUBRANGEBASETYPE, ID_DATATYPEEDITORSUBRANGEMINIMUM, |
|
218 |
ID_DATATYPEEDITORSUBRANGEMAXIMUM, ID_DATATYPEEDITORDIRECTLYINITIALVALUE, |
|
219 |
ID_DATATYPEEDITORSUBRANGEINITIALVALUE, ID_DATATYPEEDITORENUMERATEDPANEL, |
|
220 |
ID_DATATYPEEDITORENUMERATEDVALUES, ID_DATATYPEEDITORENUMERATEDINITIALVALUE, |
|
221 |
ID_DATATYPEEDITORARRAYPANEL, ID_DATATYPEEDITORARRAYBASETYPE, |
|
222 |
ID_DATATYPEEDITORARRAYDIMENSIONS, ID_DATATYPEEDITORARRAYINITIALVALUE, |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
223 |
ID_DATATYPEEDITORSTRUCTUREPANEL, ID_DATATYPEEDITORSTRUCTUREELEMENTSGRID, |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
224 |
ID_DATATYPEEDITORSTRUCTUREADDBUTTON, ID_DATATYPEEDITORSTRUCTUREDELETEBUTTON, |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
225 |
ID_DATATYPEEDITORSTRUCTUREUPBUTTON, ID_DATATYPEEDITORSTRUCTUREDOWNBUTTON, |
125 | 226 |
ID_DATATYPEEDITORSTATICTEXT1, ID_DATATYPEEDITORSTATICTEXT2, |
227 |
ID_DATATYPEEDITORSTATICTEXT3, ID_DATATYPEEDITORSTATICTEXT4, |
|
228 |
ID_DATATYPEEDITORSTATICTEXT5, ID_DATATYPEEDITORSTATICTEXT6, |
|
229 |
ID_DATATYPEEDITORSTATICTEXT7, ID_DATATYPEEDITORSTATICTEXT8, |
|
230 |
ID_DATATYPEEDITORSTATICTEXT9, ID_DATATYPEEDITORSTATICTEXT10, |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
231 |
ID_DATATYPEEDITORSTATICTEXT11, |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
232 |
] = [wx.NewId() for _init_ctrls in range(35)] |
125 | 233 |
|
391 | 234 |
def GetDatatypeTypes(): |
235 |
_ = lambda x : x |
|
236 |
return [_("Directly"), _("Subrange"), _("Enumerated"), _("Array"), _("Structure")] |
|
237 |
DATATYPE_TYPES_DICT = dict([(_(datatype), datatype) for datatype in GetDatatypeTypes()]) |
|
238 |
||
125 | 239 |
class DataTypeEditor(wx.Panel): |
240 |
||
241 |
def _init_coll_MainSizer_Items(self, parent): |
|
242 |
parent.AddSizer(self.TopSizer, 0, border=5, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
|
243 |
parent.AddSizer(self.TypeInfosSizer, 0, border=5, flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
|
244 |
||
245 |
def _init_coll_MainSizer_Growables(self, parent): |
|
246 |
parent.AddGrowableCol(0) |
|
247 |
parent.AddGrowableRow(1) |
|
248 |
||
249 |
def _init_coll_TopSizer_Items(self, parent): |
|
391 | 250 |
parent.AddWindow(self.staticText1, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT) |
251 |
parent.AddWindow(self.DerivationType, 0, border=5, flag=wx.GROW|wx.RIGHT) |
|
125 | 252 |
|
253 |
def _init_coll_TypeInfosSizer_Items(self, parent): |
|
254 |
parent.AddWindow(self.DirectlyPanel, 1, border=0, flag=wx.ALL) |
|
255 |
parent.AddWindow(self.SubrangePanel, 1, border=0, flag=wx.ALL) |
|
256 |
parent.AddWindow(self.EnumeratedPanel, 1, border=0, flag=wx.GROW|wx.ALL) |
|
257 |
parent.AddWindow(self.ArrayPanel, 1, border=0, flag=wx.ALL) |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
258 |
parent.AddWindow(self.StructurePanel, 1, border=0, flag=wx.GROW|wx.ALL) |
125 | 259 |
|
260 |
def _init_coll_DirectlyPanelSizer_Items(self, parent): |
|
391 | 261 |
parent.AddWindow(self.staticText2, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
125 | 262 |
parent.AddWindow(self.DirectlyBaseType, 1, border=5, flag=wx.GROW|wx.ALL) |
391 | 263 |
parent.AddWindow(self.staticText3, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
125 | 264 |
parent.AddWindow(self.DirectlyInitialValue, 1, border=5, flag=wx.GROW|wx.ALL) |
265 |
||
266 |
def _init_coll_SubrangePanelSizer_Items(self, parent): |
|
391 | 267 |
parent.AddWindow(self.staticText4, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
125 | 268 |
parent.AddWindow(self.SubrangeBaseType, 1, border=5, flag=wx.GROW|wx.ALL) |
391 | 269 |
parent.AddWindow(self.staticText5, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
125 | 270 |
parent.AddWindow(self.SubrangeInitialValue, 1, border=5, flag=wx.GROW|wx.ALL) |
391 | 271 |
parent.AddWindow(self.staticText6, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
125 | 272 |
parent.AddWindow(self.SubrangeMinimum, 1, border=5, flag=wx.GROW|wx.ALL) |
273 |
parent.AddWindow(wx.Size(0, 0), 1, border=5, flag=wx.GROW|wx.ALL) |
|
274 |
parent.AddWindow(wx.Size(0, 0), 1, border=5, flag=wx.GROW|wx.ALL) |
|
391 | 275 |
parent.AddWindow(self.staticText7, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
125 | 276 |
parent.AddWindow(self.SubrangeMaximum, 1, border=5, flag=wx.GROW|wx.ALL) |
277 |
||
278 |
def _init_coll_EnumeratedPanelSizer_Items(self, parent): |
|
391 | 279 |
parent.AddWindow(self.EnumeratedValues, 1, border=5, flag=wx.GROW|wx.ALL) |
280 |
parent.AddSizer(self.EnumeratedPanelRightSizer, 1, border=0, flag=0) |
|
281 |
||
282 |
def _init_coll_EnumeratedPanelRightSizer_Items(self, parent): |
|
283 |
parent.AddWindow(self.staticText8, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
|
125 | 284 |
parent.AddWindow(self.EnumeratedInitialValue, 1, border=5, flag=wx.ALL) |
285 |
||
286 |
def _init_coll_ArrayPanelSizer_Items(self, parent): |
|
287 |
parent.AddSizer(self.ArrayPanelLeftSizer, 0, border=0, flag=wx.GROW) |
|
391 | 288 |
parent.AddSizer(self.ArrayPanelRightSizer, 0, border=0, flag=0) |
125 | 289 |
parent.AddWindow(self.ArrayDimensions, 0, border=5, flag=wx.GROW|wx.ALL) |
290 |
||
291 |
def _init_coll_ArrayPanelSizer_Growables(self, parent): |
|
292 |
parent.AddGrowableCol(0) |
|
293 |
parent.AddGrowableCol(1) |
|
294 |
parent.AddGrowableRow(1) |
|
295 |
||
296 |
def _init_coll_ArrayPanelLeftSizer_Items(self, parent): |
|
391 | 297 |
parent.AddWindow(self.staticText9, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
125 | 298 |
parent.AddWindow(self.ArrayBaseType, 1, border=5, flag=wx.GROW|wx.ALL) |
299 |
||
300 |
def _init_coll_ArrayPanelRightSizer_Items(self, parent): |
|
391 | 301 |
parent.AddWindow(self.staticText10, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
125 | 302 |
parent.AddWindow(self.ArrayInitialValue, 1, border=5, flag=wx.GROW|wx.ALL) |
303 |
||
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
304 |
def _init_coll_StructurePanelSizer_Items(self, parent): |
391 | 305 |
parent.AddWindow(self.staticText11, 0, border=5, flag=wx.ALL) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
306 |
parent.AddWindow(self.StructureElementsGrid, 0, border=0, flag=wx.GROW) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
307 |
parent.AddSizer(self.StructurePanelButtonSizer, 0, border=0, flag=wx.ALIGN_RIGHT) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
308 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
309 |
def _init_coll_StructurePanelSizer_Growables(self, parent): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
310 |
parent.AddGrowableCol(0) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
311 |
parent.AddGrowableRow(1) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
312 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
313 |
def _init_coll_StructurePanelButtonSizer_Items(self, parent): |
391 | 314 |
parent.AddWindow(self.StructureAddButton, 0, border=5, flag=wx.ALL) |
315 |
parent.AddWindow(self.StructureDeleteButton, 0, border=5, flag=wx.ALL) |
|
316 |
parent.AddWindow(self.StructureUpButton, 0, border=5, flag=wx.ALL) |
|
317 |
parent.AddWindow(self.StructureDownButton, 0, border=5, flag=wx.ALL) |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
318 |
|
125 | 319 |
def _init_sizers(self): |
320 |
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
|
321 |
self.TopSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
322 |
self.TypeInfosSizer = wx.StaticBoxSizer(self.staticbox, wx.HORIZONTAL) |
|
323 |
self.DirectlyPanelSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
391 | 324 |
self.SubrangePanelSizer = wx.GridSizer(cols=4, hgap=5, rows=3, vgap=0) |
125 | 325 |
self.EnumeratedPanelSizer = wx.BoxSizer(wx.HORIZONTAL) |
391 | 326 |
self.EnumeratedPanelRightSizer = wx.BoxSizer(wx.HORIZONTAL) |
327 |
self.ArrayPanelSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=0) |
|
125 | 328 |
self.ArrayPanelLeftSizer = wx.BoxSizer(wx.HORIZONTAL) |
329 |
self.ArrayPanelRightSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
391 | 330 |
self.StructurePanelSizer = wx.FlexGridSizer(cols=1, hgap=5, rows=3, vgap=0) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
331 |
self.StructurePanelButtonSizer = wx.BoxSizer(wx.HORIZONTAL) |
125 | 332 |
self._init_coll_MainSizer_Items(self.MainSizer) |
333 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
|
334 |
self._init_coll_TopSizer_Items(self.TopSizer) |
|
335 |
self._init_coll_TypeInfosSizer_Items(self.TypeInfosSizer) |
|
336 |
self._init_coll_DirectlyPanelSizer_Items(self.DirectlyPanelSizer) |
|
337 |
self._init_coll_SubrangePanelSizer_Items(self.SubrangePanelSizer) |
|
338 |
self._init_coll_EnumeratedPanelSizer_Items(self.EnumeratedPanelSizer) |
|
391 | 339 |
self._init_coll_EnumeratedPanelRightSizer_Items(self.EnumeratedPanelRightSizer) |
125 | 340 |
self._init_coll_ArrayPanelSizer_Items(self.ArrayPanelSizer) |
341 |
self._init_coll_ArrayPanelSizer_Growables(self.ArrayPanelSizer) |
|
342 |
self._init_coll_ArrayPanelLeftSizer_Items(self.ArrayPanelLeftSizer) |
|
343 |
self._init_coll_ArrayPanelRightSizer_Items(self.ArrayPanelRightSizer) |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
344 |
self._init_coll_StructurePanelSizer_Items(self.StructurePanelSizer) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
345 |
self._init_coll_StructurePanelSizer_Growables(self.StructurePanelSizer) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
346 |
self._init_coll_StructurePanelButtonSizer_Items(self.StructurePanelButtonSizer) |
125 | 347 |
|
348 |
self.SetSizer(self.MainSizer) |
|
349 |
self.DirectlyPanel.SetSizer(self.DirectlyPanelSizer) |
|
350 |
self.SubrangePanel.SetSizer(self.SubrangePanelSizer) |
|
351 |
self.EnumeratedPanel.SetSizer(self.EnumeratedPanelSizer) |
|
352 |
self.ArrayPanel.SetSizer(self.ArrayPanelSizer) |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
353 |
self.StructurePanel.SetSizer(self.StructurePanelSizer) |
125 | 354 |
|
355 |
def _init_ctrls(self, prnt): |
|
356 |
wx.Panel.__init__(self, id=ID_DATATYPEEDITOR, name='', parent=prnt, |
|
357 |
size=wx.Size(0, 0), style=wx.SUNKEN_BORDER) |
|
358 |
||
359 |
self.staticbox = wx.StaticBox(id=ID_DATATYPEEDITORSTATICBOX, |
|
391 | 360 |
label=_('Type infos:'), name='staticBox1', parent=self, |
361 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
125 | 362 |
|
363 |
self.staticText1 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT1, |
|
391 | 364 |
label=_('Derivation Type:'), name='staticText1', parent=self, |
365 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
125 | 366 |
|
304 | 367 |
self.DerivationType = wx.ComboBox(id=ID_DATATYPEEDITORDERIVATIONTYPE, |
125 | 368 |
name='DerivationType', parent=self, pos=wx.Point(0, 0), |
313 | 369 |
size=wx.Size(200, 28), style=wx.CB_READONLY) |
304 | 370 |
self.Bind(wx.EVT_COMBOBOX, self.OnDerivationTypeChanged, id=ID_DATATYPEEDITORDERIVATIONTYPE) |
125 | 371 |
|
372 |
# Panel for Directly derived data types |
|
373 |
||
374 |
self.DirectlyPanel = wx.Panel(id=ID_DATATYPEEDITORDIRECTLYPANEL, |
|
375 |
name='DirectlyPanel', parent=self, pos=wx.Point(0, 0), |
|
376 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
377 |
||
378 |
self.staticText2 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT2, |
|
391 | 379 |
label=_('Base Type:'), name='staticText2', parent=self.DirectlyPanel, |
380 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
125 | 381 |
|
304 | 382 |
self.DirectlyBaseType = wx.ComboBox(id=ID_DATATYPEEDITORDIRECTLYBASETYPE, |
125 | 383 |
name='DirectlyBaseType', parent=self.DirectlyPanel, pos=wx.Point(0, 0), |
313 | 384 |
size=wx.Size(0, 28), style=wx.CB_READONLY) |
304 | 385 |
self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, id=ID_DATATYPEEDITORDIRECTLYBASETYPE) |
125 | 386 |
|
387 |
self.staticText3 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT3, |
|
391 | 388 |
label=_('Initial Value:'), name='staticText3', parent=self.DirectlyPanel, |
389 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
125 | 390 |
|
391 |
self.DirectlyInitialValue = wx.TextCtrl(id=ID_DATATYPEEDITORDIRECTLYINITIALVALUE, |
|
392 |
name='DirectlyInitialValue', parent=self.DirectlyPanel, pos=wx.Point(0, 0), |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
393 |
size=wx.Size(0, 24), style=wx.TAB_TRAVERSAL|wx.TE_PROCESS_ENTER|wx.TE_MULTILINE|wx.TE_RICH) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
394 |
self.Bind(wx.EVT_TEXT_ENTER, self.OnReturnKeyPressed, id=ID_DATATYPEEDITORDIRECTLYINITIALVALUE) |
125 | 395 |
|
396 |
# Panel for Subrange data types |
|
397 |
||
398 |
self.SubrangePanel = wx.Panel(id=ID_DATATYPEEDITORSUBRANGEPANEL, |
|
399 |
name='SubrangePanel', parent=self, pos=wx.Point(0, 0), |
|
400 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
401 |
||
402 |
self.staticText4 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT4, |
|
391 | 403 |
label=_('Base Type:'), name='staticText4', parent=self.SubrangePanel, |
404 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
125 | 405 |
|
304 | 406 |
self.SubrangeBaseType = wx.ComboBox(id=ID_DATATYPEEDITORSUBRANGEBASETYPE, |
125 | 407 |
name='SubrangeBaseType', parent=self.SubrangePanel, pos=wx.Point(0, 0), |
313 | 408 |
size=wx.Size(0, 28), style=wx.CB_READONLY) |
304 | 409 |
self.Bind(wx.EVT_COMBOBOX, self.OnSubrangeBaseTypeChanged, id=ID_DATATYPEEDITORSUBRANGEBASETYPE) |
125 | 410 |
|
411 |
self.staticText5 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT5, |
|
391 | 412 |
label=_('Initial Value:'), name='staticText5', parent=self.SubrangePanel, |
413 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
125 | 414 |
|
415 |
self.SubrangeInitialValue = wx.SpinCtrl(id=ID_DATATYPEEDITORSUBRANGEINITIALVALUE, |
|
416 |
name='SubrangeInitialValue', parent=self.SubrangePanel, pos=wx.Point(0, 0), |
|
417 |
size=wx.Size(0, 24), style=wx.TAB_TRAVERSAL) |
|
418 |
self.Bind(wx.EVT_SPINCTRL, self.OnInfosChanged, id=ID_DATATYPEEDITORSUBRANGEINITIALVALUE) |
|
419 |
||
420 |
self.staticText6 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT6, |
|
391 | 421 |
label=_('Minimum:'), name='staticText6', parent=self.SubrangePanel, |
422 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
125 | 423 |
|
424 |
self.SubrangeMinimum = wx.SpinCtrl(id=ID_DATATYPEEDITORSUBRANGEMINIMUM, |
|
425 |
name='SubrangeMinimum', parent=self.SubrangePanel, pos=wx.Point(0, 0), |
|
426 |
size=wx.Size(0, 24), style=wx.TAB_TRAVERSAL) |
|
427 |
self.Bind(wx.EVT_SPINCTRL, self.OnSubrangeMinimumChanged, id=ID_DATATYPEEDITORSUBRANGEMINIMUM) |
|
428 |
||
429 |
self.staticText7 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT7, |
|
391 | 430 |
label=_('Maximum:'), name='staticText7', parent=self.SubrangePanel, |
431 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
125 | 432 |
|
433 |
self.SubrangeMaximum = wx.SpinCtrl(id=ID_DATATYPEEDITORSUBRANGEMAXIMUM, |
|
434 |
name='SubrangeMaximum', parent=self.SubrangePanel, pos=wx.Point(0, 0), |
|
435 |
size=wx.Size(0, 24), style=wx.TAB_TRAVERSAL) |
|
436 |
self.Bind(wx.EVT_SPINCTRL, self.OnSubrangeMaximumChanged, id=ID_DATATYPEEDITORSUBRANGEMAXIMUM) |
|
437 |
||
438 |
# Panel for Enumerated data types |
|
439 |
||
440 |
self.EnumeratedPanel = wx.Panel(id=ID_DATATYPEEDITORENUMERATEDPANEL, |
|
441 |
name='EnumeratedPanel', parent=self, pos=wx.Point(0, 0), |
|
442 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
443 |
||
444 |
self.EnumeratedValues = wx.gizmos.EditableListBox(id=ID_DATATYPEEDITORENUMERATEDVALUES, |
|
391 | 445 |
name='EnumeratedValues', parent=self.EnumeratedPanel, label=_("Values:"), pos=wx.Point(0, 0), |
125 | 446 |
size=wx.Size(0, 0), style=wx.gizmos.EL_ALLOW_NEW | wx.gizmos.EL_ALLOW_EDIT | wx.gizmos.EL_ALLOW_DELETE) |
447 |
self.EnumeratedValues.GetListCtrl().Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnEnumeratedValueEndEdit) |
|
391 | 448 |
self.EnumeratedValues.GetEditButton().SetToolTipString(_("Edit item")) |
449 |
new_button = self.EnumeratedValues.GetNewButton() |
|
450 |
new_button.SetToolTipString(_("New item")) |
|
451 |
new_button.Bind(wx.EVT_BUTTON, self.OnEnumeratedValuesChanged) |
|
452 |
del_button = self.EnumeratedValues.GetDelButton() |
|
453 |
del_button.SetToolTipString(_("Delete item")) |
|
454 |
del_button.Bind(wx.EVT_BUTTON, self.OnEnumeratedValuesChanged) |
|
455 |
up_button = self.EnumeratedValues.GetUpButton() |
|
456 |
up_button.SetToolTipString(_("Move up")) |
|
457 |
up_button.Bind(wx.EVT_BUTTON, self.OnEnumeratedValuesChanged) |
|
458 |
down_button = self.EnumeratedValues.GetDownButton() |
|
459 |
down_button.SetToolTipString(_("Move down")) |
|
460 |
down_button.Bind(wx.EVT_BUTTON, self.OnEnumeratedValuesChanged) |
|
125 | 461 |
|
462 |
self.staticText8 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT8, |
|
391 | 463 |
label=_('Initial Value:'), name='staticText8', parent=self.EnumeratedPanel, |
464 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
125 | 465 |
|
304 | 466 |
self.EnumeratedInitialValue = wx.ComboBox(id=ID_DATATYPEEDITORENUMERATEDINITIALVALUE, |
125 | 467 |
name='EnumeratedInitialValue', parent=self.EnumeratedPanel, pos=wx.Point(0, 0), |
313 | 468 |
size=wx.Size(0, 28), style=wx.CB_READONLY) |
304 | 469 |
self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, id=ID_DATATYPEEDITORENUMERATEDINITIALVALUE) |
125 | 470 |
|
471 |
# Panel for Array data types |
|
472 |
||
473 |
self.ArrayPanel = wx.Panel(id=ID_DATATYPEEDITORARRAYPANEL, |
|
474 |
name='ArrayPanel', parent=self, pos=wx.Point(0, 0), |
|
475 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
476 |
||
477 |
self.staticText9 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT9, |
|
391 | 478 |
label=_('Base Type:'), name='staticText9', parent=self.ArrayPanel, |
479 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
125 | 480 |
|
304 | 481 |
self.ArrayBaseType = wx.ComboBox(id=ID_DATATYPEEDITORARRAYBASETYPE, |
507
42150e041dbe
Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents:
494
diff
changeset
|
482 |
name='ArrayBaseType', parent=self.ArrayPanel, pos=wx.Point(0, 0), |
313 | 483 |
size=wx.Size(0, 28), style=wx.CB_READONLY) |
304 | 484 |
self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, id=ID_DATATYPEEDITORARRAYBASETYPE) |
125 | 485 |
|
486 |
self.ArrayDimensions = wx.gizmos.EditableListBox(id=ID_DATATYPEEDITORARRAYDIMENSIONS, |
|
391 | 487 |
name='ArrayDimensions', parent=self.ArrayPanel, label=_("Dimensions:"), pos=wx.Point(0, 0), |
125 | 488 |
size=wx.Size(0, 24), style=wx.gizmos.EL_ALLOW_NEW | wx.gizmos.EL_ALLOW_EDIT | wx.gizmos.EL_ALLOW_DELETE) |
489 |
self.ArrayDimensions.GetListCtrl().Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnDimensionsChanged) |
|
391 | 490 |
self.ArrayDimensions.GetEditButton().SetToolTipString(_("Edit item")) |
491 |
new_button = self.ArrayDimensions.GetNewButton() |
|
492 |
new_button.SetToolTipString(_("New item")) |
|
493 |
new_button.Bind(wx.EVT_BUTTON, self.OnDimensionsChanged) |
|
494 |
del_button = self.ArrayDimensions.GetDelButton() |
|
495 |
del_button.SetToolTipString(_("Delete item")) |
|
496 |
del_button.Bind(wx.EVT_BUTTON, self.OnDimensionsChanged) |
|
497 |
up_button = self.ArrayDimensions.GetUpButton() |
|
498 |
up_button.SetToolTipString(_("Move up")) |
|
499 |
up_button.Bind(wx.EVT_BUTTON, self.OnDimensionsChanged) |
|
500 |
down_button = self.ArrayDimensions.GetDownButton() |
|
501 |
down_button.SetToolTipString(_("Move down")) |
|
502 |
down_button.Bind(wx.EVT_BUTTON, self.OnDimensionsChanged) |
|
125 | 503 |
|
504 |
self.staticText10 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT10, |
|
391 | 505 |
label=_('Initial Value:'), name='staticText10', parent=self.ArrayPanel, |
506 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
125 | 507 |
|
508 |
self.ArrayInitialValue = wx.TextCtrl(id=ID_DATATYPEEDITORARRAYINITIALVALUE, |
|
509 |
name='ArrayInitialValue', parent=self.ArrayPanel, pos=wx.Point(0, 0), |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
510 |
size=wx.Size(0, 24), style=wx.TAB_TRAVERSAL|wx.TE_PROCESS_ENTER|wx.TE_MULTILINE|wx.TE_RICH) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
511 |
self.Bind(wx.EVT_TEXT_ENTER, self.OnReturnKeyPressed, id=ID_DATATYPEEDITORARRAYINITIALVALUE) |
125 | 512 |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
513 |
# Panel for Structure data types |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
514 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
515 |
self.StructurePanel = wx.Panel(id=ID_DATATYPEEDITORSTRUCTUREPANEL, |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
516 |
name='StructurePanel', parent=self, pos=wx.Point(0, 0), |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
517 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
518 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
519 |
self.staticText11 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT11, |
391 | 520 |
label=_('Elements :'), name='staticText11', parent=self.StructurePanel, |
521 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
522 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
523 |
self.StructureElementsGrid = wx.grid.Grid(id=ID_DATATYPEEDITORSTRUCTUREELEMENTSGRID, |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
524 |
name='StructureElementsGrid', parent=self.StructurePanel, pos=wx.Point(0, 0), |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
525 |
size=wx.Size(0, 150), style=wx.VSCROLL) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
526 |
self.StructureElementsGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
527 |
'Sans')) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
528 |
self.StructureElementsGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
529 |
False, 'Sans')) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
530 |
self.StructureElementsGrid.SetSelectionBackground(wx.WHITE) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
531 |
self.StructureElementsGrid.SetSelectionForeground(wx.BLACK) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
532 |
if wx.VERSION >= (2, 6, 0): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
533 |
self.StructureElementsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnStructureElementsGridCellChange) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
534 |
self.StructureElementsGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnStructureElementsGridEditorShown) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
535 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
536 |
wx.grid.EVT_GRID_CELL_CHANGE(self.StructureElementsGrid, self.OnStructureElementsGridCellChange) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
537 |
wx.grid.EVT_GRID_EDITOR_SHOWN(self.StructureElementsGrid, self.OnStructureElementsGridEditorShown) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
538 |
|
391 | 539 |
self.StructureAddButton = wx.Button(id=ID_DATATYPEEDITORSTRUCTUREADDBUTTON, label=_('Add'), |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
540 |
name='StructureAddButton', parent=self.StructurePanel, pos=wx.Point(0, 0), |
391 | 541 |
size=wx.DefaultSize, style=0) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
542 |
self.Bind(wx.EVT_BUTTON, self.OnStructureAddButton, id=ID_DATATYPEEDITORSTRUCTUREADDBUTTON) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
543 |
|
391 | 544 |
self.StructureDeleteButton = wx.Button(id=ID_DATATYPEEDITORSTRUCTUREDELETEBUTTON, label=_('Delete'), |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
545 |
name='StructureDeleteButton', parent=self.StructurePanel, pos=wx.Point(0, 0), |
391 | 546 |
size=wx.DefaultSize, style=0) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
547 |
self.Bind(wx.EVT_BUTTON, self.OnStructureDeleteButton, id=ID_DATATYPEEDITORSTRUCTUREDELETEBUTTON) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
548 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
549 |
self.StructureUpButton = wx.Button(id=ID_DATATYPEEDITORSTRUCTUREUPBUTTON, label='^', |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
550 |
name='StructureUpButton', parent=self.StructurePanel, pos=wx.Point(0, 0), |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
551 |
size=wx.Size(32, 32), style=0) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
552 |
self.Bind(wx.EVT_BUTTON, self.OnStructureUpButton, id=ID_DATATYPEEDITORSTRUCTUREUPBUTTON) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
553 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
554 |
self.StructureDownButton = wx.Button(id=ID_DATATYPEEDITORSTRUCTUREDOWNBUTTON, label='v', |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
555 |
name='StructureDownButton', parent=self.StructurePanel, pos=wx.Point(0, 0), |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
556 |
size=wx.Size(32, 32), style=0) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
557 |
self.Bind(wx.EVT_BUTTON, self.OnStructureDownButton, id=ID_DATATYPEEDITORSTRUCTUREDOWNBUTTON) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
558 |
|
125 | 559 |
self._init_sizers() |
560 |
||
561 |
def __init__(self, parent, tagname, window, controler): |
|
562 |
self._init_ctrls(parent) |
|
563 |
||
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
564 |
self.StructureElementDefaultValue = {"Name" : "", "Type" : "INT", "Initial Value" : ""} |
391 | 565 |
self.StructureElementsTable = ElementsTable(self, [], GetElementsTableColnames()) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
566 |
self.StructureColSizes = [40, 150, 100, 250] |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
567 |
self.StructureColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT] |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
568 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
569 |
self.StructureElementsGrid.SetTable(self.StructureElementsTable) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
570 |
self.StructureElementsGrid.SetRowLabelSize(0) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
571 |
for col in range(self.StructureElementsTable.GetNumberCols()): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
572 |
attr = wx.grid.GridCellAttr() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
573 |
attr.SetAlignment(self.StructureColAlignements[col], wx.ALIGN_CENTRE) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
574 |
self.StructureElementsGrid.SetColAttr(col, attr) |
391 | 575 |
self.StructureElementsGrid.SetColMinimalWidth(col, self.StructureColSizes[col]) |
576 |
self.StructureElementsGrid.AutoSizeColumn(col, False) |
|
577 |
||
578 |
for datatype in GetDatatypeTypes(): |
|
579 |
self.DerivationType.Append(_(datatype)) |
|
125 | 580 |
self.SubrangePanel.Hide() |
581 |
self.EnumeratedPanel.Hide() |
|
582 |
self.ArrayPanel.Hide() |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
583 |
self.StructurePanel.Hide() |
125 | 584 |
self.CurrentPanel = "Directly" |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
585 |
self.Errors = [] |
130 | 586 |
self.Initializing = False |
125 | 587 |
|
588 |
self.ParentWindow = window |
|
589 |
self.Controler = controler |
|
590 |
self.TagName = tagname |
|
591 |
||
592 |
def SetTagName(self, tagname): |
|
593 |
self.TagName = tagname |
|
594 |
||
595 |
def GetTagName(self): |
|
596 |
return self.TagName |
|
597 |
||
598 |
def IsViewing(self, tagname): |
|
599 |
return self.TagName == tagname |
|
600 |
||
407
0a324a874981
Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents:
391
diff
changeset
|
601 |
def IsDebugging(self): |
0a324a874981
Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents:
391
diff
changeset
|
602 |
return False |
0a324a874981
Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents:
391
diff
changeset
|
603 |
|
125 | 604 |
def SetMode(self, mode): |
605 |
pass |
|
606 |
||
607 |
def ResetBuffer(self): |
|
608 |
pass |
|
609 |
||
610 |
def RefreshView(self): |
|
130 | 611 |
self.Initializing = True |
125 | 612 |
self.DirectlyBaseType.Clear() |
613 |
self.ArrayBaseType.Clear() |
|
614 |
for datatype in self.Controler.GetDataTypes(self.TagName): |
|
615 |
self.DirectlyBaseType.Append(datatype) |
|
616 |
self.ArrayBaseType.Append(datatype) |
|
617 |
self.DirectlyBaseType.SetSelection(0) |
|
618 |
self.SubrangeBaseType.Clear() |
|
619 |
words = self.TagName.split("::") |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
620 |
for base_type in self.Controler.GetSubrangeBaseTypes(words[1]): |
125 | 621 |
self.SubrangeBaseType.Append(base_type) |
622 |
self.SubrangeBaseType.SetSelection(0) |
|
623 |
self.RefreshBoundsRange() |
|
624 |
type_infos = self.Controler.GetDataTypeInfos(self.TagName) |
|
625 |
if type_infos is not None: |
|
391 | 626 |
datatype = type_infos["type"] |
627 |
self.DerivationType.SetStringSelection(_(datatype)) |
|
125 | 628 |
if type_infos["type"] == "Directly": |
629 |
self.DirectlyBaseType.SetStringSelection(type_infos["base_type"]) |
|
630 |
self.DirectlyInitialValue.SetValue(type_infos["initial"]) |
|
631 |
elif type_infos["type"] == "Subrange": |
|
632 |
self.SubrangeBaseType.SetStringSelection(type_infos["base_type"]) |
|
633 |
self.RefreshBoundsRange() |
|
389 | 634 |
self.SubrangeMinimum.SetValue(int(type_infos["min"])) |
635 |
self.SubrangeMaximum.SetValue(int(type_infos["max"])) |
|
125 | 636 |
self.RefreshSubrangeInitialValueRange() |
637 |
if type_infos["initial"] != "": |
|
638 |
self.SubrangeInitialValue.SetValue(int(type_infos["initial"])) |
|
639 |
else: |
|
640 |
self.SubrangeInitialValue.SetValue(type_infos["min"]) |
|
641 |
elif type_infos["type"] == "Enumerated": |
|
642 |
self.EnumeratedValues.SetStrings(type_infos["values"]) |
|
643 |
self.RefreshEnumeratedValues() |
|
644 |
self.EnumeratedInitialValue.SetStringSelection(type_infos["initial"]) |
|
645 |
elif type_infos["type"] == "Array": |
|
646 |
self.ArrayBaseType.SetStringSelection(type_infos["base_type"]) |
|
389 | 647 |
self.ArrayDimensions.SetStrings(map(lambda x : "..".join(x), type_infos["dimensions"])) |
125 | 648 |
self.ArrayInitialValue.SetValue(type_infos["initial"]) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
649 |
elif type_infos["type"] == "Structure": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
650 |
self.StructureElementsTable.SetData(type_infos["elements"]) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
651 |
self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
125 | 652 |
self.RefreshDisplayedInfos() |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
653 |
self.ShowErrors() |
130 | 654 |
self.Initializing = False |
125 | 655 |
|
205 | 656 |
def RefreshScaling(self, refresh=True): |
657 |
pass |
|
658 |
||
125 | 659 |
def OnDerivationTypeChanged(self, event): |
660 |
self.RefreshDisplayedInfos() |
|
661 |
self.RefreshTypeInfos() |
|
662 |
event.Skip() |
|
663 |
||
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
664 |
def OnReturnKeyPressed(self, event): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
665 |
self.RefreshTypeInfos() |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
666 |
|
125 | 667 |
def OnInfosChanged(self, event): |
668 |
self.RefreshTypeInfos() |
|
669 |
event.Skip() |
|
670 |
||
671 |
def OnSubrangeBaseTypeChanged(self, event): |
|
672 |
self.RefreshBoundsRange() |
|
673 |
self.RefreshTypeInfos() |
|
674 |
event.Skip() |
|
675 |
||
676 |
def OnSubrangeMinimumChanged(self, event): |
|
215 | 677 |
if not self.Initializing: |
130 | 678 |
wx.CallAfter(self.SubrangeMinimum.SetValue, min(self.SubrangeMaximum.GetValue(), self.SubrangeMinimum.GetValue())) |
679 |
wx.CallAfter(self.RefreshSubrangeInitialValueRange) |
|
680 |
wx.CallAfter(self.RefreshTypeInfos) |
|
125 | 681 |
event.Skip() |
682 |
||
683 |
def OnSubrangeMaximumChanged(self, event): |
|
215 | 684 |
if not self.Initializing: |
130 | 685 |
wx.CallAfter(self.SubrangeMaximum.SetValue, max(self.SubrangeMinimum.GetValue(), self.SubrangeMaximum.GetValue())) |
686 |
wx.CallAfter(self.RefreshSubrangeInitialValueRange) |
|
687 |
wx.CallAfter(self.RefreshTypeInfos) |
|
125 | 688 |
event.Skip() |
689 |
||
690 |
def OnDimensionsChanged(self, event): |
|
691 |
wx.CallAfter(self.RefreshTypeInfos) |
|
692 |
event.Skip() |
|
693 |
||
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
694 |
def OnEnumeratedValueEndEdit(self, event): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
695 |
text = event.GetText() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
696 |
values = self.EnumeratedValues.GetStrings() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
697 |
index = event.GetIndex() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
698 |
if index >= len(values) or values[index].upper() != text.upper(): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
699 |
if text.upper() in [value.upper() for value in values]: |
391 | 700 |
message = wx.MessageDialog(self, _("\"%s\" value already defined!")%text, _("Error"), wx.OK|wx.ICON_ERROR) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
701 |
message.ShowModal() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
702 |
message.Destroy() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
703 |
event.Veto() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
704 |
elif text.upper() in IEC_KEYWORDS: |
391 | 705 |
message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%text, _("Error"), wx.OK|wx.ICON_ERROR) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
706 |
message.ShowModal() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
707 |
message.Destroy() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
708 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
709 |
wx.CallAfter(self.RefreshEnumeratedValues) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
710 |
wx.CallAfter(self.RefreshTypeInfos) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
711 |
event.Skip() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
712 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
713 |
wx.CallAfter(self.RefreshEnumeratedValues) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
714 |
wx.CallAfter(self.RefreshTypeInfos) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
715 |
event.Skip() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
716 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
717 |
def OnEnumeratedValuesChanged(self, event): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
718 |
wx.CallAfter(self.RefreshEnumeratedValues) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
719 |
wx.CallAfter(self.RefreshTypeInfos) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
720 |
event.Skip() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
721 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
722 |
def OnStructureAddButton(self, event): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
723 |
new_row = self.StructureElementDefaultValue.copy() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
724 |
self.StructureElementsTable.AppendRow(new_row) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
725 |
self.RefreshTypeInfos() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
726 |
self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
727 |
event.Skip() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
728 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
729 |
def OnStructureDeleteButton(self, event): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
730 |
row = self.StructureElementsGrid.GetGridCursorRow() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
731 |
self.StructureElementsTable.RemoveRow(row) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
732 |
self.RefreshTypeInfos() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
733 |
self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
734 |
event.Skip() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
735 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
736 |
def OnStructureUpButton(self, event): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
737 |
row = self.StructureElementsGrid.GetGridCursorRow() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
738 |
new_index = self.StructureElementsTable.MoveRow(row, -1) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
739 |
if new_index is not None: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
740 |
self.RefreshTypeInfos() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
741 |
self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
742 |
self.StructureElementsGrid.SetGridCursor(new_index, self.StructureElementsGrid.GetGridCursorCol()) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
743 |
event.Skip() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
744 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
745 |
def OnStructureDownButton(self, event): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
746 |
row = self.StructureElementsGrid.GetGridCursorRow() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
747 |
new_index = self.StructureElementsTable.MoveRow(row, 1) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
748 |
if new_index is not None: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
749 |
self.RefreshTypeInfos() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
750 |
self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
751 |
self.StructureElementsGrid.SetGridCursor(new_index, self.StructureElementsGrid.GetGridCursorCol()) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
752 |
event.Skip() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
753 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
754 |
def OnStructureElementsGridCellChange(self, event): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
755 |
row, col = event.GetRow(), event.GetCol() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
756 |
colname = self.StructureElementsTable.GetColLabelValue(col) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
757 |
value = self.StructureElementsTable.GetValue(row, col) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
758 |
if colname == "Name": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
759 |
if not TestIdentifier(value): |
391 | 760 |
message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%value, _("Error"), wx.OK|wx.ICON_ERROR) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
761 |
message.ShowModal() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
762 |
message.Destroy() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
763 |
event.Veto() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
764 |
elif value.upper() in IEC_KEYWORDS: |
391 | 765 |
message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%value, _("Error"), wx.OK|wx.ICON_ERROR) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
766 |
message.ShowModal() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
767 |
message.Destroy() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
768 |
event.Veto() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
769 |
## elif value.upper() in self.PouNames: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
770 |
## message = wx.MessageDialog(self, "A pou with \"%s\" as name exists!"%value, "Error", wx.OK|wx.ICON_ERROR) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
771 |
## message.ShowModal() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
772 |
## message.Destroy() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
773 |
## event.Veto() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
774 |
elif value.upper() in [var["Name"].upper() for idx, var in enumerate(self.StructureElementsTable.GetData()) if idx != row]: |
427 | 775 |
message = wx.MessageDialog(self, _("An element named \"%s\" already exists in this structure!")%value, _("Error"), wx.OK|wx.ICON_ERROR) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
776 |
message.ShowModal() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
777 |
message.Destroy() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
778 |
event.Veto() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
779 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
780 |
self.RefreshTypeInfos() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
781 |
self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
782 |
## old_value = self.Table.GetOldValue() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
783 |
## if old_value != "": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
784 |
## self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
785 |
## self.Controler.BufferProject() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
786 |
event.Skip() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
787 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
788 |
self.RefreshTypeInfos() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
789 |
self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
790 |
event.Skip() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
791 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
792 |
def OnStructureElementsGridEditorShown(self, event): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
793 |
row, col = event.GetRow(), event.GetCol() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
794 |
if self.StructureElementsTable.GetColLabelValue(col) == "Type": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
795 |
type_menu = wx.Menu(title='') |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
796 |
base_menu = wx.Menu(title='') |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
797 |
for base_type in self.Controler.GetBaseTypes(): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
798 |
new_id = wx.NewId() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
799 |
AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
800 |
self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(base_type), id=new_id) |
391 | 801 |
type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
802 |
datatype_menu = wx.Menu(title='') |
462
9abbc90c0263
Bug when trying to choose type of struture datatype element fixed
laurent
parents:
460
diff
changeset
|
803 |
for datatype in self.Controler.GetDataTypes(self.TagName, False): |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
804 |
new_id = wx.NewId() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
805 |
AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
806 |
self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(datatype), id=new_id) |
391 | 807 |
type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
808 |
## functionblock_menu = wx.Menu(title='') |
462
9abbc90c0263
Bug when trying to choose type of struture datatype element fixed
laurent
parents:
460
diff
changeset
|
809 |
## bodytype = self.Controler.GetEditedElementBodyType(self.TagName) |
9abbc90c0263
Bug when trying to choose type of struture datatype element fixed
laurent
parents:
460
diff
changeset
|
810 |
## pouname, poutype = self.Controler.GetEditedElementType(self.TagName) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
811 |
## if classtype in ["Input","Output","InOut","External","Global"] or poutype != "function" and bodytype in ["ST", "IL"]: |
462
9abbc90c0263
Bug when trying to choose type of struture datatype element fixed
laurent
parents:
460
diff
changeset
|
812 |
## for functionblock_type in self.Controler.GetFunctionBlockTypes(self.TagName): |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
813 |
## new_id = wx.NewId() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
814 |
## AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
815 |
## self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id) |
391 | 816 |
## type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
817 |
rect = self.StructureElementsGrid.BlockToDeviceRect((row, col), (row, col)) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
818 |
self.StructureElementsGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.StructureElementsGrid.GetColLabelSize()) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
819 |
event.Veto() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
820 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
821 |
event.Skip() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
822 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
823 |
def GetElementTypeFunction(self, base_type): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
824 |
def ElementTypeFunction(event): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
825 |
row = self.StructureElementsGrid.GetGridCursorRow() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
826 |
self.StructureElementsTable.SetValueByName(row, "Type", base_type) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
827 |
self.RefreshTypeInfos() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
828 |
self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
829 |
return ElementTypeFunction |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
830 |
|
125 | 831 |
def RefreshDisplayedInfos(self): |
391 | 832 |
selected = DATATYPE_TYPES_DICT[self.DerivationType.GetStringSelection()] |
125 | 833 |
if selected != self.CurrentPanel: |
834 |
if self.CurrentPanel == "Directly": |
|
835 |
self.DirectlyPanel.Hide() |
|
836 |
elif self.CurrentPanel == "Subrange": |
|
837 |
self.SubrangePanel.Hide() |
|
838 |
elif self.CurrentPanel == "Enumerated": |
|
839 |
self.EnumeratedPanel.Hide() |
|
840 |
elif self.CurrentPanel == "Array": |
|
841 |
self.ArrayPanel.Hide() |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
842 |
elif self.CurrentPanel == "Structure": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
843 |
self.StructurePanel.Hide() |
125 | 844 |
self.CurrentPanel = selected |
845 |
if selected == "Directly": |
|
846 |
self.DirectlyPanel.Show() |
|
847 |
elif selected == "Subrange": |
|
848 |
self.SubrangePanel.Show() |
|
849 |
elif selected == "Enumerated": |
|
850 |
self.EnumeratedPanel.Show() |
|
851 |
elif selected == "Array": |
|
852 |
self.ArrayPanel.Show() |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
853 |
elif selected == "Structure": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
854 |
self.StructurePanel.Show() |
125 | 855 |
self.MainSizer.Layout() |
856 |
||
857 |
def RefreshEnumeratedValues(self): |
|
858 |
selected = self.EnumeratedInitialValue.GetStringSelection() |
|
859 |
self.EnumeratedInitialValue.Clear() |
|
860 |
self.EnumeratedInitialValue.Append("") |
|
861 |
for value in self.EnumeratedValues.GetStrings(): |
|
862 |
self.EnumeratedInitialValue.Append(value) |
|
863 |
self.EnumeratedInitialValue.SetStringSelection(selected) |
|
864 |
||
865 |
def RefreshBoundsRange(self): |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
866 |
range = self.Controler.GetDataTypeRange(self.SubrangeBaseType.GetStringSelection()) |
125 | 867 |
if range is not None: |
868 |
min_value, max_value = range |
|
869 |
self.SubrangeMinimum.SetRange(min_value, max_value) |
|
870 |
self.SubrangeMinimum.SetValue(min(max(min_value, self.SubrangeMinimum.GetValue()), max_value)) |
|
871 |
self.SubrangeMaximum.SetRange(min_value, max_value) |
|
872 |
self.SubrangeMaximum.SetValue(min(max(min_value, self.SubrangeMaximum.GetValue()), max_value)) |
|
873 |
||
874 |
def RefreshSubrangeInitialValueRange(self): |
|
875 |
self.SubrangeInitialValue.SetRange(self.SubrangeMinimum.GetValue(), self.SubrangeMaximum.GetValue()) |
|
876 |
||
877 |
def RefreshTypeInfos(self): |
|
391 | 878 |
selected = DATATYPE_TYPES_DICT[self.DerivationType.GetStringSelection()] |
125 | 879 |
infos = {"type" : selected} |
880 |
if selected == "Directly": |
|
881 |
infos["base_type"] = self.DirectlyBaseType.GetStringSelection() |
|
882 |
infos["initial"] = self.DirectlyInitialValue.GetValue() |
|
883 |
elif selected == "Subrange": |
|
884 |
infos["base_type"] = self.SubrangeBaseType.GetStringSelection() |
|
389 | 885 |
infos["min"] = str(self.SubrangeMinimum.GetValue()) |
886 |
infos["max"] = str(self.SubrangeMaximum.GetValue()) |
|
125 | 887 |
initial_value = self.SubrangeInitialValue.GetValue() |
888 |
if initial_value == infos["min"]: |
|
889 |
infos["initial"] = "" |
|
890 |
else: |
|
891 |
infos["initial"] = str(initial_value) |
|
892 |
elif selected == "Enumerated": |
|
893 |
infos["values"] = self.EnumeratedValues.GetStrings() |
|
894 |
infos["initial"] = self.EnumeratedInitialValue.GetStringSelection() |
|
895 |
elif selected == "Array": |
|
896 |
infos["base_type"] = self.ArrayBaseType.GetStringSelection() |
|
207 | 897 |
infos["dimensions"] = [] |
898 |
for dimensions in self.ArrayDimensions.GetStrings(): |
|
899 |
result = DIMENSION_MODEL.match(dimensions) |
|
900 |
if result is None: |
|
391 | 901 |
message = wx.MessageDialog(self, _("\"%s\" value isn't a valid array dimension!")%dimensions, _("Error"), wx.OK|wx.ICON_ERROR) |
207 | 902 |
message.ShowModal() |
903 |
message.Destroy() |
|
904 |
self.RefreshView() |
|
905 |
return |
|
906 |
bounds = result.groups() |
|
460 | 907 |
if int(bounds[0]) >= int(bounds[1]): |
391 | 908 |
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) |
207 | 909 |
message.ShowModal() |
910 |
message.Destroy() |
|
911 |
self.RefreshView() |
|
912 |
return |
|
389 | 913 |
infos["dimensions"].append(bounds) |
125 | 914 |
infos["initial"] = self.ArrayInitialValue.GetValue() |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
915 |
elif selected == "Structure": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
916 |
infos["elements"] = self.StructureElementsTable.GetData() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
235
diff
changeset
|
917 |
infos["initial"] = "" |
125 | 918 |
self.Controler.SetDataTypeInfos(self.TagName, infos) |
919 |
self.ParentWindow.RefreshTitle() |
|
494
c91644c2bfa7
Bug on FileMenu not refreshed when modifications fixed
laurent
parents:
462
diff
changeset
|
920 |
self.ParentWindow.RefreshFileMenu() |
125 | 921 |
self.ParentWindow.RefreshEditMenu() |
922 |
||
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
923 |
#------------------------------------------------------------------------------- |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
924 |
# Errors showing functions |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
925 |
#------------------------------------------------------------------------------- |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
926 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
927 |
def ClearErrors(self): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
928 |
self.Errors = [] |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
929 |
self.RefreshView() |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
930 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
931 |
def AddShownError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
932 |
self.Errors.append((infos, start, end)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
933 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
934 |
def ShowErrors(self): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
935 |
type_infos = self.Controler.GetDataTypeInfos(self.TagName) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
936 |
for infos, start, end in self.Errors: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
937 |
if infos[0] == "base": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
938 |
if type_infos["type"] == "Directly": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
939 |
self.DirectlyBaseType.SetBackgroundColour(wx.Colour(255, 255, 0)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
940 |
self.DirectlyBaseType.SetForegroundColour(wx.RED) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
941 |
elif type_infos["type"] == "Subrange": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
942 |
self.SubrangeBaseType.SetBackgroundColour(wx.Colour(255, 255, 0)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
943 |
self.SubrangeBaseType.SetForegroundColour(wx.RED) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
944 |
elif type_infos["type"] == "Array": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
945 |
self.ArrayBaseType.SetBackgroundColour(wx.Colour(255, 255, 0)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
946 |
self.ArrayBaseType.SetForegroundColour(wx.RED) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
947 |
elif infos[0] == "lower": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
948 |
self.SubrangeMinimum.SetBackgroundColour(wx.Colour(255, 255, 0)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
949 |
self.SubrangeMaximum.SetForegroundColour(wx.RED) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
950 |
elif infos[0] == "upper": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
951 |
self.SubrangeMinimum.SetBackgroundColour(wx.Colour(255, 255, 0)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
952 |
self.SubrangeMaximum.SetForegroundColour(wx.RED) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
953 |
elif infos[0] == "value": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
954 |
listctrl = self.EnumeratedValues.GetListCtrl() |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
955 |
listctrl.SetItemBackgroundColour(infos[1], wx.Colour(255, 255, 0)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
956 |
listctrl.SetItemTextColour(infos[1], wx.RED) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
957 |
listctrl.Select(listctrl.FocusedItem, False) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
958 |
elif infos[0] == "range": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
959 |
listctrl = self.EnumeratedValues.GetListCtrl() |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
960 |
listctrl.SetItemBackgroundColour(infos[1], wx.Colour(255, 255, 0)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
961 |
listctrl.SetItemTextColour(infos[1], wx.RED) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
962 |
listctrl.SetStringSelection("") |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
963 |
elif infos[0] == "initial": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
964 |
if type_infos["type"] == "Directly": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
965 |
text = self.DirectlyInitialValue.GetValue() |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
966 |
self.DirectlyInitialValue.SetValue(text[:start[1]]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
967 |
self.DirectlyInitialValue.SetDefaultStyle(wx.TextAttr(wx.RED, wx.Colour(255, 255, 0))) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
968 |
self.DirectlyInitialValue.AppendText(text[start[1]:end[1] + 1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
969 |
self.DirectlyInitialValue.SetDefaultStyle(wx.TextAttr(wx.BLACK, wx.WHITE)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
970 |
self.DirectlyInitialValue.AppendText(text[end[1] + 1:]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
971 |
elif type_infos["type"] == "Subrange": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
972 |
self.SubrangeInitialValue.SetBackgroundColour(wx.Colour(255, 255, 0)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
973 |
self.SubrangeInitialValue.SetForegroundColour(wx.RED) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
974 |
elif type_infos["type"] == "Enumerated": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
975 |
self.EnumeratedInitialValue.SetBackgroundColour(wx.Colour(255, 255, 0)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
976 |
self.EnumeratedInitialValue.SetForegroundColour(wx.RED) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
977 |
elif type_infos["type"] == "Array": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
978 |
text = self.ArrayInitialValue.GetValue() |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
979 |
self.ArrayInitialValue.SetValue(text[:start[1]]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
980 |
self.ArrayInitialValue.SetDefaultStyle(wx.TextAttr(wx.RED, wx.Colour(255, 255, 0))) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
981 |
self.ArrayInitialValue.AppendText(text[start[1]:end[1] + 1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
982 |
self.ArrayInitialValue.SetDefaultStyle(wx.TextAttr(wx.BLACK, wx.WHITE)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
215
diff
changeset
|
983 |
self.ArrayInitialValue.AppendText(text[end[1] + 1:]) |