author | Edouard Tisserant |
Tue, 19 Jun 2012 10:29:03 +0200 | |
changeset 746 | 3e16d9a121b8 |
parent 741 | b1a73ddc514b |
child 747 | 4725d8f909ff |
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())) |
741
b1a73ddc514b
Adding informations in data send when drag'n dropping locations
Laurent Bessard
parents:
622
diff
changeset
|
528 |
var_name = "master_%04x_%02x" % (index, subindex) |
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
529 |
size = typeinfos["size"] |
741
b1a73ddc514b
Adding informations in data send when drag'n dropping locations
Laurent Bessard
parents:
622
diff
changeset
|
530 |
data = wx.TextDataObject(str(("%s%s.%d.%d"%(SizeConversion[size], bus_id, index, subindex), "location", None, var_name, ""))) |
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
531 |
dragSource = wx.DropSource(self.SubindexGrid) |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
532 |
dragSource.SetData(data) |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
533 |
dragSource.DoDragDrop() |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
453
diff
changeset
|
534 |
elif col == 0: |
324 | 535 |
selected = self.IndexList.GetSelection() |
536 |
if selected != wx.NOT_FOUND: |
|
537 |
index = self.ListIndex[selected] |
|
538 |
subindex = event.GetRow() |
|
539 |
entry_infos = self.Manager.GetEntryInfos(index) |
|
540 |
if not entry_infos["struct"] & OD_MultipleSubindexes or subindex != 0: |
|
541 |
subentry_infos = self.Manager.GetSubentryInfos(index, subindex) |
|
542 |
typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"]) |
|
543 |
if subentry_infos["pdo"] and typeinfos: |
|
544 |
bus_id = '.'.join(map(str, self.ParentWindow.GetBusId())) |
|
545 |
node_id = self.ParentWindow.GetCurrentNodeId() |
|
741
b1a73ddc514b
Adding informations in data send when drag'n dropping locations
Laurent Bessard
parents:
622
diff
changeset
|
546 |
var_name = "%s_%04x_%02x" % (self.Manager.GetSlaveName(node_id), index, subindex) |
324 | 547 |
size = typeinfos["size"] |
741
b1a73ddc514b
Adding informations in data send when drag'n dropping locations
Laurent Bessard
parents:
622
diff
changeset
|
548 |
data = wx.TextDataObject(str(("%s%s.%d.%d.%d"%(SizeConversion[size], bus_id, node_id, index, subindex), "location", None, var_name, ""))) |
324 | 549 |
dragSource = wx.DropSource(self.SubindexGrid) |
550 |
dragSource.SetData(data) |
|
551 |
dragSource.DoDragDrop() |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
237
diff
changeset
|
552 |
event.Skip() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
237
diff
changeset
|
553 |
|
205 | 554 |
def OnAddButtonClick(self, event): |
555 |
if self.Editable: |
|
556 |
self.SubindexGrid.SetGridCursor(0, 0) |
|
557 |
selected = self.IndexChoice.GetStringSelection() |
|
558 |
if selected != "": |
|
580 | 559 |
choice = INDEXCHOICE_OPTIONS_DICT.get(selected, None) |
560 |
if choice is not None: |
|
561 |
if INDEXCHOICE_OPTIONS[choice][1] == 0: |
|
562 |
getattr(self.ParentWindow, INDEXCHOICE_OPTIONS[choice][2])() |
|
563 |
elif INDEXCHOICE_OPTIONS[choice][1] == 1: |
|
564 |
getattr(self.Manager, INDEXCHOICE_OPTIONS[choice][2])() |
|
205 | 565 |
elif selected in [menu for menu, indexes in self.Manager.GetCurrentSpecificMenu()]: |
566 |
self.Manager.AddSpecificEntryToCurrent(selected) |
|
567 |
else: |
|
568 |
index = self.ChoiceIndex[self.IndexChoice.GetSelection()] |
|
569 |
self.Manager.ManageEntriesOfCurrent([index], []) |
|
271 | 570 |
self.ParentWindow.RefreshBufferState() |
205 | 571 |
self.RefreshIndexList() |
572 |
event.Skip() |
|
573 |
||
574 |
def OnPartListBoxClick(self, event): |
|
491 | 575 |
if not self.ParentWindow.IsClosing(): |
576 |
self.SubindexGrid.SetGridCursor(0, 0) |
|
577 |
self.RefreshIndexList() |
|
205 | 578 |
event.Skip() |
579 |
||
580 |
def OnIndexListClick(self, event): |
|
491 | 581 |
if not self.ParentWindow.IsClosing(): |
582 |
self.SubindexGrid.SetGridCursor(0, 0) |
|
583 |
self.RefreshTable() |
|
205 | 584 |
event.Skip() |
585 |
||
586 |
def OnSubindexGridSelectCell(self, event): |
|
491 | 587 |
if not self.ParentWindow.IsClosing(): |
588 |
wx.CallAfter(self.ParentWindow.RefreshStatusBar) |
|
205 | 589 |
event.Skip() |
590 |
||
591 |
#------------------------------------------------------------------------------- |
|
592 |
# Refresh Functions |
|
593 |
#------------------------------------------------------------------------------- |
|
594 |
||
595 |
def RefreshIndexList(self): |
|
596 |
selected = self.IndexList.GetSelection() |
|
597 |
choice = self.IndexChoice.GetStringSelection() |
|
598 |
choiceindex = self.IndexChoice.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
599 |
if selected != wx.NOT_FOUND: |
205 | 600 |
selectedindex = self.ListIndex[selected] |
601 |
self.IndexList.Clear() |
|
602 |
self.IndexChoice.Clear() |
|
603 |
i = self.PartList.GetSelection() |
|
604 |
if i < len(DictionaryOrganisation): |
|
605 |
values = DictionaryOrganisation[i] |
|
606 |
self.ListIndex = [] |
|
607 |
for name, index in self.Manager.GetCurrentValidIndexes(values["minIndex"], values["maxIndex"]): |
|
608 |
self.IndexList.Append("0x%04X %s"%(index, name)) |
|
609 |
self.ListIndex.append(index) |
|
610 |
if self.Editable: |
|
611 |
self.ChoiceIndex = [] |
|
580 | 612 |
choices = INDEXCHOICE_SECTIONS.get(i, None) |
613 |
if choices is not None: |
|
614 |
for c in choices: |
|
615 |
self.IndexChoice.Append(INDEXCHOICE_OPTIONS[c][0]) |
|
616 |
if len(choices) > 1: |
|
617 |
if choiceindex != wx.NOT_FOUND and choice == self.IndexChoice.GetString(choiceindex): |
|
618 |
self.IndexChoice.SetStringSelection(choice) |
|
619 |
else: |
|
620 |
self.IndexChoice.SetSelection(0) |
|
205 | 621 |
else: |
622 |
for name, index in self.Manager.GetCurrentValidChoices(values["minIndex"], values["maxIndex"]): |
|
623 |
if index: |
|
624 |
self.IndexChoice.Append("0x%04X %s"%(index, name)) |
|
625 |
else: |
|
626 |
self.IndexChoice.Append(name) |
|
627 |
self.ChoiceIndex.append(index) |
|
312 | 628 |
if choiceindex != wx.NOT_FOUND and choiceindex < self.IndexChoice.GetCount() and choice == self.IndexChoice.GetString(choiceindex): |
205 | 629 |
self.IndexChoice.SetStringSelection(choice) |
630 |
if self.Editable: |
|
631 |
self.IndexChoice.Enable(self.IndexChoice.GetCount() != 0) |
|
632 |
self.AddButton.Enable(self.IndexChoice.GetCount() != 0) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
633 |
if selected == wx.NOT_FOUND or selected >= len(self.ListIndex) or selectedindex != self.ListIndex[selected]: |
205 | 634 |
self.Table.Empty() |
635 |
self.CallbackCheck.SetValue(False) |
|
636 |
self.CallbackCheck.Disable() |
|
637 |
self.Table.ResetView(self.SubindexGrid) |
|
271 | 638 |
self.ParentWindow.RefreshStatusBar() |
205 | 639 |
else: |
640 |
self.IndexList.SetSelection(selected) |
|
641 |
self.RefreshTable() |
|
642 |
||
643 |
def RefreshTable(self): |
|
644 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
645 |
if selected != wx.NOT_FOUND: |
205 | 646 |
index = self.ListIndex[selected] |
647 |
if index > 0x260 and self.Editable: |
|
648 |
self.CallbackCheck.Enable() |
|
649 |
self.CallbackCheck.SetValue(self.Manager.HasCurrentEntryCallbacks(index)) |
|
650 |
result = self.Manager.GetCurrentEntryValues(index) |
|
651 |
if result != None: |
|
652 |
self.Table.SetCurrentIndex(index) |
|
653 |
data, editors = result |
|
654 |
self.Table.SetData(data) |
|
655 |
self.Table.SetEditors(editors) |
|
656 |
self.Table.ResetView(self.SubindexGrid) |
|
271 | 657 |
self.ParentWindow.RefreshStatusBar() |
205 | 658 |
|
659 |
#------------------------------------------------------------------------------- |
|
660 |
# Editing Table value function |
|
661 |
#------------------------------------------------------------------------------- |
|
662 |
||
327 | 663 |
def OnSubindexGridEditorShown(self, event): |
664 |
row, col = event.GetRow(), event.GetCol() |
|
665 |
if self.Table.GetEditor(row, col) == "dcf": |
|
666 |
wx.CallAfter(self.ShowDCFEntryDialog, row, col) |
|
667 |
event.Veto() |
|
668 |
else: |
|
669 |
event.Skip() |
|
670 |
||
671 |
def ShowDCFEntryDialog(self, row, col): |
|
672 |
if self.Editable: |
|
673 |
selected = self.IndexList.GetSelection() |
|
674 |
if selected != wx.NOT_FOUND: |
|
675 |
index = self.ListIndex[selected] |
|
676 |
if self.Manager.IsCurrentEntry(index): |
|
677 |
dialog = DCFEntryValuesDialog(self) |
|
678 |
dialog.SetValues(self.Table.GetValue(row, col).decode("hex_codec")) |
|
679 |
if dialog.ShowModal() == wx.ID_OK: |
|
680 |
value = dialog.GetValues() |
|
681 |
self.Manager.SetCurrentEntry(index, row, value, "value", "dcf") |
|
682 |
self.ParentWindow.RefreshBufferState() |
|
683 |
wx.CallAfter(self.RefreshTable) |
|
684 |
||
205 | 685 |
def OnSubindexGridCellChange(self, event): |
686 |
if self.Editable: |
|
687 |
index = self.Table.GetCurrentIndex() |
|
688 |
subIndex = event.GetRow() |
|
689 |
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
|
690 |
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
|
691 |
value = self.Table.GetValue(subIndex, col, False) |
205 | 692 |
editor = self.Table.GetEditor(subIndex, col) |
693 |
self.Manager.SetCurrentEntry(index, subIndex, value, name, editor) |
|
271 | 694 |
self.ParentWindow.RefreshBufferState() |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
695 |
wx.CallAfter(self.RefreshTable) |
205 | 696 |
event.Skip() |
697 |
||
698 |
def OnCallbackCheck(self, event): |
|
699 |
if self.Editable: |
|
700 |
index = self.Table.GetCurrentIndex() |
|
701 |
self.Manager.SetCurrentEntryCallbacks(index, self.CallbackCheck.GetValue()) |
|
271 | 702 |
self.ParentWindow.RefreshBufferState() |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
703 |
wx.CallAfter(self.RefreshTable) |
205 | 704 |
event.Skip() |
705 |
||
706 |
#------------------------------------------------------------------------------- |
|
707 |
# Contextual Menu functions |
|
708 |
#------------------------------------------------------------------------------- |
|
709 |
||
710 |
def OnIndexListRightUp(self, event): |
|
711 |
if self.Editable: |
|
712 |
if not self.FirstCall: |
|
713 |
self.FirstCall = True |
|
714 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
715 |
if selected != wx.NOT_FOUND: |
205 | 716 |
index = self.ListIndex[selected] |
717 |
if index < 0x260: |
|
718 |
self.IndexListMenu.FindItemByPosition(0).Enable(False) |
|
719 |
self.IndexListMenu.FindItemByPosition(1).Enable(True) |
|
720 |
self.PopupMenu(self.IndexListMenu) |
|
273 | 721 |
elif 0x1000 <= index <= 0x1FFF: |
205 | 722 |
self.IndexListMenu.FindItemByPosition(0).Enable(False) |
723 |
self.IndexListMenu.FindItemByPosition(1).Enable(False) |
|
724 |
self.PopupMenu(self.IndexListMenu) |
|
725 |
elif 0x2000 <= index <= 0x5FFF: |
|
726 |
self.IndexListMenu.FindItemByPosition(0).Enable(True) |
|
727 |
self.IndexListMenu.FindItemByPosition(1).Enable(False) |
|
728 |
self.PopupMenu(self.IndexListMenu) |
|
729 |
elif index >= 0x6000: |
|
730 |
self.IndexListMenu.FindItemByPosition(0).Enable(False) |
|
731 |
self.IndexListMenu.FindItemByPosition(1).Enable(False) |
|
732 |
self.PopupMenu(self.IndexListMenu) |
|
733 |
else: |
|
734 |
self.FirstCall = False |
|
735 |
event.Skip() |
|
736 |
||
737 |
def OnSubindexGridRightClick(self, event): |
|
299 | 738 |
self.SubindexGrid.SetGridCursor(event.GetRow(), event.GetCol()) |
205 | 739 |
if self.Editable: |
740 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
741 |
if selected != wx.NOT_FOUND: |
205 | 742 |
index = self.ListIndex[selected] |
743 |
if self.Manager.IsCurrentEntry(index): |
|
299 | 744 |
showpopup = False |
205 | 745 |
infos = self.Manager.GetEntryInfos(index) |
310 | 746 |
if 0x2000 <= index <= 0x5FFF and infos["struct"] & OD_MultipleSubindexes or infos["struct"] & OD_IdenticalSubindexes: |
299 | 747 |
showpopup = True |
748 |
self.SubindexGridMenu.FindItemByPosition(0).Enable(True) |
|
749 |
self.SubindexGridMenu.FindItemByPosition(1).Enable(True) |
|
750 |
else: |
|
751 |
self.SubindexGridMenu.FindItemByPosition(0).Enable(False) |
|
752 |
self.SubindexGridMenu.FindItemByPosition(1).Enable(False) |
|
622 | 753 |
if self.Table.GetColLabelValue(event.GetCol(), False) == "value": |
299 | 754 |
showpopup = True |
755 |
self.SubindexGridMenu.FindItemByPosition(3).Enable(True) |
|
756 |
else: |
|
757 |
self.SubindexGridMenu.FindItemByPosition(3).Enable(False) |
|
758 |
if showpopup: |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
237
diff
changeset
|
759 |
self.PopupMenu(self.SubindexGridMenu) |
622 | 760 |
elif self.Table.GetColLabelValue(event.GetCol(), False) == "value": |
327 | 761 |
selected = self.IndexList.GetSelection() |
762 |
if selected != wx.NOT_FOUND: |
|
763 |
index = self.ListIndex[selected] |
|
764 |
if self.Manager.IsCurrentEntry(index): |
|
765 |
infos = self.Manager.GetEntryInfos(index) |
|
766 |
if not infos["struct"] & OD_MultipleSubindexes or event.GetRow() > 0: |
|
767 |
self.SubindexGridMenu.FindItemByPosition(0).Enable(False) |
|
768 |
self.SubindexGridMenu.FindItemByPosition(1).Enable(False) |
|
769 |
self.SubindexGridMenu.FindItemByPosition(3).Enable(False) |
|
770 |
self.SubindexGridMenu.FindItemByPosition(4).Enable(True) |
|
771 |
self.PopupMenu(self.SubindexGridMenu) |
|
772 |
event.Skip() |
|
773 |
||
774 |
def OnAddToDCFSubindexMenu(self, event): |
|
775 |
if not self.Editable: |
|
776 |
selected = self.IndexList.GetSelection() |
|
777 |
if selected != wx.NOT_FOUND: |
|
778 |
index = self.ListIndex[selected] |
|
779 |
subindex = self.SubindexGrid.GetGridCursorRow() |
|
780 |
entry_infos = self.Manager.GetEntryInfos(index) |
|
781 |
if not entry_infos["struct"] & OD_MultipleSubindexes or subindex != 0: |
|
782 |
subentry_infos = self.Manager.GetSubentryInfos(index, subindex) |
|
783 |
typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"]) |
|
784 |
if typeinfos: |
|
785 |
node_id = self.ParentWindow.GetCurrentNodeId() |
|
336 | 786 |
value = self.Table.GetValueByName(subindex, "value") |
787 |
if value == "True": |
|
340 | 788 |
value = 1 |
789 |
elif value == "False": |
|
336 | 790 |
value = 0 |
791 |
elif value.isdigit(): |
|
792 |
value = int(value) |
|
793 |
elif value.startswith("0x"): |
|
794 |
value = int(value, 16) |
|
795 |
else: |
|
796 |
value = int(value.encode("hex_codec"), 16) |
|
797 |
self.Manager.AddToMasterDCF(node_id, index, subindex, max(1, typeinfos["size"] / 8), value) |
|
327 | 798 |
self.ParentWindow.OpenMasterDCFDialog(node_id) |
799 |
||
336 | 800 |
def OpenDCFDialog(self, node_id): |
327 | 801 |
self.PartList.SetSelection(7) |
802 |
self.RefreshIndexList() |
|
803 |
self.IndexList.SetSelection(self.ListIndex.index(0x1F22)) |
|
804 |
self.RefreshTable() |
|
805 |
self.SubindexGrid.SetGridCursor(node_id, 3) |
|
806 |
self.ShowDCFEntryDialog(node_id, 3) |
|
205 | 807 |
|
808 |
def OnRenameIndexMenu(self, event): |
|
809 |
if self.Editable: |
|
810 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
811 |
if selected != wx.NOT_FOUND: |
205 | 812 |
index = self.ListIndex[selected] |
813 |
if self.Manager.IsCurrentEntry(index): |
|
814 |
infos = self.Manager.GetEntryInfos(index) |
|
580 | 815 |
dialog = wx.TextEntryDialog(self, _("Give a new name for index 0x%04X")%index, |
816 |
_("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
|
817 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 818 |
self.Manager.SetCurrentEntryName(index, dialog.GetValue()) |
271 | 819 |
self.ParentWindow.RefreshBufferState() |
205 | 820 |
self.RefreshIndexList() |
821 |
dialog.Destroy() |
|
608 | 822 |
|
205 | 823 |
def OnModifyIndexMenu(self, event): |
824 |
if self.Editable: |
|
825 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
826 |
if selected != wx.NOT_FOUND: |
205 | 827 |
index = self.ListIndex[selected] |
828 |
if self.Manager.IsCurrentEntry(index) and index < 0x260: |
|
829 |
values, valuetype = self.Manager.GetCustomisedTypeValues(index) |
|
830 |
dialog = UserTypeDialog(self) |
|
831 |
dialog.SetTypeList(self.Manager.GetCustomisableTypes(), values[1]) |
|
832 |
if valuetype == 0: |
|
833 |
dialog.SetValues(min = values[2], max = values[3]) |
|
834 |
elif valuetype == 1: |
|
835 |
dialog.SetValues(length = values[2]) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
836 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 837 |
type, min, max, length = dialog.GetValues() |
838 |
self.Manager.SetCurrentUserType(index, type, min, max, length) |
|
271 | 839 |
self.ParentWindow.RefreshBufferState() |
205 | 840 |
self.RefreshIndexList() |
841 |
||
842 |
def OnDeleteIndexMenu(self, event): |
|
843 |
if self.Editable: |
|
844 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
845 |
if selected != wx.NOT_FOUND: |
205 | 846 |
index = self.ListIndex[selected] |
847 |
if self.Manager.IsCurrentEntry(index): |
|
848 |
self.Manager.ManageEntriesOfCurrent([],[index]) |
|
271 | 849 |
self.ParentWindow.RefreshBufferState() |
205 | 850 |
self.RefreshIndexList() |
608 | 851 |
|
205 | 852 |
def OnAddSubindexMenu(self, event): |
853 |
if self.Editable: |
|
854 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
855 |
if selected != wx.NOT_FOUND: |
205 | 856 |
index = self.ListIndex[selected] |
857 |
if self.Manager.IsCurrentEntry(index): |
|
580 | 858 |
dialog = wx.TextEntryDialog(self, _("Number of subindexes to add:"), |
859 |
_("Add subindexes"), "1", wx.OK|wx.CANCEL) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
860 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 861 |
try: |
862 |
number = int(dialog.GetValue()) |
|
863 |
self.Manager.AddSubentriesToCurrent(index, number) |
|
271 | 864 |
self.ParentWindow.RefreshBufferState() |
205 | 865 |
self.RefreshIndexList() |
866 |
except: |
|
580 | 867 |
message = wx.MessageDialog(self, _("An integer is required!"), _("ERROR"), wx.OK|wx.ICON_ERROR) |
205 | 868 |
message.ShowModal() |
869 |
message.Destroy() |
|
870 |
dialog.Destroy() |
|
608 | 871 |
|
205 | 872 |
def OnDeleteSubindexMenu(self, event): |
873 |
if self.Editable: |
|
874 |
selected = self.IndexList.GetSelection() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
875 |
if selected != wx.NOT_FOUND: |
205 | 876 |
index = self.ListIndex[selected] |
877 |
if self.Manager.IsCurrentEntry(index): |
|
580 | 878 |
dialog = wx.TextEntryDialog(self, _("Number of subindexes to delete:"), |
879 |
_("Delete subindexes"), "1", wx.OK|wx.CANCEL) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
880 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 881 |
try: |
882 |
number = int(dialog.GetValue()) |
|
883 |
self.Manager.RemoveSubentriesFromCurrent(index, number) |
|
271 | 884 |
self.ParentWindow.RefreshBufferState() |
205 | 885 |
self.RefreshIndexList() |
886 |
except: |
|
580 | 887 |
message = wx.MessageDialog(self, _("An integer is required!"), _("ERROR"), wx.OK|wx.ICON_ERROR) |
205 | 888 |
message.ShowModal() |
889 |
message.Destroy() |
|
890 |
dialog.Destroy() |
|
608 | 891 |
|
299 | 892 |
def OnDefaultValueSubindexMenu(self, event): |
893 |
if self.Editable: |
|
894 |
selected = self.IndexList.GetSelection() |
|
895 |
if selected != wx.NOT_FOUND: |
|
896 |
index = self.ListIndex[selected] |
|
897 |
if self.Manager.IsCurrentEntry(index): |
|
898 |
row = self.SubindexGrid.GetGridCursorRow() |
|
899 |
self.Manager.SetCurrentEntryToDefault(index, row) |
|
900 |
self.ParentWindow.RefreshBufferState() |
|
901 |
self.RefreshIndexList() |
|
608 | 902 |