124 sys.exit() |
124 sys.exit() |
125 |
125 |
126 filesOpen = args |
126 filesOpen = args |
127 ScriptDirectory = sys.path[0] |
127 ScriptDirectory = sys.path[0] |
128 |
128 |
129 ColSizes = [75, 250, 150, 125, 100, 60, 250] |
|
130 ColAlignements = [wxALIGN_CENTER, wxALIGN_LEFT, wxALIGN_CENTER, wxALIGN_RIGHT, wxALIGN_CENTER, wxALIGN_CENTER, wxALIGN_LEFT] |
|
131 AccessList = "Read Only,Write Only,Read/Write" |
|
132 RAccessList = "Read Only,Read/Write" |
|
133 BoolList = "True,False" |
|
134 OptionList = "Yes,No" |
|
135 |
|
136 DictionaryOrganisation = [ |
|
137 {"minIndex" : 0x0001, "maxIndex" : 0x0FFF, "name" : "Data Type Definitions"}, |
|
138 {"minIndex" : 0x1000, "maxIndex" : 0x1029, "name" : "Communication Parameters"}, |
|
139 {"minIndex" : 0x1200, "maxIndex" : 0x12FF, "name" : "SDO Parameters"}, |
|
140 {"minIndex" : 0x1400, "maxIndex" : 0x15FF, "name" : "Receive PDO Parameters"}, |
|
141 {"minIndex" : 0x1600, "maxIndex" : 0x17FF, "name" : "Receive PDO Mapping"}, |
|
142 {"minIndex" : 0x1800, "maxIndex" : 0x19FF, "name" : "Transmit PDO Parameters"}, |
|
143 {"minIndex" : 0x1A00, "maxIndex" : 0x1BFF, "name" : "Transmit PDO Mapping"}, |
|
144 {"minIndex" : 0x1C00, "maxIndex" : 0x1FFF, "name" : "Other Communication Parameters"}, |
|
145 {"minIndex" : 0x2000, "maxIndex" : 0x5FFF, "name" : "Manufacturer Specific"}, |
|
146 {"minIndex" : 0x6000, "maxIndex" : 0x9FFF, "name" : "Standardized Device Profile"}, |
|
147 {"minIndex" : 0xA000, "maxIndex" : 0xBFFF, "name" : "Standardized Interface Profile"}] |
|
148 |
|
149 class SubindexTable(wxPyGridTableBase): |
|
150 |
|
151 """ |
|
152 A custom wxGrid Table using user supplied data |
|
153 """ |
|
154 def __init__(self, parent, data, editors, colnames): |
|
155 # The base class must be initialized *first* |
|
156 wxPyGridTableBase.__init__(self) |
|
157 self.data = data |
|
158 self.editors = editors |
|
159 self.CurrentIndex = 0 |
|
160 self.colnames = colnames |
|
161 self.Parent = parent |
|
162 # XXX |
|
163 # we need to store the row length and collength to |
|
164 # see if the table has changed size |
|
165 self._rows = self.GetNumberRows() |
|
166 self._cols = self.GetNumberCols() |
|
167 |
|
168 def GetNumberCols(self): |
|
169 return len(self.colnames) |
|
170 |
|
171 def GetNumberRows(self): |
|
172 return len(self.data) |
|
173 |
|
174 def GetColLabelValue(self, col): |
|
175 if col < len(self.colnames): |
|
176 return self.colnames[col] |
|
177 |
|
178 def GetRowLabelValues(self, row): |
|
179 return row |
|
180 |
|
181 def GetValue(self, row, col): |
|
182 if row < self.GetNumberRows(): |
|
183 value = self.data[row].get(self.GetColLabelValue(col), "") |
|
184 if (type(value) == UnicodeType): |
|
185 return value |
|
186 else: |
|
187 return str(value) |
|
188 |
|
189 def GetEditor(self, row, col): |
|
190 if row < self.GetNumberRows(): |
|
191 return self.editors[row].get(self.GetColLabelValue(col), "") |
|
192 |
|
193 def GetValueByName(self, row, colname): |
|
194 return self.data[row].get(colname) |
|
195 |
|
196 def SetValue(self, row, col, value): |
|
197 if col < len(self.colnames): |
|
198 self.data[row][self.GetColLabelValue(col)] = value |
|
199 |
|
200 def ResetView(self, grid): |
|
201 """ |
|
202 (wxGrid) -> Reset the grid view. Call this to |
|
203 update the grid if rows and columns have been added or deleted |
|
204 """ |
|
205 grid.BeginBatch() |
|
206 for current, new, delmsg, addmsg in [ |
|
207 (self._rows, self.GetNumberRows(), wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_NOTIFY_ROWS_APPENDED), |
|
208 (self._cols, self.GetNumberCols(), wxGRIDTABLE_NOTIFY_COLS_DELETED, wxGRIDTABLE_NOTIFY_COLS_APPENDED), |
|
209 ]: |
|
210 if new < current: |
|
211 msg = wxGridTableMessage(self,delmsg,new,current-new) |
|
212 grid.ProcessTableMessage(msg) |
|
213 elif new > current: |
|
214 msg = wxGridTableMessage(self,addmsg,new-current) |
|
215 grid.ProcessTableMessage(msg) |
|
216 self.UpdateValues(grid) |
|
217 grid.EndBatch() |
|
218 |
|
219 self._rows = self.GetNumberRows() |
|
220 self._cols = self.GetNumberCols() |
|
221 # update the column rendering scheme |
|
222 self._updateColAttrs(grid) |
|
223 |
|
224 # update the scrollbars and the displayed part of the grid |
|
225 grid.AdjustScrollbars() |
|
226 grid.ForceRefresh() |
|
227 |
|
228 |
|
229 def UpdateValues(self, grid): |
|
230 """Update all displayed values""" |
|
231 # This sends an event to the grid table to update all of the values |
|
232 msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES) |
|
233 grid.ProcessTableMessage(msg) |
|
234 |
|
235 def _updateColAttrs(self, grid): |
|
236 """ |
|
237 wxGrid -> update the column attributes to add the |
|
238 appropriate renderer given the column name. |
|
239 |
|
240 Otherwise default to the default renderer. |
|
241 """ |
|
242 |
|
243 for col in range(self.GetNumberCols()): |
|
244 attr = wxGridCellAttr() |
|
245 attr.SetAlignment(ColAlignements[col], wxALIGN_CENTRE) |
|
246 grid.SetColAttr(col, attr) |
|
247 grid.SetColSize(col, ColSizes[col]) |
|
248 |
|
249 typelist = None |
|
250 accesslist = None |
|
251 for row in range(self.GetNumberRows()): |
|
252 editors = self.editors[row] |
|
253 for col in range(self.GetNumberCols()): |
|
254 editor = None |
|
255 renderer = None |
|
256 |
|
257 colname = self.GetColLabelValue(col) |
|
258 editortype = editors[colname] |
|
259 if editortype: |
|
260 grid.SetReadOnly(row, col, False) |
|
261 if editortype == "string": |
|
262 editor = wxGridCellTextEditor() |
|
263 renderer = wxGridCellStringRenderer() |
|
264 if colname == "value" and "length" in editors: |
|
265 editor.SetParameters(editors["length"]) |
|
266 elif editortype == "number": |
|
267 editor = wxGridCellNumberEditor() |
|
268 renderer = wxGridCellNumberRenderer() |
|
269 if colname == "value" and "min" in editors and "max" in editors: |
|
270 editor.SetParameters("%s,%s"%(editors["min"],editors["max"])) |
|
271 elif editortype == "real": |
|
272 editor = wxGridCellFloatEditor() |
|
273 renderer = wxGridCellFloatRenderer() |
|
274 if colname == "value" and "min" in editors and "max" in editors: |
|
275 editor.SetParameters("%s,%s"%(editors["min"],editors["max"])) |
|
276 elif editortype == "bool": |
|
277 editor = wxGridCellChoiceEditor() |
|
278 editor.SetParameters(BoolList) |
|
279 elif editortype == "access": |
|
280 editor = wxGridCellChoiceEditor() |
|
281 editor.SetParameters(AccessList) |
|
282 elif editortype == "raccess": |
|
283 editor = wxGridCellChoiceEditor() |
|
284 editor.SetParameters(RAccessList) |
|
285 elif editortype == "option": |
|
286 editor = wxGridCellChoiceEditor() |
|
287 editor.SetParameters(OptionList) |
|
288 elif editortype == "type": |
|
289 editor = wxGridCellChoiceEditor() |
|
290 editor.SetParameters(self.Parent.Manager.GetCurrentTypeList()) |
|
291 elif editortype == "map": |
|
292 editor = wxGridCellChoiceEditor() |
|
293 editor.SetParameters(self.Parent.Manager.GetCurrentMapList()) |
|
294 elif editortype == "time": |
|
295 editor = wxGridCellTextEditor() |
|
296 renderer = wxGridCellStringRenderer() |
|
297 elif editortype == "domain": |
|
298 editor = wxGridCellTextEditor() |
|
299 renderer = wxGridCellStringRenderer() |
|
300 else: |
|
301 grid.SetReadOnly(row, col, True) |
|
302 |
|
303 grid.SetCellEditor(row, col, editor) |
|
304 grid.SetCellRenderer(row, col, renderer) |
|
305 |
|
306 grid.SetCellBackgroundColour(row, col, wxWHITE) |
|
307 |
|
308 def SetData(self, data): |
|
309 self.data = data |
|
310 |
|
311 def SetEditors(self, editors): |
|
312 self.editors = editors |
|
313 |
|
314 def GetCurrentIndex(self): |
|
315 return self.CurrentIndex |
|
316 |
|
317 def SetCurrentIndex(self, index): |
|
318 self.CurrentIndex = index |
|
319 |
|
320 def AppendRow(self, row_content): |
|
321 self.data.append(row_content) |
|
322 |
|
323 def Empty(self): |
|
324 self.data = [] |
|
325 self.editors = [] |
|
326 |
|
327 [wxID_EDITINGPANEL, wxID_EDITINGPANELADDBUTTON, wxID_EDITINGPANELINDEXCHOICE, |
|
328 wxID_EDITINGPANELINDEXLIST, wxID_EDITINGPANELINDEXLISTPANEL, wxID_EDITINGPANELPARTLIST, |
|
329 wxID_EDITINGPANELSECONDSPLITTER, wxID_EDITINGPANELSUBINDEXGRID, |
|
330 wxID_EDITINGPANELSUBINDEXGRIDPANEL, wxID_EDITINGPANELCALLBACKCHECK, |
|
331 ] = [wx.NewId() for _init_ctrls in range(10)] |
|
332 |
|
333 [wxID_EDITINGPANELINDEXLISTMENUITEMS0, wxID_EDITINGPANELINDEXLISTMENUITEMS1, |
|
334 wxID_EDITINGPANELINDEXLISTMENUITEMS2, |
|
335 ] = [wx.NewId() for _init_coll_IndexListMenu_Items in range(3)] |
|
336 |
|
337 [wxID_EDITINGPANELMENU1ITEMS0, wxID_EDITINGPANELMENU1ITEMS1, |
|
338 ] = [wx.NewId() for _init_coll_SubindexGridMenu_Items in range(2)] |
|
339 |
|
340 class EditingPanel(wx.SplitterWindow): |
|
341 def _init_coll_AddToListSizer_Items(self, parent): |
|
342 # generated method, don't edit |
|
343 |
|
344 parent.AddWindow(self.AddButton, 0, border=0, flag=0) |
|
345 parent.AddWindow(self.IndexChoice, 0, border=0, flag=wxGROW) |
|
346 |
|
347 def _init_coll_SubindexGridSizer_Items(self, parent): |
|
348 # generated method, don't edit |
|
349 |
|
350 parent.AddWindow(self.CallbackCheck, 0, border=0, flag=0) |
|
351 parent.AddWindow(self.SubindexGrid, 0, border=0, flag=wxGROW) |
|
352 |
|
353 def _init_coll_IndexListSizer_Items(self, parent): |
|
354 # generated method, don't edit |
|
355 |
|
356 parent.AddWindow(self.IndexList, 0, border=0, flag=wxGROW) |
|
357 parent.AddSizer(self.AddToListSizer, 0, border=0, flag=wxGROW) |
|
358 |
|
359 def _init_coll_AddToListSizer_Growables(self, parent): |
|
360 # generated method, don't edit |
|
361 |
|
362 parent.AddGrowableCol(1) |
|
363 |
|
364 def _init_coll_SubindexGridSizer_Growables(self, parent): |
|
365 # generated method, don't edit |
|
366 |
|
367 parent.AddGrowableCol(0) |
|
368 parent.AddGrowableRow(1) |
|
369 |
|
370 def _init_coll_IndexListSizer_Growables(self, parent): |
|
371 # generated method, don't edit |
|
372 |
|
373 parent.AddGrowableCol(0) |
|
374 parent.AddGrowableRow(0) |
|
375 |
|
376 def _init_coll_SubindexGridMenu_Items(self, parent): |
|
377 # generated method, don't edit |
|
378 |
|
379 parent.Append(help='', id=wxID_EDITINGPANELMENU1ITEMS0, |
|
380 kind=wx.ITEM_NORMAL, text='Add') |
|
381 parent.Append(help='', id=wxID_EDITINGPANELMENU1ITEMS1, |
|
382 kind=wx.ITEM_NORMAL, text='Delete') |
|
383 self.Bind(wx.EVT_MENU, self.OnAddSubindexMenu, |
|
384 id=wxID_EDITINGPANELMENU1ITEMS0) |
|
385 self.Bind(wx.EVT_MENU, self.OnDeleteSubindexMenu, |
|
386 id=wxID_EDITINGPANELMENU1ITEMS1) |
|
387 |
|
388 def _init_coll_IndexListMenu_Items(self, parent): |
|
389 # generated method, don't edit |
|
390 |
|
391 parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS0, |
|
392 kind=wx.ITEM_NORMAL, text='Rename') |
|
393 parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS2, |
|
394 kind=wx.ITEM_NORMAL, text='Modify') |
|
395 parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS1, |
|
396 kind=wx.ITEM_NORMAL, text='Delete') |
|
397 self.Bind(wx.EVT_MENU, self.OnRenameIndexMenu, |
|
398 id=wxID_EDITINGPANELINDEXLISTMENUITEMS0) |
|
399 self.Bind(wx.EVT_MENU, self.OnDeleteIndexMenu, |
|
400 id=wxID_EDITINGPANELINDEXLISTMENUITEMS1) |
|
401 self.Bind(wx.EVT_MENU, self.OnModifyIndexMenu, |
|
402 id=wxID_EDITINGPANELINDEXLISTMENUITEMS2) |
|
403 |
|
404 def _init_utils(self): |
|
405 # generated method, don't edit |
|
406 self.IndexListMenu = wx.Menu(title='') |
|
407 |
|
408 self.SubindexGridMenu = wx.Menu(title='') |
|
409 |
|
410 self._init_coll_IndexListMenu_Items(self.IndexListMenu) |
|
411 self._init_coll_SubindexGridMenu_Items(self.SubindexGridMenu) |
|
412 |
|
413 def _init_sizers(self): |
|
414 # generated method, don't edit |
|
415 self.IndexListSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
416 |
|
417 self.SubindexGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
418 |
|
419 self.AddToListSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0) |
|
420 |
|
421 self._init_coll_IndexListSizer_Growables(self.IndexListSizer) |
|
422 self._init_coll_IndexListSizer_Items(self.IndexListSizer) |
|
423 self._init_coll_SubindexGridSizer_Growables(self.SubindexGridSizer) |
|
424 self._init_coll_SubindexGridSizer_Items(self.SubindexGridSizer) |
|
425 self._init_coll_AddToListSizer_Growables(self.AddToListSizer) |
|
426 self._init_coll_AddToListSizer_Items(self.AddToListSizer) |
|
427 |
|
428 self.SubindexGridPanel.SetSizer(self.SubindexGridSizer) |
|
429 self.IndexListPanel.SetSizer(self.IndexListSizer) |
|
430 |
|
431 def _init_ctrls(self, prnt): |
|
432 wx.SplitterWindow.__init__(self, id=wxID_EDITINGPANEL, |
|
433 name='MainSplitter', parent=prnt, point=wx.Point(0, 0), |
|
434 size=wx.Size(-1, -1), style=wx.SP_3D) |
|
435 self._init_utils() |
|
436 self.SetNeedUpdating(True) |
|
437 self.SetMinimumPaneSize(1) |
|
438 |
|
439 self.PartList = wx.ListBox(choices=[], id=wxID_EDITINGPANELPARTLIST, |
|
440 name='PartList', parent=self, pos=wx.Point(0, 0), |
|
441 size=wx.Size(-1, -1), style=0) |
|
442 self.PartList.Bind(wx.EVT_LISTBOX, self.OnPartListBoxClick, |
|
443 id=wxID_EDITINGPANELPARTLIST) |
|
444 |
|
445 self.SecondSplitter = wx.SplitterWindow(id=wxID_EDITINGPANELSECONDSPLITTER, |
|
446 name='SecondSplitter', parent=self, point=wx.Point(0, |
|
447 0), size=wx.Size(-1, -1), style=wx.SP_3D) |
|
448 self.SecondSplitter.SetMinimumPaneSize(1) |
|
449 self.SplitHorizontally(self.PartList, self.SecondSplitter, |
|
450 110) |
|
451 |
|
452 self.SubindexGridPanel = wx.Panel(id=wxID_EDITINGPANELSUBINDEXGRIDPANEL, |
|
453 name='SubindexGridPanel', parent=self.SecondSplitter, pos=wx.Point(0, |
|
454 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) |
|
455 |
|
456 self.IndexListPanel = wx.Panel(id=wxID_EDITINGPANELINDEXLISTPANEL, |
|
457 name='IndexListPanel', parent=self.SecondSplitter, pos=wx.Point(0, |
|
458 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) |
|
459 self.SecondSplitter.SplitVertically(self.IndexListPanel, |
|
460 self.SubindexGridPanel, 280) |
|
461 |
|
462 self.SubindexGrid = wx.grid.Grid(id=wxID_EDITINGPANELSUBINDEXGRID, |
|
463 name='SubindexGrid', parent=self.SubindexGridPanel, pos=wx.Point(0, |
|
464 0), size=wx.Size(-1, -1), style=0) |
|
465 self.SubindexGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
|
466 'Sans')) |
|
467 self.SubindexGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
468 False, 'Sans')) |
|
469 self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, |
|
470 self.OnSubindexGridCellChange) |
|
471 self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, |
|
472 self.OnSubindexGridRightClick) |
|
473 self.SubindexGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL, |
|
474 self.OnSubindexGridSelectCell) |
|
475 |
|
476 self.CallbackCheck = wx.CheckBox(id=wxID_EDITINGPANELCALLBACKCHECK, |
|
477 label='Have Callbacks', name='CallbackCheck', |
|
478 parent=self.SubindexGridPanel, pos=wx.Point(0, 0), size=wx.Size(152, |
|
479 24), style=0) |
|
480 self.CallbackCheck.Bind(wx.EVT_CHECKBOX, self.OnCallbackCheck, |
|
481 id=wxID_EDITINGPANELCALLBACKCHECK) |
|
482 |
|
483 self.IndexList = wx.ListBox(choices=[], id=wxID_EDITINGPANELINDEXLIST, |
|
484 name='IndexList', parent=self.IndexListPanel, pos=wx.Point(0, 0), |
|
485 size=wx.Size(-1, -1), style=0) |
|
486 self.IndexList.Bind(wx.EVT_LISTBOX, self.OnIndexListClick, |
|
487 id=wxID_EDITINGPANELINDEXLIST) |
|
488 self.IndexList.Bind(wx.EVT_RIGHT_UP, self.OnIndexListRightUp) |
|
489 |
|
490 self.AddButton = wx.Button(id=wxID_EDITINGPANELADDBUTTON, label='Add', |
|
491 name='AddButton', parent=self.IndexListPanel, pos=wx.Point(0, 0), |
|
492 size=wx.Size(50, 30), style=0) |
|
493 self.AddButton.Bind(wx.EVT_BUTTON, self.OnAddButtonClick, |
|
494 id=wxID_EDITINGPANELADDBUTTON) |
|
495 |
|
496 self.IndexChoice = wx.Choice(choices=[], id=wxID_EDITINGPANELINDEXCHOICE, |
|
497 name='IndexChoice', parent=self.IndexListPanel, pos=wx.Point(50, |
|
498 0), size=wx.Size(-1, 30), style=0) |
|
499 |
|
500 self._init_sizers() |
|
501 |
|
502 def __init__(self, parent, manager): |
|
503 self._init_ctrls(parent.GetNoteBook()) |
|
504 self.Parent = parent |
|
505 self.Manager = manager |
|
506 self.ListIndex = [] |
|
507 self.ChoiceIndex = [] |
|
508 self.FirstCall = False |
|
509 |
|
510 for values in DictionaryOrganisation: |
|
511 text = " 0x%04X-0x%04X %s"%(values["minIndex"],values["maxIndex"],values["name"]) |
|
512 self.PartList.Append(text) |
|
513 self.Table = SubindexTable(self, [], [], ["subindex", "name", "type", "value", "access", "save", "comment"]) |
|
514 self.SubindexGrid.SetTable(self.Table) |
|
515 self.SubindexGrid.SetRowLabelSize(0) |
|
516 self.CallbackCheck.Disable() |
|
517 self.Table.ResetView(self.SubindexGrid) |
|
518 |
|
519 def GetSelection(self): |
|
520 selected = self.IndexList.GetSelection() |
|
521 if selected != wxNOT_FOUND: |
|
522 index = self.ListIndex[selected] |
|
523 subIndex = self.SubindexGrid.GetGridCursorRow() |
|
524 return index, subIndex |
|
525 return None |
|
526 |
|
527 def OnAddButtonClick(self, event): |
|
528 self.SubindexGrid.SetGridCursor(0, 0) |
|
529 selected = self.IndexChoice.GetStringSelection() |
|
530 if selected != "": |
|
531 if selected == "User Type": |
|
532 self.Parent.AddUserType() |
|
533 elif selected == "SDO Server": |
|
534 self.Manager.AddSDOServerToCurrent() |
|
535 elif selected == "SDO Client": |
|
536 self.Manager.AddSDOClientToCurrent() |
|
537 elif selected == "PDO Receive": |
|
538 self.Manager.AddPDOReceiveToCurrent() |
|
539 elif selected == "PDO Transmit": |
|
540 self.Manager.AddPDOTransmitToCurrent() |
|
541 elif selected == "Map Variable": |
|
542 self.Parent.AddMapVariable() |
|
543 elif selected in [menu for menu, indexes in self.Manager.GetCurrentSpecificMenu()]: |
|
544 self.Manager.AddSpecificEntryToCurrent(selected) |
|
545 else: |
|
546 index = self.ChoiceIndex[self.IndexChoice.GetSelection()] |
|
547 self.Manager.ManageEntriesOfCurrent([index], []) |
|
548 self.Parent.RefreshBufferState() |
|
549 self.RefreshIndexList() |
|
550 event.Skip() |
|
551 |
|
552 def OnPartListBoxClick(self, event): |
|
553 self.SubindexGrid.SetGridCursor(0, 0) |
|
554 self.RefreshIndexList() |
|
555 event.Skip() |
|
556 |
|
557 def OnIndexListClick(self, event): |
|
558 self.SubindexGrid.SetGridCursor(0, 0) |
|
559 self.RefreshTable() |
|
560 event.Skip() |
|
561 |
|
562 def OnSubindexGridSelectCell(self, event): |
|
563 wxCallAfter(self.Parent.RefreshStatusBar) |
|
564 event.Skip() |
|
565 |
|
566 #------------------------------------------------------------------------------- |
|
567 # Refresh Functions |
|
568 #------------------------------------------------------------------------------- |
|
569 |
|
570 def RefreshIndexList(self): |
|
571 selected = self.IndexList.GetSelection() |
|
572 choice = self.IndexChoice.GetStringSelection() |
|
573 choiceindex = self.IndexChoice.GetSelection() |
|
574 if selected != wxNOT_FOUND: |
|
575 selectedindex = self.ListIndex[selected] |
|
576 self.IndexList.Clear() |
|
577 self.IndexChoice.Clear() |
|
578 i = self.PartList.GetSelection() |
|
579 if i < len(DictionaryOrganisation): |
|
580 values = DictionaryOrganisation[i] |
|
581 self.ListIndex = [] |
|
582 for name, index in self.Manager.GetCurrentValidIndexes(values["minIndex"], values["maxIndex"]): |
|
583 self.IndexList.Append("0x%04X %s"%(index, name)) |
|
584 self.ListIndex.append(index) |
|
585 self.ChoiceIndex = [] |
|
586 if i == 0: |
|
587 self.IndexChoice.Append("User Type") |
|
588 self.IndexChoice.SetStringSelection("User Type") |
|
589 elif i == 2: |
|
590 self.IndexChoice.Append("SDO Server") |
|
591 self.IndexChoice.Append("SDO Client") |
|
592 if choiceindex != wxNOT_FOUND and choice == self.IndexChoice.GetString(choiceindex): |
|
593 self.IndexChoice.SetStringSelection(choice) |
|
594 elif i in (3, 4): |
|
595 self.IndexChoice.Append("PDO Receive") |
|
596 self.IndexChoice.SetStringSelection("PDO Receive") |
|
597 elif i in (5, 6): |
|
598 self.IndexChoice.Append("PDO Transmit") |
|
599 self.IndexChoice.SetStringSelection("PDO Transmit") |
|
600 elif i == 8: |
|
601 self.IndexChoice.Append("Map Variable") |
|
602 self.IndexChoice.SetStringSelection("Map Variable") |
|
603 else: |
|
604 for name, index in self.Manager.GetCurrentValidChoices(values["minIndex"], values["maxIndex"]): |
|
605 if index: |
|
606 self.IndexChoice.Append("0x%04X %s"%(index, name)) |
|
607 else: |
|
608 self.IndexChoice.Append(name) |
|
609 self.ChoiceIndex.append(index) |
|
610 if choiceindex != wxNOT_FOUND and choice == self.IndexChoice.GetString(choiceindex): |
|
611 self.IndexChoice.SetStringSelection(choice) |
|
612 self.IndexChoice.Enable(self.IndexChoice.GetCount() != 0) |
|
613 self.AddButton.Enable(self.IndexChoice.GetCount() != 0) |
|
614 if selected == wxNOT_FOUND or selected >= len(self.ListIndex) or selectedindex != self.ListIndex[selected]: |
|
615 self.Table.Empty() |
|
616 self.CallbackCheck.SetValue(False) |
|
617 self.CallbackCheck.Disable() |
|
618 self.Table.ResetView(self.SubindexGrid) |
|
619 self.Parent.RefreshStatusBar() |
|
620 else: |
|
621 self.IndexList.SetSelection(selected) |
|
622 self.RefreshTable() |
|
623 |
|
624 def RefreshTable(self): |
|
625 selected = self.IndexList.GetSelection() |
|
626 if selected != wxNOT_FOUND: |
|
627 index = self.ListIndex[selected] |
|
628 if index > 0x260: |
|
629 self.CallbackCheck.Enable() |
|
630 self.CallbackCheck.SetValue(self.Manager.HasCurrentEntryCallbacks(index)) |
|
631 result = self.Manager.GetCurrentEntryValues(index) |
|
632 if result != None: |
|
633 self.Table.SetCurrentIndex(index) |
|
634 data, editors = result |
|
635 self.Table.SetData(data) |
|
636 self.Table.SetEditors(editors) |
|
637 self.Table.ResetView(self.SubindexGrid) |
|
638 self.Parent.RefreshStatusBar() |
|
639 |
|
640 #------------------------------------------------------------------------------- |
|
641 # Editing Table value function |
|
642 #------------------------------------------------------------------------------- |
|
643 |
|
644 def OnSubindexGridCellChange(self, event): |
|
645 index = self.Table.GetCurrentIndex() |
|
646 subIndex = event.GetRow() |
|
647 col = event.GetCol() |
|
648 name = self.Table.GetColLabelValue(col) |
|
649 value = self.Table.GetValue(subIndex, col) |
|
650 editor = self.Table.GetEditor(subIndex, col) |
|
651 self.Manager.SetCurrentEntry(index, subIndex, value, name, editor) |
|
652 self.Parent.RefreshBufferState() |
|
653 wxCallAfter(self.RefreshTable) |
|
654 event.Skip() |
|
655 |
|
656 def OnCallbackCheck(self, event): |
|
657 index = self.Table.GetCurrentIndex() |
|
658 self.Manager.SetCurrentEntryCallbacks(index, self.CallbackCheck.GetValue()) |
|
659 self.Parent.RefreshBufferState() |
|
660 wxCallAfter(self.RefreshTable) |
|
661 event.Skip() |
|
662 |
|
663 #------------------------------------------------------------------------------- |
|
664 # Contextual Menu functions |
|
665 #------------------------------------------------------------------------------- |
|
666 |
|
667 def OnIndexListRightUp(self, event): |
|
668 if not self.FirstCall: |
|
669 self.FirstCall = True |
|
670 selected = self.IndexList.GetSelection() |
|
671 if selected != wxNOT_FOUND: |
|
672 index = self.ListIndex[selected] |
|
673 if index < 0x260: |
|
674 self.IndexListMenu.FindItemByPosition(0).Enable(False) |
|
675 self.IndexListMenu.FindItemByPosition(1).Enable(True) |
|
676 self.PopupMenu(self.IndexListMenu) |
|
677 elif 0x1000 <= index <= 0x1BFF: |
|
678 self.IndexListMenu.FindItemByPosition(0).Enable(False) |
|
679 self.IndexListMenu.FindItemByPosition(1).Enable(False) |
|
680 self.PopupMenu(self.IndexListMenu) |
|
681 elif 0x2000 <= index <= 0x5FFF: |
|
682 self.IndexListMenu.FindItemByPosition(0).Enable(True) |
|
683 self.IndexListMenu.FindItemByPosition(1).Enable(False) |
|
684 self.PopupMenu(self.IndexListMenu) |
|
685 elif index >= 0x6000: |
|
686 self.IndexListMenu.FindItemByPosition(0).Enable(False) |
|
687 self.IndexListMenu.FindItemByPosition(1).Enable(False) |
|
688 self.PopupMenu(self.IndexListMenu) |
|
689 else: |
|
690 self.FirstCall = False |
|
691 event.Skip() |
|
692 |
|
693 def OnSubindexGridRightClick(self, event): |
|
694 selected = self.IndexList.GetSelection() |
|
695 if selected != wxNOT_FOUND: |
|
696 index = self.ListIndex[selected] |
|
697 if self.Manager.IsCurrentEntry(index): |
|
698 infos = self.Manager.GetEntryInfos(index) |
|
699 if index >= 0x2000 and infos["struct"] & OD_MultipleSubindexes or infos["struct"] & OD_IdenticalSubindexes: |
|
700 self.PopupMenu(self.SubindexGridMenu) |
|
701 event.Skip() |
|
702 |
|
703 def OnRenameIndexMenu(self, event): |
|
704 selected = self.IndexList.GetSelection() |
|
705 if selected != wxNOT_FOUND: |
|
706 index = self.ListIndex[selected] |
|
707 if self.Manager.IsCurrentEntry(index): |
|
708 infos = self.Manager.GetEntryInfos(index) |
|
709 dialog = wxTextEntryDialog(self, "Give a new name for index 0x%04X"%index, |
|
710 "Rename an index", infos["name"], wxOK|wxCANCEL) |
|
711 if dialog.ShowModal() == wxID_OK: |
|
712 self.Manager.SetCurrentEntryName(index, dialog.GetValue()) |
|
713 self.Parent.RefreshBufferState() |
|
714 self.RefreshIndexList() |
|
715 dialog.Destroy() |
|
716 event.Skip() |
|
717 |
|
718 def OnModifyIndexMenu(self, event): |
|
719 selected = self.IndexList.GetSelection() |
|
720 if selected != wxNOT_FOUND: |
|
721 index = self.ListIndex[selected] |
|
722 if self.Manager.IsCurrentEntry(index) and index < 0x260: |
|
723 values, valuetype = self.Manager.GetCustomisedTypeValues(index) |
|
724 dialog = UserTypeDialog(self) |
|
725 dialog.SetTypeList(self.Manager.GetCustomisableTypes(), values[1]) |
|
726 if valuetype == 0: |
|
727 dialog.SetValues(min = values[2], max = values[3]) |
|
728 elif valuetype == 1: |
|
729 dialog.SetValues(length = values[2]) |
|
730 if dialog.ShowModal() == wxID_OK: |
|
731 type, min, max, length = dialog.GetValues() |
|
732 self.Manager.SetCurrentUserType(index, type, min, max, length) |
|
733 self.Parent.RefreshBufferState() |
|
734 self.RefreshIndexList() |
|
735 event.Skip() |
|
736 |
|
737 def OnDeleteIndexMenu(self, event): |
|
738 selected = self.IndexList.GetSelection() |
|
739 if selected != wxNOT_FOUND: |
|
740 index = self.ListIndex[selected] |
|
741 if self.Manager.IsCurrentEntry(index): |
|
742 self.Manager.ManageEntriesOfCurrent([],[index]) |
|
743 self.Parent.RefreshBufferState() |
|
744 self.RefreshIndexList() |
|
745 event.Skip() |
|
746 |
|
747 def OnAddSubindexMenu(self, event): |
|
748 selected = self.IndexList.GetSelection() |
|
749 if selected != wxNOT_FOUND: |
|
750 index = self.ListIndex[selected] |
|
751 if self.Manager.IsCurrentEntry(index): |
|
752 dialog = wxTextEntryDialog(self, "Number of subindexes to add:", |
|
753 "Add subindexes", "1", wxOK|wxCANCEL) |
|
754 if dialog.ShowModal() == wxID_OK: |
|
755 try: |
|
756 number = int(dialog.GetValue()) |
|
757 self.Manager.AddSubentriesToCurrent(index, number) |
|
758 self.Parent.RefreshBufferState() |
|
759 self.RefreshIndexList() |
|
760 except: |
|
761 message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR) |
|
762 message.ShowModal() |
|
763 message.Destroy() |
|
764 dialog.Destroy() |
|
765 event.Skip() |
|
766 |
|
767 def OnDeleteSubindexMenu(self, event): |
|
768 selected = self.IndexList.GetSelection() |
|
769 if selected != wxNOT_FOUND: |
|
770 index = self.ListIndex[selected] |
|
771 if self.Manager.IsCurrentEntry(index): |
|
772 dialog = wxTextEntryDialog(self, "Number of subindexes to delete:", |
|
773 "Delete subindexes", "1", wxOK|wxCANCEL) |
|
774 if dialog.ShowModal() == wxID_OK: |
|
775 try: |
|
776 number = int(dialog.GetValue()) |
|
777 self.Manager.RemoveSubentriesFromCurrent(index, number) |
|
778 self.Parent.RefreshBufferState() |
|
779 self.RefreshIndexList() |
|
780 except: |
|
781 message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR) |
|
782 message.ShowModal() |
|
783 message.Destroy() |
|
784 dialog.Destroy() |
|
785 event.Skip() |
|
786 |
129 |
787 [wxID_OBJDICTEDIT, wxID_OBJDICTEDITFILEOPENED, |
130 [wxID_OBJDICTEDIT, wxID_OBJDICTEDITFILEOPENED, |
788 wxID_OBJDICTEDITHELPBAR, |
131 wxID_OBJDICTEDITHELPBAR, |
789 ] = [wx.NewId() for _init_ctrls in range(3)] |
132 ] = [wx.NewId() for _init_ctrls in range(3)] |
790 |
133 |
1549 dialog = UserTypeDialog(self) |
898 dialog = UserTypeDialog(self) |
1550 dialog.SetTypeList(self.Manager.GetCustomisableTypes()) |
899 dialog.SetTypeList(self.Manager.GetCustomisableTypes()) |
1551 if dialog.ShowModal() == wxID_OK: |
900 if dialog.ShowModal() == wxID_OK: |
1552 type, min, max, length = dialog.GetValues() |
901 type, min, max, length = dialog.GetValues() |
1553 result = self.Manager.AddUserTypeToCurrent(type, min, max, length) |
902 result = self.Manager.AddUserTypeToCurrent(type, min, max, length) |
1554 if not IsOfType(result, StringType): |
903 if not result: |
1555 self.RefreshBufferState() |
904 self.RefreshBufferState() |
1556 self.RefreshCurrentIndexList() |
905 self.RefreshCurrentIndexList() |
1557 else: |
906 else: |
1558 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
907 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
1559 message.ShowModal() |
908 message.ShowModal() |
1560 message.Destroy() |
909 message.Destroy() |
1561 dialog.Destroy() |
910 dialog.Destroy() |
1562 |
|
1563 |
|
1564 |
|
1565 #------------------------------------------------------------------------------- |
|
1566 # Editing Communication Dialog |
|
1567 #------------------------------------------------------------------------------- |
|
1568 |
|
1569 |
|
1570 [wxID_COMMUNICATIONDIALOG, wxID_COMMUNICATIONDIALOGMAINPANEL, |
|
1571 wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES, wxID_COMMUNICATIONDIALOGCURRENTINDEXES, |
|
1572 wxID_COMMUNICATIONDIALOGSELECT, wxID_COMMUNICATIONDIALOGUNSELECT, |
|
1573 wxID_COMMUNICATIONDIALOGSTATICTEXT1, wxID_COMMUNICATIONDIALOGSTATICTEXT2 |
|
1574 ] = [wx.NewId() for _init_ctrls in range(8)] |
|
1575 |
|
1576 class CommunicationDialog(wx.Dialog): |
|
1577 def _init_coll_flexGridSizer1_Items(self, parent): |
|
1578 # generated method, don't edit |
|
1579 |
|
1580 parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1581 |
|
1582 def _init_sizers(self): |
|
1583 # generated method, don't edit |
|
1584 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1585 |
|
1586 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1587 |
|
1588 self.SetSizer(self.flexGridSizer1) |
|
1589 |
|
1590 def _init_ctrls(self, prnt): |
|
1591 # generated method, don't edit |
|
1592 wx.Dialog.__init__(self, id=wxID_COMMUNICATIONDIALOG, |
|
1593 name='CommunicationDialog', parent=prnt, pos=wx.Point(234, 216), |
|
1594 size=wx.Size(726, 437), style=wx.DEFAULT_DIALOG_STYLE, |
|
1595 title='Edit Communication Profile') |
|
1596 self.SetClientSize(wx.Size(726, 437)) |
|
1597 |
|
1598 self.MainPanel = wx.Panel(id=wxID_COMMUNICATIONDIALOGMAINPANEL, |
|
1599 name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1600 size=wx.Size(688, 382), style=wx.TAB_TRAVERSAL) |
|
1601 self.MainPanel.SetAutoLayout(True) |
|
1602 |
|
1603 self.PossibleIndexes = wx.ListBox(choices=[], |
|
1604 id=wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES, |
|
1605 name='PossibleIndexes', parent=self.MainPanel, pos=wx.Point(40, |
|
1606 48), size=wx.Size(280, 320), style=wxLB_EXTENDED) |
|
1607 self.PossibleIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnPossibleIndexesDClick, |
|
1608 id=wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES) |
|
1609 |
|
1610 self.CurrentIndexes = wx.ListBox(choices=[], |
|
1611 id=wxID_COMMUNICATIONDIALOGCURRENTINDEXES, name='CurrentIndexes', |
|
1612 parent=self.MainPanel, pos=wx.Point(400, 48), size=wx.Size(280, |
|
1613 320), style=wxLB_EXTENDED) |
|
1614 self.CurrentIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnCurrentIndexesDClick, |
|
1615 id=wxID_COMMUNICATIONDIALOGCURRENTINDEXES) |
|
1616 |
|
1617 self.Select = wx.Button(id=wxID_COMMUNICATIONDIALOGSELECT, label='>>', |
|
1618 name='Select', parent=self.MainPanel, pos=wx.Point(345, 136), |
|
1619 size=wx.Size(32, 32), style=0) |
|
1620 self.Select.Bind(wx.EVT_BUTTON, self.OnSelectButton, |
|
1621 id=wxID_COMMUNICATIONDIALOGSELECT) |
|
1622 |
|
1623 self.Unselect = wx.Button(id=wxID_COMMUNICATIONDIALOGUNSELECT, |
|
1624 label='<<', name='Unselect', parent=self.MainPanel, |
|
1625 pos=wx.Point(345, 216), size=wx.Size(32, 30), style=0) |
|
1626 self.Unselect.Bind(wx.EVT_BUTTON, self.OnUnselectButton, |
|
1627 id=wxID_COMMUNICATIONDIALOGUNSELECT) |
|
1628 |
|
1629 self.staticText1 = wx.StaticText(id=wxID_COMMUNICATIONDIALOGSTATICTEXT1, |
|
1630 label='Possible Profile Indexes:', name='staticText1', |
|
1631 parent=self.MainPanel, pos=wx.Point(40, 24), size=wx.Size(156, |
|
1632 17), style=0) |
|
1633 |
|
1634 self.staticText2 = wx.StaticText(id=wxID_COMMUNICATIONDIALOGSTATICTEXT2, |
|
1635 label='Current Profile Indexes:', name='staticText2', |
|
1636 parent=self.MainPanel, pos=wx.Point(400, 24), size=wx.Size(152, |
|
1637 17), style=0) |
|
1638 |
|
1639 self._init_sizers() |
|
1640 |
|
1641 def __init__(self, parent): |
|
1642 self._init_ctrls(parent) |
|
1643 self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) |
|
1644 self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER) |
|
1645 self.AllList = [] |
|
1646 self.CurrentList = [] |
|
1647 self.IndexDictionary = {} |
|
1648 |
|
1649 def SetIndexDictionary(self, dictionary): |
|
1650 self.IndexDictionary = dictionary |
|
1651 |
|
1652 def SetCurrentList(self, list): |
|
1653 self.CurrentList = [] |
|
1654 self.CurrentList.extend(list) |
|
1655 self.CurrentList.sort() |
|
1656 |
|
1657 def GetCurrentList(self): |
|
1658 return self.CurrentList |
|
1659 |
|
1660 def RefreshLists(self): |
|
1661 self.PossibleIndexes.Clear() |
|
1662 self.CurrentIndexes.Clear() |
|
1663 self.AllList = [] |
|
1664 for index in self.IndexDictionary.iterkeys(): |
|
1665 if index not in self.CurrentList: |
|
1666 self.AllList.append(index) |
|
1667 self.AllList.sort() |
|
1668 for index in self.AllList: |
|
1669 self.PossibleIndexes.Append("0x%04X %s"%(index, self.IndexDictionary[index][0])) |
|
1670 for index in self.CurrentList: |
|
1671 if index in self.IndexDictionary: |
|
1672 self.CurrentIndexes.Append("0x%04X %s"%(index, self.IndexDictionary[index][0])) |
|
1673 |
|
1674 def OnPossibleIndexesDClick(self, event): |
|
1675 self.SelectPossible() |
|
1676 event.Skip() |
|
1677 |
|
1678 def OnCurrentIndexesDClick(self, event): |
|
1679 self.UnselectCurrent() |
|
1680 event.Skip() |
|
1681 |
|
1682 def OnSelectButton(self, event): |
|
1683 self.SelectPossible() |
|
1684 event.Skip() |
|
1685 |
|
1686 def OnUnselectButton(self, event): |
|
1687 self.UnselectCurrent() |
|
1688 event.Skip() |
|
1689 |
|
1690 def SelectPossible(self): |
|
1691 selected = self.PossibleIndexes.GetSelections() |
|
1692 for i in selected: |
|
1693 self.CurrentList.append(self.AllList[i]) |
|
1694 self.CurrentList.sort() |
|
1695 self.RefreshLists() |
|
1696 |
|
1697 def UnselectCurrent(self): |
|
1698 selected = self.CurrentIndexes.GetSelections() |
|
1699 for i in selected: |
|
1700 if not self.IndexDictionary[self.CurrentList[i]][1]: |
|
1701 self.CurrentList.pop(i) |
|
1702 self.CurrentList.sort() |
|
1703 self.RefreshLists() |
|
1704 |
|
1705 |
|
1706 |
|
1707 #------------------------------------------------------------------------------- |
|
1708 # Create Map Variable Dialog |
|
1709 #------------------------------------------------------------------------------- |
|
1710 |
|
1711 |
|
1712 [wxID_MAPVARIABLEDIALOG, wxID_MAPVARIABLEDIALOGINDEX, |
|
1713 wxID_MAPVARIABLEDIALOGINDEXNAME, wxID_MAPVARIABLEDIALOGMAINPANEL, |
|
1714 wxID_MAPVARIABLEDIALOGNUMBER, wxID_MAPVARIABLEDIALOGRADIOBUTTON1, |
|
1715 wxID_MAPVARIABLEDIALOGRADIOBUTTON2, wxID_MAPVARIABLEDIALOGRADIOBUTTON3, |
|
1716 wxID_MAPVARIABLEDIALOGSTATICTEXT1, wxID_MAPVARIABLEDIALOGSTATICTEXT2, |
|
1717 wxID_MAPVARIABLEDIALOGSTATICTEXT3, wxID_MAPVARIABLEDIALOGSTATICTEXT4, |
|
1718 ] = [wx.NewId() for _init_ctrls in range(12)] |
|
1719 |
|
1720 class MapVariableDialog(wx.Dialog): |
|
1721 def _init_coll_flexGridSizer1_Items(self, parent): |
|
1722 # generated method, don't edit |
|
1723 |
|
1724 parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1725 |
|
1726 def _init_sizers(self): |
|
1727 # generated method, don't edit |
|
1728 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1729 |
|
1730 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1731 |
|
1732 self.SetSizer(self.flexGridSizer1) |
|
1733 |
|
1734 def _init_ctrls(self, prnt): |
|
1735 # generated method, don't edit |
|
1736 wx.Dialog.__init__(self, id=wxID_MAPVARIABLEDIALOG, |
|
1737 name='CommunicationDialog', parent=prnt, pos=wx.Point(376, 223), |
|
1738 size=wx.Size(444, 186), style=wx.DEFAULT_DIALOG_STYLE, |
|
1739 title='Add Map Variable') |
|
1740 self.SetClientSize(wx.Size(444, 186)) |
|
1741 |
|
1742 self.MainPanel = wx.Panel(id=wxID_MAPVARIABLEDIALOGMAINPANEL, |
|
1743 name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1744 size=wx.Size(431, 142), style=wx.TAB_TRAVERSAL) |
|
1745 self.MainPanel.SetAutoLayout(True) |
|
1746 |
|
1747 self.staticText1 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT1, |
|
1748 label='Index:', name='staticText1', parent=self.MainPanel, |
|
1749 pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0) |
|
1750 |
|
1751 self.Index = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGINDEX, name='Index', |
|
1752 parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(152, |
|
1753 25), style=0, value='0x2000') |
|
1754 |
|
1755 self.staticText3 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT3, |
|
1756 label='Name:', name='staticText3', parent=self.MainPanel, |
|
1757 pos=wx.Point(24, 80), size=wx.Size(47, 17), style=0) |
|
1758 |
|
1759 self.IndexName = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGINDEXNAME, |
|
1760 name='IndexName', parent=self.MainPanel, pos=wx.Point(24, 104), |
|
1761 size=wx.Size(152, 24), style=0, value='Undefined') |
|
1762 |
|
1763 self.staticText2 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT2, |
|
1764 label='Type:', name='staticText2', parent=self.MainPanel, |
|
1765 pos=wx.Point(208, 24), size=wx.Size(38, 17), style=0) |
|
1766 |
|
1767 self.radioButton1 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON1, |
|
1768 label='VAR', name='radioButton1', parent=self.MainPanel, |
|
1769 pos=wx.Point(208, 48), size=wx.Size(72, 24), style=wxRB_GROUP) |
|
1770 self.radioButton1.SetValue(True) |
|
1771 self.radioButton1.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton1Click, |
|
1772 id=wxID_MAPVARIABLEDIALOGRADIOBUTTON1) |
|
1773 |
|
1774 self.radioButton2 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON2, |
|
1775 label='ARRAY', name='radioButton2', parent=self.MainPanel, |
|
1776 pos=wx.Point(208, 72), size=wx.Size(80, 24), style=wxRB_SINGLE) |
|
1777 self.radioButton2.SetValue(False) |
|
1778 self.radioButton2.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton2Click, |
|
1779 id=wxID_MAPVARIABLEDIALOGRADIOBUTTON2) |
|
1780 |
|
1781 self.radioButton3 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON3, |
|
1782 label='REC', name='radioButton3', parent=self.MainPanel, |
|
1783 pos=wx.Point(208, 96), size=wx.Size(96, 24), style=wxRB_SINGLE) |
|
1784 self.radioButton3.SetValue(False) |
|
1785 self.radioButton3.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton3Click, |
|
1786 id=wxID_MAPVARIABLEDIALOGRADIOBUTTON3) |
|
1787 |
|
1788 self.staticText4 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT4, |
|
1789 label='Number:', name='staticText4', parent=self.MainPanel, |
|
1790 pos=wx.Point(312, 80), size=wx.Size(88, 16), style=0) |
|
1791 |
|
1792 self.Number = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGNUMBER, |
|
1793 name='Number', parent=self.MainPanel, pos=wx.Point(312, 104), |
|
1794 size=wx.Size(112, 24), style=wx.TE_RIGHT, value='0') |
|
1795 |
|
1796 self._init_sizers() |
|
1797 |
|
1798 def __init__(self, parent): |
|
1799 self._init_ctrls(parent) |
|
1800 self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) |
|
1801 self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER) |
|
1802 self.staticText4.Enable(False) |
|
1803 self.Number.Enable(False) |
|
1804 |
|
1805 EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
|
1806 |
|
1807 def SetIndex(self, index): |
|
1808 self.Index.SetValue("0x%04X"%index) |
|
1809 |
|
1810 def OnOK(self, event): |
|
1811 error = [] |
|
1812 try: |
|
1813 int(self.Index.GetValue(), 16) |
|
1814 except: |
|
1815 error.append("Index") |
|
1816 if self.radioButton2.GetValue() or self.radioButton3.GetValue(): |
|
1817 try: |
|
1818 int(self.Number.GetValue()) |
|
1819 except: |
|
1820 error.append("Number") |
|
1821 if len(error) > 0: |
|
1822 text = "" |
|
1823 if len(error) > 1: |
|
1824 suffix = "s" |
|
1825 else: |
|
1826 suffix = "" |
|
1827 for i, item in enumerate(error): |
|
1828 if i == 0: |
|
1829 text += item |
|
1830 elif i == len(error) - 1: |
|
1831 text += " and %s"%item |
|
1832 else: |
|
1833 text += ", %s"%item |
|
1834 message = wxMessageDialog(self, "Form isn't valid. %s must be integer%s!"%(text,suffix), "Error", wxOK|wxICON_ERROR) |
|
1835 message.ShowModal() |
|
1836 message.Destroy() |
|
1837 else: |
|
1838 self.EndModal(wxID_OK) |
|
1839 |
|
1840 def GetValues(self): |
|
1841 name = self.IndexName.GetValue() |
|
1842 index = int(self.Index.GetValue(), 16) |
|
1843 if self.radioButton1.GetValue(): |
|
1844 struct = 1 |
|
1845 number = None |
|
1846 elif self.radioButton2.GetValue(): |
|
1847 struct = 3 |
|
1848 number = int(self.Number.GetValue()) |
|
1849 elif self.radioButton3.GetValue(): |
|
1850 struct = 7 |
|
1851 number = int(self.Number.GetValue()) |
|
1852 return index, name, struct, number |
|
1853 |
|
1854 def OnRadioButton1Click(self, event): |
|
1855 self.EnableNumberTyping(False) |
|
1856 event.Skip() |
|
1857 |
|
1858 def OnRadioButton2Click(self, event): |
|
1859 self.EnableNumberTyping(True) |
|
1860 event.Skip() |
|
1861 |
|
1862 def OnRadioButton3Click(self, event): |
|
1863 self.EnableNumberTyping(True) |
|
1864 event.Skip() |
|
1865 |
|
1866 def EnableNumberTyping(self, enable): |
|
1867 self.staticText4.Enable(enable) |
|
1868 self.Number.Enable(enable) |
|
1869 |
|
1870 |
|
1871 #------------------------------------------------------------------------------- |
|
1872 # Create User Type Dialog |
|
1873 #------------------------------------------------------------------------------- |
|
1874 |
|
1875 |
|
1876 [wxID_USERTYPEDIALOG, wxID_USERTYPEDIALOGLENGTH, wxID_USERTYPEDIALOGMAINPANEL, |
|
1877 wxID_USERTYPEDIALOGMAX, wxID_USERTYPEDIALOGMIN, |
|
1878 wxID_USERTYPEDIALOGSTATICBOX1, wxID_USERTYPEDIALOGSTATICTEXT1, |
|
1879 wxID_USERTYPEDIALOGSTATICTEXT2, wxID_USERTYPEDIALOGSTATICTEXT3, |
|
1880 wxID_USERTYPEDIALOGSTATICTEXT4, wxID_USERTYPEDIALOGTYPE, |
|
1881 ] = [wx.NewId() for _init_ctrls in range(11)] |
|
1882 |
|
1883 class UserTypeDialog(wx.Dialog): |
|
1884 def _init_coll_flexGridSizer1_Items(self, parent): |
|
1885 # generated method, don't edit |
|
1886 |
|
1887 parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1888 |
|
1889 def _init_sizers(self): |
|
1890 # generated method, don't edit |
|
1891 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1892 |
|
1893 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1894 |
|
1895 self.SetSizer(self.flexGridSizer1) |
|
1896 |
|
1897 def _init_ctrls(self, prnt): |
|
1898 # generated method, don't edit |
|
1899 wx.Dialog.__init__(self, id=wxID_USERTYPEDIALOG, name='UserTypeDialog', |
|
1900 parent=prnt, pos=wx.Point(376, 223), size=wx.Size(444, 228), |
|
1901 style=wx.DEFAULT_DIALOG_STYLE, title='Add User Type') |
|
1902 self.SetClientSize(wx.Size(444, 228)) |
|
1903 |
|
1904 self.MainPanel = wx.Panel(id=wxID_USERTYPEDIALOGMAINPANEL, |
|
1905 name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1906 size=wx.Size(431, 182), style=wx.TAB_TRAVERSAL) |
|
1907 self.MainPanel.SetAutoLayout(True) |
|
1908 |
|
1909 self.staticText1 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT1, |
|
1910 label='Type:', name='staticText1', parent=self.MainPanel, |
|
1911 pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0) |
|
1912 |
|
1913 self.Type = wx.Choice(choices=[], id=wxID_USERTYPEDIALOGTYPE, |
|
1914 name='Type', parent=self.MainPanel, pos=wx.Point(24, 48), |
|
1915 size=wx.Size(160, 24), style=0) |
|
1916 self.Type.Bind(wx.EVT_CHOICE, self.OnTypeChoice, |
|
1917 id=wxID_USERTYPEDIALOGTYPE) |
|
1918 |
|
1919 self.staticBox1 = wx.StaticBox(id=wxID_USERTYPEDIALOGSTATICBOX1, |
|
1920 label='Values', name='staticBox1', parent=self.MainPanel, |
|
1921 pos=wx.Point(200, 24), size=wx.Size(224, 144), style=0) |
|
1922 |
|
1923 self.staticText2 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT2, |
|
1924 label='Minimum:', name='staticText2', parent=self.MainPanel, |
|
1925 pos=wx.Point(216, 48), size=wx.Size(67, 17), style=0) |
|
1926 |
|
1927 self.Min = wx.TextCtrl(id=wxID_USERTYPEDIALOGMIN, name='Min', |
|
1928 parent=self.MainPanel, pos=wx.Point(296, 48), size=wx.Size(112, |
|
1929 24), style=wx.TE_RIGHT, value='0') |
|
1930 |
|
1931 self.staticText3 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT3, |
|
1932 label='Maximum:', name='staticText3', parent=self.MainPanel, |
|
1933 pos=wx.Point(216, 88), size=wx.Size(71, 17), style=0) |
|
1934 |
|
1935 self.Max = wx.TextCtrl(id=wxID_USERTYPEDIALOGMAX, name='Max', |
|
1936 parent=self.MainPanel, pos=wx.Point(296, 88), size=wx.Size(112, |
|
1937 25), style=wx.TE_RIGHT, value='0') |
|
1938 |
|
1939 self.staticText4 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT4, |
|
1940 label='Length:', name='staticText4', parent=self.MainPanel, |
|
1941 pos=wx.Point(216, 128), size=wx.Size(52, 17), style=0) |
|
1942 |
|
1943 self.Length = wx.TextCtrl(id=wxID_USERTYPEDIALOGLENGTH, name='Length', |
|
1944 parent=self.MainPanel, pos=wx.Point(296, 128), size=wx.Size(112, |
|
1945 25), style=wx.TE_RIGHT, value='0') |
|
1946 |
|
1947 self._init_sizers() |
|
1948 |
|
1949 def __init__(self, parent): |
|
1950 self._init_ctrls(parent) |
|
1951 self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) |
|
1952 self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER) |
|
1953 self.TypeDictionary = {} |
|
1954 |
|
1955 EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
|
1956 |
|
1957 def OnOK(self, event): |
|
1958 error = [] |
|
1959 good = True |
|
1960 firstmessage = "" |
|
1961 secondmessage = "" |
|
1962 name = self.Type.GetStringSelection() |
|
1963 if name != "": |
|
1964 valuetype = self.TypeDictionary[name][1] |
|
1965 if valuetype == 0: |
|
1966 try: |
|
1967 int(self.Min.GetValue(), 16) |
|
1968 except: |
|
1969 error.append("Minimum") |
|
1970 good = False |
|
1971 try: |
|
1972 int(self.Max.GetValue(), 16) |
|
1973 except: |
|
1974 error.append("Maximum") |
|
1975 good = False |
|
1976 elif valuetype == 1: |
|
1977 try: |
|
1978 int(self.Length.GetValue(), 16) |
|
1979 except: |
|
1980 error.append("Length") |
|
1981 good = False |
|
1982 if len(error) > 0: |
|
1983 secondmessage = ". " |
|
1984 for i, item in enumerate(error): |
|
1985 if i == 0: |
|
1986 secondmessage += item |
|
1987 elif i == len(error) - 1: |
|
1988 secondmessage += " and %s"%item |
|
1989 else: |
|
1990 secondmessage += ", %s"%item |
|
1991 secondmessage += " must be integer" |
|
1992 if len(error) > 1: |
|
1993 secondmessage += "s" |
|
1994 else: |
|
1995 firstmessage = ". A type must be selected" |
|
1996 good = False |
|
1997 if not good: |
|
1998 message = wxMessageDialog(self, "Form isn't valid%s%s%s!"%(firstmessage,secondmessage), "Error", wxOK|wxICON_ERROR) |
|
1999 message.ShowModal() |
|
2000 message.Destroy() |
|
2001 self.Name.SetFocus() |
|
2002 else: |
|
2003 self.EndModal(wxID_OK) |
|
2004 |
|
2005 def SetValues(self, min = None, max = None, length = None): |
|
2006 if min != None: |
|
2007 self.Min.SetValue(str(min)) |
|
2008 if max != None: |
|
2009 self.Max.SetValue(str(max)) |
|
2010 if length != None: |
|
2011 self.Length.SetValue(str(length)) |
|
2012 |
|
2013 def SetTypeList(self, typedic, type = None): |
|
2014 self.Type.Clear() |
|
2015 list = [] |
|
2016 for index, (name, valuetype) in typedic.iteritems(): |
|
2017 self.TypeDictionary[name] = (index, valuetype) |
|
2018 list.append((index, name)) |
|
2019 list.sort() |
|
2020 for index, name in list: |
|
2021 self.Type.Append(name) |
|
2022 if type != None: |
|
2023 self.Type.SetStringSelection(typedic[type][0]) |
|
2024 self.RefreshValues() |
|
2025 |
|
2026 def OnTypeChoice(self, event): |
|
2027 self.RefreshValues() |
|
2028 event.Skip() |
|
2029 |
|
2030 def RefreshValues(self): |
|
2031 name = self.Type.GetStringSelection() |
|
2032 if name != "": |
|
2033 valuetype = self.TypeDictionary[name][1] |
|
2034 if valuetype == 0: |
|
2035 self.staticText2.Enable(True) |
|
2036 self.staticText3.Enable(True) |
|
2037 self.staticText4.Enable(False) |
|
2038 self.Min.Enable(True) |
|
2039 self.Max.Enable(True) |
|
2040 self.Length.Enable(False) |
|
2041 elif valuetype == 1: |
|
2042 self.staticText2.Enable(False) |
|
2043 self.staticText3.Enable(False) |
|
2044 self.staticText4.Enable(True) |
|
2045 self.Min.Enable(False) |
|
2046 self.Max.Enable(False) |
|
2047 self.Length.Enable(True) |
|
2048 else: |
|
2049 self.staticText2.Enable(False) |
|
2050 self.staticText3.Enable(False) |
|
2051 self.staticText4.Enable(False) |
|
2052 self.Min.Enable(False) |
|
2053 self.Max.Enable(False) |
|
2054 self.Length.Enable(False) |
|
2055 |
|
2056 def GetValues(self): |
|
2057 name = self.Type.GetStringSelection() |
|
2058 type = self.TypeDictionary[name][0] |
|
2059 min = int(self.Min.GetValue()) |
|
2060 max = int(self.Max.GetValue()) |
|
2061 length = int(self.Length.GetValue()) |
|
2062 return type, min, max, length |
|
2063 |
|
2064 |
|
2065 |
|
2066 #------------------------------------------------------------------------------- |
|
2067 # Editing Node Infos Dialog |
|
2068 #------------------------------------------------------------------------------- |
|
2069 |
|
2070 |
|
2071 [wxID_NODEINFOSDIALOG, wxID_NODEINFOSDIALOGMAINPANEL, |
|
2072 wxID_NODEINFOSDIALOGNAME, wxID_NODEINFOSDIALOGNODEID, |
|
2073 wxID_NODEINFOSDIALOGDESCRIPTION, wxID_NODEINFOSDIALOGSTATICTEXT1, |
|
2074 wxID_NODEINFOSDIALOGSTATICTEXT2, wxID_NODEINFOSDIALOGSTATICTEXT3, |
|
2075 wxID_NODEINFOSDIALOGSTATICTEXT4, wxID_NODEINFOSDIALOGTYPE, |
|
2076 ] = [wx.NewId() for _init_ctrls in range(10)] |
|
2077 |
|
2078 class NodeInfosDialog(wx.Dialog): |
|
2079 def _init_coll_flexGridSizer1_Items(self, parent): |
|
2080 # generated method, don't edit |
|
2081 |
|
2082 parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
2083 |
|
2084 def _init_sizers(self): |
|
2085 # generated method, don't edit |
|
2086 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
2087 |
|
2088 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
2089 |
|
2090 self.SetSizer(self.flexGridSizer1) |
|
2091 |
|
2092 def _init_ctrls(self, prnt): |
|
2093 # generated method, don't edit |
|
2094 wx.Dialog.__init__(self, id=wxID_NODEINFOSDIALOG, |
|
2095 name='NodeInfosDialog', parent=prnt, pos=wx.Point(376, 223), |
|
2096 size=wx.Size(300, 300), style=wx.DEFAULT_DIALOG_STYLE, |
|
2097 title='Node Infos') |
|
2098 self.SetClientSize(wx.Size(300, 300)) |
|
2099 |
|
2100 self.MainPanel = wx.Panel(id=wxID_NODEINFOSDIALOGMAINPANEL, |
|
2101 name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
2102 size=wx.Size(280, 264), style=wx.TAB_TRAVERSAL) |
|
2103 self.MainPanel.SetAutoLayout(True) |
|
2104 |
|
2105 self.staticText1 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT1, |
|
2106 label='Name:', |
|
2107 name='staticText1', parent=self.MainPanel, |
|
2108 pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0) |
|
2109 |
|
2110 self.Name = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNAME, name='Name', |
|
2111 parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(250, |
|
2112 25), style=0, value='') |
|
2113 |
|
2114 self.staticText2 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT2, |
|
2115 label='Node ID:', name='staticText2', parent=self.MainPanel, |
|
2116 pos=wx.Point(24, 80), size=wx.Size(67, 17), style=0) |
|
2117 |
|
2118 self.NodeID = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNODEID, name='NodeID', |
|
2119 parent=self.MainPanel, pos=wx.Point(24, 104), size=wx.Size(250, |
|
2120 25), style=wx.TE_RIGHT, value='') |
|
2121 |
|
2122 self.staticText3 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT3, |
|
2123 label='Type:', name='staticText3', parent=self.MainPanel, |
|
2124 pos=wx.Point(24, 136), size=wx.Size(71, 17), style=0) |
|
2125 |
|
2126 self.Type = wx.Choice(choices=[], id=wxID_NODEINFOSDIALOGTYPE, |
|
2127 name='Type', parent=self.MainPanel, pos=wx.Point(24, 160), |
|
2128 size=wx.Size(250, 25), style=0) |
|
2129 |
|
2130 self.staticText4 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT4, |
|
2131 label='Description:', name='staticText4', parent=self.MainPanel, |
|
2132 pos=wx.Point(24, 192), size=wx.Size(71, 17), style=0) |
|
2133 |
|
2134 self.Description = wx.TextCtrl(id=wxID_NODEINFOSDIALOGDESCRIPTION, |
|
2135 name='Description', parent=self.MainPanel, pos=wx.Point(24, 216), |
|
2136 size=wx.Size(250, 25), style=0, value='') |
|
2137 |
|
2138 self._init_sizers() |
|
2139 |
|
2140 def __init__(self, parent): |
|
2141 self._init_ctrls(parent) |
|
2142 self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) |
|
2143 self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER) |
|
2144 self.Type.Append("master") |
|
2145 self.Type.Append("slave") |
|
2146 |
|
2147 EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
|
2148 |
|
2149 def OnOK(self, event): |
|
2150 name = self.Name.GetValue() |
|
2151 message = "" |
|
2152 if name != "": |
|
2153 good = not name[0].isdigit() |
|
2154 for item in name.split("_"): |
|
2155 good &= item.isalnum() |
|
2156 if not good: |
|
2157 message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!" |
|
2158 if message != "": |
|
2159 try: |
|
2160 nodeid = int(self.NodeID.GetValue(), 16) |
|
2161 except: |
|
2162 message = "Node ID must be integer!" |
|
2163 if message != "": |
|
2164 message = wxMessageDialog(self, message, "ERROR", wxOK|wxICON_ERROR) |
|
2165 message.ShowModal() |
|
2166 message.Destroy() |
|
2167 self.Name.SetFocus() |
|
2168 else: |
|
2169 self.EndModal(wxID_OK) |
|
2170 |
|
2171 def SetValues(self, name, id, type, description): |
|
2172 self.Name.SetValue(name) |
|
2173 self.NodeID.SetValue("0x%02X"%id) |
|
2174 self.Type.SetStringSelection(type) |
|
2175 self.Description.SetValue(description) |
|
2176 |
|
2177 def GetValues(self): |
|
2178 name = self.Name.GetValue() |
|
2179 nodeid = int(self.NodeID.GetValue(), 16) |
|
2180 type = self.Type.GetStringSelection() |
|
2181 description = self.Description.GetValue() |
|
2182 return name, nodeid, type, description |
|
2183 |
|
2184 |
|
2185 |
|
2186 #------------------------------------------------------------------------------- |
|
2187 # Create New Node Dialog |
|
2188 #------------------------------------------------------------------------------- |
|
2189 |
|
2190 |
|
2191 [wxID_CREATENODEDIALOG, wxID_CREATENODEDIALOGEMERGENCY, |
|
2192 wxID_CREATENODEDIALOGGENSYNC, wxID_CREATENODEDIALOGMAINPANEL, |
|
2193 wxID_CREATENODEDIALOGNAME, wxID_CREATENODEDIALOGNMT_HEARTBEAT, |
|
2194 wxID_CREATENODEDIALOGNMT_NODEGUARDING, wxID_CREATENODEDIALOGNMT_NONE, |
|
2195 wxID_CREATENODEDIALOGNODEID, wxID_CREATENODEDIALOGPROFILE, |
|
2196 wxID_CREATENODEDIALOGSAVECONFIG, wxID_CREATENODEDIALOGSTATICTEXT1, |
|
2197 wxID_CREATENODEDIALOGSTATICTEXT2, wxID_CREATENODEDIALOGSTATICTEXT3, |
|
2198 wxID_CREATENODEDIALOGSTATICTEXT4, wxID_CREATENODEDIALOGSTATICTEXT5, |
|
2199 wxID_CREATENODEDIALOGSTATICTEXT6, wxID_CREATENODEDIALOGSTATICTEXT7, |
|
2200 wxID_CREATENODEDIALOGSTOREEDS, wxID_CREATENODEDIALOGDESCRIPTION, |
|
2201 wxID_CREATENODEDIALOGTYPE, |
|
2202 ] = [wx.NewId() for _init_ctrls in range(21)] |
|
2203 |
|
2204 class CreateNodeDialog(wx.Dialog): |
|
2205 def _init_coll_flexGridSizer1_Items(self, parent): |
|
2206 # generated method, don't edit |
|
2207 |
|
2208 parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
2209 |
|
2210 def _init_sizers(self): |
|
2211 # generated method, don't edit |
|
2212 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
2213 |
|
2214 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
2215 |
|
2216 self.SetSizer(self.flexGridSizer1) |
|
2217 |
|
2218 def _init_ctrls(self, prnt): |
|
2219 # generated method, don't edit |
|
2220 wx.Dialog.__init__(self, id=wxID_CREATENODEDIALOG, |
|
2221 name='CreateNodeDialog', parent=prnt, pos=wx.Point(376, 223), |
|
2222 size=wx.Size(451, 376), style=wx.DEFAULT_DIALOG_STYLE, |
|
2223 title='Create a new Node') |
|
2224 self.SetClientSize(wx.Size(451, 376)) |
|
2225 |
|
2226 self.MainPanel = wx.Panel(id=wxID_CREATENODEDIALOGMAINPANEL, |
|
2227 name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
2228 size=wx.Size(440, 278), style=wx.TAB_TRAVERSAL) |
|
2229 self.MainPanel.SetAutoLayout(True) |
|
2230 |
|
2231 self.staticText1 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT1, |
|
2232 label='Name:', name='staticText1', parent=self.MainPanel, |
|
2233 pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0) |
|
2234 |
|
2235 self.staticText2 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT2, |
|
2236 label='Node ID:', name='staticText2', parent=self.MainPanel, |
|
2237 pos=wx.Point(24, 80), size=wx.Size(67, 17), style=0) |
|
2238 |
|
2239 self.staticText3 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT3, |
|
2240 label='Type:', name='staticText3', parent=self.MainPanel, |
|
2241 pos=wx.Point(24, 136), size=wx.Size(71, 17), style=0) |
|
2242 |
|
2243 self.Type = wx.Choice(choices=[], id=wxID_CREATENODEDIALOGTYPE, |
|
2244 name='Type', parent=self.MainPanel, pos=wx.Point(24, 160), |
|
2245 size=wx.Size(200, 24), style=0) |
|
2246 |
|
2247 self.Name = wx.TextCtrl(id=wxID_CREATENODEDIALOGNAME, name='Name', |
|
2248 parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(200, |
|
2249 25), style=0, value='') |
|
2250 |
|
2251 self.NodeID = wx.TextCtrl(id=wxID_CREATENODEDIALOGNODEID, name='NodeID', |
|
2252 parent=self.MainPanel, pos=wx.Point(24, 104), size=wx.Size(200, |
|
2253 25), style=wx.TE_RIGHT, value='') |
|
2254 |
|
2255 self.staticText4 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT4, |
|
2256 label='Profile:', name='staticText4', parent=self.MainPanel, |
|
2257 pos=wx.Point(24, 192), size=wx.Size(47, 17), style=0) |
|
2258 |
|
2259 self.Profile = wx.Choice(choices=[], id=wxID_CREATENODEDIALOGPROFILE, |
|
2260 name='Profile', parent=self.MainPanel, pos=wx.Point(24, 216), |
|
2261 size=wx.Size(200, 24), style=0) |
|
2262 self.Profile.Bind(wx.EVT_CHOICE, self.OnProfileChoice, |
|
2263 id=wxID_CREATENODEDIALOGPROFILE) |
|
2264 |
|
2265 self.staticText5 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT5, |
|
2266 label='Network Management:', name='staticText5', |
|
2267 parent=self.MainPanel, pos=wx.Point(256, 24), size=wx.Size(152, |
|
2268 16), style=0) |
|
2269 |
|
2270 self.NMT_None = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_NONE, |
|
2271 label='None', name='NMT_None', parent=self.MainPanel, |
|
2272 pos=wx.Point(256, 40), size=wx.Size(114, 24), style=0) |
|
2273 self.NMT_None.SetValue(True) |
|
2274 |
|
2275 self.NMT_NodeGuarding = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_NODEGUARDING, |
|
2276 label='Node Guarding', name='NMT_NodeGuarding', |
|
2277 parent=self.MainPanel, pos=wx.Point(256, 64), size=wx.Size(128, |
|
2278 24), style=0) |
|
2279 self.NMT_NodeGuarding.SetValue(False) |
|
2280 |
|
2281 self.NMT_Heartbeat = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_HEARTBEAT, |
|
2282 label='Heartbeat', name='NMT_Heartbeat', parent=self.MainPanel, |
|
2283 pos=wx.Point(256, 88), size=wx.Size(114, 24), style=0) |
|
2284 self.NMT_Heartbeat.SetValue(False) |
|
2285 |
|
2286 self.staticText6 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT6, |
|
2287 label='Options:', name='staticText6', parent=self.MainPanel, |
|
2288 pos=wx.Point(256, 128), size=wx.Size(72, 17), style=0) |
|
2289 |
|
2290 self.DS302 = wx.CheckBox(id=wxID_CREATENODEDIALOGGENSYNC, |
|
2291 label='DS-302 Profile', name='DS302', parent=self.MainPanel, |
|
2292 pos=wx.Point(256, 144), size=wx.Size(128, 24), style=0) |
|
2293 self.DS302.SetValue(False) |
|
2294 #self.DS302.Enable(False) |
|
2295 |
|
2296 self.GenSYNC = wx.CheckBox(id=wxID_CREATENODEDIALOGGENSYNC, |
|
2297 label='Generate SYNC', name='GenSYNC', parent=self.MainPanel, |
|
2298 pos=wx.Point(256, 168), size=wx.Size(128, 24), style=0) |
|
2299 self.GenSYNC.SetValue(False) |
|
2300 |
|
2301 self.Emergency = wx.CheckBox(id=wxID_CREATENODEDIALOGEMERGENCY, |
|
2302 label='Emergency support', name='Emergency', |
|
2303 parent=self.MainPanel, pos=wx.Point(256, 192), size=wx.Size(152, |
|
2304 24), style=0) |
|
2305 self.Emergency.SetValue(False) |
|
2306 self.Emergency.Enable(False) |
|
2307 |
|
2308 self.SaveConfig = wx.CheckBox(id=wxID_CREATENODEDIALOGSAVECONFIG, |
|
2309 label='Save Configuration', name='SaveConfig', |
|
2310 parent=self.MainPanel, pos=wx.Point(256, 216), size=wx.Size(152, |
|
2311 24), style=0) |
|
2312 self.SaveConfig.SetValue(False) |
|
2313 self.SaveConfig.Enable(False) |
|
2314 |
|
2315 # self.StoreEDS = wx.CheckBox(id=wxID_CREATENODEDIALOGSTOREEDS, |
|
2316 # label='Store EDS', name='StoreEDS', parent=self.MainPanel, |
|
2317 # pos=wx.Point(256, 240), size=wx.Size(144, 24), style=0) |
|
2318 # self.StoreEDS.SetValue(False) |
|
2319 |
|
2320 self.staticText7 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT7, |
|
2321 label='Description:', name='staticText7', parent=self.MainPanel, |
|
2322 pos=wx.Point(24, 248), size=wx.Size(71, 17), style=0) |
|
2323 |
|
2324 self.Description = wx.TextCtrl(id=wxID_CREATENODEDIALOGDESCRIPTION, |
|
2325 name='Description', parent=self.MainPanel, pos=wx.Point(24, 272), |
|
2326 size=wx.Size(400, 25), style=0, value='') |
|
2327 |
|
2328 self._init_sizers() |
|
2329 |
|
2330 def __init__(self, parent): |
|
2331 self._init_ctrls(parent) |
|
2332 self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) |
|
2333 self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER) |
|
2334 self.NodeID.SetValue("0x00") |
|
2335 self.Type.Append("master") |
|
2336 self.Type.Append("slave") |
|
2337 self.Type.SetStringSelection("slave") |
|
2338 self.Description.SetValue("") |
|
2339 self.ListProfile = {"None" : ""} |
|
2340 self.Profile.Append("None") |
|
2341 self.Directory = os.path.join(ScriptDirectory, "config") |
|
2342 listfiles = os.listdir(self.Directory) |
|
2343 listfiles.sort() |
|
2344 for item in listfiles: |
|
2345 name, extend = os.path.splitext(item) |
|
2346 if os.path.isfile(os.path.join(self.Directory, item)) and extend == ".prf" and name != "DS-302": |
|
2347 self.ListProfile[name] = os.path.join(self.Directory, item) |
|
2348 self.Profile.Append(name) |
|
2349 self.Profile.Append("Other") |
|
2350 self.Profile.SetStringSelection("None") |
|
2351 self.Name.SetFocus() |
|
2352 |
|
2353 EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
|
2354 |
|
2355 def OnOK(self, event): |
|
2356 name = self.Name.GetValue() |
|
2357 message = "" |
|
2358 if name != "": |
|
2359 good = not name[0].isdigit() |
|
2360 for item in name.split("_"): |
|
2361 good &= item.isalnum() |
|
2362 if not good: |
|
2363 message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!" |
|
2364 if message != "": |
|
2365 try: |
|
2366 nodeid = int(self.NodeID.GetValue(), 16) |
|
2367 except: |
|
2368 message = "Node ID must be an integer!" |
|
2369 if message != "": |
|
2370 message = wxMessageDialog(self, message, "ERROR", wxOK|wxICON_ERROR) |
|
2371 message.ShowModal() |
|
2372 message.Destroy() |
|
2373 self.Name.SetFocus() |
|
2374 else: |
|
2375 self.EndModal(wxID_OK) |
|
2376 |
|
2377 def GetValues(self): |
|
2378 name = self.Name.GetValue() |
|
2379 nodeid = 0 |
|
2380 if self.NodeID.GetValue() != "": |
|
2381 nodeid = int(self.NodeID.GetValue(), 16) |
|
2382 type = self.Type.GetStringSelection() |
|
2383 description = self.Description.GetValue() |
|
2384 return name, nodeid, type, description |
|
2385 |
|
2386 def GetProfile(self): |
|
2387 name = self.Profile.GetStringSelection() |
|
2388 return name, self.ListProfile[name] |
|
2389 |
|
2390 def GetNMTManagement(self): |
|
2391 if self.NMT_None.GetValue(): |
|
2392 return "None" |
|
2393 elif self.NMT_NodeGuarding.GetValue(): |
|
2394 return "NodeGuarding" |
|
2395 elif self.NMT_Heartbeat.GetValue(): |
|
2396 return "Heartbeat" |
|
2397 return None |
|
2398 |
|
2399 def GetOptions(self): |
|
2400 options = [] |
|
2401 if self.DS302.GetValue(): |
|
2402 options.append("DS302") |
|
2403 if self.GenSYNC.GetValue(): |
|
2404 options.append("GenSYNC") |
|
2405 if self.Emergency.GetValue(): |
|
2406 options.append("Emergency") |
|
2407 if self.SaveConfig.GetValue(): |
|
2408 options.append("SaveConfig") |
|
2409 # if self.StoreEDS.GetValue(): |
|
2410 # options.append("StoreEDS") |
|
2411 return options |
|
2412 |
|
2413 def OnProfileChoice(self, event): |
|
2414 if self.Profile.GetStringSelection() == "Other": |
|
2415 dialog = wxFileDialog(self, "Choose a file", self.Directory, "", "OD Profile files (*.prf)|*.prf|All files|*.*", wxOPEN|wxCHANGE_DIR) |
|
2416 dialog.ShowModal() |
|
2417 filepath = dialog.GetPath() |
|
2418 dialog.Destroy() |
|
2419 if os.path.isfile(filepath): |
|
2420 name = os.path.splitext(os.path.basename(filepath))[0] |
|
2421 self.ListProfile[name] = filepath |
|
2422 length = self.Profile.GetCount() |
|
2423 self.Profile.Insert(name, length - 2) |
|
2424 self.Profile.SetStringSelection(name) |
|
2425 else: |
|
2426 self.Profile.SetStringSelection("None") |
|
2427 event.Skip() |
|
2428 |
911 |
2429 |
912 |
2430 #------------------------------------------------------------------------------- |
913 #------------------------------------------------------------------------------- |
2431 # Exception Handler |
914 # Exception Handler |
2432 #------------------------------------------------------------------------------- |
915 #------------------------------------------------------------------------------- |