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 |
|
|
252 |
[wxID_EDITINGPANELMENU1ITEMS0, wxID_EDITINGPANELMENU1ITEMS1,
|
|
253 |
] = [wx.NewId() for _init_coll_SubindexGridMenu_Items in range(2)]
|
|
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')
|
|
298 |
self.Bind(wx.EVT_MENU, self.OnAddSubindexMenu,
|
|
299 |
id=wxID_EDITINGPANELMENU1ITEMS0)
|
|
300 |
self.Bind(wx.EVT_MENU, self.OnDeleteSubindexMenu,
|
|
301 |
id=wxID_EDITINGPANELMENU1ITEMS1)
|
|
302 |
|
|
303 |
def _init_coll_IndexListMenu_Items(self, parent):
|
|
304 |
# generated method, don't edit
|
|
305 |
|
|
306 |
parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS0,
|
|
307 |
kind=wx.ITEM_NORMAL, text='Rename')
|
|
308 |
parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS2,
|
|
309 |
kind=wx.ITEM_NORMAL, text='Modify')
|
|
310 |
parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS1,
|
|
311 |
kind=wx.ITEM_NORMAL, text='Delete')
|
|
312 |
self.Bind(wx.EVT_MENU, self.OnRenameIndexMenu,
|
|
313 |
id=wxID_EDITINGPANELINDEXLISTMENUITEMS0)
|
|
314 |
self.Bind(wx.EVT_MENU, self.OnDeleteIndexMenu,
|
|
315 |
id=wxID_EDITINGPANELINDEXLISTMENUITEMS1)
|
|
316 |
self.Bind(wx.EVT_MENU, self.OnModifyIndexMenu,
|
|
317 |
id=wxID_EDITINGPANELINDEXLISTMENUITEMS2)
|
|
318 |
|
|
319 |
def _init_utils(self):
|
|
320 |
# generated method, don't edit
|
|
321 |
self.IndexListMenu = wx.Menu(title='')
|
|
322 |
|
|
323 |
self.SubindexGridMenu = wx.Menu(title='')
|
|
324 |
|
|
325 |
self._init_coll_IndexListMenu_Items(self.IndexListMenu)
|
|
326 |
self._init_coll_SubindexGridMenu_Items(self.SubindexGridMenu)
|
|
327 |
|
|
328 |
def _init_sizers(self):
|
|
329 |
# generated method, don't edit
|
|
330 |
self.IndexListSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
|
|
331 |
|
|
332 |
self.SubindexGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
|
|
333 |
|
|
334 |
self.AddToListSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
|
|
335 |
|
|
336 |
self._init_coll_IndexListSizer_Growables(self.IndexListSizer)
|
|
337 |
self._init_coll_IndexListSizer_Items(self.IndexListSizer)
|
|
338 |
self._init_coll_SubindexGridSizer_Growables(self.SubindexGridSizer)
|
|
339 |
self._init_coll_SubindexGridSizer_Items(self.SubindexGridSizer)
|
|
340 |
self._init_coll_AddToListSizer_Growables(self.AddToListSizer)
|
|
341 |
self._init_coll_AddToListSizer_Items(self.AddToListSizer)
|
|
342 |
|
|
343 |
self.SubindexGridPanel.SetSizer(self.SubindexGridSizer)
|
|
344 |
self.IndexListPanel.SetSizer(self.IndexListSizer)
|
|
345 |
|
|
346 |
def _init_ctrls(self, prnt):
|
|
347 |
wx.SplitterWindow.__init__(self, id=wxID_EDITINGPANEL,
|
|
348 |
name='MainSplitter', parent=prnt, point=wx.Point(0, 0),
|
|
349 |
size=wx.Size(-1, -1), style=wx.SP_3D)
|
|
350 |
self._init_utils()
|
|
351 |
self.SetNeedUpdating(True)
|
|
352 |
self.SetMinimumPaneSize(1)
|
|
353 |
|
|
354 |
self.PartList = wx.ListBox(choices=[], id=wxID_EDITINGPANELPARTLIST,
|
|
355 |
name='PartList', parent=self, pos=wx.Point(0, 0),
|
|
356 |
size=wx.Size(-1, -1), style=0)
|
|
357 |
self.PartList.Bind(wx.EVT_LISTBOX, self.OnPartListBoxClick,
|
|
358 |
id=wxID_EDITINGPANELPARTLIST)
|
|
359 |
|
|
360 |
self.SecondSplitter = wx.SplitterWindow(id=wxID_EDITINGPANELSECONDSPLITTER,
|
|
361 |
name='SecondSplitter', parent=self, point=wx.Point(0,
|
|
362 |
0), size=wx.Size(-1, -1), style=wx.SP_3D)
|
|
363 |
self.SecondSplitter.SetMinimumPaneSize(1)
|
|
364 |
self.SplitHorizontally(self.PartList, self.SecondSplitter,
|
|
365 |
110)
|
|
366 |
|
|
367 |
self.SubindexGridPanel = wx.Panel(id=wxID_EDITINGPANELSUBINDEXGRIDPANEL,
|
|
368 |
name='SubindexGridPanel', parent=self.SecondSplitter, pos=wx.Point(0,
|
|
369 |
0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
|
|
370 |
|
|
371 |
self.IndexListPanel = wx.Panel(id=wxID_EDITINGPANELINDEXLISTPANEL,
|
|
372 |
name='IndexListPanel', parent=self.SecondSplitter, pos=wx.Point(0,
|
|
373 |
0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
|
|
374 |
self.SecondSplitter.SplitVertically(self.IndexListPanel,
|
|
375 |
self.SubindexGridPanel, 280)
|
|
376 |
|
|
377 |
self.SubindexGrid = wx.grid.Grid(id=wxID_EDITINGPANELSUBINDEXGRID,
|
|
378 |
name='SubindexGrid', parent=self.SubindexGridPanel, pos=wx.Point(0,
|
|
379 |
0), size=wx.Size(-1, -1), style=0)
|
|
380 |
self.SubindexGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
|
|
381 |
'Sans'))
|
|
382 |
self.SubindexGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
|
|
383 |
False, 'Sans'))
|
|
384 |
self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
|
|
385 |
self.OnSubindexGridCellChange)
|
|
386 |
self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK,
|
|
387 |
self.OnSubindexGridRightClick)
|
|
388 |
self.SubindexGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL,
|
|
389 |
self.OnSubindexGridSelectCell)
|
|
390 |
|
|
391 |
self.CallbackCheck = wx.CheckBox(id=wxID_EDITINGPANELCALLBACKCHECK,
|
|
392 |
label='Have Callbacks', name='CallbackCheck',
|
|
393 |
parent=self.SubindexGridPanel, pos=wx.Point(0, 0), size=wx.Size(152,
|
|
394 |
24), style=0)
|
|
395 |
self.CallbackCheck.Bind(wx.EVT_CHECKBOX, self.OnCallbackCheck,
|
|
396 |
id=wxID_EDITINGPANELCALLBACKCHECK)
|
|
397 |
|
|
398 |
self.IndexList = wx.ListBox(choices=[], id=wxID_EDITINGPANELINDEXLIST,
|
|
399 |
name='IndexList', parent=self.IndexListPanel, pos=wx.Point(0, 0),
|
|
400 |
size=wx.Size(-1, -1), style=0)
|
|
401 |
self.IndexList.Bind(wx.EVT_LISTBOX, self.OnIndexListClick,
|
|
402 |
id=wxID_EDITINGPANELINDEXLIST)
|
|
403 |
self.IndexList.Bind(wx.EVT_RIGHT_UP, self.OnIndexListRightUp)
|
|
404 |
|
|
405 |
self.AddButton = wx.Button(id=wxID_EDITINGPANELADDBUTTON, label='Add',
|
|
406 |
name='AddButton', parent=self.IndexListPanel, pos=wx.Point(0, 0),
|
|
407 |
size=wx.Size(50, 30), style=0)
|
|
408 |
self.AddButton.Bind(wx.EVT_BUTTON, self.OnAddButtonClick,
|
|
409 |
id=wxID_EDITINGPANELADDBUTTON)
|
|
410 |
|
|
411 |
self.IndexChoice = wx.Choice(choices=[], id=wxID_EDITINGPANELINDEXCHOICE,
|
|
412 |
name='IndexChoice', parent=self.IndexListPanel, pos=wx.Point(50,
|
|
413 |
0), size=wx.Size(-1, 30), style=0)
|
|
414 |
|
|
415 |
self._init_sizers()
|
|
416 |
|
|
417 |
def __init__(self, parent, manager, editable = True):
|
|
418 |
self._init_ctrls(parent.GetNoteBook())
|
|
419 |
self.Parent = parent
|
|
420 |
self.Manager = manager
|
|
421 |
self.ListIndex = []
|
|
422 |
self.ChoiceIndex = []
|
|
423 |
self.FirstCall = False
|
|
424 |
self.Editable = editable
|
|
425 |
self.Index = None
|
|
426 |
|
|
427 |
for values in DictionaryOrganisation:
|
|
428 |
text = " 0x%04X-0x%04X %s"%(values["minIndex"],values["maxIndex"],values["name"])
|
|
429 |
self.PartList.Append(text)
|
|
430 |
self.Table = SubindexTable(self, [], [], ["subindex", "name", "type", "value", "access", "save", "comment"])
|
|
431 |
self.SubindexGrid.SetTable(self.Table)
|
|
432 |
self.SubindexGrid.SetRowLabelSize(0)
|
|
433 |
self.CallbackCheck.Disable()
|
|
434 |
self.Table.ResetView(self.SubindexGrid)
|
|
435 |
|
|
436 |
if not self.Editable:
|
|
437 |
self.AddButton.Disable()
|
|
438 |
self.IndexChoice.Disable()
|
|
439 |
self.CallbackCheck.Disable()
|
|
440 |
self.Table.Disable()
|
|
441 |
|
|
442 |
def GetIndex(self):
|
|
443 |
return self.Index
|
|
444 |
|
|
445 |
def SetIndex(self, index):
|
|
446 |
self.Index = index
|
|
447 |
|
|
448 |
def GetSelection(self):
|
|
449 |
selected = self.IndexList.GetSelection()
|
|
450 |
if selected != wxNOT_FOUND:
|
|
451 |
index = self.ListIndex[selected]
|
|
452 |
subIndex = self.SubindexGrid.GetGridCursorRow()
|
|
453 |
return index, subIndex
|
|
454 |
return None
|
|
455 |
|
|
456 |
def OnAddButtonClick(self, event):
|
|
457 |
if self.Editable:
|
|
458 |
self.SubindexGrid.SetGridCursor(0, 0)
|
|
459 |
selected = self.IndexChoice.GetStringSelection()
|
|
460 |
if selected != "":
|
|
461 |
if selected == "User Type":
|
|
462 |
self.Parent.AddUserType()
|
|
463 |
elif selected == "SDO Server":
|
|
464 |
self.Manager.AddSDOServerToCurrent()
|
|
465 |
elif selected == "SDO Client":
|
|
466 |
self.Manager.AddSDOClientToCurrent()
|
|
467 |
elif selected == "PDO Receive":
|
|
468 |
self.Manager.AddPDOReceiveToCurrent()
|
|
469 |
elif selected == "PDO Transmit":
|
|
470 |
self.Manager.AddPDOTransmitToCurrent()
|
|
471 |
elif selected == "Map Variable":
|
|
472 |
self.Parent.AddMapVariable()
|
|
473 |
elif selected in [menu for menu, indexes in self.Manager.GetCurrentSpecificMenu()]:
|
|
474 |
self.Manager.AddSpecificEntryToCurrent(selected)
|
|
475 |
else:
|
|
476 |
index = self.ChoiceIndex[self.IndexChoice.GetSelection()]
|
|
477 |
self.Manager.ManageEntriesOfCurrent([index], [])
|
|
478 |
self.Parent.RefreshBufferState()
|
|
479 |
self.RefreshIndexList()
|
|
480 |
event.Skip()
|
|
481 |
|
|
482 |
def OnPartListBoxClick(self, event):
|
|
483 |
self.SubindexGrid.SetGridCursor(0, 0)
|
|
484 |
self.RefreshIndexList()
|
|
485 |
event.Skip()
|
|
486 |
|
|
487 |
def OnIndexListClick(self, event):
|
|
488 |
self.SubindexGrid.SetGridCursor(0, 0)
|
|
489 |
self.RefreshTable()
|
|
490 |
event.Skip()
|
|
491 |
|
|
492 |
def OnSubindexGridSelectCell(self, event):
|
|
493 |
wxCallAfter(self.Parent.RefreshStatusBar)
|
|
494 |
event.Skip()
|
|
495 |
|
|
496 |
#-------------------------------------------------------------------------------
|
|
497 |
# Refresh Functions
|
|
498 |
#-------------------------------------------------------------------------------
|
|
499 |
|
|
500 |
def RefreshIndexList(self):
|
|
501 |
selected = self.IndexList.GetSelection()
|
|
502 |
choice = self.IndexChoice.GetStringSelection()
|
|
503 |
choiceindex = self.IndexChoice.GetSelection()
|
|
504 |
if selected != wxNOT_FOUND:
|
|
505 |
selectedindex = self.ListIndex[selected]
|
|
506 |
self.IndexList.Clear()
|
|
507 |
self.IndexChoice.Clear()
|
|
508 |
i = self.PartList.GetSelection()
|
|
509 |
if i < len(DictionaryOrganisation):
|
|
510 |
values = DictionaryOrganisation[i]
|
|
511 |
self.ListIndex = []
|
|
512 |
for name, index in self.Manager.GetCurrentValidIndexes(values["minIndex"], values["maxIndex"]):
|
|
513 |
self.IndexList.Append("0x%04X %s"%(index, name))
|
|
514 |
self.ListIndex.append(index)
|
|
515 |
if self.Editable:
|
|
516 |
self.ChoiceIndex = []
|
|
517 |
if i == 0:
|
|
518 |
self.IndexChoice.Append("User Type")
|
|
519 |
self.IndexChoice.SetStringSelection("User Type")
|
|
520 |
elif i == 2:
|
|
521 |
self.IndexChoice.Append("SDO Server")
|
|
522 |
self.IndexChoice.Append("SDO Client")
|
|
523 |
if choiceindex != wxNOT_FOUND and choice == self.IndexChoice.GetString(choiceindex):
|
|
524 |
self.IndexChoice.SetStringSelection(choice)
|
|
525 |
elif i in (3, 4):
|
|
526 |
self.IndexChoice.Append("PDO Receive")
|
|
527 |
self.IndexChoice.SetStringSelection("PDO Receive")
|
|
528 |
elif i in (5, 6):
|
|
529 |
self.IndexChoice.Append("PDO Transmit")
|
|
530 |
self.IndexChoice.SetStringSelection("PDO Transmit")
|
|
531 |
elif i == 8:
|
|
532 |
self.IndexChoice.Append("Map Variable")
|
|
533 |
self.IndexChoice.SetStringSelection("Map Variable")
|
|
534 |
else:
|
|
535 |
for name, index in self.Manager.GetCurrentValidChoices(values["minIndex"], values["maxIndex"]):
|
|
536 |
if index:
|
|
537 |
self.IndexChoice.Append("0x%04X %s"%(index, name))
|
|
538 |
else:
|
|
539 |
self.IndexChoice.Append(name)
|
|
540 |
self.ChoiceIndex.append(index)
|
|
541 |
if choiceindex != wxNOT_FOUND and choice == self.IndexChoice.GetString(choiceindex):
|
|
542 |
self.IndexChoice.SetStringSelection(choice)
|
|
543 |
if self.Editable:
|
|
544 |
self.IndexChoice.Enable(self.IndexChoice.GetCount() != 0)
|
|
545 |
self.AddButton.Enable(self.IndexChoice.GetCount() != 0)
|
|
546 |
if selected == wxNOT_FOUND or selected >= len(self.ListIndex) or selectedindex != self.ListIndex[selected]:
|
|
547 |
self.Table.Empty()
|
|
548 |
self.CallbackCheck.SetValue(False)
|
|
549 |
self.CallbackCheck.Disable()
|
|
550 |
self.Table.ResetView(self.SubindexGrid)
|
|
551 |
self.Parent.RefreshStatusBar()
|
|
552 |
else:
|
|
553 |
self.IndexList.SetSelection(selected)
|
|
554 |
self.RefreshTable()
|
|
555 |
|
|
556 |
def RefreshTable(self):
|
|
557 |
selected = self.IndexList.GetSelection()
|
|
558 |
if selected != wxNOT_FOUND:
|
|
559 |
index = self.ListIndex[selected]
|
|
560 |
if index > 0x260 and self.Editable:
|
|
561 |
self.CallbackCheck.Enable()
|
|
562 |
self.CallbackCheck.SetValue(self.Manager.HasCurrentEntryCallbacks(index))
|
|
563 |
result = self.Manager.GetCurrentEntryValues(index)
|
|
564 |
if result != None:
|
|
565 |
self.Table.SetCurrentIndex(index)
|
|
566 |
data, editors = result
|
|
567 |
self.Table.SetData(data)
|
|
568 |
self.Table.SetEditors(editors)
|
|
569 |
self.Table.ResetView(self.SubindexGrid)
|
|
570 |
self.Parent.RefreshStatusBar()
|
|
571 |
|
|
572 |
#-------------------------------------------------------------------------------
|
|
573 |
# Editing Table value function
|
|
574 |
#-------------------------------------------------------------------------------
|
|
575 |
|
|
576 |
def OnSubindexGridCellChange(self, event):
|
|
577 |
if self.Editable:
|
|
578 |
index = self.Table.GetCurrentIndex()
|
|
579 |
subIndex = event.GetRow()
|
|
580 |
col = event.GetCol()
|
|
581 |
name = self.Table.GetColLabelValue(col)
|
|
582 |
value = self.Table.GetValue(subIndex, col)
|
|
583 |
editor = self.Table.GetEditor(subIndex, col)
|
|
584 |
self.Manager.SetCurrentEntry(index, subIndex, value, name, editor)
|
|
585 |
self.Parent.RefreshBufferState()
|
|
586 |
wxCallAfter(self.RefreshTable)
|
|
587 |
event.Skip()
|
|
588 |
|
|
589 |
def OnCallbackCheck(self, event):
|
|
590 |
if self.Editable:
|
|
591 |
index = self.Table.GetCurrentIndex()
|
|
592 |
self.Manager.SetCurrentEntryCallbacks(index, self.CallbackCheck.GetValue())
|
|
593 |
self.Parent.RefreshBufferState()
|
|
594 |
wxCallAfter(self.RefreshTable)
|
|
595 |
event.Skip()
|
|
596 |
|
|
597 |
#-------------------------------------------------------------------------------
|
|
598 |
# Contextual Menu functions
|
|
599 |
#-------------------------------------------------------------------------------
|
|
600 |
|
|
601 |
def OnIndexListRightUp(self, event):
|
|
602 |
if self.Editable:
|
|
603 |
if not self.FirstCall:
|
|
604 |
self.FirstCall = True
|
|
605 |
selected = self.IndexList.GetSelection()
|
|
606 |
if selected != wxNOT_FOUND:
|
|
607 |
index = self.ListIndex[selected]
|
|
608 |
if index < 0x260:
|
|
609 |
self.IndexListMenu.FindItemByPosition(0).Enable(False)
|
|
610 |
self.IndexListMenu.FindItemByPosition(1).Enable(True)
|
|
611 |
self.PopupMenu(self.IndexListMenu)
|
|
612 |
elif 0x1000 <= index <= 0x1BFF:
|
|
613 |
self.IndexListMenu.FindItemByPosition(0).Enable(False)
|
|
614 |
self.IndexListMenu.FindItemByPosition(1).Enable(False)
|
|
615 |
self.PopupMenu(self.IndexListMenu)
|
|
616 |
elif 0x2000 <= index <= 0x5FFF:
|
|
617 |
self.IndexListMenu.FindItemByPosition(0).Enable(True)
|
|
618 |
self.IndexListMenu.FindItemByPosition(1).Enable(False)
|
|
619 |
self.PopupMenu(self.IndexListMenu)
|
|
620 |
elif index >= 0x6000:
|
|
621 |
self.IndexListMenu.FindItemByPosition(0).Enable(False)
|
|
622 |
self.IndexListMenu.FindItemByPosition(1).Enable(False)
|
|
623 |
self.PopupMenu(self.IndexListMenu)
|
|
624 |
else:
|
|
625 |
self.FirstCall = False
|
|
626 |
event.Skip()
|
|
627 |
|
|
628 |
def OnSubindexGridRightClick(self, event):
|
|
629 |
if self.Editable:
|
|
630 |
selected = self.IndexList.GetSelection()
|
|
631 |
if selected != wxNOT_FOUND:
|
|
632 |
index = self.ListIndex[selected]
|
|
633 |
if self.Manager.IsCurrentEntry(index):
|
|
634 |
infos = self.Manager.GetEntryInfos(index)
|
|
635 |
if index >= 0x2000 and infos["struct"] & OD_MultipleSubindexes or infos["struct"] & OD_IdenticalSubindexes:
|
|
636 |
self.PopupMenu(self.SubindexGridMenu)
|
|
637 |
event.Skip()
|
|
638 |
|
|
639 |
def OnRenameIndexMenu(self, event):
|
|
640 |
if self.Editable:
|
|
641 |
selected = self.IndexList.GetSelection()
|
|
642 |
if selected != wxNOT_FOUND:
|
|
643 |
index = self.ListIndex[selected]
|
|
644 |
if self.Manager.IsCurrentEntry(index):
|
|
645 |
infos = self.Manager.GetEntryInfos(index)
|
|
646 |
dialog = wxTextEntryDialog(self, "Give a new name for index 0x%04X"%index,
|
|
647 |
"Rename an index", infos["name"], wxOK|wxCANCEL)
|
|
648 |
if dialog.ShowModal() == wxID_OK:
|
|
649 |
self.Manager.SetCurrentEntryName(index, dialog.GetValue())
|
|
650 |
self.Parent.RefreshBufferState()
|
|
651 |
self.RefreshIndexList()
|
|
652 |
dialog.Destroy()
|
|
653 |
event.Skip()
|
|
654 |
|
|
655 |
def OnModifyIndexMenu(self, event):
|
|
656 |
if self.Editable:
|
|
657 |
selected = self.IndexList.GetSelection()
|
|
658 |
if selected != wxNOT_FOUND:
|
|
659 |
index = self.ListIndex[selected]
|
|
660 |
if self.Manager.IsCurrentEntry(index) and index < 0x260:
|
|
661 |
values, valuetype = self.Manager.GetCustomisedTypeValues(index)
|
|
662 |
dialog = UserTypeDialog(self)
|
|
663 |
dialog.SetTypeList(self.Manager.GetCustomisableTypes(), values[1])
|
|
664 |
if valuetype == 0:
|
|
665 |
dialog.SetValues(min = values[2], max = values[3])
|
|
666 |
elif valuetype == 1:
|
|
667 |
dialog.SetValues(length = values[2])
|
|
668 |
if dialog.ShowModal() == wxID_OK:
|
|
669 |
type, min, max, length = dialog.GetValues()
|
|
670 |
self.Manager.SetCurrentUserType(index, type, min, max, length)
|
|
671 |
self.Parent.RefreshBufferState()
|
|
672 |
self.RefreshIndexList()
|
|
673 |
event.Skip()
|
|
674 |
|
|
675 |
def OnDeleteIndexMenu(self, event):
|
|
676 |
if self.Editable:
|
|
677 |
selected = self.IndexList.GetSelection()
|
|
678 |
if selected != wxNOT_FOUND:
|
|
679 |
index = self.ListIndex[selected]
|
|
680 |
if self.Manager.IsCurrentEntry(index):
|
|
681 |
self.Manager.ManageEntriesOfCurrent([],[index])
|
|
682 |
self.Parent.RefreshBufferState()
|
|
683 |
self.RefreshIndexList()
|
|
684 |
event.Skip()
|
|
685 |
|
|
686 |
def OnAddSubindexMenu(self, event):
|
|
687 |
if self.Editable:
|
|
688 |
selected = self.IndexList.GetSelection()
|
|
689 |
if selected != wxNOT_FOUND:
|
|
690 |
index = self.ListIndex[selected]
|
|
691 |
if self.Manager.IsCurrentEntry(index):
|
|
692 |
dialog = wxTextEntryDialog(self, "Number of subindexes to add:",
|
|
693 |
"Add subindexes", "1", wxOK|wxCANCEL)
|
|
694 |
if dialog.ShowModal() == wxID_OK:
|
|
695 |
try:
|
|
696 |
number = int(dialog.GetValue())
|
|
697 |
self.Manager.AddSubentriesToCurrent(index, number)
|
|
698 |
self.Parent.RefreshBufferState()
|
|
699 |
self.RefreshIndexList()
|
|
700 |
except:
|
|
701 |
message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR)
|
|
702 |
message.ShowModal()
|
|
703 |
message.Destroy()
|
|
704 |
dialog.Destroy()
|
|
705 |
event.Skip()
|
|
706 |
|
|
707 |
def OnDeleteSubindexMenu(self, event):
|
|
708 |
if self.Editable:
|
|
709 |
selected = self.IndexList.GetSelection()
|
|
710 |
if selected != wxNOT_FOUND:
|
|
711 |
index = self.ListIndex[selected]
|
|
712 |
if self.Manager.IsCurrentEntry(index):
|
|
713 |
dialog = wxTextEntryDialog(self, "Number of subindexes to delete:",
|
|
714 |
"Delete subindexes", "1", wxOK|wxCANCEL)
|
|
715 |
if dialog.ShowModal() == wxID_OK:
|
|
716 |
try:
|
|
717 |
number = int(dialog.GetValue())
|
|
718 |
self.Manager.RemoveSubentriesFromCurrent(index, number)
|
|
719 |
self.Parent.RefreshBufferState()
|
|
720 |
self.RefreshIndexList()
|
|
721 |
except:
|
|
722 |
message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR)
|
|
723 |
message.ShowModal()
|
|
724 |
message.Destroy()
|
|
725 |
dialog.Destroy()
|
|
726 |
event.Skip()
|
|
727 |
|