author | etisserant |
Tue, 17 Jul 2007 18:20:50 +0200 | |
changeset 241 | 4ecc2f3690f4 |
parent 237 | 5dcfc996e563 |
child 242 | 4864f7f01e1d |
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 |
from wxPython.wx import * |
|
25 |
from wxPython.grid import * |
|
26 |
import wx |
|
27 |
import wx.grid |
|
28 |
||
29 |
from types import * |
|
30 |
||
206 | 31 |
from node import OD_Subindex, OD_MultipleSubindexes, OD_IdenticalSubindexes, OD_IdenticalIndexes |
205 | 32 |
|
33 |
ColSizes = [75, 250, 150, 125, 100, 60, 250] |
|
34 |
ColAlignements = [wxALIGN_CENTER, wxALIGN_LEFT, wxALIGN_CENTER, wxALIGN_RIGHT, wxALIGN_CENTER, wxALIGN_CENTER, wxALIGN_LEFT] |
|
35 |
AccessList = "Read Only,Write Only,Read/Write" |
|
36 |
RAccessList = "Read Only,Read/Write" |
|
37 |
BoolList = "True,False" |
|
38 |
OptionList = "Yes,No" |
|
39 |
||
40 |
DictionaryOrganisation = [ |
|
41 |
{"minIndex" : 0x0001, "maxIndex" : 0x0FFF, "name" : "Data Type Definitions"}, |
|
42 |
{"minIndex" : 0x1000, "maxIndex" : 0x1029, "name" : "Communication Parameters"}, |
|
43 |
{"minIndex" : 0x1200, "maxIndex" : 0x12FF, "name" : "SDO Parameters"}, |
|
44 |
{"minIndex" : 0x1400, "maxIndex" : 0x15FF, "name" : "Receive PDO Parameters"}, |
|
45 |
{"minIndex" : 0x1600, "maxIndex" : 0x17FF, "name" : "Receive PDO Mapping"}, |
|
46 |
{"minIndex" : 0x1800, "maxIndex" : 0x19FF, "name" : "Transmit PDO Parameters"}, |
|
47 |
{"minIndex" : 0x1A00, "maxIndex" : 0x1BFF, "name" : "Transmit PDO Mapping"}, |
|
48 |
{"minIndex" : 0x1C00, "maxIndex" : 0x1FFF, "name" : "Other Communication Parameters"}, |
|
49 |
{"minIndex" : 0x2000, "maxIndex" : 0x5FFF, "name" : "Manufacturer Specific"}, |
|
50 |
{"minIndex" : 0x6000, "maxIndex" : 0x9FFF, "name" : "Standardized Device Profile"}, |
|
51 |
{"minIndex" : 0xA000, "maxIndex" : 0xBFFF, "name" : "Standardized Interface Profile"}] |
|
52 |
||
53 |
class SubindexTable(wxPyGridTableBase): |
|
54 |
||
55 |
""" |
|
56 |
A custom wxGrid Table using user supplied data |
|
57 |
""" |
|
58 |
def __init__(self, parent, data, editors, colnames): |
|
59 |
# The base class must be initialized *first* |
|
60 |
wxPyGridTableBase.__init__(self) |
|
61 |
self.data = data |
|
62 |
self.editors = editors |
|
63 |
self.CurrentIndex = 0 |
|
64 |
self.colnames = colnames |
|
65 |
self.Parent = parent |
|
66 |
self.Editable = True |
|
67 |
# XXX |
|
68 |
# we need to store the row length and collength to |
|
69 |
# see if the table has changed size |
|
70 |
self._rows = self.GetNumberRows() |
|
71 |
self._cols = self.GetNumberCols() |
|
72 |
||
73 |
def Disable(self): |
|
74 |
self.Editable = False |
|
75 |
||
76 |
def Enable(self): |
|
77 |
self.Editable = True |
|
78 |
||
79 |
def GetNumberCols(self): |
|
80 |
return len(self.colnames) |
|
81 |
||
82 |
def GetNumberRows(self): |
|
83 |
return len(self.data) |
|
84 |
||
85 |
def GetColLabelValue(self, col): |
|
86 |
if col < len(self.colnames): |
|
87 |
return self.colnames[col] |
|
88 |
||
89 |
def GetRowLabelValues(self, row): |
|
90 |
return row |
|
91 |
||
92 |
def GetValue(self, row, col): |
|
93 |
if row < self.GetNumberRows(): |
|
94 |
value = self.data[row].get(self.GetColLabelValue(col), "") |
|
95 |
if (type(value) == UnicodeType): |
|
96 |
return value |
|
97 |
else: |
|
98 |
return str(value) |
|
99 |
||
100 |
def GetEditor(self, row, col): |
|
101 |
if row < self.GetNumberRows(): |
|
102 |
return self.editors[row].get(self.GetColLabelValue(col), "") |
|
103 |
||
104 |
def GetValueByName(self, row, colname): |
|
105 |
return self.data[row].get(colname) |
|
106 |
||
107 |
def SetValue(self, row, col, value): |
|
108 |
if col < len(self.colnames): |
|
109 |
self.data[row][self.GetColLabelValue(col)] = value |
|
110 |
||
111 |
def ResetView(self, grid): |
|
112 |
""" |
|
113 |
(wxGrid) -> Reset the grid view. Call this to |
|
114 |
update the grid if rows and columns have been added or deleted |
|
115 |
""" |
|
116 |
grid.BeginBatch() |
|
117 |
for current, new, delmsg, addmsg in [ |
|
118 |
(self._rows, self.GetNumberRows(), wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_NOTIFY_ROWS_APPENDED), |
|
119 |
(self._cols, self.GetNumberCols(), wxGRIDTABLE_NOTIFY_COLS_DELETED, wxGRIDTABLE_NOTIFY_COLS_APPENDED), |
|
120 |
]: |
|
121 |
if new < current: |
|
122 |
msg = wxGridTableMessage(self,delmsg,new,current-new) |
|
123 |
grid.ProcessTableMessage(msg) |
|
124 |
elif new > current: |
|
125 |
msg = wxGridTableMessage(self,addmsg,new-current) |
|
126 |
grid.ProcessTableMessage(msg) |
|
127 |
self.UpdateValues(grid) |
|
128 |
grid.EndBatch() |
|
129 |
||
130 |
self._rows = self.GetNumberRows() |
|
131 |
self._cols = self.GetNumberCols() |
|
132 |
# update the column rendering scheme |
|
133 |
self._updateColAttrs(grid) |
|
134 |
||
135 |
# update the scrollbars and the displayed part of the grid |
|
136 |
grid.AdjustScrollbars() |
|
137 |
grid.ForceRefresh() |
|
138 |
||
139 |
||
140 |
def UpdateValues(self, grid): |
|
141 |
"""Update all displayed values""" |
|
142 |
# This sends an event to the grid table to update all of the values |
|
143 |
msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES) |
|
144 |
grid.ProcessTableMessage(msg) |
|
145 |
||
146 |
def _updateColAttrs(self, grid): |
|
147 |
""" |
|
148 |
wxGrid -> update the column attributes to add the |
|
149 |
appropriate renderer given the column name. |
|
150 |
||
151 |
Otherwise default to the default renderer. |
|
152 |
""" |
|
153 |
||
154 |
for col in range(self.GetNumberCols()): |
|
155 |
attr = wxGridCellAttr() |
|
156 |
attr.SetAlignment(ColAlignements[col], wxALIGN_CENTRE) |
|
157 |
grid.SetColAttr(col, attr) |
|
158 |
grid.SetColSize(col, ColSizes[col]) |
|
159 |
||
160 |
typelist = None |
|
161 |
maplist = None |
|
162 |
for row in range(self.GetNumberRows()): |
|
163 |
editors = self.editors[row] |
|
164 |
for col in range(self.GetNumberCols()): |
|
165 |
editor = None |
|
166 |
renderer = None |
|
167 |
||
168 |
colname = self.GetColLabelValue(col) |
|
169 |
editortype = editors[colname] |
|
170 |
if editortype and self.Editable: |
|
171 |
grid.SetReadOnly(row, col, False) |
|
172 |
if editortype == "string": |
|
173 |
editor = wxGridCellTextEditor() |
|
174 |
renderer = wxGridCellStringRenderer() |
|
175 |
if colname == "value" and "length" in editors: |
|
176 |
editor.SetParameters(editors["length"]) |
|
177 |
elif editortype == "number": |
|
178 |
editor = wxGridCellNumberEditor() |
|
179 |
renderer = wxGridCellNumberRenderer() |
|
180 |
if colname == "value" and "min" in editors and "max" in editors: |
|
181 |
editor.SetParameters("%s,%s"%(editors["min"],editors["max"])) |
|
182 |
elif editortype == "real": |
|
183 |
editor = wxGridCellFloatEditor() |
|
184 |
renderer = wxGridCellFloatRenderer() |
|
185 |
if colname == "value" and "min" in editors and "max" in editors: |
|
186 |
editor.SetParameters("%s,%s"%(editors["min"],editors["max"])) |
|
187 |
elif editortype == "bool": |
|
188 |
editor = wxGridCellChoiceEditor() |
|
189 |
editor.SetParameters(BoolList) |
|
190 |
elif editortype == "access": |
|
191 |
editor = wxGridCellChoiceEditor() |
|
192 |
editor.SetParameters(AccessList) |
|
193 |
elif editortype == "raccess": |
|
194 |
editor = wxGridCellChoiceEditor() |
|
195 |
editor.SetParameters(RAccessList) |
|
196 |
elif editortype == "option": |
|
197 |
editor = wxGridCellChoiceEditor() |
|
198 |
editor.SetParameters(OptionList) |
|
199 |
elif editortype == "type": |
|
200 |
editor = wxGridCellChoiceEditor() |
|
201 |
if typelist == None: |
|
202 |
typelist = self.Parent.Manager.GetCurrentTypeList() |
|
203 |
editor.SetParameters(typelist) |
|
204 |
elif editortype == "map": |
|
205 |
editor = wxGridCellChoiceEditor() |
|
206 |
if maplist == None: |
|
207 |
maplist = self.Parent.Manager.GetCurrentMapList() |
|
208 |
editor.SetParameters(maplist) |
|
209 |
elif editortype == "time": |
|
210 |
editor = wxGridCellTextEditor() |
|
211 |
renderer = wxGridCellStringRenderer() |
|
212 |
elif editortype == "domain": |
|
213 |
editor = wxGridCellTextEditor() |
|
214 |
renderer = wxGridCellStringRenderer() |
|
215 |
else: |
|
216 |
grid.SetReadOnly(row, col, True) |
|
217 |
||
218 |
grid.SetCellEditor(row, col, editor) |
|
219 |
grid.SetCellRenderer(row, col, renderer) |
|
220 |
||
221 |
grid.SetCellBackgroundColour(row, col, wxWHITE) |
|
222 |
||
223 |
def SetData(self, data): |
|
224 |
self.data = data |
|
225 |
||
226 |
def SetEditors(self, editors): |
|
227 |
self.editors = editors |
|
228 |
||
229 |
def GetCurrentIndex(self): |
|
230 |
return self.CurrentIndex |
|
231 |
||
232 |
def SetCurrentIndex(self, index): |
|
233 |
self.CurrentIndex = index |
|
234 |
||
235 |
def AppendRow(self, row_content): |
|
236 |
self.data.append(row_content) |
|
237 |
||
238 |
def Empty(self): |
|
239 |
self.data = [] |
|
240 |
self.editors = [] |
|
241 |
||
242 |
[wxID_EDITINGPANEL, wxID_EDITINGPANELADDBUTTON, wxID_EDITINGPANELINDEXCHOICE, |
|
243 |
wxID_EDITINGPANELINDEXLIST, wxID_EDITINGPANELINDEXLISTPANEL, wxID_EDITINGPANELPARTLIST, |
|
244 |
wxID_EDITINGPANELSECONDSPLITTER, wxID_EDITINGPANELSUBINDEXGRID, |
|
245 |
wxID_EDITINGPANELSUBINDEXGRIDPANEL, wxID_EDITINGPANELCALLBACKCHECK, |
|
246 |
] = [wx.NewId() for _init_ctrls in range(10)] |
|
247 |
||
248 |
[wxID_EDITINGPANELINDEXLISTMENUITEMS0, wxID_EDITINGPANELINDEXLISTMENUITEMS1, |
|
249 |
wxID_EDITINGPANELINDEXLISTMENUITEMS2, |
|
250 |
] = [wx.NewId() for _init_coll_IndexListMenu_Items in range(3)] |
|
251 |
||
237
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
252 |
[wxID_EDITINGPANELMENU1ITEMS0, wxID_EDITINGPANELMENU1ITEMS1, wxID_EDITINGPANELMENU1ITEMS2, |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
253 |
] = [wx.NewId() for _init_coll_SubindexGridMenu_Items in range(3)] |
205 | 254 |
|
255 |
class EditingPanel(wx.SplitterWindow): |
|
256 |
def _init_coll_AddToListSizer_Items(self, parent): |
|
257 |
# generated method, don't edit |
|
258 |
||
259 |
parent.AddWindow(self.AddButton, 0, border=0, flag=0) |
|
260 |
parent.AddWindow(self.IndexChoice, 0, border=0, flag=wxGROW) |
|
261 |
||
262 |
def _init_coll_SubindexGridSizer_Items(self, parent): |
|
263 |
# generated method, don't edit |
|
264 |
||
265 |
parent.AddWindow(self.CallbackCheck, 0, border=0, flag=0) |
|
266 |
parent.AddWindow(self.SubindexGrid, 0, border=0, flag=wxGROW) |
|
267 |
||
268 |
def _init_coll_IndexListSizer_Items(self, parent): |
|
269 |
# generated method, don't edit |
|
270 |
||
271 |
parent.AddWindow(self.IndexList, 0, border=0, flag=wxGROW) |
|
272 |
parent.AddSizer(self.AddToListSizer, 0, border=0, flag=wxGROW) |
|
273 |
||
274 |
def _init_coll_AddToListSizer_Growables(self, parent): |
|
275 |
# generated method, don't edit |
|
276 |
||
277 |
parent.AddGrowableCol(1) |
|
278 |
||
279 |
def _init_coll_SubindexGridSizer_Growables(self, parent): |
|
280 |
# generated method, don't edit |
|
281 |
||
282 |
parent.AddGrowableCol(0) |
|
283 |
parent.AddGrowableRow(1) |
|
284 |
||
285 |
def _init_coll_IndexListSizer_Growables(self, parent): |
|
286 |
# generated method, don't edit |
|
287 |
||
288 |
parent.AddGrowableCol(0) |
|
289 |
parent.AddGrowableRow(0) |
|
290 |
||
291 |
def _init_coll_SubindexGridMenu_Items(self, parent): |
|
292 |
# generated method, don't edit |
|
293 |
||
294 |
parent.Append(help='', id=wxID_EDITINGPANELMENU1ITEMS0, |
|
295 |
kind=wx.ITEM_NORMAL, text='Add') |
|
296 |
parent.Append(help='', id=wxID_EDITINGPANELMENU1ITEMS1, |
|
297 |
kind=wx.ITEM_NORMAL, text='Delete') |
|
237
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
298 |
parent.Append(help='', id=wxID_EDITINGPANELMENU1ITEMS2, |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
299 |
kind=wx.ITEM_NORMAL, text='Default Value') |
205 | 300 |
self.Bind(wx.EVT_MENU, self.OnAddSubindexMenu, |
301 |
id=wxID_EDITINGPANELMENU1ITEMS0) |
|
302 |
self.Bind(wx.EVT_MENU, self.OnDeleteSubindexMenu, |
|
303 |
id=wxID_EDITINGPANELMENU1ITEMS1) |
|
237
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
304 |
self.Bind(wx.EVT_MENU, self.OnDefaultValueSubindexMenu, |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
305 |
id=wxID_EDITINGPANELMENU1ITEMS2) |
205 | 306 |
|
307 |
def _init_coll_IndexListMenu_Items(self, parent): |
|
308 |
# generated method, don't edit |
|
309 |
||
310 |
parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS0, |
|
311 |
kind=wx.ITEM_NORMAL, text='Rename') |
|
312 |
parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS2, |
|
313 |
kind=wx.ITEM_NORMAL, text='Modify') |
|
314 |
parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS1, |
|
315 |
kind=wx.ITEM_NORMAL, text='Delete') |
|
316 |
self.Bind(wx.EVT_MENU, self.OnRenameIndexMenu, |
|
317 |
id=wxID_EDITINGPANELINDEXLISTMENUITEMS0) |
|
318 |
self.Bind(wx.EVT_MENU, self.OnDeleteIndexMenu, |
|
319 |
id=wxID_EDITINGPANELINDEXLISTMENUITEMS1) |
|
320 |
self.Bind(wx.EVT_MENU, self.OnModifyIndexMenu, |
|
321 |
id=wxID_EDITINGPANELINDEXLISTMENUITEMS2) |
|
322 |
||
323 |
def _init_utils(self): |
|
324 |
# generated method, don't edit |
|
325 |
self.IndexListMenu = wx.Menu(title='') |
|
326 |
||
327 |
self.SubindexGridMenu = wx.Menu(title='') |
|
328 |
||
329 |
self._init_coll_IndexListMenu_Items(self.IndexListMenu) |
|
330 |
self._init_coll_SubindexGridMenu_Items(self.SubindexGridMenu) |
|
331 |
||
332 |
def _init_sizers(self): |
|
333 |
# generated method, don't edit |
|
334 |
self.IndexListSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
335 |
||
336 |
self.SubindexGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
337 |
||
338 |
self.AddToListSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0) |
|
339 |
||
340 |
self._init_coll_IndexListSizer_Growables(self.IndexListSizer) |
|
341 |
self._init_coll_IndexListSizer_Items(self.IndexListSizer) |
|
342 |
self._init_coll_SubindexGridSizer_Growables(self.SubindexGridSizer) |
|
343 |
self._init_coll_SubindexGridSizer_Items(self.SubindexGridSizer) |
|
344 |
self._init_coll_AddToListSizer_Growables(self.AddToListSizer) |
|
345 |
self._init_coll_AddToListSizer_Items(self.AddToListSizer) |
|
346 |
||
347 |
self.SubindexGridPanel.SetSizer(self.SubindexGridSizer) |
|
348 |
self.IndexListPanel.SetSizer(self.IndexListSizer) |
|
349 |
||
350 |
def _init_ctrls(self, prnt): |
|
351 |
wx.SplitterWindow.__init__(self, id=wxID_EDITINGPANEL, |
|
352 |
name='MainSplitter', parent=prnt, point=wx.Point(0, 0), |
|
353 |
size=wx.Size(-1, -1), style=wx.SP_3D) |
|
354 |
self._init_utils() |
|
355 |
self.SetNeedUpdating(True) |
|
356 |
self.SetMinimumPaneSize(1) |
|
357 |
||
358 |
self.PartList = wx.ListBox(choices=[], id=wxID_EDITINGPANELPARTLIST, |
|
359 |
name='PartList', parent=self, pos=wx.Point(0, 0), |
|
360 |
size=wx.Size(-1, -1), style=0) |
|
361 |
self.PartList.Bind(wx.EVT_LISTBOX, self.OnPartListBoxClick, |
|
362 |
id=wxID_EDITINGPANELPARTLIST) |
|
363 |
||
364 |
self.SecondSplitter = wx.SplitterWindow(id=wxID_EDITINGPANELSECONDSPLITTER, |
|
365 |
name='SecondSplitter', parent=self, point=wx.Point(0, |
|
366 |
0), size=wx.Size(-1, -1), style=wx.SP_3D) |
|
367 |
self.SecondSplitter.SetMinimumPaneSize(1) |
|
368 |
self.SplitHorizontally(self.PartList, self.SecondSplitter, |
|
369 |
110) |
|
370 |
||
371 |
self.SubindexGridPanel = wx.Panel(id=wxID_EDITINGPANELSUBINDEXGRIDPANEL, |
|
372 |
name='SubindexGridPanel', parent=self.SecondSplitter, pos=wx.Point(0, |
|
373 |
0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) |
|
374 |
||
375 |
self.IndexListPanel = wx.Panel(id=wxID_EDITINGPANELINDEXLISTPANEL, |
|
376 |
name='IndexListPanel', parent=self.SecondSplitter, pos=wx.Point(0, |
|
377 |
0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) |
|
378 |
self.SecondSplitter.SplitVertically(self.IndexListPanel, |
|
379 |
self.SubindexGridPanel, 280) |
|
380 |
||
381 |
self.SubindexGrid = wx.grid.Grid(id=wxID_EDITINGPANELSUBINDEXGRID, |
|
382 |
name='SubindexGrid', parent=self.SubindexGridPanel, pos=wx.Point(0, |
|
383 |
0), size=wx.Size(-1, -1), style=0) |
|
384 |
self.SubindexGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
|
385 |
'Sans')) |
|
386 |
self.SubindexGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
387 |
False, 'Sans')) |
|
388 |
self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, |
|
389 |
self.OnSubindexGridCellChange) |
|
390 |
self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, |
|
391 |
self.OnSubindexGridRightClick) |
|
392 |
self.SubindexGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL, |
|
393 |
self.OnSubindexGridSelectCell) |
|
394 |
||
395 |
self.CallbackCheck = wx.CheckBox(id=wxID_EDITINGPANELCALLBACKCHECK, |
|
396 |
label='Have Callbacks', name='CallbackCheck', |
|
397 |
parent=self.SubindexGridPanel, pos=wx.Point(0, 0), size=wx.Size(152, |
|
398 |
24), style=0) |
|
399 |
self.CallbackCheck.Bind(wx.EVT_CHECKBOX, self.OnCallbackCheck, |
|
400 |
id=wxID_EDITINGPANELCALLBACKCHECK) |
|
401 |
||
402 |
self.IndexList = wx.ListBox(choices=[], id=wxID_EDITINGPANELINDEXLIST, |
|
403 |
name='IndexList', parent=self.IndexListPanel, pos=wx.Point(0, 0), |
|
404 |
size=wx.Size(-1, -1), style=0) |
|
405 |
self.IndexList.Bind(wx.EVT_LISTBOX, self.OnIndexListClick, |
|
406 |
id=wxID_EDITINGPANELINDEXLIST) |
|
407 |
self.IndexList.Bind(wx.EVT_RIGHT_UP, self.OnIndexListRightUp) |
|
408 |
||
409 |
self.AddButton = wx.Button(id=wxID_EDITINGPANELADDBUTTON, label='Add', |
|
410 |
name='AddButton', parent=self.IndexListPanel, pos=wx.Point(0, 0), |
|
411 |
size=wx.Size(50, 30), style=0) |
|
412 |
self.AddButton.Bind(wx.EVT_BUTTON, self.OnAddButtonClick, |
|
413 |
id=wxID_EDITINGPANELADDBUTTON) |
|
414 |
||
415 |
self.IndexChoice = wx.Choice(choices=[], id=wxID_EDITINGPANELINDEXCHOICE, |
|
416 |
name='IndexChoice', parent=self.IndexListPanel, pos=wx.Point(50, |
|
417 |
0), size=wx.Size(-1, 30), style=0) |
|
418 |
||
419 |
self._init_sizers() |
|
420 |
||
421 |
def __init__(self, parent, manager, editable = True): |
|
422 |
self._init_ctrls(parent.GetNoteBook()) |
|
423 |
self.Parent = parent |
|
424 |
self.Manager = manager |
|
425 |
self.ListIndex = [] |
|
426 |
self.ChoiceIndex = [] |
|
427 |
self.FirstCall = False |
|
428 |
self.Editable = editable |
|
429 |
self.Index = None |
|
430 |
||
431 |
for values in DictionaryOrganisation: |
|
432 |
text = " 0x%04X-0x%04X %s"%(values["minIndex"],values["maxIndex"],values["name"]) |
|
433 |
self.PartList.Append(text) |
|
434 |
self.Table = SubindexTable(self, [], [], ["subindex", "name", "type", "value", "access", "save", "comment"]) |
|
435 |
self.SubindexGrid.SetTable(self.Table) |
|
436 |
self.SubindexGrid.SetRowLabelSize(0) |
|
437 |
self.CallbackCheck.Disable() |
|
438 |
self.Table.ResetView(self.SubindexGrid) |
|
439 |
||
440 |
if not self.Editable: |
|
441 |
self.AddButton.Disable() |
|
442 |
self.IndexChoice.Disable() |
|
443 |
self.CallbackCheck.Disable() |
|
444 |
self.Table.Disable() |
|
445 |
||
446 |
def GetIndex(self): |
|
447 |
return self.Index |
|
448 |
||
449 |
def SetIndex(self, index): |
|
450 |
self.Index = index |
|
451 |
||
452 |
def GetSelection(self): |
|
453 |
selected = self.IndexList.GetSelection() |
|
454 |
if selected != wxNOT_FOUND: |
|
455 |
index = self.ListIndex[selected] |
|
456 |
subIndex = self.SubindexGrid.GetGridCursorRow() |
|
457 |
return index, subIndex |
|
458 |
return None |
|
459 |
||
460 |
def OnAddButtonClick(self, event): |
|
461 |
if self.Editable: |
|
462 |
self.SubindexGrid.SetGridCursor(0, 0) |
|
463 |
selected = self.IndexChoice.GetStringSelection() |
|
464 |
if selected != "": |
|
465 |
if selected == "User Type": |
|
466 |
self.Parent.AddUserType() |
|
467 |
elif selected == "SDO Server": |
|
468 |
self.Manager.AddSDOServerToCurrent() |
|
469 |
elif selected == "SDO Client": |
|
470 |
self.Manager.AddSDOClientToCurrent() |
|
471 |
elif selected == "PDO Receive": |
|
472 |
self.Manager.AddPDOReceiveToCurrent() |
|
473 |
elif selected == "PDO Transmit": |
|
474 |
self.Manager.AddPDOTransmitToCurrent() |
|
475 |
elif selected == "Map Variable": |
|
476 |
self.Parent.AddMapVariable() |
|
477 |
elif selected in [menu for menu, indexes in self.Manager.GetCurrentSpecificMenu()]: |
|
478 |
self.Manager.AddSpecificEntryToCurrent(selected) |
|
479 |
else: |
|
480 |
index = self.ChoiceIndex[self.IndexChoice.GetSelection()] |
|
481 |
self.Manager.ManageEntriesOfCurrent([index], []) |
|
482 |
self.Parent.RefreshBufferState() |
|
483 |
self.RefreshIndexList() |
|
484 |
event.Skip() |
|
485 |
||
486 |
def OnPartListBoxClick(self, event): |
|
487 |
self.SubindexGrid.SetGridCursor(0, 0) |
|
488 |
self.RefreshIndexList() |
|
489 |
event.Skip() |
|
490 |
||
491 |
def OnIndexListClick(self, event): |
|
492 |
self.SubindexGrid.SetGridCursor(0, 0) |
|
493 |
self.RefreshTable() |
|
494 |
event.Skip() |
|
495 |
||
496 |
def OnSubindexGridSelectCell(self, event): |
|
497 |
wxCallAfter(self.Parent.RefreshStatusBar) |
|
498 |
event.Skip() |
|
499 |
||
500 |
#------------------------------------------------------------------------------- |
|
501 |
# Refresh Functions |
|
502 |
#------------------------------------------------------------------------------- |
|
503 |
||
504 |
def RefreshIndexList(self): |
|
505 |
selected = self.IndexList.GetSelection() |
|
506 |
choice = self.IndexChoice.GetStringSelection() |
|
507 |
choiceindex = self.IndexChoice.GetSelection() |
|
508 |
if selected != wxNOT_FOUND: |
|
509 |
selectedindex = self.ListIndex[selected] |
|
510 |
self.IndexList.Clear() |
|
511 |
self.IndexChoice.Clear() |
|
512 |
i = self.PartList.GetSelection() |
|
513 |
if i < len(DictionaryOrganisation): |
|
514 |
values = DictionaryOrganisation[i] |
|
515 |
self.ListIndex = [] |
|
516 |
for name, index in self.Manager.GetCurrentValidIndexes(values["minIndex"], values["maxIndex"]): |
|
517 |
self.IndexList.Append("0x%04X %s"%(index, name)) |
|
518 |
self.ListIndex.append(index) |
|
519 |
if self.Editable: |
|
520 |
self.ChoiceIndex = [] |
|
521 |
if i == 0: |
|
522 |
self.IndexChoice.Append("User Type") |
|
523 |
self.IndexChoice.SetStringSelection("User Type") |
|
524 |
elif i == 2: |
|
525 |
self.IndexChoice.Append("SDO Server") |
|
526 |
self.IndexChoice.Append("SDO Client") |
|
527 |
if choiceindex != wxNOT_FOUND and choice == self.IndexChoice.GetString(choiceindex): |
|
528 |
self.IndexChoice.SetStringSelection(choice) |
|
529 |
elif i in (3, 4): |
|
530 |
self.IndexChoice.Append("PDO Receive") |
|
531 |
self.IndexChoice.SetStringSelection("PDO Receive") |
|
532 |
elif i in (5, 6): |
|
533 |
self.IndexChoice.Append("PDO Transmit") |
|
534 |
self.IndexChoice.SetStringSelection("PDO Transmit") |
|
535 |
elif i == 8: |
|
536 |
self.IndexChoice.Append("Map Variable") |
|
537 |
self.IndexChoice.SetStringSelection("Map Variable") |
|
538 |
else: |
|
539 |
for name, index in self.Manager.GetCurrentValidChoices(values["minIndex"], values["maxIndex"]): |
|
540 |
if index: |
|
541 |
self.IndexChoice.Append("0x%04X %s"%(index, name)) |
|
542 |
else: |
|
543 |
self.IndexChoice.Append(name) |
|
544 |
self.ChoiceIndex.append(index) |
|
545 |
if choiceindex != wxNOT_FOUND and choice == self.IndexChoice.GetString(choiceindex): |
|
546 |
self.IndexChoice.SetStringSelection(choice) |
|
547 |
if self.Editable: |
|
548 |
self.IndexChoice.Enable(self.IndexChoice.GetCount() != 0) |
|
549 |
self.AddButton.Enable(self.IndexChoice.GetCount() != 0) |
|
550 |
if selected == wxNOT_FOUND or selected >= len(self.ListIndex) or selectedindex != self.ListIndex[selected]: |
|
551 |
self.Table.Empty() |
|
552 |
self.CallbackCheck.SetValue(False) |
|
553 |
self.CallbackCheck.Disable() |
|
554 |
self.Table.ResetView(self.SubindexGrid) |
|
555 |
self.Parent.RefreshStatusBar() |
|
556 |
else: |
|
557 |
self.IndexList.SetSelection(selected) |
|
558 |
self.RefreshTable() |
|
559 |
||
560 |
def RefreshTable(self): |
|
561 |
selected = self.IndexList.GetSelection() |
|
562 |
if selected != wxNOT_FOUND: |
|
563 |
index = self.ListIndex[selected] |
|
564 |
if index > 0x260 and self.Editable: |
|
565 |
self.CallbackCheck.Enable() |
|
566 |
self.CallbackCheck.SetValue(self.Manager.HasCurrentEntryCallbacks(index)) |
|
567 |
result = self.Manager.GetCurrentEntryValues(index) |
|
568 |
if result != None: |
|
569 |
self.Table.SetCurrentIndex(index) |
|
570 |
data, editors = result |
|
571 |
self.Table.SetData(data) |
|
572 |
self.Table.SetEditors(editors) |
|
573 |
self.Table.ResetView(self.SubindexGrid) |
|
574 |
self.Parent.RefreshStatusBar() |
|
575 |
||
576 |
#------------------------------------------------------------------------------- |
|
577 |
# Editing Table value function |
|
578 |
#------------------------------------------------------------------------------- |
|
579 |
||
580 |
def OnSubindexGridCellChange(self, event): |
|
581 |
if self.Editable: |
|
582 |
index = self.Table.GetCurrentIndex() |
|
583 |
subIndex = event.GetRow() |
|
584 |
col = event.GetCol() |
|
585 |
name = self.Table.GetColLabelValue(col) |
|
586 |
value = self.Table.GetValue(subIndex, col) |
|
587 |
editor = self.Table.GetEditor(subIndex, col) |
|
588 |
self.Manager.SetCurrentEntry(index, subIndex, value, name, editor) |
|
589 |
self.Parent.RefreshBufferState() |
|
590 |
wxCallAfter(self.RefreshTable) |
|
591 |
event.Skip() |
|
592 |
||
593 |
def OnCallbackCheck(self, event): |
|
594 |
if self.Editable: |
|
595 |
index = self.Table.GetCurrentIndex() |
|
596 |
self.Manager.SetCurrentEntryCallbacks(index, self.CallbackCheck.GetValue()) |
|
597 |
self.Parent.RefreshBufferState() |
|
598 |
wxCallAfter(self.RefreshTable) |
|
599 |
event.Skip() |
|
600 |
||
601 |
#------------------------------------------------------------------------------- |
|
602 |
# Contextual Menu functions |
|
603 |
#------------------------------------------------------------------------------- |
|
604 |
||
605 |
def OnIndexListRightUp(self, event): |
|
606 |
if self.Editable: |
|
607 |
if not self.FirstCall: |
|
608 |
self.FirstCall = True |
|
609 |
selected = self.IndexList.GetSelection() |
|
610 |
if selected != wxNOT_FOUND: |
|
611 |
index = self.ListIndex[selected] |
|
612 |
if index < 0x260: |
|
613 |
self.IndexListMenu.FindItemByPosition(0).Enable(False) |
|
614 |
self.IndexListMenu.FindItemByPosition(1).Enable(True) |
|
615 |
self.PopupMenu(self.IndexListMenu) |
|
616 |
elif 0x1000 <= index <= 0x1BFF: |
|
617 |
self.IndexListMenu.FindItemByPosition(0).Enable(False) |
|
618 |
self.IndexListMenu.FindItemByPosition(1).Enable(False) |
|
619 |
self.PopupMenu(self.IndexListMenu) |
|
620 |
elif 0x2000 <= index <= 0x5FFF: |
|
621 |
self.IndexListMenu.FindItemByPosition(0).Enable(True) |
|
622 |
self.IndexListMenu.FindItemByPosition(1).Enable(False) |
|
623 |
self.PopupMenu(self.IndexListMenu) |
|
624 |
elif index >= 0x6000: |
|
625 |
self.IndexListMenu.FindItemByPosition(0).Enable(False) |
|
626 |
self.IndexListMenu.FindItemByPosition(1).Enable(False) |
|
627 |
self.PopupMenu(self.IndexListMenu) |
|
628 |
else: |
|
629 |
self.FirstCall = False |
|
630 |
event.Skip() |
|
631 |
||
632 |
def OnSubindexGridRightClick(self, event): |
|
633 |
if self.Editable: |
|
634 |
selected = self.IndexList.GetSelection() |
|
635 |
if selected != wxNOT_FOUND: |
|
636 |
index = self.ListIndex[selected] |
|
637 |
if self.Manager.IsCurrentEntry(index): |
|
638 |
infos = self.Manager.GetEntryInfos(index) |
|
237
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
639 |
if 0x5fff >= index >= 0x2000 and infos["struct"] & OD_MultipleSubindexes or infos["struct"] & OD_IdenticalSubindexes: |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
640 |
# enable add and delet entries |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
641 |
self.SubindexGridMenu.FindItemById(wxID_EDITINGPANELMENU1ITEMS0).Enable(True) |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
642 |
self.SubindexGridMenu.FindItemById(wxID_EDITINGPANELMENU1ITEMS1).Enable(True) |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
643 |
else: |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
644 |
# disable add and delet entries |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
645 |
self.SubindexGridMenu.FindItemById(wxID_EDITINGPANELMENU1ITEMS0).Enable(False) |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
646 |
self.SubindexGridMenu.FindItemById(wxID_EDITINGPANELMENU1ITEMS1).Enable(False) |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
647 |
self.SubindexGrid.SetGridCursor(event.GetRow(), event.GetCol()) |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
648 |
wxCallAfter(self.PopupMenu,self.SubindexGridMenu) |
205 | 649 |
event.Skip() |
650 |
||
651 |
def OnRenameIndexMenu(self, event): |
|
652 |
if self.Editable: |
|
653 |
selected = self.IndexList.GetSelection() |
|
654 |
if selected != wxNOT_FOUND: |
|
655 |
index = self.ListIndex[selected] |
|
656 |
if self.Manager.IsCurrentEntry(index): |
|
657 |
infos = self.Manager.GetEntryInfos(index) |
|
658 |
dialog = wxTextEntryDialog(self, "Give a new name for index 0x%04X"%index, |
|
659 |
"Rename an index", infos["name"], wxOK|wxCANCEL) |
|
660 |
if dialog.ShowModal() == wxID_OK: |
|
661 |
self.Manager.SetCurrentEntryName(index, dialog.GetValue()) |
|
662 |
self.Parent.RefreshBufferState() |
|
663 |
self.RefreshIndexList() |
|
664 |
dialog.Destroy() |
|
665 |
event.Skip() |
|
666 |
||
667 |
def OnModifyIndexMenu(self, event): |
|
668 |
if self.Editable: |
|
669 |
selected = self.IndexList.GetSelection() |
|
670 |
if selected != wxNOT_FOUND: |
|
671 |
index = self.ListIndex[selected] |
|
672 |
if self.Manager.IsCurrentEntry(index) and index < 0x260: |
|
673 |
values, valuetype = self.Manager.GetCustomisedTypeValues(index) |
|
674 |
dialog = UserTypeDialog(self) |
|
675 |
dialog.SetTypeList(self.Manager.GetCustomisableTypes(), values[1]) |
|
676 |
if valuetype == 0: |
|
677 |
dialog.SetValues(min = values[2], max = values[3]) |
|
678 |
elif valuetype == 1: |
|
679 |
dialog.SetValues(length = values[2]) |
|
680 |
if dialog.ShowModal() == wxID_OK: |
|
681 |
type, min, max, length = dialog.GetValues() |
|
682 |
self.Manager.SetCurrentUserType(index, type, min, max, length) |
|
683 |
self.Parent.RefreshBufferState() |
|
684 |
self.RefreshIndexList() |
|
685 |
event.Skip() |
|
686 |
||
687 |
def OnDeleteIndexMenu(self, event): |
|
688 |
if self.Editable: |
|
689 |
selected = self.IndexList.GetSelection() |
|
690 |
if selected != wxNOT_FOUND: |
|
691 |
index = self.ListIndex[selected] |
|
692 |
if self.Manager.IsCurrentEntry(index): |
|
693 |
self.Manager.ManageEntriesOfCurrent([],[index]) |
|
694 |
self.Parent.RefreshBufferState() |
|
695 |
self.RefreshIndexList() |
|
696 |
event.Skip() |
|
697 |
||
698 |
def OnAddSubindexMenu(self, event): |
|
699 |
if self.Editable: |
|
700 |
selected = self.IndexList.GetSelection() |
|
701 |
if selected != wxNOT_FOUND: |
|
702 |
index = self.ListIndex[selected] |
|
703 |
if self.Manager.IsCurrentEntry(index): |
|
704 |
dialog = wxTextEntryDialog(self, "Number of subindexes to add:", |
|
705 |
"Add subindexes", "1", wxOK|wxCANCEL) |
|
706 |
if dialog.ShowModal() == wxID_OK: |
|
707 |
try: |
|
708 |
number = int(dialog.GetValue()) |
|
709 |
self.Manager.AddSubentriesToCurrent(index, number) |
|
710 |
self.Parent.RefreshBufferState() |
|
711 |
self.RefreshIndexList() |
|
712 |
except: |
|
713 |
message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR) |
|
714 |
message.ShowModal() |
|
715 |
message.Destroy() |
|
716 |
dialog.Destroy() |
|
717 |
event.Skip() |
|
718 |
||
719 |
def OnDeleteSubindexMenu(self, event): |
|
720 |
if self.Editable: |
|
721 |
selected = self.IndexList.GetSelection() |
|
722 |
if selected != wxNOT_FOUND: |
|
723 |
index = self.ListIndex[selected] |
|
724 |
if self.Manager.IsCurrentEntry(index): |
|
725 |
dialog = wxTextEntryDialog(self, "Number of subindexes to delete:", |
|
726 |
"Delete subindexes", "1", wxOK|wxCANCEL) |
|
727 |
if dialog.ShowModal() == wxID_OK: |
|
728 |
try: |
|
729 |
number = int(dialog.GetValue()) |
|
730 |
self.Manager.RemoveSubentriesFromCurrent(index, number) |
|
731 |
self.Parent.RefreshBufferState() |
|
732 |
self.RefreshIndexList() |
|
733 |
except: |
|
734 |
message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR) |
|
735 |
message.ShowModal() |
|
736 |
message.Destroy() |
|
737 |
dialog.Destroy() |
|
738 |
event.Skip() |
|
739 |
||
237
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
740 |
def OnDefaultValueSubindexMenu(self, event): |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
741 |
if self.Editable: |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
742 |
selected = self.IndexList.GetSelection() |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
743 |
if selected != wxNOT_FOUND: |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
744 |
index = self.ListIndex[selected] |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
745 |
if self.Manager.IsCurrentEntry(index): |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
746 |
self.Manager.ResetCurrentDefaultValue(index,self.SubindexGrid.GetGridCursorRow()) |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
747 |
self.Parent.RefreshBufferState() |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
748 |
self.RefreshIndexList() |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
749 |
event.Skip() |
5dcfc996e563
Added "Default value" to context menu on subindex grid in objdictedit.
etisserant
parents:
206
diff
changeset
|
750 |