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