author | Edouard Tisserant |
Thu, 23 Jun 2011 18:12:34 +0200 | |
changeset 662 | aad111ad0018 |
parent 622 | f0935accb93b |
child 741 | b1a73ddc514b |
permissions | -rw-r--r-- |
205 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of CanFestival, a library implementing CanOpen Stack. |
|
5 |
# |
|
6 |
#Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD |
|
7 |
# |
|
8 |
#See COPYING file for copyrights details. |
|
9 |
# |
|
10 |
#This library is free software; you can redistribute it and/or |
|
11 |
#modify it under the terms of the GNU Lesser General Public |
|
12 |
#License as published by the Free Software Foundation; either |
|
13 |
#version 2.1 of the License, or (at your option) any later version. |
|
14 |
# |
|
15 |
#This library is distributed in the hope that it will be useful, |
|
16 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
18 |
#Lesser General Public License for more details. |
|
19 |
# |
|
20 |
#You should have received a copy of the GNU Lesser General Public |
|
21 |
#License along with this library; if not, write to the Free Software |
|
22 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
||
24 |
import wx |
|
25 |
import wx.grid |
|
26 |
||
27 |
from types import * |
|
281
685d9a26e4f9
Obsolete example files in objdictgen/examples replaced by some new equivalents
lbessard
parents:
277
diff
changeset
|
28 |
from commondialogs import * |
205 | 29 |
|
206 | 30 |
from node import OD_Subindex, OD_MultipleSubindexes, OD_IdenticalSubindexes, OD_IdenticalIndexes |
205 | 31 |
|
32 |
ColSizes = [75, 250, 150, 125, 100, 60, 250] |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
33 |
ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_RIGHT, wx.ALIGN_CENTER, wx.ALIGN_CENTER, wx.ALIGN_LEFT] |
580 | 34 |
|
35 |
def GetAccessList(write=True): |
|
36 |
_ = lambda x : x |
|
37 |
if write: |
|
38 |
return [_("Read Only"), _("Write Only"), _("Read/Write")] |
|
39 |
return [_("Read Only"), _("Read/Write")] |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
580
diff
changeset
|
40 |
AccessList = ",".join(map(_, GetAccessList())) |
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
580
diff
changeset
|
41 |
RAccessList = ",".join(map(_, GetAccessList(False))) |
580 | 42 |
ACCESS_LIST_DICT = dict([(_(access), access) for access in GetAccessList()]) |
43 |
||
44 |
def GetBoolList(): |
|
45 |
_ = lambda x : x |
|
46 |
return [_("True"), _("False")] |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
580
diff
changeset
|
47 |
BoolList = ",".join(map(_, GetBoolList())) |
580 | 48 |
BOOL_LIST_DICT = dict([(_(bool), bool) for bool in GetBoolList()]) |
49 |
||
50 |
def GetOptionList(): |
|
51 |
_ = lambda x : x |
|
52 |
return [_("Yes"), _("No")] |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
580
diff
changeset
|
53 |
OptionList = ",".join(map(_, GetOptionList())) |
580 | 54 |
OPTION_LIST_DICT = dict([(_(option), option) for option in GetOptionList()]) |
55 |
||
56 |
[USER_TYPE, SDO_SERVER, SDO_CLIENT, |
|
57 |
PDO_TRANSMIT, PDO_RECEIVE, MAP_VARIABLE] = range(6) |
|
58 |
||
59 |
INDEXCHOICE_OPTIONS = { |
|
60 |
USER_TYPE: (_("User Type"), 0, "AddUserType"), |
|
61 |
SDO_SERVER: (_("SDO Server"), 1, "AddSDOServerToCurrent"), |
|
62 |
SDO_CLIENT: (_("SDO Client"), 1, "AddSDOClientToCurrent"), |
|
63 |
PDO_RECEIVE: (_("PDO Receive"), 1, "AddPDOReceiveToCurrent"), |
|
64 |
PDO_TRANSMIT: (_("PDO Transmit"), 1, "AddPDOTransmitToCurrent"), |
|
65 |
MAP_VARIABLE: (_("Map Variable"), 0, "AddMapVariable") |
|
66 |
} |
|
67 |
||
68 |
INDEXCHOICE_OPTIONS_DICT = dict([(translation, option) for option, (translation, object, function) in INDEXCHOICE_OPTIONS.iteritems()]) |
|
69 |
||
70 |
INDEXCHOICE_SECTIONS = { |
|
71 |
0 : [USER_TYPE], |
|
72 |
2 : [SDO_SERVER, SDO_CLIENT], |
|
73 |
3 : [PDO_RECEIVE], |
|
74 |
4 : [PDO_RECEIVE], |
|
75 |
5 : [PDO_TRANSMIT], |
|
76 |
6 : [PDO_TRANSMIT], |
|
77 |
8 : [MAP_VARIABLE], |
|
78 |
} |
|
79 |
||
80 |
def GetSubindexTableColnames(): |
|
81 |
_ = lambda x : x |
|
82 |
return [_("subindex"), _("name"), _("type"), _("value"), _("access"), _("save"), _("comment")] |
|
205 | 83 |
|
84 |
DictionaryOrganisation = [ |
|
85 |
{"minIndex" : 0x0001, "maxIndex" : 0x0FFF, "name" : "Data Type Definitions"}, |
|
86 |
{"minIndex" : 0x1000, "maxIndex" : 0x1029, "name" : "Communication Parameters"}, |
|
87 |
{"minIndex" : 0x1200, "maxIndex" : 0x12FF, "name" : "SDO Parameters"}, |
|
88 |
{"minIndex" : 0x1400, "maxIndex" : 0x15FF, "name" : "Receive PDO Parameters"}, |
|
89 |
{"minIndex" : 0x1600, "maxIndex" : 0x17FF, "name" : "Receive PDO Mapping"}, |
|
90 |
{"minIndex" : 0x1800, "maxIndex" : 0x19FF, "name" : "Transmit PDO Parameters"}, |
|
91 |
{"minIndex" : 0x1A00, "maxIndex" : 0x1BFF, "name" : "Transmit PDO Mapping"}, |
|
92 |
{"minIndex" : 0x1C00, "maxIndex" : 0x1FFF, "name" : "Other Communication Parameters"}, |
|
93 |
{"minIndex" : 0x2000, "maxIndex" : 0x5FFF, "name" : "Manufacturer Specific"}, |
|
94 |
{"minIndex" : 0x6000, "maxIndex" : 0x9FFF, "name" : "Standardized Device Profile"}, |
|
95 |
{"minIndex" : 0xA000, "maxIndex" : 0xBFFF, "name" : "Standardized Interface Profile"}] |
|
96 |
||
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
237
diff
changeset
|
97 |
SizeConversion = {1 : "X", 8 : "B", 16 : "W", 24 : "D", 32 : "D", 40 : "L", 48 : "L", 56 : "L", 64 : "L"} |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
237
diff
changeset
|
98 |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
99 |
class SubindexTable(wx.grid.PyGridTableBase): |
205 | 100 |
|
101 |
""" |
|
102 |
A custom wxGrid Table using user supplied data |
|
103 |
""" |
|
104 |
def __init__(self, parent, data, editors, colnames): |
|
105 |
# The base class must be initialized *first* |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
106 |
wx.grid.PyGridTableBase.__init__(self) |
205 | 107 |
self.data = data |
108 |
self.editors = editors |
|
109 |
self.CurrentIndex = 0 |
|
110 |
self.colnames = colnames |
|
111 |
self.Parent = parent |
|
112 |
self.Editable = True |
|
113 |
# XXX |
|
114 |
# we need to store the row length and collength to |
|
115 |
# see if the table has changed size |
|
116 |
self._rows = self.GetNumberRows() |
|
117 |
self._cols = self.GetNumberCols() |
|
118 |
||
119 |
def Disable(self): |
|
120 |
self.Editable = False |
|
121 |
||
122 |
def Enable(self): |
|
123 |
self.Editable = True |
|
124 |
||
125 |
def GetNumberCols(self): |
|
126 |
return len(self.colnames) |
|
127 |
||
128 |
def GetNumberRows(self): |
|
129 |
return len(self.data) |
|
130 |
||
580 | 131 |
def GetColLabelValue(self, col, translate=True): |
205 | 132 |
if col < len(self.colnames): |
580 | 133 |
if translate: |
134 |
return _(self.colnames[col]) |
|
205 | 135 |
return self.colnames[col] |
136 |
||
580 | 137 |
def GetRowLabelValues(self, row, translate=True): |
205 | 138 |
return row |
139 |
||
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
580
diff
changeset
|
140 |
def GetValue(self, row, col, translate=True): |
205 | 141 |
if row < self.GetNumberRows(): |
580 | 142 |
colname = self.GetColLabelValue(col, False) |
143 |
value = unicode(self.data[row].get(colname, "")) |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
580
diff
changeset
|
144 |
if translate and (colname == "access" or |
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
580
diff
changeset
|
145 |
self.editors[row][colname] in ["bool", "option"] or |
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
580
diff
changeset
|
146 |
self.editors[row][colname] == "map" and value == "None"): |
580 | 147 |
value = _(value) |
148 |
return value |
|
266 | 149 |
|
205 | 150 |
def GetEditor(self, row, col): |
151 |
if row < self.GetNumberRows(): |
|
580 | 152 |
return self.editors[row].get(self.GetColLabelValue(col, False), "") |
205 | 153 |
|
154 |
def GetValueByName(self, row, colname): |
|
155 |
return self.data[row].get(colname) |
|
156 |
||
157 |
def SetValue(self, row, col, value): |
|
158 |
if col < len(self.colnames): |
|
580 | 159 |
colname = self.GetColLabelValue(col, False) |
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
580
diff
changeset
|
160 |
if colname == "access": |
580 | 161 |
value = ACCESS_LIST_DICT[value] |
162 |
elif self.editors[row][colname] == "bool": |
|
163 |
value = BOOL_LIST_DICT[value] |
|
164 |
elif self.editors[row][colname] == "option": |
|
165 |
value = OPTION_LIST_DICT[value] |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
580
diff
changeset
|
166 |
elif self.editors[row][colname] == "map" and value == _("None"): |
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
580
diff
changeset
|
167 |
value = "None" |
580 | 168 |
self.data[row][colname] = value |
205 | 169 |
|
170 |
def ResetView(self, grid): |
|
171 |
""" |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
172 |
(wx.grid.Grid) -> Reset the grid view. Call this to |
205 | 173 |
update the grid if rows and columns have been added or deleted |
174 |
""" |
|
175 |
grid.BeginBatch() |
|
176 |
for current, new, delmsg, addmsg in [ |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
177 |
(self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED), |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
178 |
(self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), |
205 | 179 |
]: |
180 |
if new < current: |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
181 |
msg = wx.grid.GridTableMessage(self,delmsg,new,current-new) |
205 | 182 |
grid.ProcessTableMessage(msg) |
183 |
elif new > current: |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
184 |
msg = wx.grid.GridTableMessage(self,addmsg,new-current) |
205 | 185 |
grid.ProcessTableMessage(msg) |
186 |
self.UpdateValues(grid) |
|
187 |
grid.EndBatch() |
|
188 |
||
189 |
self._rows = self.GetNumberRows() |
|
190 |
self._cols = self.GetNumberCols() |
|
191 |
# update the column rendering scheme |
|
192 |
self._updateColAttrs(grid) |
|
193 |
||
194 |
# update the scrollbars and the displayed part of the grid |
|
195 |
grid.AdjustScrollbars() |
|
196 |
grid.ForceRefresh() |
|
197 |
||
198 |
||
199 |
def UpdateValues(self, grid): |
|
200 |
"""Update all displayed values""" |
|
201 |
# This sends an event to the grid table to update all of the values |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
202 |
msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) |
205 | 203 |
grid.ProcessTableMessage(msg) |
204 |
||
205 |
def _updateColAttrs(self, grid): |
|
206 |
""" |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
207 |
wx.grid.Grid -> update the column attributes to add the |
205 | 208 |
appropriate renderer given the column name. |
209 |
||
210 |
Otherwise default to the default renderer. |
|
211 |
""" |
|
212 |
||
213 |
for col in range(self.GetNumberCols()): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
214 |
attr = wx.grid.GridCellAttr() |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
215 |
attr.SetAlignment(ColAlignements[col], wx.ALIGN_CENTRE) |
205 | 216 |
grid.SetColAttr(col, attr) |
580 | 217 |
grid.SetColMinimalWidth(col, ColSizes[col]) |
218 |
grid.AutoSizeColumn(col, False) |
|
205 | 219 |
|
220 |
typelist = None |
|
221 |
maplist = None |
|
222 |
for row in range(self.GetNumberRows()): |
|
223 |
editors = self.editors[row] |
|
585
d62424ba12bf
Replacing wx.Choice controls by wx.ComboBox controls
laurent
parents:
584
diff
changeset
|
224 |
grid.SetRowMinimalHeight(row, 28) |
d62424ba12bf
Replacing wx.Choice controls by wx.ComboBox controls
laurent
parents:
584
diff
changeset
|
225 |
grid.AutoSizeRow(row, False) |
205 | 226 |
for col in range(self.GetNumberCols()): |
227 |
editor = None |
|
228 |
renderer = None |
|
229 |
||
580 | 230 |
colname = self.GetColLabelValue(col, False) |
205 | 231 |
editortype = editors[colname] |
232 |
if editortype and self.Editable: |
|
233 |
grid.SetReadOnly(row, col, False) |
|
234 |
if editortype == "string": |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
235 |
editor = wx.grid.GridCellTextEditor() |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
236 |
renderer = wx.grid.GridCellStringRenderer() |
205 | 237 |
if colname == "value" and "length" in editors: |
238 |
editor.SetParameters(editors["length"]) |
|
239 |
elif editortype == "number": |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
240 |
editor = wx.grid.GridCellNumberEditor() |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
241 |
renderer = wx.grid.GridCellNumberRenderer() |
205 | 242 |
if colname == "value" and "min" in editors and "max" in editors: |
243 |
editor.SetParameters("%s,%s"%(editors["min"],editors["max"])) |
|
453 | 244 |
elif editortype == "float": |
245 |
editor = wx.grid.GridCellTextEditor() |
|
246 |
renderer = wx.grid.GridCellStringRenderer() |
|
205 | 247 |
elif editortype == "bool": |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
248 |
editor = wx.grid.GridCellChoiceEditor() |
205 | 249 |
editor.SetParameters(BoolList) |
250 |
elif editortype == "access": |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
251 |
editor = wx.grid.GridCellChoiceEditor() |
205 | 252 |
editor.SetParameters(AccessList) |
253 |
elif editortype == "raccess": |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
254 |
editor = wx.grid.GridCellChoiceEditor() |
205 | 255 |
editor.SetParameters(RAccessList) |
256 |
elif editortype == "option": |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
257 |
editor = wx.grid.GridCellChoiceEditor() |
205 | 258 |
editor.SetParameters(OptionList) |
259 |
elif editortype == "type": |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
260 |
editor = wx.grid.GridCellChoiceEditor() |
205 | 261 |
if typelist == None: |
262 |
typelist = self.Parent.Manager.GetCurrentTypeList() |
|
263 |
editor.SetParameters(typelist) |
|
264 |
elif editortype == "map": |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
265 |
editor = wx.grid.GridCellChoiceEditor() |
205 | 266 |
if maplist == None: |
267 |
maplist = self.Parent.Manager.GetCurrentMapList() |
|
268 |
editor.SetParameters(maplist) |
|
269 |
elif editortype == "time": |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
270 |
editor = wx.grid.GridCellTextEditor() |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
271 |
renderer = wx.grid.GridCellStringRenderer() |
205 | 272 |
elif editortype == "domain": |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
273 |
editor = wx.grid.GridCellTextEditor() |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
274 |
renderer = wx.grid.GridCellStringRenderer() |
327 | 275 |
elif editortype == "dcf": |
276 |
editor = wx.grid.GridCellTextEditor() |
|
277 |
renderer = wx.grid.GridCellStringRenderer() |
|
205 | 278 |
else: |
279 |
grid.SetReadOnly(row, col, True) |
|
280 |
||
281 |
grid.SetCellEditor(row, col, editor) |
|
282 |
grid.SetCellRenderer(row, col, renderer) |
|
283 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
284 |
grid.SetCellBackgroundColour(row, col, wx.WHITE) |
205 | 285 |
|
286 |
def SetData(self, data): |
|
287 |
self.data = data |
|
288 |
||
289 |
def SetEditors(self, editors): |
|
290 |
self.editors = editors |
|
291 |
||
292 |
def GetCurrentIndex(self): |
|
293 |
return self.CurrentIndex |
|
294 |
||
295 |
def SetCurrentIndex(self, index): |
|
296 |
self.CurrentIndex = index |
|
297 |
||
298 |
def AppendRow(self, row_content): |
|
299 |
self.data.append(row_content) |
|
300 |
||
301 |
def Empty(self): |
|
302 |
self.data = [] |
|
303 |
self.editors = [] |
|
304 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
305 |
[ID_EDITINGPANEL, ID_EDITINGPANELADDBUTTON, ID_EDITINGPANELINDEXCHOICE, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
306 |
ID_EDITINGPANELINDEXLIST, ID_EDITINGPANELINDEXLISTPANEL, ID_EDITINGPANELPARTLIST, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
307 |
ID_EDITINGPANELSECONDSPLITTER, ID_EDITINGPANELSUBINDEXGRID, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
308 |
ID_EDITINGPANELSUBINDEXGRIDPANEL, ID_EDITINGPANELCALLBACKCHECK, |
205 | 309 |
] = [wx.NewId() for _init_ctrls in range(10)] |
310 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
311 |
[ID_EDITINGPANELINDEXLISTMENUITEMS0, ID_EDITINGPANELINDEXLISTMENUITEMS1, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
312 |
ID_EDITINGPANELINDEXLISTMENUITEMS2, |
205 | 313 |
] = [wx.NewId() for _init_coll_IndexListMenu_Items in range(3)] |
314 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
315 |
[ID_EDITINGPANELMENU1ITEMS0, ID_EDITINGPANELMENU1ITEMS1, |
327 | 316 |
ID_EDITINGPANELMENU1ITEMS3, ID_EDITINGPANELMENU1ITEMS4, |
317 |
] = [wx.NewId() for _init_coll_SubindexGridMenu_Items in range(4)] |
|
205 | 318 |
|
319 |
class EditingPanel(wx.SplitterWindow): |
|
320 |
def _init_coll_AddToListSizer_Items(self, parent): |
|
321 |
parent.AddWindow(self.AddButton, 0, border=0, flag=0) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
322 |
parent.AddWindow(self.IndexChoice, 0, border=0, flag=wx.GROW) |
205 | 323 |
|
324 |
def _init_coll_SubindexGridSizer_Items(self, parent): |
|
325 |
parent.AddWindow(self.CallbackCheck, 0, border=0, flag=0) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
326 |
parent.AddWindow(self.SubindexGrid, 0, border=0, flag=wx.GROW) |
205 | 327 |
|
328 |
def _init_coll_IndexListSizer_Items(self, parent): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
329 |
parent.AddWindow(self.IndexList, 0, border=0, flag=wx.GROW) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
330 |
parent.AddSizer(self.AddToListSizer, 0, border=0, flag=wx.GROW) |
205 | 331 |
|
332 |
def _init_coll_AddToListSizer_Growables(self, parent): |
|
333 |
parent.AddGrowableCol(1) |
|
334 |
||
335 |
def _init_coll_SubindexGridSizer_Growables(self, parent): |
|
336 |
parent.AddGrowableCol(0) |
|
337 |
parent.AddGrowableRow(1) |
|
338 |
||
339 |
def _init_coll_IndexListSizer_Growables(self, parent): |
|
340 |
parent.AddGrowableCol(0) |
|
341 |
parent.AddGrowableRow(0) |
|
342 |
||
343 |
def _init_coll_SubindexGridMenu_Items(self, parent): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
344 |
parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS0, |
580 | 345 |
kind=wx.ITEM_NORMAL, text=_('Add subindexes')) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
346 |
parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS1, |
580 | 347 |
kind=wx.ITEM_NORMAL, text=_('Delete subindexes')) |
299 | 348 |
parent.AppendSeparator() |
349 |
parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS3, |
|
580 | 350 |
kind=wx.ITEM_NORMAL, text=_('Default value')) |
327 | 351 |
if not self.Editable: |
352 |
parent.Append(help='', id=ID_EDITINGPANELMENU1ITEMS4, |
|
580 | 353 |
kind=wx.ITEM_NORMAL, text=_('Add to DCF')) |
205 | 354 |
self.Bind(wx.EVT_MENU, self.OnAddSubindexMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
355 |
id=ID_EDITINGPANELMENU1ITEMS0) |
205 | 356 |
self.Bind(wx.EVT_MENU, self.OnDeleteSubindexMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
357 |
id=ID_EDITINGPANELMENU1ITEMS1) |
299 | 358 |
self.Bind(wx.EVT_MENU, self.OnDefaultValueSubindexMenu, |
359 |
id=ID_EDITINGPANELMENU1ITEMS3) |
|
327 | 360 |
if not self.Editable: |
361 |
self.Bind(wx.EVT_MENU, self.OnAddToDCFSubindexMenu, |
|
362 |
id=ID_EDITINGPANELMENU1ITEMS4) |
|
205 | 363 |
|
364 |
def _init_coll_IndexListMenu_Items(self, parent): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
365 |
parent.Append(help='', id=ID_EDITINGPANELINDEXLISTMENUITEMS0, |
580 | 366 |
kind=wx.ITEM_NORMAL, text=_('Rename')) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
367 |
parent.Append(help='', id=ID_EDITINGPANELINDEXLISTMENUITEMS2, |
580 | 368 |
kind=wx.ITEM_NORMAL, text=_('Modify')) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
369 |
parent.Append(help='', id=ID_EDITINGPANELINDEXLISTMENUITEMS1, |
580 | 370 |
kind=wx.ITEM_NORMAL, text=_('Delete')) |
205 | 371 |
self.Bind(wx.EVT_MENU, self.OnRenameIndexMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
372 |
id=ID_EDITINGPANELINDEXLISTMENUITEMS0) |
205 | 373 |
self.Bind(wx.EVT_MENU, self.OnDeleteIndexMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
374 |
id=ID_EDITINGPANELINDEXLISTMENUITEMS1) |
205 | 375 |
self.Bind(wx.EVT_MENU, self.OnModifyIndexMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
376 |
id=ID_EDITINGPANELINDEXLISTMENUITEMS2) |
205 | 377 |
|
378 |
def _init_utils(self): |
|
379 |
self.IndexListMenu = wx.Menu(title='') |
|
380 |
self.SubindexGridMenu = wx.Menu(title='') |
|
381 |
||
382 |
self._init_coll_IndexListMenu_Items(self.IndexListMenu) |
|
383 |
self._init_coll_SubindexGridMenu_Items(self.SubindexGridMenu) |
|
384 |
||
385 |
def _init_sizers(self): |
|
386 |
self.IndexListSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
387 |
self.SubindexGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
388 |
self.AddToListSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0) |
|
389 |
||
390 |
self._init_coll_IndexListSizer_Growables(self.IndexListSizer) |
|
391 |
self._init_coll_IndexListSizer_Items(self.IndexListSizer) |
|
392 |
self._init_coll_SubindexGridSizer_Growables(self.SubindexGridSizer) |
|
393 |
self._init_coll_SubindexGridSizer_Items(self.SubindexGridSizer) |
|
394 |
self._init_coll_AddToListSizer_Growables(self.AddToListSizer) |
|
395 |
self._init_coll_AddToListSizer_Items(self.AddToListSizer) |
|
396 |
||
397 |
self.SubindexGridPanel.SetSizer(self.SubindexGridSizer) |
|
398 |
self.IndexListPanel.SetSizer(self.IndexListSizer) |
|
399 |
||
400 |
def _init_ctrls(self, prnt): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
401 |
wx.SplitterWindow.__init__(self, id=ID_EDITINGPANEL, |
205 | 402 |
name='MainSplitter', parent=prnt, point=wx.Point(0, 0), |
403 |
size=wx.Size(-1, -1), style=wx.SP_3D) |
|
404 |
self._init_utils() |
|
405 |
self.SetNeedUpdating(True) |
|
406 |
self.SetMinimumPaneSize(1) |
|
407 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
408 |
self.PartList = wx.ListBox(choices=[], id=ID_EDITINGPANELPARTLIST, |
205 | 409 |
name='PartList', parent=self, pos=wx.Point(0, 0), |
410 |
size=wx.Size(-1, -1), style=0) |
|
411 |
self.PartList.Bind(wx.EVT_LISTBOX, self.OnPartListBoxClick, |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
412 |
id=ID_EDITINGPANELPARTLIST) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
413 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
414 |
self.SecondSplitter = wx.SplitterWindow(id=ID_EDITINGPANELSECONDSPLITTER, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
415 |
name='SecondSplitter', parent=self, point=wx.Point(0, 0), |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
416 |
size=wx.Size(-1, -1), style=wx.SP_3D) |
205 | 417 |
self.SecondSplitter.SetMinimumPaneSize(1) |
418 |
self.SplitHorizontally(self.PartList, self.SecondSplitter, |
|
419 |
110) |
|
420 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
421 |
self.SubindexGridPanel = wx.Panel(id=ID_EDITINGPANELSUBINDEXGRIDPANEL, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
422 |
name='SubindexGridPanel', parent=self.SecondSplitter, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
423 |
pos=wx.Point(0, 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
424 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
425 |
self.IndexListPanel = wx.Panel(id=ID_EDITINGPANELINDEXLISTPANEL, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
426 |
name='IndexListPanel', parent=self.SecondSplitter, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
427 |
pos=wx.Point(0, 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) |
205 | 428 |
self.SecondSplitter.SplitVertically(self.IndexListPanel, |
429 |
self.SubindexGridPanel, 280) |
|
430 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
431 |
self.SubindexGrid = wx.grid.Grid(id=ID_EDITINGPANELSUBINDEXGRID, |
205 | 432 |
name='SubindexGrid', parent=self.SubindexGridPanel, pos=wx.Point(0, |
433 |
0), size=wx.Size(-1, -1), style=0) |
|
434 |
self.SubindexGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
|
435 |
'Sans')) |
|
436 |
self.SubindexGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
437 |
False, 'Sans')) |
|
438 |
self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, |
|
439 |
self.OnSubindexGridCellChange) |
|
440 |
self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, |
|
441 |
self.OnSubindexGridRightClick) |
|
442 |
self.SubindexGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL, |
|
443 |
self.OnSubindexGridSelectCell) |
|
324 | 444 |
self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, |
445 |
self.OnSubindexGridCellLeftClick) |
|
327 | 446 |
self.SubindexGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, |
447 |
self.OnSubindexGridEditorShown) |
|
205 | 448 |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
449 |
self.CallbackCheck = wx.CheckBox(id=ID_EDITINGPANELCALLBACKCHECK, |
580 | 450 |
label=_('Have Callbacks'), name='CallbackCheck', |
205 | 451 |
parent=self.SubindexGridPanel, pos=wx.Point(0, 0), size=wx.Size(152, |
452 |
24), style=0) |
|
453 |
self.CallbackCheck.Bind(wx.EVT_CHECKBOX, self.OnCallbackCheck, |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
454 |
id=ID_EDITINGPANELCALLBACKCHECK) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
455 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
456 |
self.IndexList = wx.ListBox(choices=[], id=ID_EDITINGPANELINDEXLIST, |
205 | 457 |
name='IndexList', parent=self.IndexListPanel, pos=wx.Point(0, 0), |
458 |
size=wx.Size(-1, -1), style=0) |
|
459 |
self.IndexList.Bind(wx.EVT_LISTBOX, self.OnIndexListClick, |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
460 |
id=ID_EDITINGPANELINDEXLIST) |
205 | 461 |
self.IndexList.Bind(wx.EVT_RIGHT_UP, self.OnIndexListRightUp) |
462 |
||
580 | 463 |
self.AddButton = wx.Button(id=ID_EDITINGPANELADDBUTTON, label=_('Add'), |
205 | 464 |
name='AddButton', parent=self.IndexListPanel, pos=wx.Point(0, 0), |
580 | 465 |
size=wx.DefaultSize, style=0) |
205 | 466 |
self.AddButton.Bind(wx.EVT_BUTTON, self.OnAddButtonClick, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
467 |
id=ID_EDITINGPANELADDBUTTON) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
468 |
|
585
d62424ba12bf
Replacing wx.Choice controls by wx.ComboBox controls
laurent
parents:
584
diff
changeset
|
469 |
self.IndexChoice = wx.ComboBox(choices=[], id=ID_EDITINGPANELINDEXCHOICE, |
205 | 470 |
name='IndexChoice', parent=self.IndexListPanel, pos=wx.Point(50, |
585
d62424ba12bf
Replacing wx.Choice controls by wx.ComboBox controls
laurent
parents:
584
diff
changeset
|
471 |
0), size=wx.Size(-1, 30), style=wx.CB_READONLY) |
205 | 472 |
|
473 |
self._init_sizers() |
|
474 |
||
299 | 475 |
def __init__(self, parent, window, manager, editable = True): |
327 | 476 |
self.Editable = editable |
299 | 477 |
self._init_ctrls(parent) |
478 |
self.ParentWindow = window |
|
205 | 479 |
self.Manager = manager |
480 |
self.ListIndex = [] |
|
481 |
self.ChoiceIndex = [] |
|
482 |
self.FirstCall = False |
|
483 |
self.Index = None |
|
484 |
||
485 |
for values in DictionaryOrganisation: |
|
299 | 486 |
text = " 0x%04X-0x%04X %s"%(values["minIndex"], values["maxIndex"], values["name"]) |
205 | 487 |
self.PartList.Append(text) |
580 | 488 |
self.Table = SubindexTable(self, [], [], GetSubindexTableColnames()) |
205 | 489 |
self.SubindexGrid.SetTable(self.Table) |
490 |
self.SubindexGrid.SetRowLabelSize(0) |
|
491 |
self.CallbackCheck.Disable() |
|
492 |
self.Table.ResetView(self.SubindexGrid) |
|
493 |
||
494 |
if not self.Editable: |
|
495 |
self.AddButton.Disable() |
|
496 |
self.IndexChoice.Disable() |
|
497 |
self.CallbackCheck.Disable() |
|
498 |
self.Table.Disable() |
|
499 |
||
500 |
def GetIndex(self): |
|
501 |
return self.Index |
|
502 |
||
503 |
def SetIndex(self, index): |
|
504 |
self.Index = index |
|
505 |
||
506 |
def GetSelection(self): |
|
507 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
508 |
if selected != wx.NOT_FOUND: |
205 | 509 |
index = self.ListIndex[selected] |
510 |
subIndex = self.SubindexGrid.GetGridCursorRow() |
|
511 |
return index, subIndex |
|
512 |
return None |
|
513 |
||
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
237
diff
changeset
|
514 |
def OnSubindexGridCellLeftClick(self, event): |
324 | 515 |
if not self.ParentWindow.ModeSolo: |
516 |
col = event.GetCol() |
|
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
517 |
if self.Editable and col == 0: |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
518 |
selected = self.IndexList.GetSelection() |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
519 |
if selected != wx.NOT_FOUND: |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
520 |
index = self.ListIndex[selected] |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
521 |
subindex = event.GetRow() |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
522 |
entry_infos = self.Manager.GetEntryInfos(index) |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
523 |
if not entry_infos["struct"] & OD_MultipleSubindexes or subindex != 0: |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
524 |
subentry_infos = self.Manager.GetSubentryInfos(index, subindex) |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
525 |
typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"]) |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
526 |
if typeinfos: |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
527 |
bus_id = '.'.join(map(str, self.ParentWindow.GetBusId())) |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
528 |
size = typeinfos["size"] |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
529 |
data = wx.TextDataObject(str(("%s%s.%d.%d"%(SizeConversion[size], bus_id, index, subindex), "location"))) |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
530 |
dragSource = wx.DropSource(self.SubindexGrid) |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
531 |
dragSource.SetData(data) |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
532 |
dragSource.DoDragDrop() |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
533 |
elif col == 0: |
324 | 534 |
selected = self.IndexList.GetSelection() |
535 |
if selected != wx.NOT_FOUND: |
|
536 |
index = self.ListIndex[selected] |
|
537 |
subindex = event.GetRow() |
|
538 |
entry_infos = self.Manager.GetEntryInfos(index) |
|
539 |
if not entry_infos["struct"] & OD_MultipleSubindexes or subindex != 0: |
|
540 |
subentry_infos = self.Manager.GetSubentryInfos(index, subindex) |
|
541 |
typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"]) |
|
542 |
if subentry_infos["pdo"] and typeinfos: |
|
543 |
bus_id = '.'.join(map(str, self.ParentWindow.GetBusId())) |
|
544 |
node_id = self.ParentWindow.GetCurrentNodeId() |
|
545 |
size = typeinfos["size"] |
|
546 |
data = wx.TextDataObject(str(("%s%s.%d.%d.%d"%(SizeConversion[size], bus_id, node_id, index, subindex), "location"))) |
|
547 |
dragSource = wx.DropSource(self.SubindexGrid) |
|
548 |
dragSource.SetData(data) |
|
549 |
dragSource.DoDragDrop() |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
237
diff
changeset
|
550 |
event.Skip() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
237
diff
changeset
|
551 |
|
205 | 552 |
def OnAddButtonClick(self, event): |
553 |
if self.Editable: |
|
554 |
self.SubindexGrid.SetGridCursor(0, 0) |
|
555 |
selected = self.IndexChoice.GetStringSelection() |
|
556 |
if selected != "": |
|
580 | 557 |
choice = INDEXCHOICE_OPTIONS_DICT.get(selected, None) |
558 |
if choice is not None: |
|
559 |
if INDEXCHOICE_OPTIONS[choice][1] == 0: |
|
560 |
getattr(self.ParentWindow, INDEXCHOICE_OPTIONS[choice][2])() |
|
561 |
elif INDEXCHOICE_OPTIONS[choice][1] == 1: |
|
562 |
getattr(self.Manager, INDEXCHOICE_OPTIONS[choice][2])() |
|
205 | 563 |
elif selected in [menu for menu, indexes in self.Manager.GetCurrentSpecificMenu()]: |
564 |
self.Manager.AddSpecificEntryToCurrent(selected) |
|
565 |
else: |
|
566 |
index = self.ChoiceIndex[self.IndexChoice.GetSelection()] |
|
567 |
self.Manager.ManageEntriesOfCurrent([index], []) |
|
271 | 568 |
self.ParentWindow.RefreshBufferState() |
205 | 569 |
self.RefreshIndexList() |
570 |
event.Skip() |
|
571 |
||
572 |
def OnPartListBoxClick(self, event): |
|
491 | 573 |
if not self.ParentWindow.IsClosing(): |
574 |
self.SubindexGrid.SetGridCursor(0, 0) |
|
575 |
self.RefreshIndexList() |
|
205 | 576 |
event.Skip() |
577 |
||
578 |
def OnIndexListClick(self, event): |
|
491 | 579 |
if not self.ParentWindow.IsClosing(): |
580 |
self.SubindexGrid.SetGridCursor(0, 0) |
|
581 |
self.RefreshTable() |
|
205 | 582 |
event.Skip() |
583 |
||
584 |
def OnSubindexGridSelectCell(self, event): |
|
491 | 585 |
if not self.ParentWindow.IsClosing(): |
586 |
wx.CallAfter(self.ParentWindow.RefreshStatusBar) |
|
205 | 587 |
event.Skip() |
588 |
||
589 |
#------------------------------------------------------------------------------- |
|
590 |
# Refresh Functions |
|
591 |
#------------------------------------------------------------------------------- |
|
592 |
||
593 |
def RefreshIndexList(self): |
|
594 |
selected = self.IndexList.GetSelection() |
|
595 |
choice = self.IndexChoice.GetStringSelection() |
|
596 |
choiceindex = self.IndexChoice.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
597 |
if selected != wx.NOT_FOUND: |
205 | 598 |
selectedindex = self.ListIndex[selected] |
599 |
self.IndexList.Clear() |
|
600 |
self.IndexChoice.Clear() |
|
601 |
i = self.PartList.GetSelection() |
|
602 |
if i < len(DictionaryOrganisation): |
|
603 |
values = DictionaryOrganisation[i] |
|
604 |
self.ListIndex = [] |
|
605 |
for name, index in self.Manager.GetCurrentValidIndexes(values["minIndex"], values["maxIndex"]): |
|
606 |
self.IndexList.Append("0x%04X %s"%(index, name)) |
|
607 |
self.ListIndex.append(index) |
|
608 |
if self.Editable: |
|
609 |
self.ChoiceIndex = [] |
|
580 | 610 |
choices = INDEXCHOICE_SECTIONS.get(i, None) |
611 |
if choices is not None: |
|
612 |
for c in choices: |
|
613 |
self.IndexChoice.Append(INDEXCHOICE_OPTIONS[c][0]) |
|
614 |
if len(choices) > 1: |
|
615 |
if choiceindex != wx.NOT_FOUND and choice == self.IndexChoice.GetString(choiceindex): |
|
616 |
self.IndexChoice.SetStringSelection(choice) |
|
617 |
else: |
|
618 |
self.IndexChoice.SetSelection(0) |
|
205 | 619 |
else: |
620 |
for name, index in self.Manager.GetCurrentValidChoices(values["minIndex"], values["maxIndex"]): |
|
621 |
if index: |
|
622 |
self.IndexChoice.Append("0x%04X %s"%(index, name)) |
|
623 |
else: |
|
624 |
self.IndexChoice.Append(name) |
|
625 |
self.ChoiceIndex.append(index) |
|
312 | 626 |
if choiceindex != wx.NOT_FOUND and choiceindex < self.IndexChoice.GetCount() and choice == self.IndexChoice.GetString(choiceindex): |
205 | 627 |
self.IndexChoice.SetStringSelection(choice) |
628 |
if self.Editable: |
|
629 |
self.IndexChoice.Enable(self.IndexChoice.GetCount() != 0) |
|
630 |
self.AddButton.Enable(self.IndexChoice.GetCount() != 0) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
631 |
if selected == wx.NOT_FOUND or selected >= len(self.ListIndex) or selectedindex != self.ListIndex[selected]: |
205 | 632 |
self.Table.Empty() |
633 |
self.CallbackCheck.SetValue(False) |
|
634 |
self.CallbackCheck.Disable() |
|
635 |
self.Table.ResetView(self.SubindexGrid) |
|
271 | 636 |
self.ParentWindow.RefreshStatusBar() |
205 | 637 |
else: |
638 |
self.IndexList.SetSelection(selected) |
|
639 |
self.RefreshTable() |
|
640 |
||
641 |
def RefreshTable(self): |
|
642 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
643 |
if selected != wx.NOT_FOUND: |
205 | 644 |
index = self.ListIndex[selected] |
645 |
if index > 0x260 and self.Editable: |
|
646 |
self.CallbackCheck.Enable() |
|
647 |
self.CallbackCheck.SetValue(self.Manager.HasCurrentEntryCallbacks(index)) |
|
648 |
result = self.Manager.GetCurrentEntryValues(index) |
|
649 |
if result != None: |
|
650 |
self.Table.SetCurrentIndex(index) |
|
651 |
data, editors = result |
|
652 |
self.Table.SetData(data) |
|
653 |
self.Table.SetEditors(editors) |
|
654 |
self.Table.ResetView(self.SubindexGrid) |
|
271 | 655 |
self.ParentWindow.RefreshStatusBar() |
205 | 656 |
|
657 |
#------------------------------------------------------------------------------- |
|
658 |
# Editing Table value function |
|
659 |
#------------------------------------------------------------------------------- |
|
660 |
||
327 | 661 |
def OnSubindexGridEditorShown(self, event): |
662 |
row, col = event.GetRow(), event.GetCol() |
|
663 |
if self.Table.GetEditor(row, col) == "dcf": |
|
664 |
wx.CallAfter(self.ShowDCFEntryDialog, row, col) |
|
665 |
event.Veto() |
|
666 |
else: |
|
667 |
event.Skip() |
|
668 |
||
669 |
def ShowDCFEntryDialog(self, row, col): |
|
670 |
if self.Editable: |
|
671 |
selected = self.IndexList.GetSelection() |
|
672 |
if selected != wx.NOT_FOUND: |
|
673 |
index = self.ListIndex[selected] |
|
674 |
if self.Manager.IsCurrentEntry(index): |
|
675 |
dialog = DCFEntryValuesDialog(self) |
|
676 |
dialog.SetValues(self.Table.GetValue(row, col).decode("hex_codec")) |
|
677 |
if dialog.ShowModal() == wx.ID_OK: |
|
678 |
value = dialog.GetValues() |
|
679 |
self.Manager.SetCurrentEntry(index, row, value, "value", "dcf") |
|
680 |
self.ParentWindow.RefreshBufferState() |
|
681 |
wx.CallAfter(self.RefreshTable) |
|
682 |
||
205 | 683 |
def OnSubindexGridCellChange(self, event): |
684 |
if self.Editable: |
|
685 |
index = self.Table.GetCurrentIndex() |
|
686 |
subIndex = event.GetRow() |
|
687 |
col = event.GetCol() |
|
584
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
580
diff
changeset
|
688 |
name = self.Table.GetColLabelValue(col, False) |
e23359f62023
Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents:
580
diff
changeset
|
689 |
value = self.Table.GetValue(subIndex, col, False) |
205 | 690 |
editor = self.Table.GetEditor(subIndex, col) |
691 |
self.Manager.SetCurrentEntry(index, subIndex, value, name, editor) |
|
271 | 692 |
self.ParentWindow.RefreshBufferState() |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
693 |
wx.CallAfter(self.RefreshTable) |
205 | 694 |
event.Skip() |
695 |
||
696 |
def OnCallbackCheck(self, event): |
|
697 |
if self.Editable: |
|
698 |
index = self.Table.GetCurrentIndex() |
|
699 |
self.Manager.SetCurrentEntryCallbacks(index, self.CallbackCheck.GetValue()) |
|
271 | 700 |
self.ParentWindow.RefreshBufferState() |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
701 |
wx.CallAfter(self.RefreshTable) |
205 | 702 |
event.Skip() |
703 |
||
704 |
#------------------------------------------------------------------------------- |
|
705 |
# Contextual Menu functions |
|
706 |
#------------------------------------------------------------------------------- |
|
707 |
||
708 |
def OnIndexListRightUp(self, event): |
|
709 |
if self.Editable: |
|
710 |
if not self.FirstCall: |
|
711 |
self.FirstCall = True |
|
712 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
713 |
if selected != wx.NOT_FOUND: |
205 | 714 |
index = self.ListIndex[selected] |
715 |
if index < 0x260: |
|
716 |
self.IndexListMenu.FindItemByPosition(0).Enable(False) |
|
717 |
self.IndexListMenu.FindItemByPosition(1).Enable(True) |
|
718 |
self.PopupMenu(self.IndexListMenu) |
|
273 | 719 |
elif 0x1000 <= index <= 0x1FFF: |
205 | 720 |
self.IndexListMenu.FindItemByPosition(0).Enable(False) |
721 |
self.IndexListMenu.FindItemByPosition(1).Enable(False) |
|
722 |
self.PopupMenu(self.IndexListMenu) |
|
723 |
elif 0x2000 <= index <= 0x5FFF: |
|
724 |
self.IndexListMenu.FindItemByPosition(0).Enable(True) |
|
725 |
self.IndexListMenu.FindItemByPosition(1).Enable(False) |
|
726 |
self.PopupMenu(self.IndexListMenu) |
|
727 |
elif index >= 0x6000: |
|
728 |
self.IndexListMenu.FindItemByPosition(0).Enable(False) |
|
729 |
self.IndexListMenu.FindItemByPosition(1).Enable(False) |
|
730 |
self.PopupMenu(self.IndexListMenu) |
|
731 |
else: |
|
732 |
self.FirstCall = False |
|
733 |
event.Skip() |
|
734 |
||
735 |
def OnSubindexGridRightClick(self, event): |
|
299 | 736 |
self.SubindexGrid.SetGridCursor(event.GetRow(), event.GetCol()) |
205 | 737 |
if self.Editable: |
738 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
739 |
if selected != wx.NOT_FOUND: |
205 | 740 |
index = self.ListIndex[selected] |
741 |
if self.Manager.IsCurrentEntry(index): |
|
299 | 742 |
showpopup = False |
205 | 743 |
infos = self.Manager.GetEntryInfos(index) |
310 | 744 |
if 0x2000 <= index <= 0x5FFF and infos["struct"] & OD_MultipleSubindexes or infos["struct"] & OD_IdenticalSubindexes: |
299 | 745 |
showpopup = True |
746 |
self.SubindexGridMenu.FindItemByPosition(0).Enable(True) |
|
747 |
self.SubindexGridMenu.FindItemByPosition(1).Enable(True) |
|
748 |
else: |
|
749 |
self.SubindexGridMenu.FindItemByPosition(0).Enable(False) |
|
750 |
self.SubindexGridMenu.FindItemByPosition(1).Enable(False) |
|
622 | 751 |
if self.Table.GetColLabelValue(event.GetCol(), False) == "value": |
299 | 752 |
showpopup = True |
753 |
self.SubindexGridMenu.FindItemByPosition(3).Enable(True) |
|
754 |
else: |
|
755 |
self.SubindexGridMenu.FindItemByPosition(3).Enable(False) |
|
756 |
if showpopup: |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
237
diff
changeset
|
757 |
self.PopupMenu(self.SubindexGridMenu) |
622 | 758 |
elif self.Table.GetColLabelValue(event.GetCol(), False) == "value": |
327 | 759 |
selected = self.IndexList.GetSelection() |
760 |
if selected != wx.NOT_FOUND: |
|
761 |
index = self.ListIndex[selected] |
|
762 |
if self.Manager.IsCurrentEntry(index): |
|
763 |
infos = self.Manager.GetEntryInfos(index) |
|
764 |
if not infos["struct"] & OD_MultipleSubindexes or event.GetRow() > 0: |
|
765 |
self.SubindexGridMenu.FindItemByPosition(0).Enable(False) |
|
766 |
self.SubindexGridMenu.FindItemByPosition(1).Enable(False) |
|
767 |
self.SubindexGridMenu.FindItemByPosition(3).Enable(False) |
|
768 |
self.SubindexGridMenu.FindItemByPosition(4).Enable(True) |
|
769 |
self.PopupMenu(self.SubindexGridMenu) |
|
770 |
event.Skip() |
|
771 |
||
772 |
def OnAddToDCFSubindexMenu(self, event): |
|
773 |
if not self.Editable: |
|
774 |
selected = self.IndexList.GetSelection() |
|
775 |
if selected != wx.NOT_FOUND: |
|
776 |
index = self.ListIndex[selected] |
|
777 |
subindex = self.SubindexGrid.GetGridCursorRow() |
|
778 |
entry_infos = self.Manager.GetEntryInfos(index) |
|
779 |
if not entry_infos["struct"] & OD_MultipleSubindexes or subindex != 0: |
|
780 |
subentry_infos = self.Manager.GetSubentryInfos(index, subindex) |
|
781 |
typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"]) |
|
782 |
if typeinfos: |
|
783 |
node_id = self.ParentWindow.GetCurrentNodeId() |
|
336 | 784 |
value = self.Table.GetValueByName(subindex, "value") |
785 |
if value == "True": |
|
340 | 786 |
value = 1 |
787 |
elif value == "False": |
|
336 | 788 |
value = 0 |
789 |
elif value.isdigit(): |
|
790 |
value = int(value) |
|
791 |
elif value.startswith("0x"): |
|
792 |
value = int(value, 16) |
|
793 |
else: |
|
794 |
value = int(value.encode("hex_codec"), 16) |
|
795 |
self.Manager.AddToMasterDCF(node_id, index, subindex, max(1, typeinfos["size"] / 8), value) |
|
327 | 796 |
self.ParentWindow.OpenMasterDCFDialog(node_id) |
797 |
||
336 | 798 |
def OpenDCFDialog(self, node_id): |
327 | 799 |
self.PartList.SetSelection(7) |
800 |
self.RefreshIndexList() |
|
801 |
self.IndexList.SetSelection(self.ListIndex.index(0x1F22)) |
|
802 |
self.RefreshTable() |
|
803 |
self.SubindexGrid.SetGridCursor(node_id, 3) |
|
804 |
self.ShowDCFEntryDialog(node_id, 3) |
|
205 | 805 |
|
806 |
def OnRenameIndexMenu(self, event): |
|
807 |
if self.Editable: |
|
808 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
809 |
if selected != wx.NOT_FOUND: |
205 | 810 |
index = self.ListIndex[selected] |
811 |
if self.Manager.IsCurrentEntry(index): |
|
812 |
infos = self.Manager.GetEntryInfos(index) |
|
580 | 813 |
dialog = wx.TextEntryDialog(self, _("Give a new name for index 0x%04X")%index, |
814 |
_("Rename an index"), infos["name"], wx.OK|wx.CANCEL) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
815 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 816 |
self.Manager.SetCurrentEntryName(index, dialog.GetValue()) |
271 | 817 |
self.ParentWindow.RefreshBufferState() |
205 | 818 |
self.RefreshIndexList() |
819 |
dialog.Destroy() |
|
608 | 820 |
|
205 | 821 |
def OnModifyIndexMenu(self, event): |
822 |
if self.Editable: |
|
823 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
824 |
if selected != wx.NOT_FOUND: |
205 | 825 |
index = self.ListIndex[selected] |
826 |
if self.Manager.IsCurrentEntry(index) and index < 0x260: |
|
827 |
values, valuetype = self.Manager.GetCustomisedTypeValues(index) |
|
828 |
dialog = UserTypeDialog(self) |
|
829 |
dialog.SetTypeList(self.Manager.GetCustomisableTypes(), values[1]) |
|
830 |
if valuetype == 0: |
|
831 |
dialog.SetValues(min = values[2], max = values[3]) |
|
832 |
elif valuetype == 1: |
|
833 |
dialog.SetValues(length = values[2]) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
834 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 835 |
type, min, max, length = dialog.GetValues() |
836 |
self.Manager.SetCurrentUserType(index, type, min, max, length) |
|
271 | 837 |
self.ParentWindow.RefreshBufferState() |
205 | 838 |
self.RefreshIndexList() |
839 |
||
840 |
def OnDeleteIndexMenu(self, event): |
|
841 |
if self.Editable: |
|
842 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
843 |
if selected != wx.NOT_FOUND: |
205 | 844 |
index = self.ListIndex[selected] |
845 |
if self.Manager.IsCurrentEntry(index): |
|
846 |
self.Manager.ManageEntriesOfCurrent([],[index]) |
|
271 | 847 |
self.ParentWindow.RefreshBufferState() |
205 | 848 |
self.RefreshIndexList() |
608 | 849 |
|
205 | 850 |
def OnAddSubindexMenu(self, event): |
851 |
if self.Editable: |
|
852 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
853 |
if selected != wx.NOT_FOUND: |
205 | 854 |
index = self.ListIndex[selected] |
855 |
if self.Manager.IsCurrentEntry(index): |
|
580 | 856 |
dialog = wx.TextEntryDialog(self, _("Number of subindexes to add:"), |
857 |
_("Add subindexes"), "1", wx.OK|wx.CANCEL) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
858 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 859 |
try: |
860 |
number = int(dialog.GetValue()) |
|
861 |
self.Manager.AddSubentriesToCurrent(index, number) |
|
271 | 862 |
self.ParentWindow.RefreshBufferState() |
205 | 863 |
self.RefreshIndexList() |
864 |
except: |
|
580 | 865 |
message = wx.MessageDialog(self, _("An integer is required!"), _("ERROR"), wx.OK|wx.ICON_ERROR) |
205 | 866 |
message.ShowModal() |
867 |
message.Destroy() |
|
868 |
dialog.Destroy() |
|
608 | 869 |
|
205 | 870 |
def OnDeleteSubindexMenu(self, event): |
871 |
if self.Editable: |
|
872 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
873 |
if selected != wx.NOT_FOUND: |
205 | 874 |
index = self.ListIndex[selected] |
875 |
if self.Manager.IsCurrentEntry(index): |
|
580 | 876 |
dialog = wx.TextEntryDialog(self, _("Number of subindexes to delete:"), |
877 |
_("Delete subindexes"), "1", wx.OK|wx.CANCEL) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
878 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 879 |
try: |
880 |
number = int(dialog.GetValue()) |
|
881 |
self.Manager.RemoveSubentriesFromCurrent(index, number) |
|
271 | 882 |
self.ParentWindow.RefreshBufferState() |
205 | 883 |
self.RefreshIndexList() |
884 |
except: |
|
580 | 885 |
message = wx.MessageDialog(self, _("An integer is required!"), _("ERROR"), wx.OK|wx.ICON_ERROR) |
205 | 886 |
message.ShowModal() |
887 |
message.Destroy() |
|
888 |
dialog.Destroy() |
|
608 | 889 |
|
299 | 890 |
def OnDefaultValueSubindexMenu(self, event): |
891 |
if self.Editable: |
|
892 |
selected = self.IndexList.GetSelection() |
|
893 |
if selected != wx.NOT_FOUND: |
|
894 |
index = self.ListIndex[selected] |
|
895 |
if self.Manager.IsCurrentEntry(index): |
|
896 |
row = self.SubindexGrid.GetGridCursorRow() |
|
897 |
self.Manager.SetCurrentEntryToDefault(index, row) |
|
898 |
self.ParentWindow.RefreshBufferState() |
|
899 |
self.RefreshIndexList() |
|
608 | 900 |