]> rtime.felk.cvut.cz Git - CanFestival-3.git/blob - objdictgen/objdictedit.py
EDS import
[CanFestival-3.git] / objdictgen / objdictedit.py
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 from wx.lib.anchors import LayoutAnchors
28 import wx.grid
29
30 from types import *
31 import os, re, platform, sys, time, traceback, getopt
32
33 __version__ = "$Revision: 1.15 $"
34
35 from nodemanager import *
36 from node import OD_Subindex,OD_MultipleSubindexes,OD_IdenticalSubindexes,OD_IdenticalIndexes
37 from doc_index.DS301_index import *
38
39 try:
40     from wxPython.html import *
41
42     wxEVT_HTML_URL_CLICK = wxNewId()
43
44     def EVT_HTML_URL_CLICK(win, func):
45         win.Connect(-1, -1, wxEVT_HTML_URL_CLICK, func)
46
47     class wxHtmlWindowUrlClick(wxPyEvent):
48         def __init__(self, linkinfo):
49             wxPyEvent.__init__(self)
50             self.SetEventType(wxEVT_HTML_URL_CLICK)
51             self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget())
52
53     class wxUrlClickHtmlWindow(wxHtmlWindow):
54         """ HTML window that generates and OnLinkClicked event.
55
56         Use this to avoid having to override HTMLWindow
57         """
58         def OnLinkClicked(self, linkinfo):
59             wxPostEvent(self, wxHtmlWindowUrlClick(linkinfo))
60     
61 #-------------------------------------------------------------------------------
62 #                                Html Frame
63 #-------------------------------------------------------------------------------
64
65     [wxID_HTMLFRAME, wxID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)]
66
67     class HtmlFrame(wx.Frame):
68         def _init_ctrls(self, prnt):
69             # generated method, don't edit
70             wx.Frame.__init__(self, id=wxID_HTMLFRAME, name='HtmlFrame',
71                   parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616),
72                   style=wx.DEFAULT_FRAME_STYLE, title='')
73             self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=wxID_HTMLFRAME)
74             
75             self.HtmlContent = wxUrlClickHtmlWindow(id=wxID_HTMLFRAMEHTMLCONTENT,
76                   name='HtmlContent', parent=self, pos=wx.Point(0, 0),
77                   size=wx.Size(-1, -1), style=wxHW_SCROLLBAR_AUTO|wxHW_NO_SELECTION)
78             EVT_HTML_URL_CLICK(self.HtmlContent, self.OnLinkClick)
79
80         def __init__(self, parent, opened):
81             self._init_ctrls(parent)
82             self.HtmlFrameOpened = opened
83         
84         def SetHtmlCode(self, htmlcode):
85             self.HtmlContent.SetPage(htmlcode)
86             
87         def SetHtmlPage(self, htmlpage):
88             self.HtmlContent.LoadPage(htmlpage)
89             
90         def OnCloseFrame(self, event):
91             self.HtmlFrameOpened.remove(self.GetTitle())
92             event.Skip()
93         
94         def OnLinkClick(self, event):
95             url = event.linkinfo[0]
96             try:
97                 import webbrowser
98             except ImportError:
99                 wxMessageBox('Please point your browser at: %s' % url)
100             else:
101                 webbrowser.open(url)
102     
103     Html_Window = True
104 except:
105     Html_Window = False
106
107 def create(parent):
108     return objdictedit(parent)
109
110 def usage():
111     print "\nUsage of objectdict.py :"
112     print "\n   %s [Filepath, ...]\n"%sys.argv[0]
113
114 try:
115     opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
116 except getopt.GetoptError:
117     # print help information and exit:
118     usage()
119     sys.exit(2)
120
121 for o, a in opts:
122     if o in ("-h", "--help"):
123         usage()
124         sys.exit()
125
126 filesOpen = args
127 ScriptDirectory = sys.path[0]
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                 else:
298                     grid.SetReadOnly(row, col, True)
299                     
300                 grid.SetCellEditor(row, col, editor)
301                 grid.SetCellRenderer(row, col, renderer)
302                 
303                 grid.SetCellBackgroundColour(row, col, wxWHITE)
304     
305     def SetData(self, data):
306         self.data = data
307         
308     def SetEditors(self, editors):
309         self.editors = editors
310     
311     def GetCurrentIndex(self):
312         return self.CurrentIndex
313     
314     def SetCurrentIndex(self, index):
315         self.CurrentIndex = index
316     
317     def AppendRow(self, row_content):
318         self.data.append(row_content)
319
320     def Empty(self):
321         self.data = []
322         self.editors = []
323
324 [wxID_EDITINGPANEL, wxID_EDITINGPANELADDBUTTON, wxID_EDITINGPANELINDEXCHOICE, 
325  wxID_EDITINGPANELINDEXLIST, wxID_EDITINGPANELINDEXLISTPANEL, wxID_EDITINGPANELPARTLIST, 
326  wxID_EDITINGPANELSECONDSPLITTER, wxID_EDITINGPANELSUBINDEXGRID,
327  wxID_EDITINGPANELSUBINDEXGRIDPANEL, wxID_EDITINGPANELCALLBACKCHECK,
328 ] = [wx.NewId() for _init_ctrls in range(10)]
329
330 [wxID_EDITINGPANELINDEXLISTMENUITEMS0, wxID_EDITINGPANELINDEXLISTMENUITEMS1, 
331  wxID_EDITINGPANELINDEXLISTMENUITEMS2, 
332 ] = [wx.NewId() for _init_coll_IndexListMenu_Items in range(3)]
333
334 [wxID_EDITINGPANELMENU1ITEMS0, wxID_EDITINGPANELMENU1ITEMS1, 
335 ] = [wx.NewId() for _init_coll_SubindexGridMenu_Items in range(2)]
336
337 class EditingPanel(wx.SplitterWindow):
338     def _init_coll_AddToListSizer_Items(self, parent):
339         # generated method, don't edit
340
341         parent.AddWindow(self.AddButton, 0, border=0, flag=0)
342         parent.AddWindow(self.IndexChoice, 0, border=0, flag=wxGROW)
343
344     def _init_coll_SubindexGridSizer_Items(self, parent):
345         # generated method, don't edit
346
347         parent.AddWindow(self.CallbackCheck, 0, border=0, flag=0)
348         parent.AddWindow(self.SubindexGrid, 0, border=0, flag=wxGROW)
349
350     def _init_coll_IndexListSizer_Items(self, parent):
351         # generated method, don't edit
352
353         parent.AddWindow(self.IndexList, 0, border=0, flag=wxGROW)
354         parent.AddSizer(self.AddToListSizer, 0, border=0, flag=wxGROW)
355
356     def _init_coll_AddToListSizer_Growables(self, parent):
357         # generated method, don't edit
358
359         parent.AddGrowableCol(1)
360
361     def _init_coll_SubindexGridSizer_Growables(self, parent):
362         # generated method, don't edit
363
364         parent.AddGrowableCol(0)
365         parent.AddGrowableRow(1)
366
367     def _init_coll_IndexListSizer_Growables(self, parent):
368         # generated method, don't edit
369
370         parent.AddGrowableCol(0)
371         parent.AddGrowableRow(0)
372
373     def _init_coll_SubindexGridMenu_Items(self, parent):
374         # generated method, don't edit
375
376         parent.Append(help='', id=wxID_EDITINGPANELMENU1ITEMS0,
377               kind=wx.ITEM_NORMAL, text='Add')
378         parent.Append(help='', id=wxID_EDITINGPANELMENU1ITEMS1,
379               kind=wx.ITEM_NORMAL, text='Delete')
380         self.Bind(wx.EVT_MENU, self.OnAddSubindexMenu,
381               id=wxID_EDITINGPANELMENU1ITEMS0)
382         self.Bind(wx.EVT_MENU, self.OnDeleteSubindexMenu,
383               id=wxID_EDITINGPANELMENU1ITEMS1)
384
385     def _init_coll_IndexListMenu_Items(self, parent):
386         # generated method, don't edit
387
388         parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS0,
389               kind=wx.ITEM_NORMAL, text='Rename')
390         parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS2,
391               kind=wx.ITEM_NORMAL, text='Modify')
392         parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS1,
393               kind=wx.ITEM_NORMAL, text='Delete')
394         self.Bind(wx.EVT_MENU, self.OnRenameIndexMenu,
395               id=wxID_EDITINGPANELINDEXLISTMENUITEMS0)
396         self.Bind(wx.EVT_MENU, self.OnDeleteIndexMenu,
397               id=wxID_EDITINGPANELINDEXLISTMENUITEMS1)
398         self.Bind(wx.EVT_MENU, self.OnModifyIndexMenu,
399               id=wxID_EDITINGPANELINDEXLISTMENUITEMS2)
400
401     def _init_utils(self):
402         # generated method, don't edit
403         self.IndexListMenu = wx.Menu(title='')
404
405         self.SubindexGridMenu = wx.Menu(title='')
406
407         self._init_coll_IndexListMenu_Items(self.IndexListMenu)
408         self._init_coll_SubindexGridMenu_Items(self.SubindexGridMenu)
409
410     def _init_sizers(self):
411         # generated method, don't edit
412         self.IndexListSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
413
414         self.SubindexGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
415
416         self.AddToListSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
417
418         self._init_coll_IndexListSizer_Growables(self.IndexListSizer)
419         self._init_coll_IndexListSizer_Items(self.IndexListSizer)
420         self._init_coll_SubindexGridSizer_Growables(self.SubindexGridSizer)
421         self._init_coll_SubindexGridSizer_Items(self.SubindexGridSizer)
422         self._init_coll_AddToListSizer_Growables(self.AddToListSizer)
423         self._init_coll_AddToListSizer_Items(self.AddToListSizer)
424
425         self.SubindexGridPanel.SetSizer(self.SubindexGridSizer)
426         self.IndexListPanel.SetSizer(self.IndexListSizer)
427         
428     def _init_ctrls(self, prnt):
429         wx.SplitterWindow.__init__(self, id=wxID_EDITINGPANEL,
430               name='MainSplitter', parent=prnt, point=wx.Point(0, 0),
431               size=wx.Size(-1, -1), style=wx.SP_3D)
432         self._init_utils()
433         self.SetNeedUpdating(True)
434         self.SetMinimumPaneSize(1)
435
436         self.PartList = wx.ListBox(choices=[], id=wxID_EDITINGPANELPARTLIST,
437               name='PartList', parent=self, pos=wx.Point(0, 0),
438               size=wx.Size(-1, -1), style=0)
439         self.PartList.Bind(wx.EVT_LISTBOX, self.OnPartListBoxClick,
440               id=wxID_EDITINGPANELPARTLIST)
441
442         self.SecondSplitter = wx.SplitterWindow(id=wxID_EDITINGPANELSECONDSPLITTER,
443               name='SecondSplitter', parent=self, point=wx.Point(0,
444               0), size=wx.Size(-1, -1), style=wx.SP_3D)
445         self.SecondSplitter.SetMinimumPaneSize(1)
446         self.SplitHorizontally(self.PartList, self.SecondSplitter,
447               110)
448
449         self.SubindexGridPanel = wx.Panel(id=wxID_EDITINGPANELSUBINDEXGRIDPANEL,
450               name='SubindexGridPanel', parent=self.SecondSplitter, pos=wx.Point(0,
451               0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
452
453         self.IndexListPanel = wx.Panel(id=wxID_EDITINGPANELINDEXLISTPANEL,
454               name='IndexListPanel', parent=self.SecondSplitter, pos=wx.Point(0,
455               0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
456         self.SecondSplitter.SplitVertically(self.IndexListPanel,
457               self.SubindexGridPanel, 280)
458
459         self.SubindexGrid = wx.grid.Grid(id=wxID_EDITINGPANELSUBINDEXGRID,
460               name='SubindexGrid', parent=self.SubindexGridPanel, pos=wx.Point(0,
461               0), size=wx.Size(-1, -1), style=0)
462         self.SubindexGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
463               'Sans'))
464         self.SubindexGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
465               False, 'Sans'))
466         self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
467               self.OnSubindexGridCellChange)
468         self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK,
469               self.OnSubindexGridRightClick)
470         self.SubindexGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL,
471               self.OnSubindexGridSelectCell)
472
473         self.CallbackCheck = wx.CheckBox(id=wxID_EDITINGPANELCALLBACKCHECK,
474               label='Have Callbacks', name='CallbackCheck',
475               parent=self.SubindexGridPanel, pos=wx.Point(0, 0), size=wx.Size(152,
476               24), style=0)
477         self.CallbackCheck.Bind(wx.EVT_CHECKBOX, self.OnCallbackCheck,
478               id=wxID_EDITINGPANELCALLBACKCHECK)
479
480         self.IndexList = wx.ListBox(choices=[], id=wxID_EDITINGPANELINDEXLIST,
481               name='IndexList', parent=self.IndexListPanel, pos=wx.Point(0, 0),
482               size=wx.Size(-1, -1), style=0)
483         self.IndexList.Bind(wx.EVT_LISTBOX, self.OnIndexListClick,
484               id=wxID_EDITINGPANELINDEXLIST)
485         self.IndexList.Bind(wx.EVT_RIGHT_UP, self.OnIndexListRightUp)
486
487         self.AddButton = wx.Button(id=wxID_EDITINGPANELADDBUTTON, label='Add',
488               name='AddButton', parent=self.IndexListPanel, pos=wx.Point(0, 0),
489               size=wx.Size(50, 30), style=0)
490         self.AddButton.Bind(wx.EVT_BUTTON, self.OnAddButtonClick,
491               id=wxID_EDITINGPANELADDBUTTON)
492
493         self.IndexChoice = wx.Choice(choices=[], id=wxID_EDITINGPANELINDEXCHOICE,
494               name='IndexChoice', parent=self.IndexListPanel, pos=wx.Point(50,
495               0), size=wx.Size(-1, 30), style=0)
496
497         self._init_sizers()
498
499     def __init__(self, parent, manager):
500         self._init_ctrls(parent.GetNoteBook())
501         self.Parent = parent
502         self.Manager = manager
503         self.ListIndex = []
504         self.ChoiceIndex = []
505         self.FirstCall = False
506         
507         for values in DictionaryOrganisation:
508             text = "   0x%04X-0x%04X      %s"%(values["minIndex"],values["maxIndex"],values["name"])
509             self.PartList.Append(text)
510         self.Table = SubindexTable(self, [], [], ["subindex", "name", "type", "value", "access", "save", "comment"])
511         self.SubindexGrid.SetTable(self.Table)
512         self.SubindexGrid.SetRowLabelSize(0)
513         self.CallbackCheck.Disable()
514         self.Table.ResetView(self.SubindexGrid)
515
516     def GetSelection(self):
517         selected = self.IndexList.GetSelection()
518         if selected != wxNOT_FOUND:
519             index = self.ListIndex[selected]
520             subIndex = self.SubindexGrid.GetGridCursorRow()
521             return index, subIndex
522         return None
523
524     def OnAddButtonClick(self, event):
525         self.SubindexGrid.SetGridCursor(0, 0)
526         selected = self.IndexChoice.GetStringSelection()
527         if selected != "":
528             if selected == "User Type":
529                 self.Parent.AddUserType()
530             elif selected == "SDO Server":
531                 self.Manager.AddSDOServerToCurrent()
532             elif selected == "SDO Client":
533                 self.Manager.AddSDOClientToCurrent()
534             elif selected == "PDO Receive":
535                 self.Manager.AddPDOReceiveToCurrent()
536             elif selected == "PDO Transmit":
537                 self.Manager.AddPDOTransmitToCurrent()
538             elif selected == "Map Variable":
539                 self.Parent.AddMapVariable()
540             elif selected in [menu for menu, indexes in self.Manager.GetCurrentSpecificMenu()]:
541                 self.Manager.AddSpecificEntryToCurrent(selected)
542             else:
543                 index = self.ChoiceIndex[self.IndexChoice.GetSelection()]
544                 self.Manager.ManageEntriesOfCurrent([index], [])
545             self.Parent.RefreshBufferState()
546             self.RefreshIndexList()
547         event.Skip()
548
549     def OnPartListBoxClick(self, event):
550         self.SubindexGrid.SetGridCursor(0, 0)
551         self.RefreshIndexList()
552         event.Skip()
553
554     def OnIndexListClick(self, event):
555         self.SubindexGrid.SetGridCursor(0, 0)
556         self.RefreshTable()
557         event.Skip()
558
559     def OnSubindexGridSelectCell(self, event):
560         wxCallAfter(self.Parent.RefreshStatusBar)
561         event.Skip()
562
563 #-------------------------------------------------------------------------------
564 #                             Refresh Functions
565 #-------------------------------------------------------------------------------
566
567     def RefreshIndexList(self):
568         selected = self.IndexList.GetSelection()
569         choice = self.IndexChoice.GetStringSelection()
570         choiceindex = self.IndexChoice.GetSelection()
571         if selected != wxNOT_FOUND:
572             selectedindex = self.ListIndex[selected]
573         self.IndexList.Clear()
574         self.IndexChoice.Clear()
575         i = self.PartList.GetSelection()
576         if i < len(DictionaryOrganisation):
577             values = DictionaryOrganisation[i]
578             self.ListIndex = []
579             for name, index in self.Manager.GetCurrentValidIndexes(values["minIndex"], values["maxIndex"]):
580                 self.IndexList.Append("0x%04X   %s"%(index, name))
581                 self.ListIndex.append(index)
582             self.ChoiceIndex = []
583             if i == 0:
584                 self.IndexChoice.Append("User Type")
585                 self.IndexChoice.SetStringSelection("User Type")
586             elif i == 2:
587                 self.IndexChoice.Append("SDO Server")
588                 self.IndexChoice.Append("SDO Client")
589                 if choiceindex != wxNOT_FOUND and choice == self.IndexChoice.GetString(choiceindex):
590                      self.IndexChoice.SetStringSelection(choice)
591             elif i in (3, 4):
592                 self.IndexChoice.Append("PDO Receive")
593                 self.IndexChoice.SetStringSelection("PDO Receive")
594             elif i in (5, 6):
595                 self.IndexChoice.Append("PDO Transmit")
596                 self.IndexChoice.SetStringSelection("PDO Transmit")
597             elif i == 8:
598                 self.IndexChoice.Append("Map Variable")
599                 self.IndexChoice.SetStringSelection("Map Variable")
600             else:
601                 for name, index in self.Manager.GetCurrentValidChoices(values["minIndex"], values["maxIndex"]):
602                     if index:
603                         self.IndexChoice.Append("0x%04X   %s"%(index, name))
604                     else:
605                         self.IndexChoice.Append(name)
606                     self.ChoiceIndex.append(index)
607             if choiceindex != wxNOT_FOUND and choice == self.IndexChoice.GetString(choiceindex):
608                 self.IndexChoice.SetStringSelection(choice)
609         self.IndexChoice.Enable(self.IndexChoice.GetCount() != 0)
610         self.AddButton.Enable(self.IndexChoice.GetCount() != 0)
611         if selected == wxNOT_FOUND or selected >= len(self.ListIndex) or selectedindex != self.ListIndex[selected]:
612             self.Table.Empty()
613             self.CallbackCheck.SetValue(False)
614             self.CallbackCheck.Disable()
615             self.Table.ResetView(self.SubindexGrid)
616             self.Parent.RefreshStatusBar()
617         else:
618             self.IndexList.SetSelection(selected)
619             self.RefreshTable()
620
621     def RefreshTable(self):
622         selected = self.IndexList.GetSelection()
623         if selected != wxNOT_FOUND:
624             index = self.ListIndex[selected]
625             if index > 0x260:
626                 self.CallbackCheck.Enable()
627                 self.CallbackCheck.SetValue(self.Manager.HasCurrentEntryCallbacks(index))
628             result = self.Manager.GetCurrentEntryValues(index)
629             if result != None:
630                 self.Table.SetCurrentIndex(index)
631                 data, editors = result
632                 self.Table.SetData(data)
633                 self.Table.SetEditors(editors)
634                 self.Table.ResetView(self.SubindexGrid)
635         self.Parent.RefreshStatusBar()
636
637 #-------------------------------------------------------------------------------
638 #                        Editing Table value function
639 #-------------------------------------------------------------------------------
640
641     def OnSubindexGridCellChange(self, event):
642         index = self.Table.GetCurrentIndex()
643         subIndex = event.GetRow()
644         col = event.GetCol()
645         name = self.Table.GetColLabelValue(col)
646         value = self.Table.GetValue(subIndex, col)
647         editor = self.Table.GetEditor(subIndex, col)
648         self.Manager.SetCurrentEntry(index, subIndex, value, name, editor)
649         self.Parent.RefreshBufferState()
650         wxCallAfter(self.RefreshTable)
651         event.Skip()
652
653     def OnCallbackCheck(self, event):
654         index = self.Table.GetCurrentIndex()
655         self.Manager.SetCurrentEntryCallbacks(index, self.CallbackCheck.GetValue())
656         self.Parent.RefreshBufferState()
657         wxCallAfter(self.RefreshTable)
658         event.Skip()
659
660 #-------------------------------------------------------------------------------
661 #                          Contextual Menu functions
662 #-------------------------------------------------------------------------------
663
664     def OnIndexListRightUp(self, event):
665         if not self.FirstCall:
666             self.FirstCall = True
667             selected = self.IndexList.GetSelection()
668             if selected != wxNOT_FOUND:
669                 index = self.ListIndex[selected]
670                 if index < 0x260:
671                     self.IndexListMenu.FindItemByPosition(0).Enable(False)
672                     self.IndexListMenu.FindItemByPosition(1).Enable(True)
673                     self.PopupMenu(self.IndexListMenu)
674                 elif 0x1000 <= index <= 0x1BFF:
675                     self.IndexListMenu.FindItemByPosition(0).Enable(False)
676                     self.IndexListMenu.FindItemByPosition(1).Enable(False)
677                     self.PopupMenu(self.IndexListMenu)
678                 elif 0x2000 <= index <= 0x5FFF:
679                     self.IndexListMenu.FindItemByPosition(0).Enable(True)
680                     self.IndexListMenu.FindItemByPosition(1).Enable(False)
681                     self.PopupMenu(self.IndexListMenu)
682                 elif index >= 0x6000:
683                     self.IndexListMenu.FindItemByPosition(0).Enable(False)
684                     self.IndexListMenu.FindItemByPosition(1).Enable(False)
685                     self.PopupMenu(self.IndexListMenu)
686         else:
687             self.FirstCall = False
688         event.Skip()
689
690     def OnSubindexGridRightClick(self, event):
691         selected = self.IndexList.GetSelection()
692         if selected != wxNOT_FOUND:
693             index = self.ListIndex[selected]
694             if self.Manager.IsCurrentEntry(index):
695                 infos = self.Manager.GetEntryInfos(index)
696                 if index >= 0x2000 and infos["struct"] & OD_MultipleSubindexes or infos["struct"] & OD_IdenticalSubindexes:
697                     self.PopupMenu(self.SubindexGridMenu)
698         event.Skip()
699
700     def OnRenameIndexMenu(self, event):
701         selected = self.IndexList.GetSelection()
702         if selected != wxNOT_FOUND:
703             index = self.ListIndex[selected]
704             if self.Manager.IsCurrentEntry(index):
705                 infos = self.Manager.GetEntryInfos(index)
706                 dialog = wxTextEntryDialog(self, "Give a new name for index 0x%04X"%index,
707                              "Rename an index", infos["name"], wxOK|wxCANCEL)
708                 if dialog.ShowModal() == wxID_OK:
709                     self.Manager.SetCurrentEntryName(index, dialog.GetValue())
710                     self.Parent.RefreshBufferState()
711                     self.RefreshIndexList()
712                 dialog.Destroy()
713         event.Skip()
714
715     def OnModifyIndexMenu(self, event):
716         selected = self.IndexList.GetSelection()
717         if selected != wxNOT_FOUND:
718             index = self.ListIndex[selected]
719             if self.Manager.IsCurrentEntry(index) and index < 0x260:
720                 values, valuetype = self.Manager.GetCustomisedTypeValues(index)
721                 dialog = UserTypeDialog(self)
722                 dialog.SetTypeList(self.Manager.GetCustomisableTypes(), values[1])
723                 if valuetype == 0:
724                     dialog.SetValues(min = values[2], max = values[3])
725                 elif valuetype == 1:
726                     dialog.SetValues(length = values[2])
727                 if dialog.ShowModal() == wxID_OK:
728                     type, min, max, length = dialog.GetValues()
729                     self.Manager.SetCurrentUserType(index, type, min, max, length)
730                     self.Parent.RefreshBufferState()
731                     self.RefreshIndexList()
732         event.Skip()
733         
734     def OnDeleteIndexMenu(self, event):
735         selected = self.IndexList.GetSelection()
736         if selected != wxNOT_FOUND:
737             index = self.ListIndex[selected]
738             if self.Manager.IsCurrentEntry(index):
739                 self.Manager.ManageEntriesOfCurrent([],[index])
740                 self.Parent.RefreshBufferState()
741                 self.RefreshIndexList()
742         event.Skip()
743
744     def OnAddSubindexMenu(self, event):
745         selected = self.IndexList.GetSelection()
746         if selected != wxNOT_FOUND:
747             index = self.ListIndex[selected]
748             if self.Manager.IsCurrentEntry(index):
749                 dialog = wxTextEntryDialog(self, "Number of subindexes to add:",
750                              "Add subindexes", "1", wxOK|wxCANCEL)
751                 if dialog.ShowModal() == wxID_OK:
752                     number = eval(dialog.GetValue())
753                     if type(number) == IntType:
754                         self.Manager.AddSubentriesToCurrent(index, number)
755                         self.Parent.RefreshBufferState()
756                         self.RefreshIndexList()
757                     else:
758                         message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR)
759                         message.ShowModal()
760                         message.Destroy()
761                 dialog.Destroy()
762         event.Skip()
763
764     def OnDeleteSubindexMenu(self, event):
765         selected = self.IndexList.GetSelection()
766         if selected != wxNOT_FOUND:
767             index = self.ListIndex[selected]
768             if self.Manager.IsCurrentEntry(index):
769                 dialog = wxTextEntryDialog(self, "Number of subindexes to delete:",
770                              "Delete subindexes", "1", wxOK|wxCANCEL)
771                 if dialog.ShowModal() == wxID_OK:
772                     number = eval(dialog.GetValue())
773                     if type(number) == IntType:
774                         self.Manager.RemoveSubentriesFromCurrent(index, number)
775                         self.Parent.RefreshBufferState()
776                         self.RefreshIndexList()
777                     else:
778                         message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR)
779                         message.ShowModal()
780                         message.Destroy()
781                 dialog.Destroy()
782         event.Skip()
783
784 [wxID_OBJDICTEDIT, wxID_OBJDICTEDITFILEOPENED, 
785  wxID_OBJDICTEDITHELPBAR,
786 ] = [wx.NewId() for _init_ctrls in range(3)]
787
788 [wxID_OBJDICTEDITADDMENUITEMS0, wxID_OBJDICTEDITADDMENUITEMS1, 
789  wxID_OBJDICTEDITADDMENUITEMS2, wxID_OBJDICTEDITADDMENUITEMS3, 
790  wxID_OBJDICTEDITADDMENUITEMS4, wxID_OBJDICTEDITADDMENUITEMS5, 
791 ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)]
792
793 [wxID_OBJDICTEDITFILEMENUITEMS0, wxID_OBJDICTEDITFILEMENUITEMS1, 
794  wxID_OBJDICTEDITFILEMENUITEMS2, wxID_OBJDICTEDITFILEMENUITEMS4, 
795  wxID_OBJDICTEDITFILEMENUITEMS5, wxID_OBJDICTEDITFILEMENUITEMS6, 
796  wxID_OBJDICTEDITFILEMENUITEMS7, wxID_OBJDICTEDITFILEMENUITEMS8,
797 ] = [wx.NewId() for _init_coll_FileMenu_Items in range(8)]
798
799 [wxID_OBJDICTEDITEDITMENUITEMS0, wxID_OBJDICTEDITEDITMENUITEMS1, 
800  wxID_OBJDICTEDITEDITMENUITEMS2, wxID_OBJDICTEDITEDITMENUITEMS4, 
801  wxID_OBJDICTEDITEDITMENUITEMS6, wxID_OBJDICTEDITEDITMENUITEMS7, 
802  wxID_OBJDICTEDITEDITMENUITEMS8, 
803 ] = [wx.NewId() for _init_coll_EditMenu_Items in range(7)]
804
805 [wxID_OBJDICTEDITHELPMENUITEMS0, wxID_OBJDICTEDITHELPMENUITEMS1,
806  wxID_OBJDICTEDITHELPMENUITEMS2,
807 ] = [wx.NewId() for _init_coll_HelpMenu_Items in range(3)]
808
809 class objdictedit(wx.Frame):
810     def _init_coll_menuBar1_Menus(self, parent):
811         # generated method, don't edit
812
813         parent.Append(menu=self.FileMenu, title='File')
814         parent.Append(menu=self.EditMenu, title='Edit')
815         parent.Append(menu=self.AddMenu, title='Add')
816         parent.Append(menu=self.HelpMenu, title='Help')
817
818     def _init_coll_EditMenu_Items(self, parent):
819         # generated method, don't edit
820
821         parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS4,
822               kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R')
823         parent.AppendSeparator()
824         parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS1,
825               kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z')
826         parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS0,
827               kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y')
828         parent.AppendSeparator()
829         parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS6,
830               kind=wx.ITEM_NORMAL, text='Node infos')
831         parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS2,
832               kind=wx.ITEM_NORMAL, text='DS-301 Profile')
833         parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS8,
834               kind=wx.ITEM_NORMAL, text='DS-302 Profile')
835         parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS7,
836               kind=wx.ITEM_NORMAL, text='Other Profile')
837         self.Bind(wx.EVT_MENU, self.OnUndoMenu,
838               id=wxID_OBJDICTEDITEDITMENUITEMS1)
839         self.Bind(wx.EVT_MENU, self.OnRedoMenu,
840               id=wxID_OBJDICTEDITEDITMENUITEMS0)
841         self.Bind(wx.EVT_MENU, self.OnCommunicationMenu,
842               id=wxID_OBJDICTEDITEDITMENUITEMS2)
843         self.Bind(wx.EVT_MENU, self.OnRefreshMenu,
844               id=wxID_OBJDICTEDITEDITMENUITEMS4)
845         self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu,
846               id=wxID_OBJDICTEDITEDITMENUITEMS6)
847         self.Bind(wx.EVT_MENU, self.OnEditProfileMenu,
848               id=wxID_OBJDICTEDITEDITMENUITEMS7)
849         self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu,
850               id=wxID_OBJDICTEDITEDITMENUITEMS8)
851
852     def _init_coll_HelpMenu_Items(self, parent):
853         # generated method, don't edit
854
855         parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS0,
856               kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1')
857         self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu,
858               id=wxID_OBJDICTEDITHELPMENUITEMS0)
859         if Html_Window:
860             parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS1,
861                   kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2')
862             parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS2,
863                   kind=wx.ITEM_NORMAL, text='About')
864             self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu,
865                   id=wxID_OBJDICTEDITHELPMENUITEMS1)
866             self.Bind(wx.EVT_MENU, self.OnAboutMenu,
867                   id=wxID_OBJDICTEDITHELPMENUITEMS2)
868
869     def _init_coll_FileMenu_Items(self, parent):
870         # generated method, don't edit
871
872         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS5,
873               kind=wx.ITEM_NORMAL, text='New\tCTRL+N')
874         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS0,
875               kind=wx.ITEM_NORMAL, text='Open\tCTRL+O')
876         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS1,
877               kind=wx.ITEM_NORMAL, text='Save\tCTRL+S')
878         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS6,
879               kind=wx.ITEM_NORMAL, text='Save As...\tALT+S')
880         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS2,
881               kind=wx.ITEM_NORMAL, text='Close\tCTRL+W')
882         parent.AppendSeparator()
883         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS7,
884               kind=wx.ITEM_NORMAL, text='Import EDS file')
885         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS8,
886               kind=wx.ITEM_NORMAL, text='Build Dictionary\tCTRL+B')
887         parent.AppendSeparator()
888         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS4,
889               kind=wx.ITEM_NORMAL, text='Exit')
890         self.Bind(wx.EVT_MENU, self.OnOpenMenu,
891               id=wxID_OBJDICTEDITFILEMENUITEMS0)
892         self.Bind(wx.EVT_MENU, self.OnSaveMenu,
893               id=wxID_OBJDICTEDITFILEMENUITEMS1)
894         self.Bind(wx.EVT_MENU, self.OnCloseMenu,
895               id=wxID_OBJDICTEDITFILEMENUITEMS2)
896         self.Bind(wx.EVT_MENU, self.OnQuitMenu,
897               id=wxID_OBJDICTEDITFILEMENUITEMS4)
898         self.Bind(wx.EVT_MENU, self.OnNewMenu,
899               id=wxID_OBJDICTEDITFILEMENUITEMS5)
900         self.Bind(wx.EVT_MENU, self.OnSaveAsMenu,
901               id=wxID_OBJDICTEDITFILEMENUITEMS6)
902         self.Bind(wx.EVT_MENU, self.OnImportMenu,
903               id=wxID_OBJDICTEDITFILEMENUITEMS7)
904         self.Bind(wx.EVT_MENU, self.OnExportMenu,
905               id=wxID_OBJDICTEDITFILEMENUITEMS8)
906
907     def _init_coll_AddMenu_Items(self, parent):
908         # generated method, don't edit
909
910         parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS0,
911               kind=wx.ITEM_NORMAL, text='SDO Server')
912         parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS1,
913               kind=wx.ITEM_NORMAL, text='SDO Client')
914         parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS2,
915               kind=wx.ITEM_NORMAL, text='PDO Transmit')
916         parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS3,
917               kind=wx.ITEM_NORMAL, text='PDO Receive')
918         parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS4,
919               kind=wx.ITEM_NORMAL, text='Map Variable')
920         parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS5,
921               kind=wx.ITEM_NORMAL, text='User Type')
922         self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu,
923               id=wxID_OBJDICTEDITADDMENUITEMS0)
924         self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu,
925               id=wxID_OBJDICTEDITADDMENUITEMS1)
926         self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu,
927               id=wxID_OBJDICTEDITADDMENUITEMS2)
928         self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu,
929               id=wxID_OBJDICTEDITADDMENUITEMS3)
930         self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu,
931               id=wxID_OBJDICTEDITADDMENUITEMS4)
932         self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu,
933               id=wxID_OBJDICTEDITADDMENUITEMS5)
934
935     def _init_coll_HelpBar_Fields(self, parent):
936         # generated method, don't edit
937         parent.SetFieldsCount(3)
938
939         parent.SetStatusText(number=0, text='')
940         parent.SetStatusText(number=1, text='')
941         parent.SetStatusText(number=2, text='')
942
943         parent.SetStatusWidths([100, 110, -1])
944
945     def _init_utils(self):
946         # generated method, don't edit
947         self.menuBar1 = wx.MenuBar()
948         self.menuBar1.SetEvtHandlerEnabled(True)
949
950         self.FileMenu = wx.Menu(title='')
951
952         self.EditMenu = wx.Menu(title='')
953
954         self.AddMenu = wx.Menu(title='')
955
956         self.HelpMenu = wx.Menu(title='')
957
958         self._init_coll_menuBar1_Menus(self.menuBar1)
959         self._init_coll_FileMenu_Items(self.FileMenu)
960         self._init_coll_EditMenu_Items(self.EditMenu)
961         self._init_coll_AddMenu_Items(self.AddMenu)
962         self._init_coll_HelpMenu_Items(self.HelpMenu)
963
964     def _init_ctrls(self, prnt):
965         # generated method, don't edit
966         wx.Frame.__init__(self, id=wxID_OBJDICTEDIT, name='objdictedit',
967               parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700),
968               style=wx.DEFAULT_FRAME_STYLE, title='Objdictedit')
969         self._init_utils()
970         self.SetClientSize(wx.Size(1000, 700))
971         self.SetMenuBar(self.menuBar1)
972         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=wxID_OBJDICTEDIT)
973
974         self.FileOpened = wx.Notebook(id=wxID_OBJDICTEDITFILEOPENED,
975               name='FileOpened', parent=self, pos=wx.Point(0, 0),
976               size=wx.Size(0, 0), style=0)
977         self.FileOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
978               self.OnFileSelectedChanged, id=wxID_OBJDICTEDITFILEOPENED)
979
980         self.HelpBar = wx.StatusBar(id=wxID_OBJDICTEDITHELPBAR, name='HelpBar',
981               parent=self, style=wxST_SIZEGRIP)
982         self._init_coll_HelpBar_Fields(self.HelpBar)
983         self.SetStatusBar(self.HelpBar)
984
985     def __init__(self, parent):
986         self._init_ctrls(parent)
987         self.HtmlFrameOpened = []
988         
989         self.Manager = NodeManager()
990         for filepath in filesOpen:
991             self.Manager.OpenFileInCurrent(filepath)
992             new_editingpanel = EditingPanel(self, self.Manager)
993             self.FileOpened.AddPage(new_editingpanel, "")
994             self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex())
995         if self.Manager.CurrentDS302Defined(): 
996             self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True)
997         else:
998             self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False)
999         self.RefreshEditMenu()
1000         self.RefreshBufferState()
1001         self.RefreshProfileMenu()
1002         self.RefreshMainMenu()
1003
1004         self.RefreshBufferState()
1005         self.RefreshTitle()
1006         self.RefreshMainMenu()
1007
1008     def GetNoteBook(self):
1009         return self.FileOpened
1010
1011     def OnAddSDOServerMenu(self, event):
1012         self.Manager.AddSDOServerToCurrent()
1013         self.RefreshBufferState()
1014         self.RefreshCurrentIndexList()
1015         event.Skip()
1016     
1017     def OnAddSDOClientMenu(self, event):
1018         self.Manager.AddSDOClientToCurrent()
1019         self.RefreshBufferState()
1020         self.RefreshCurrentIndexList()
1021         event.Skip()
1022
1023     def OnAddPDOTransmitMenu(self, event):
1024         self.Manager.AddPDOTransmitToCurrent()
1025         self.RefreshBufferState()
1026         self.RefreshCurrentIndexList()
1027         event.Skip()
1028
1029     def OnAddPDOReceiveMenu(self, event):
1030         self.Manager.AddPDOReceiveToCurrent()
1031         self.RefreshBufferState()
1032         self.RefreshCurrentIndexList()
1033         event.Skip()
1034
1035     def OnAddMapVariableMenu(self, event):
1036         self.AddMapVariable()
1037         event.Skip()
1038
1039     def OnAddUserTypeMenu(self, event):
1040         self.AddUserType()
1041         event.Skip()
1042
1043     def OnFileSelectedChanged(self, event):
1044         selected = event.GetSelection()
1045         # At init selected = -1
1046         if selected >= 0:
1047                 self.Manager.ChangeCurrentNode(selected)
1048                 self.RefreshBufferState()
1049                 self.RefreshProfileMenu()
1050         event.Skip()
1051
1052     def OnHelpDS301Menu(self, event):
1053         find_index = False
1054         selected = self.FileOpened.GetSelection()
1055         if selected >= 0:
1056             window = self.FileOpened.GetPage(selected)
1057             result = window.GetSelection()
1058             if result:
1059                 find_index = True
1060                 index, subIndex = result
1061                 result = OpenPDFDocIndex(index, ScriptDirectory)
1062                 if type(result) == StringType:
1063                     message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR)
1064                     message.ShowModal()
1065                     message.Destroy()
1066         if not find_index:
1067             result = OpenPDFDocIndex(None, ScriptDirectory)
1068             if type(result) == StringType:
1069                 message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR)
1070                 message.ShowModal()
1071                 message.Destroy()
1072         event.Skip()
1073         
1074     def OnHelpCANFestivalMenu(self, event):
1075         #self.OpenHtmlFrame("CAN Festival Reference", os.path.join(ScriptDirectory, "doc/canfestival.html"), wx.Size(1000, 600))
1076         os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16))
1077         event.Skip()
1078
1079     def OnAboutMenu(self, event):
1080         self.OpenHtmlFrame("About CAN Festival", os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450))
1081         event.Skip()
1082
1083     def OpenHtmlFrame(self, title, file, size):
1084         if title not in self.HtmlFrameOpened:
1085             self.HtmlFrameOpened.append(title)
1086             window = HtmlFrame(self, self.HtmlFrameOpened)
1087             window.SetTitle(title)
1088             window.SetHtmlPage(file)
1089             window.SetClientSize(size)
1090             window.Show()
1091
1092     def OnQuitMenu(self, event):
1093         self.Close()
1094         event.Skip()
1095     
1096     def OnCloseFrame(self, event):
1097         if self.Manager.OneFileHasChanged():
1098             dialog = wxMessageDialog(self, "There are changes, do you want to save?",  "Close Application", wxYES_NO|wxCANCEL|wxICON_QUESTION)
1099             answer = dialog.ShowModal()
1100             dialog.Destroy()
1101             if answer == wxID_YES:
1102                 self.Manager.ChangeCurrentNode(0)
1103                 for i in xrange(self.FileOpened.GetPageCount()):
1104                     if self.Manager.CurrentIsSaved():
1105                         self.Manager.CloseCurrent()
1106                     else:
1107                         self.Save()
1108                         self.Manager.CloseCurrent(True)
1109                 event.Skip()
1110             elif answer == wxID_NO:
1111                 for i in xrange(self.FileOpened.GetPageCount()):
1112                     self.Manager.CloseCurrent(True)
1113                 wxCallAfter(self.Close)
1114                 event.Skip()
1115         else:
1116             event.Skip()
1117
1118 #-------------------------------------------------------------------------------
1119 #                             Refresh Functions
1120 #-------------------------------------------------------------------------------
1121
1122     def RefreshTitle(self):
1123         if self.FileOpened.GetPageCount() > 0:
1124             self.SetTitle("Objdictedit - %s"%self.Manager.GetCurrentFilename())
1125         else:
1126             self.SetTitle("Objdictedit")
1127
1128     def OnRefreshMenu(self, event):
1129         self.RefreshCurrentIndexList()
1130         event.Skip()
1131
1132     def RefreshCurrentIndexList(self):
1133         selected = self.FileOpened.GetSelection()
1134         window = self.FileOpened.GetPage(selected)
1135         window.RefreshIndexList()
1136
1137     def RefreshStatusBar(self):
1138         window = self.FileOpened.GetPage(self.FileOpened.GetSelection())
1139         selection = window.GetSelection()
1140         if selection:
1141             index, subIndex = selection
1142             if self.Manager.IsCurrentEntry(index):
1143                 self.HelpBar.SetStatusText("Index: 0x%04X"%index, 0)
1144                 self.HelpBar.SetStatusText("Subindex: 0x%02X"%subIndex, 1)
1145                 entryinfos = self.Manager.GetEntryInfos(index)
1146                 name = entryinfos["name"]
1147                 category = "Optional"
1148                 if entryinfos["need"]:
1149                     category = "Mandatory"
1150                 struct = "VAR"
1151                 number = ""
1152                 if entryinfos["struct"] & OD_IdenticalIndexes:
1153                     number = " possibly defined %d times"%entryinfos["nbmax"]
1154                 if entryinfos["struct"] & OD_IdenticalSubindexes:
1155                     struct = "REC"
1156                 elif entryinfos["struct"] & OD_MultipleSubindexes:
1157                     struct = "ARRAY"
1158                 text = "%s: %s entry of struct %s%s."%(name,category,struct,number)
1159                 self.HelpBar.SetStatusText(text, 2)
1160             else:
1161                 for i in xrange(3):
1162                     self.HelpBar.SetStatusText("", i)
1163         else:
1164             for i in xrange(3):
1165                 self.HelpBar.SetStatusText("", i)
1166
1167     def RefreshMainMenu(self):
1168         if self.FileOpened.GetPageCount() > 0:
1169             self.menuBar1.EnableTop(1, True)
1170             self.menuBar1.EnableTop(2, True)
1171             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, True)
1172             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, True)
1173             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, True)
1174             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, True)
1175         else:
1176             self.menuBar1.EnableTop(1, False)      
1177             self.menuBar1.EnableTop(2, False)
1178             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, False)
1179             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, False)
1180             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, False)
1181             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, False)
1182
1183     def RefreshEditMenu(self):
1184         if self.FileOpened.GetPageCount() > 0:
1185             undo, redo = self.Manager.GetCurrentBufferState()
1186             self.EditMenu.FindItemByPosition(2).Enable(undo)
1187             self.EditMenu.FindItemByPosition(3).Enable(redo)
1188         else:
1189             self.EditMenu.FindItemByPosition(2).Enable(False)
1190             self.EditMenu.FindItemByPosition(3).Enable(False)
1191
1192     def RefreshProfileMenu(self):
1193         profile = self.Manager.GetCurrentProfileName()
1194         edititem = self.EditMenu.FindItemByPosition(8)
1195         length = self.AddMenu.GetMenuItemCount()
1196         for i in xrange(length-6):
1197             additem = self.AddMenu.FindItemByPosition(6)
1198             self.AddMenu.Delete(additem.GetId())
1199         if profile not in ("None", "DS-301"):
1200             edititem.SetText("%s Profile"%profile)
1201             edititem.Enable(True)
1202             self.AddMenu.AppendSeparator()
1203             for text, indexes in self.Manager.GetCurrentSpecificMenu():
1204                 new_id = wx.NewId()
1205                 self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text)
1206                 self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id)
1207         else:
1208             edititem.SetText("Other Profile")
1209             edititem.Enable(False)
1210         
1211
1212 #-------------------------------------------------------------------------------
1213 #                            Buffer Functions
1214 #-------------------------------------------------------------------------------
1215
1216     def RefreshBufferState(self):
1217         fileopened = self.Manager.GetAllFilenames()
1218         for idx, filename in enumerate(fileopened):
1219             self.FileOpened.SetPageText(idx, filename)
1220         self.RefreshEditMenu()
1221         self.RefreshTitle()
1222
1223     def OnUndoMenu(self, event):
1224         self.Manager.LoadCurrentPrevious()
1225         self.RefreshCurrentIndexList()
1226         self.RefreshBufferState()
1227         event.Skip()
1228
1229     def OnRedoMenu(self, event):
1230         self.Manager.LoadCurrentNext()
1231         self.RefreshCurrentIndexList()
1232         self.RefreshBufferState()
1233         event.Skip()
1234
1235
1236 #-------------------------------------------------------------------------------
1237 #                         Load and Save Funtions
1238 #-------------------------------------------------------------------------------
1239
1240     def OnNewMenu(self, event):
1241         self.FilePath = ""
1242         dialog = CreateNodeDialog(self)
1243         if dialog.ShowModal() == wxID_OK:
1244             name, id, type = dialog.GetValues()
1245             profile, filepath = dialog.GetProfile()
1246             NMT = dialog.GetNMTManagement()
1247             options = dialog.GetOptions()
1248             result = self.Manager.CreateNewNode(name, id, type, profile, filepath, NMT, options)
1249             if not IsOfType(result, StringType):
1250                 new_editingpanel = EditingPanel(self, self.Manager)
1251                 self.FileOpened.AddPage(new_editingpanel, "")
1252                 self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex())
1253                 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False)
1254                 if "DS302" in options:
1255                     self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True)
1256                 self.RefreshBufferState()
1257                 self.RefreshProfileMenu()
1258                 self.RefreshMainMenu()
1259             else:
1260                 message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR)
1261                 message.ShowModal()
1262                 message.Destroy()
1263         event.Skip()
1264
1265     def OnOpenMenu(self, event):
1266         filepath = self.Manager.GetCurrentFilePath()
1267         if filepath != "":
1268             directory = os.path.dirname(filepath)
1269         else:
1270             directory = os.getcwd()
1271         dialog = wxFileDialog(self, "Choose a file", directory, "",  "OD files (*.od)|*.od|All files|*.*", wxOPEN|wxCHANGE_DIR)
1272         if dialog.ShowModal() == wxID_OK:
1273             filepath = dialog.GetPath()
1274             if os.path.isfile(filepath):
1275                 result = self.Manager.OpenFileInCurrent(filepath)
1276                 if type(result) != StringType:
1277                     new_editingpanel = EditingPanel(self, self.Manager)
1278                     self.FileOpened.AddPage(new_editingpanel, "")
1279                     self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex())
1280                     if self.Manager.CurrentDS302Defined(): 
1281                         self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True)
1282                     else:
1283                         self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False)
1284                     self.RefreshEditMenu()
1285                     self.RefreshBufferState()
1286                     self.RefreshProfileMenu()
1287                     self.RefreshMainMenu()
1288                 else:
1289                     message = wxMessageDialog(self, e.args[0], "Error", wxOK|wxICON_ERROR)
1290                     message.ShowModal()
1291                     message.Destroy()
1292         dialog.Destroy()
1293         event.Skip()
1294
1295     def OnSaveMenu(self, event):
1296         self.Save()
1297         event.Skip()
1298     
1299     def OnSaveAsMenu(self, event):
1300         self.SaveAs()
1301         event.Skip()
1302         
1303     def Save(self):
1304         result = self.Manager.SaveCurrentInFile()
1305         if not result:
1306             self.SaveAs()
1307         elif type(result) != StringType:
1308             self.RefreshBufferState()
1309         else:
1310             message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
1311             message.ShowModal()
1312             message.Destroy()
1313
1314     def SaveAs(self):
1315         filepath = self.Manager.GetCurrentFilePath()
1316         if filepath != "":
1317             directory, filename = os.path.split(filepath)
1318         else:
1319             directory, filename = os.getcwd(), "%s.od"%self.Manager.GetCurrentNodeInfos()[0]
1320         dialog = wxFileDialog(self, "Choose a file", directory, filename,  "OD files (*.od)|*.od|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR)
1321         if dialog.ShowModal() == wxID_OK:
1322             filepath = dialog.GetPath()
1323             if os.path.isdir(os.path.dirname(filepath)):
1324                 result = self.Manager.SaveCurrentInFile(filepath)
1325                 if type(result) != StringType:
1326                     self.RefreshBufferState()
1327                 else:
1328                     message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
1329                     message.ShowModal()
1330                     message.Destroy()
1331             else:
1332                 message = wxMessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR)
1333                 message.ShowModal()
1334                 message.Destroy()
1335         dialog.Destroy()
1336
1337     def OnCloseMenu(self, event):
1338         answer = wxID_YES
1339         result = self.Manager.CloseCurrent()
1340         if not result:
1341             dialog = wxMessageDialog(self, "There are changes, do you want to save?",  "Close File", wxYES_NO|wxCANCEL|wxICON_QUESTION)
1342             answer = dialog.ShowModal()
1343             dialog.Destroy()
1344             if answer == wxID_YES:
1345                 self.OnSaveMenu(event)
1346                 if self.Manager.CurrentIsSaved():
1347                     self.Manager.CloseCurrent()
1348             elif answer == wxID_NO:
1349                 self.Manager.CloseCurrent(True)
1350         if self.FileOpened.GetPageCount() > self.Manager.GetBufferNumber():
1351             current = self.FileOpened.GetSelection()
1352             self.FileOpened.DeletePage(current)
1353             if self.FileOpened.GetPageCount() > 0:
1354                 self.FileOpened.SetSelection(min(current, self.FileOpened.GetPageCount() - 1))
1355             self.RefreshBufferState()
1356             self.RefreshMainMenu()
1357         event.Skip()
1358         
1359
1360 #-------------------------------------------------------------------------------
1361 #                         Import and Export Functions
1362 #-------------------------------------------------------------------------------
1363
1364     def OnImportMenu(self, event):
1365         dialog = wxFileDialog(self, "Choose a file", os.getcwd(), "",  "XML OD files (*.xml)|*.xml|All files|*.*", wxOPEN|wxCHANGE_DIR)
1366         if dialog.ShowModal() == wxID_OK:
1367             filepath = dialog.GetPath()
1368             if os.path.isfile(filepath):
1369                 result = self.Manager.ImportCurrentFromFile(filepath)
1370                 if result:
1371                     if self.FileOpened.GetPageCount() == 0:
1372                         new_editingpanel = EditingPanel(self, self.Manager)
1373                         self.FileOpened.AddPage(new_editingpanel, "")
1374                         self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex())
1375                     self.RefreshBufferState()
1376                     self.RefreshCurrentIndexList()
1377                     self.RefreshProfileMenu()
1378                     self.RefreshMainMenu()
1379                     message = wxMessageDialog(self, "Import successful", "Information", wxOK|wxICON_INFORMATION)
1380                     message.ShowModal()
1381                     message.Destroy()
1382         dialog.Destroy()
1383         event.Skip()
1384
1385     def OnExportMenu(self, event):
1386         dialog = wxFileDialog(self, "Choose a file", os.getcwd(), self.Manager.GetCurrentNodeInfos()[0],  "CANFestival OD files (*.c)|*.c|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR)
1387         if dialog.ShowModal() == wxID_OK:
1388             filepath = dialog.GetPath()
1389             if os.path.isdir(os.path.dirname(filepath)):
1390                 path, extend = os.path.splitext(filepath)
1391                 if extend in ("", "."):
1392                     filepath = path + ".c"
1393                 result = self.Manager.ExportCurrentToFile(filepath)
1394                 if result:
1395                     message = wxMessageDialog(self, "Export successful", "Information", wxOK|wxICON_INFORMATION)
1396                     message.ShowModal()
1397                     message.Destroy()
1398             else:
1399                 message = wxMessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR)
1400                 message.ShowModal()
1401                 message.Destroy()
1402         dialog.Destroy()
1403         event.Skip()
1404
1405 #-------------------------------------------------------------------------------
1406 #                          Editing Profiles functions
1407 #-------------------------------------------------------------------------------
1408
1409     def OnCommunicationMenu(self, event):
1410         dictionary,current = self.Manager.GetCurrentCommunicationLists()
1411         self.EditProfile("Edit DS-301 Profile", dictionary, current)
1412         event.Skip()
1413     
1414     def OnOtherCommunicationMenu(self, event):
1415         dictionary,current = self.Manager.GetCurrentDS302Lists()
1416         self.EditProfile("Edit DS-301 Profile", dictionary, current)
1417         event.Skip()
1418     
1419     def OnEditProfileMenu(self, event):
1420         title = "Edit %s Profile"%self.Manager.GetCurrentProfileName()
1421         dictionary,current = self.Manager.GetCurrentProfileLists()
1422         self.EditProfile(title, dictionary, current)
1423         event.Skip()
1424     
1425     def EditProfile(self, title, dictionary, current):
1426         dialog = CommunicationDialog(self)
1427         dialog.SetTitle(title)
1428         dialog.SetIndexDictionary(dictionary)
1429         dialog.SetCurrentList(current)
1430         dialog.RefreshLists()
1431         if dialog.ShowModal() == wxID_OK:
1432             new_profile = dialog.GetCurrentList()
1433             addinglist = []
1434             removinglist = []
1435             for index in new_profile:
1436                 if index not in current:
1437                     addinglist.append(index)
1438             for index in current:
1439                 if index not in new_profile:
1440                     removinglist.append(index)
1441             self.Manager.ManageEntriesOfCurrent(addinglist, removinglist)
1442             self.Manager.GenerateMapList()
1443             self.Manager.BufferCurrentNode()
1444             self.RefreshBufferState()
1445             self.RefreshCurrentIndexList()
1446         dialog.Destroy()
1447
1448     def GetProfileCallBack(self, text):
1449         def ProfileCallBack(event):
1450             self.Manager.AddSpecificEntryToCurrent(text)
1451             self.RefreshBufferState()
1452             self.RefreshCurrentIndexList()
1453             event.Skip()
1454         return ProfileCallBack
1455
1456 #-------------------------------------------------------------------------------
1457 #                         Edit Node informations function
1458 #-------------------------------------------------------------------------------
1459
1460     def OnNodeInfosMenu(self, event):
1461         dialog = NodeInfosDialog(self)
1462         name,id,type = self.Manager.GetCurrentNodeInfos()
1463         profile = self.Manager.GetCurrentProfileName()
1464         dialog.SetProfiles([profile])
1465         dialog.SetValues(name, id, type, profile)
1466         if dialog.ShowModal() == wxID_OK:
1467             name,id,type,profile = dialog.GetValues()
1468             self.Manager.SetCurrentNodeInfos(name, id, type)
1469             self.RefreshBufferState()
1470             self.RefreshProfileMenu()
1471         event.Skip()
1472
1473
1474 #-------------------------------------------------------------------------------
1475 #                           Add User Types and Variables
1476 #-------------------------------------------------------------------------------
1477         
1478     def AddMapVariable(self):
1479         index = self.Manager.GetCurrentNextMapIndex()
1480         if index:
1481             dialog = MapVariableDialog(self)
1482             dialog.SetIndex(index)
1483             if dialog.ShowModal() == wxID_OK:
1484                 index, name, struct, number = dialog.GetValues()
1485                 result = self.Manager.AddMapVariableToCurrent(index, name, struct, number)
1486                 if type(result) != StringType:
1487                     self.RefreshBufferState()
1488                     self.RefreshCurrentIndexList()
1489                 else:
1490                     message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
1491                     message.ShowModal()
1492                     message.Destroy()
1493             dialog.Destroy()
1494         else:
1495             message = wxMessageDialog(self, result, "No map variable index left!", wxOK|wxICON_ERROR)
1496             message.ShowModal()
1497             message.Destroy()
1498         
1499     def AddUserType(self):
1500         dialog = UserTypeDialog(self)
1501         dialog.SetTypeList(self.Manager.GetCustomisableTypes())
1502         if dialog.ShowModal() == wxID_OK:
1503             type, min, max, length = dialog.GetValues()
1504             result = self.Manager.AddUserTypeToCurrent(type, min, max, length)
1505             if not IsOfType(result, StringType):
1506                 self.RefreshBufferState()
1507                 self.RefreshCurrentIndexList()
1508             else:
1509                 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
1510                 message.ShowModal()
1511                 message.Destroy()
1512         dialog.Destroy()
1513
1514
1515
1516 #-------------------------------------------------------------------------------
1517 #                          Editing Communication Dialog
1518 #-------------------------------------------------------------------------------
1519
1520
1521 [wxID_COMMUNICATIONDIALOG, wxID_COMMUNICATIONDIALOGMAINPANEL,
1522  wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES, wxID_COMMUNICATIONDIALOGCURRENTINDEXES,
1523  wxID_COMMUNICATIONDIALOGSELECT, wxID_COMMUNICATIONDIALOGUNSELECT, 
1524  wxID_COMMUNICATIONDIALOGSTATICTEXT1, wxID_COMMUNICATIONDIALOGSTATICTEXT2
1525 ] = [wx.NewId() for _init_ctrls in range(8)]
1526
1527 class CommunicationDialog(wx.Dialog):
1528     def _init_coll_flexGridSizer1_Items(self, parent):
1529         # generated method, don't edit
1530
1531         parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
1532
1533     def _init_sizers(self):
1534         # generated method, don't edit
1535         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
1536
1537         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
1538
1539         self.SetSizer(self.flexGridSizer1)
1540
1541     def _init_ctrls(self, prnt):
1542         # generated method, don't edit
1543         wx.Dialog.__init__(self, id=wxID_COMMUNICATIONDIALOG,
1544               name='CommunicationDialog', parent=prnt, pos=wx.Point(234, 216),
1545               size=wx.Size(726, 437), style=wx.DEFAULT_DIALOG_STYLE,
1546               title='Edit Communication Profile')
1547         self.SetClientSize(wx.Size(726, 437))
1548
1549         self.MainPanel = wx.Panel(id=wxID_COMMUNICATIONDIALOGMAINPANEL,
1550               name='MainPanel', parent=self, pos=wx.Point(0, 0),
1551               size=wx.Size(688, 382), style=wx.TAB_TRAVERSAL)
1552         self.MainPanel.SetAutoLayout(True)
1553
1554         self.PossibleIndexes = wx.ListBox(choices=[],
1555               id=wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES,
1556               name='PossibleIndexes', parent=self.MainPanel, pos=wx.Point(40,
1557               48), size=wx.Size(280, 320), style=wxLB_EXTENDED)
1558         self.PossibleIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnPossibleIndexesDClick,
1559               id=wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES)
1560
1561         self.CurrentIndexes = wx.ListBox(choices=[],
1562               id=wxID_COMMUNICATIONDIALOGCURRENTINDEXES, name='CurrentIndexes',
1563               parent=self.MainPanel, pos=wx.Point(400, 48), size=wx.Size(280,
1564               320), style=wxLB_EXTENDED)
1565         self.CurrentIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnCurrentIndexesDClick,
1566               id=wxID_COMMUNICATIONDIALOGCURRENTINDEXES)
1567
1568         self.Select = wx.Button(id=wxID_COMMUNICATIONDIALOGSELECT, label='>>',
1569               name='Select', parent=self.MainPanel, pos=wx.Point(345, 136),
1570               size=wx.Size(32, 32), style=0)
1571         self.Select.Bind(wx.EVT_BUTTON, self.OnSelectButton,
1572               id=wxID_COMMUNICATIONDIALOGSELECT)
1573
1574         self.Unselect = wx.Button(id=wxID_COMMUNICATIONDIALOGUNSELECT,
1575               label='<<', name='Unselect', parent=self.MainPanel,
1576               pos=wx.Point(345, 216), size=wx.Size(32, 30), style=0)
1577         self.Unselect.Bind(wx.EVT_BUTTON, self.OnUnselectButton,
1578               id=wxID_COMMUNICATIONDIALOGUNSELECT)
1579
1580         self.staticText1 = wx.StaticText(id=wxID_COMMUNICATIONDIALOGSTATICTEXT1,
1581               label='Possible Profile Indexes:', name='staticText1',
1582               parent=self.MainPanel, pos=wx.Point(40, 24), size=wx.Size(156,
1583               17), style=0)
1584
1585         self.staticText2 = wx.StaticText(id=wxID_COMMUNICATIONDIALOGSTATICTEXT2,
1586               label='Current Profile Indexes:', name='staticText2',
1587               parent=self.MainPanel, pos=wx.Point(400, 24), size=wx.Size(152,
1588               17), style=0)
1589
1590         self._init_sizers()
1591
1592     def __init__(self, parent):
1593         self._init_ctrls(parent)
1594         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
1595         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
1596         self.AllList = []
1597         self.CurrentList = []
1598         self.IndexDictionary = {}
1599
1600     def SetIndexDictionary(self, dictionary):
1601         self.IndexDictionary = dictionary
1602         
1603     def SetCurrentList(self, list):
1604         self.CurrentList = []
1605         self.CurrentList.extend(list)
1606         self.CurrentList.sort()
1607         
1608     def GetCurrentList(self):
1609         return self.CurrentList
1610         
1611     def RefreshLists(self):
1612         self.PossibleIndexes.Clear()
1613         self.CurrentIndexes.Clear()
1614         self.AllList = []
1615         for index in self.IndexDictionary.iterkeys():
1616             if index not in self.CurrentList:
1617                 self.AllList.append(index)
1618         self.AllList.sort()
1619         for index in self.AllList:
1620             self.PossibleIndexes.Append("0x%04X   %s"%(index, self.IndexDictionary[index][0]))
1621         for index in self.CurrentList:
1622             if index in self.IndexDictionary:
1623                 self.CurrentIndexes.Append("0x%04X   %s"%(index, self.IndexDictionary[index][0]))
1624
1625     def OnPossibleIndexesDClick(self, event):
1626         self.SelectPossible()
1627         event.Skip()
1628
1629     def OnCurrentIndexesDClick(self, event):
1630         self.UnselectCurrent()
1631         event.Skip()
1632
1633     def OnSelectButton(self, event):
1634         self.SelectPossible()
1635         event.Skip()
1636
1637     def OnUnselectButton(self, event):
1638         self.UnselectCurrent()
1639         event.Skip()
1640
1641     def SelectPossible(self):
1642         selected = self.PossibleIndexes.GetSelections()
1643         for i in selected:
1644             self.CurrentList.append(self.AllList[i])
1645         self.CurrentList.sort()
1646         self.RefreshLists()
1647
1648     def UnselectCurrent(self):
1649         selected = self.CurrentIndexes.GetSelections()
1650         for i in selected:
1651             if not self.IndexDictionary[self.CurrentList[i]][1]:
1652                 self.CurrentList.pop(i)
1653         self.CurrentList.sort()
1654         self.RefreshLists()
1655
1656
1657
1658 #-------------------------------------------------------------------------------
1659 #                          Create Map Variable Dialog
1660 #-------------------------------------------------------------------------------
1661
1662
1663 [wxID_MAPVARIABLEDIALOG, wxID_MAPVARIABLEDIALOGINDEX, 
1664  wxID_MAPVARIABLEDIALOGINDEXNAME, wxID_MAPVARIABLEDIALOGMAINPANEL, 
1665  wxID_MAPVARIABLEDIALOGNUMBER, wxID_MAPVARIABLEDIALOGRADIOBUTTON1, 
1666  wxID_MAPVARIABLEDIALOGRADIOBUTTON2, wxID_MAPVARIABLEDIALOGRADIOBUTTON3, 
1667  wxID_MAPVARIABLEDIALOGSTATICTEXT1, wxID_MAPVARIABLEDIALOGSTATICTEXT2, 
1668  wxID_MAPVARIABLEDIALOGSTATICTEXT3, wxID_MAPVARIABLEDIALOGSTATICTEXT4, 
1669 ] = [wx.NewId() for _init_ctrls in range(12)]
1670
1671 class MapVariableDialog(wx.Dialog):
1672     def _init_coll_flexGridSizer1_Items(self, parent):
1673         # generated method, don't edit
1674
1675         parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
1676
1677     def _init_sizers(self):
1678         # generated method, don't edit
1679         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
1680
1681         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
1682
1683         self.SetSizer(self.flexGridSizer1)
1684
1685     def _init_ctrls(self, prnt):
1686         # generated method, don't edit
1687         wx.Dialog.__init__(self, id=wxID_MAPVARIABLEDIALOG,
1688               name='CommunicationDialog', parent=prnt, pos=wx.Point(376, 223),
1689               size=wx.Size(444, 186), style=wx.DEFAULT_DIALOG_STYLE,
1690               title='Add Map Variable')
1691         self.SetClientSize(wx.Size(444, 186))
1692
1693         self.MainPanel = wx.Panel(id=wxID_MAPVARIABLEDIALOGMAINPANEL,
1694               name='MainPanel', parent=self, pos=wx.Point(0, 0),
1695               size=wx.Size(431, 142), style=wx.TAB_TRAVERSAL)
1696         self.MainPanel.SetAutoLayout(True)
1697
1698         self.staticText1 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT1,
1699               label='Index:', name='staticText1', parent=self.MainPanel,
1700               pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0)
1701
1702         self.Index = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGINDEX, name='Index',
1703               parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(152,
1704               25), style=0, value='0x2000')
1705
1706         self.staticText3 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT3,
1707               label='Name:', name='staticText3', parent=self.MainPanel,
1708               pos=wx.Point(24, 80), size=wx.Size(47, 17), style=0)
1709
1710         self.IndexName = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGINDEXNAME,
1711               name='IndexName', parent=self.MainPanel, pos=wx.Point(24, 104),
1712               size=wx.Size(152, 24), style=0, value='Undefined')
1713
1714         self.staticText2 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT2,
1715               label='Type:', name='staticText2', parent=self.MainPanel,
1716               pos=wx.Point(208, 24), size=wx.Size(38, 17), style=0)
1717
1718         self.radioButton1 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON1,
1719               label='VAR', name='radioButton1', parent=self.MainPanel,
1720               pos=wx.Point(208, 48), size=wx.Size(72, 24), style=wxRB_GROUP)
1721         self.radioButton1.SetValue(True)
1722         self.radioButton1.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton1Click,
1723               id=wxID_MAPVARIABLEDIALOGRADIOBUTTON1)
1724
1725         self.radioButton2 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON2,
1726               label='ARRAY', name='radioButton2', parent=self.MainPanel,
1727               pos=wx.Point(208, 72), size=wx.Size(80, 24), style=wxRB_SINGLE)
1728         self.radioButton2.SetValue(False)
1729         self.radioButton2.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton2Click,
1730               id=wxID_MAPVARIABLEDIALOGRADIOBUTTON2)
1731
1732         self.radioButton3 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON3,
1733               label='REC', name='radioButton3', parent=self.MainPanel,
1734               pos=wx.Point(208, 96), size=wx.Size(96, 24), style=wxRB_SINGLE)
1735         self.radioButton3.SetValue(False)
1736         self.radioButton3.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton3Click,
1737               id=wxID_MAPVARIABLEDIALOGRADIOBUTTON3)
1738
1739         self.staticText4 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT4,
1740               label='Number:', name='staticText4', parent=self.MainPanel,
1741               pos=wx.Point(312, 80), size=wx.Size(88, 16), style=0)
1742
1743         self.Number = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGNUMBER,
1744               name='Number', parent=self.MainPanel, pos=wx.Point(312, 104),
1745               size=wx.Size(112, 24), style=wx.TE_RIGHT, value='0')
1746
1747         self._init_sizers()
1748
1749     def __init__(self, parent):
1750         self._init_ctrls(parent)
1751         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
1752         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
1753         self.staticText4.Enable(False)
1754         self.Number.Enable(False)
1755
1756     def SetIndex(self, index):
1757         self.Index.SetValue("0x%04X"%index)
1758
1759     def GetValues(self):
1760         if self.radioButton1.GetValue():
1761             struct = 1
1762         elif self.radioButton2.GetValue():
1763             struct = 3
1764         elif self.radioButton3.GetValue():
1765             struct = 7
1766         name = self.IndexName.GetValue()
1767         index = eval(self.Index.GetValue())
1768         number = eval(self.Number.GetValue())
1769         return index, name, struct, number
1770
1771     def OnRadioButton1Click(self, event):
1772         self.EnableNumberTyping(False)
1773         event.Skip()
1774
1775     def OnRadioButton2Click(self, event):
1776         self.EnableNumberTyping(True)
1777         event.Skip()
1778
1779     def OnRadioButton3Click(self, event):
1780         self.EnableNumberTyping(True)
1781         event.Skip()
1782
1783     def EnableNumberTyping(self, enable):
1784         self.staticText4.Enable(enable)
1785         self.Number.Enable(enable)
1786
1787
1788 #-------------------------------------------------------------------------------
1789 #                          Create User Type Dialog
1790 #-------------------------------------------------------------------------------
1791
1792
1793 [wxID_USERTYPEDIALOG, wxID_USERTYPEDIALOGLENGTH, wxID_USERTYPEDIALOGMAINPANEL, 
1794  wxID_USERTYPEDIALOGMAX, wxID_USERTYPEDIALOGMIN, 
1795  wxID_USERTYPEDIALOGSTATICBOX1, wxID_USERTYPEDIALOGSTATICTEXT1, 
1796  wxID_USERTYPEDIALOGSTATICTEXT2, wxID_USERTYPEDIALOGSTATICTEXT3, 
1797  wxID_USERTYPEDIALOGSTATICTEXT4, wxID_USERTYPEDIALOGTYPE, 
1798 ] = [wx.NewId() for _init_ctrls in range(11)]
1799
1800 class UserTypeDialog(wx.Dialog):
1801     def _init_coll_flexGridSizer1_Items(self, parent):
1802         # generated method, don't edit
1803
1804         parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
1805
1806     def _init_sizers(self):
1807         # generated method, don't edit
1808         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
1809
1810         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
1811
1812         self.SetSizer(self.flexGridSizer1)
1813
1814     def _init_ctrls(self, prnt):
1815         # generated method, don't edit
1816         wx.Dialog.__init__(self, id=wxID_USERTYPEDIALOG, name='UserTypeDialog',
1817               parent=prnt, pos=wx.Point(376, 223), size=wx.Size(444, 228),
1818               style=wx.DEFAULT_DIALOG_STYLE, title='Add User Type')
1819         self.SetClientSize(wx.Size(444, 228))
1820
1821         self.MainPanel = wx.Panel(id=wxID_USERTYPEDIALOGMAINPANEL,
1822               name='MainPanel', parent=self, pos=wx.Point(0, 0),
1823               size=wx.Size(431, 182), style=wx.TAB_TRAVERSAL)
1824         self.MainPanel.SetAutoLayout(True)
1825
1826         self.staticText1 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT1,
1827               label='Type:', name='staticText1', parent=self.MainPanel,
1828               pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0)
1829
1830         self.Type = wx.Choice(choices=[], id=wxID_USERTYPEDIALOGTYPE,
1831               name='Type', parent=self.MainPanel, pos=wx.Point(24, 48),
1832               size=wx.Size(160, 24), style=0)
1833         self.Type.Bind(wx.EVT_CHOICE, self.OnTypeChoice,
1834               id=wxID_USERTYPEDIALOGTYPE)
1835
1836         self.staticBox1 = wx.StaticBox(id=wxID_USERTYPEDIALOGSTATICBOX1,
1837               label='Values', name='staticBox1', parent=self.MainPanel,
1838               pos=wx.Point(200, 24), size=wx.Size(224, 144), style=0)
1839
1840         self.staticText2 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT2,
1841               label='Minimum:', name='staticText2', parent=self.MainPanel,
1842               pos=wx.Point(216, 48), size=wx.Size(67, 17), style=0)
1843
1844         self.Min = wx.TextCtrl(id=wxID_USERTYPEDIALOGMIN, name='Min',
1845               parent=self.MainPanel, pos=wx.Point(296, 48), size=wx.Size(112,
1846               24), style=wx.TE_RIGHT, value='0')
1847
1848         self.staticText3 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT3,
1849               label='Maximum:', name='staticText3', parent=self.MainPanel,
1850               pos=wx.Point(216, 88), size=wx.Size(71, 17), style=0)
1851
1852         self.Max = wx.TextCtrl(id=wxID_USERTYPEDIALOGMAX, name='Max',
1853               parent=self.MainPanel, pos=wx.Point(296, 88), size=wx.Size(112,
1854               25), style=wx.TE_RIGHT, value='0')
1855
1856         self.staticText4 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT4,
1857               label='Length:', name='staticText4', parent=self.MainPanel,
1858               pos=wx.Point(216, 128), size=wx.Size(52, 17), style=0)
1859
1860         self.Length = wx.TextCtrl(id=wxID_USERTYPEDIALOGLENGTH, name='Length',
1861               parent=self.MainPanel, pos=wx.Point(296, 128), size=wx.Size(112,
1862               25), style=wx.TE_RIGHT, value='0')
1863
1864         self._init_sizers()
1865
1866     def __init__(self, parent):
1867         self._init_ctrls(parent)
1868         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
1869         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
1870         self.TypeDictionary = {}
1871         
1872     def SetValues(self, min = None, max = None, length = None):
1873         if min != None:
1874             self.Min.SetValue(str(min))
1875         if max != None:
1876             self.Max.SetValue(str(max))
1877         if length != None:
1878             self.Length.SetValue(str(length))
1879
1880     def SetTypeList(self, typedic, type = None):
1881         self.Type.Clear()
1882         list = []
1883         for index, (name, valuetype) in typedic.iteritems():
1884             self.TypeDictionary[name] = (index, valuetype)
1885             list.append((index, name))
1886         list.sort()
1887         for index, name in list:
1888             self.Type.Append(name)
1889         if type != None:
1890             self.Type.SetStringSelection(typedic[type][0])
1891         self.RefreshValues()
1892
1893     def OnTypeChoice(self, event):
1894         self.RefreshValues()
1895         event.Skip()
1896     
1897     def RefreshValues(self):
1898         name = self.Type.GetStringSelection()
1899         if name != "":
1900             valuetype = self.TypeDictionary[name][1]
1901             if valuetype == 0:
1902                 self.staticText2.Enable(True)
1903                 self.staticText3.Enable(True)
1904                 self.staticText4.Enable(False)
1905                 self.Min.Enable(True)
1906                 self.Max.Enable(True)
1907                 self.Length.Enable(False)
1908             elif valuetype == 1:
1909                 self.staticText2.Enable(False)
1910                 self.staticText3.Enable(False)
1911                 self.staticText4.Enable(True)
1912                 self.Min.Enable(False)
1913                 self.Max.Enable(False)
1914                 self.Length.Enable(True)
1915         else:
1916             self.staticText2.Enable(False)
1917             self.staticText3.Enable(False)
1918             self.staticText4.Enable(False)
1919             self.Min.Enable(False)
1920             self.Max.Enable(False)
1921             self.Length.Enable(False)
1922
1923     def GetValues(self):
1924         name = self.Type.GetStringSelection()
1925         type = self.TypeDictionary[name][0]
1926         min = eval(self.Min.GetValue())
1927         max = eval(self.Max.GetValue())
1928         length = eval(self.Length.GetValue())
1929         return type, min, max, length
1930
1931
1932
1933 #-------------------------------------------------------------------------------
1934 #                          Editing Node Infos Dialog
1935 #-------------------------------------------------------------------------------
1936
1937
1938 [wxID_NODEINFOSDIALOG, wxID_NODEINFOSDIALOGMAINPANEL, 
1939  wxID_NODEINFOSDIALOGNAME, wxID_NODEINFOSDIALOGNODEID, 
1940  wxID_NODEINFOSDIALOGPROFILE, wxID_NODEINFOSDIALOGSTATICTEXT1, 
1941  wxID_NODEINFOSDIALOGSTATICTEXT2, wxID_NODEINFOSDIALOGSTATICTEXT3, 
1942  wxID_NODEINFOSDIALOGSTATICTEXT4, wxID_NODEINFOSDIALOGTYPE, 
1943 ] = [wx.NewId() for _init_ctrls in range(10)]
1944
1945 class NodeInfosDialog(wx.Dialog):
1946     def _init_coll_flexGridSizer1_Items(self, parent):
1947         # generated method, don't edit
1948
1949         parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
1950
1951     def _init_sizers(self):
1952         # generated method, don't edit
1953         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
1954
1955         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
1956
1957         self.SetSizer(self.flexGridSizer1)
1958
1959     def _init_ctrls(self, prnt):
1960         # generated method, don't edit
1961         wx.Dialog.__init__(self, id=wxID_NODEINFOSDIALOG,
1962               name='NodeInfosDialog', parent=prnt, pos=wx.Point(376, 223),
1963               size=wx.Size(249, 250), style=wx.DEFAULT_DIALOG_STYLE,
1964               title='Node Infos')
1965         self.SetClientSize(wx.Size(249, 250))
1966
1967         self.MainPanel = wx.Panel(id=wxID_NODEINFOSDIALOGMAINPANEL,
1968               name='MainPanel', parent=self, pos=wx.Point(0, 0),
1969               size=wx.Size(231, 264), style=wx.TAB_TRAVERSAL)
1970         self.MainPanel.SetAutoLayout(True)
1971
1972         self.staticText1 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT1,
1973               label='Name:', 
1974               name='staticText1', parent=self.MainPanel,
1975               pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0)
1976
1977         self.Name = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNAME, name='Name',
1978               parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(200,
1979               25), style=0, value='')
1980
1981         self.staticText2 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT2,
1982               label='Node ID:', name='staticText2', parent=self.MainPanel,
1983               pos=wx.Point(24, 80), size=wx.Size(67, 17), style=0)
1984
1985         self.NodeID = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNODEID, name='NodeID',
1986               parent=self.MainPanel, pos=wx.Point(24, 104), size=wx.Size(200,
1987               25), style=wx.TE_RIGHT, value='')
1988
1989         self.staticText3 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT3,
1990               label='Type:', name='staticText3', parent=self.MainPanel,
1991               pos=wx.Point(24, 136), size=wx.Size(71, 17), style=0)
1992
1993         self.Type = wx.Choice(choices=[], id=wxID_NODEINFOSDIALOGTYPE,
1994               name='Type', parent=self.MainPanel, pos=wx.Point(24, 160),
1995               size=wx.Size(200, 25), style=0)
1996
1997         self.staticText4 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT4,
1998               label='Profile:', name='staticText4', parent=self.MainPanel,
1999               pos=wx.Point(24, 192), size=wx.Size(47, 17), style=0)
2000
2001         self.Profile = wx.Choice(choices=[], id=wxID_NODEINFOSDIALOGPROFILE,
2002               name='Profile', parent=self.MainPanel, pos=wx.Point(24, 216),
2003               size=wx.Size(200, 25), style=0)
2004
2005         self._init_sizers()
2006
2007     def __init__(self, parent):
2008         self._init_ctrls(parent)
2009         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
2010         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
2011         self.Type.Append("master")
2012         self.Type.Append("slave")
2013         self.staticText4.Hide()
2014         self.Profile.Hide()
2015
2016         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
2017
2018     def OnOK(self, event):
2019         name = self.Name.GetValue()
2020         if name != "":
2021             good = not name[0].isdigit()
2022             for item in name.split("_"):
2023                 good &= item.isalnum()
2024         else:
2025             good = False
2026         if not good:
2027             message = wxMessageDialog(self, "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!", "ERROR", wxOK|wxICON_ERROR)
2028             message.ShowModal()
2029             message.Destroy()
2030             self.Name.SetFocus()
2031         else:
2032             self.EndModal(wxID_OK)
2033     
2034     def SetProfiles(self, profiles):
2035         for profile in profiles:
2036             self.Profile.Append(profile)
2037     
2038     def SetValues(self, name, id, type, profile):
2039         self.Name.SetValue(name)
2040         self.NodeID.SetValue("0x%02X"%id)
2041         self.Type.SetStringSelection(type)
2042         self.Profile.SetStringSelection(profile)
2043
2044     def GetValues(self):
2045         name = self.Name.GetValue()
2046         nodeid = eval(self.NodeID.GetValue())
2047         type = self.Type.GetStringSelection()
2048         profile = self.Profile.GetStringSelection()
2049         return name, nodeid, type, profile
2050
2051
2052
2053 #-------------------------------------------------------------------------------
2054 #                          Create New Node Dialog
2055 #-------------------------------------------------------------------------------
2056
2057
2058 [wxID_CREATENODEDIALOG, wxID_CREATENODEDIALOGEMERGENCY, 
2059  wxID_CREATENODEDIALOGGENSYNC, wxID_CREATENODEDIALOGMAINPANEL, 
2060  wxID_CREATENODEDIALOGNAME, wxID_CREATENODEDIALOGNMT_HEARTBEAT, 
2061  wxID_CREATENODEDIALOGNMT_NODEGUARDING, wxID_CREATENODEDIALOGNMT_NONE, 
2062  wxID_CREATENODEDIALOGNODEID, wxID_CREATENODEDIALOGPROFILE, 
2063  wxID_CREATENODEDIALOGSAVECONFIG, wxID_CREATENODEDIALOGSTATICTEXT1, 
2064  wxID_CREATENODEDIALOGSTATICTEXT2, wxID_CREATENODEDIALOGSTATICTEXT3, 
2065  wxID_CREATENODEDIALOGSTATICTEXT4, wxID_CREATENODEDIALOGSTATICTEXT5, 
2066  wxID_CREATENODEDIALOGSTATICTEXT6, wxID_CREATENODEDIALOGSTOREEDS, 
2067  wxID_CREATENODEDIALOGTYPE, 
2068 ] = [wx.NewId() for _init_ctrls in range(19)]
2069
2070 class CreateNodeDialog(wx.Dialog):
2071     def _init_coll_flexGridSizer1_Items(self, parent):
2072         # generated method, don't edit
2073
2074         parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
2075
2076     def _init_sizers(self):
2077         # generated method, don't edit
2078         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
2079
2080         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
2081
2082         self.SetSizer(self.flexGridSizer1)
2083
2084     def _init_ctrls(self, prnt):
2085         # generated method, don't edit
2086         wx.Dialog.__init__(self, id=wxID_CREATENODEDIALOG,
2087               name='CreateNodeDialog', parent=prnt, pos=wx.Point(376, 223),
2088               size=wx.Size(451, 316), style=wx.DEFAULT_DIALOG_STYLE,
2089               title='Create a new Node')
2090         self.SetClientSize(wx.Size(451, 316))
2091
2092         self.MainPanel = wx.Panel(id=wxID_CREATENODEDIALOGMAINPANEL,
2093               name='MainPanel', parent=self, pos=wx.Point(0, 0),
2094               size=wx.Size(440, 278), style=wx.TAB_TRAVERSAL)
2095         self.MainPanel.SetAutoLayout(True)
2096
2097         self.staticText1 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT1,
2098               label='Name:', name='staticText1', parent=self.MainPanel,
2099               pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0)
2100
2101         self.staticText2 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT2,
2102               label='Node ID:', name='staticText2', parent=self.MainPanel,
2103               pos=wx.Point(24, 80), size=wx.Size(67, 17), style=0)
2104
2105         self.staticText3 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT3,
2106               label='Type:', name='staticText3', parent=self.MainPanel,
2107               pos=wx.Point(24, 136), size=wx.Size(71, 17), style=0)
2108
2109         self.Type = wx.Choice(choices=[], id=wxID_CREATENODEDIALOGTYPE,
2110               name='Type', parent=self.MainPanel, pos=wx.Point(24, 160),
2111               size=wx.Size(200, 24), style=0)
2112
2113         self.Name = wx.TextCtrl(id=wxID_CREATENODEDIALOGNAME, name='Name',
2114               parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(200,
2115               25), style=0, value='')
2116
2117         self.NodeID = wx.TextCtrl(id=wxID_CREATENODEDIALOGNODEID, name='NodeID',
2118               parent=self.MainPanel, pos=wx.Point(24, 104), size=wx.Size(200,
2119               25), style=wx.TE_RIGHT, value='')
2120
2121         self.staticText4 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT4,
2122               label='Profile:', name='staticText4', parent=self.MainPanel,
2123               pos=wx.Point(24, 192), size=wx.Size(47, 17), style=0)
2124
2125         self.Profile = wx.Choice(choices=[], id=wxID_CREATENODEDIALOGPROFILE,
2126               name='Profile', parent=self.MainPanel, pos=wx.Point(24, 216),
2127               size=wx.Size(200, 24), style=0)
2128         self.Profile.Bind(wx.EVT_CHOICE, self.OnProfileChoice,
2129               id=wxID_CREATENODEDIALOGPROFILE)
2130
2131         self.staticText5 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT5,
2132               label='Network Management:', name='staticText5',
2133               parent=self.MainPanel, pos=wx.Point(256, 24), size=wx.Size(152,
2134               16), style=0)
2135
2136         self.NMT_None = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_NONE,
2137               label='None', name='NMT_None', parent=self.MainPanel,
2138               pos=wx.Point(256, 40), size=wx.Size(114, 24), style=0)
2139         self.NMT_None.SetValue(True)
2140
2141         self.NMT_NodeGuarding = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_NODEGUARDING,
2142               label='Node Guarding', name='NMT_NodeGuarding',
2143               parent=self.MainPanel, pos=wx.Point(256, 64), size=wx.Size(128,
2144               24), style=0)
2145         self.NMT_NodeGuarding.SetValue(False)
2146
2147         self.NMT_Heartbeat = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_HEARTBEAT,
2148               label='Heartbeat', name='NMT_Heartbeat', parent=self.MainPanel,
2149               pos=wx.Point(256, 88), size=wx.Size(114, 24), style=0)
2150         self.NMT_Heartbeat.SetValue(False)
2151
2152         self.staticText6 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT6,
2153               label='Options:', name='staticText6', parent=self.MainPanel,
2154               pos=wx.Point(256, 128), size=wx.Size(72, 17), style=0)
2155
2156         self.DS302 = wx.CheckBox(id=wxID_CREATENODEDIALOGGENSYNC,
2157               label='DS-302 Profile', name='DS302', parent=self.MainPanel,
2158               pos=wx.Point(256, 144), size=wx.Size(128, 24), style=0)
2159         self.DS302.SetValue(False)
2160         self.DS302.Enable(False)
2161
2162         self.GenSYNC = wx.CheckBox(id=wxID_CREATENODEDIALOGGENSYNC,
2163               label='Generate SYNC', name='GenSYNC', parent=self.MainPanel,
2164               pos=wx.Point(256, 168), size=wx.Size(128, 24), style=0)
2165         self.GenSYNC.SetValue(False)
2166
2167         self.Emergency = wx.CheckBox(id=wxID_CREATENODEDIALOGEMERGENCY,
2168               label='Emergency support', name='Emergency',
2169               parent=self.MainPanel, pos=wx.Point(256, 192), size=wx.Size(152,
2170               24), style=0)
2171         self.Emergency.SetValue(False)
2172         self.Emergency.Enable(False)
2173
2174         self.SaveConfig = wx.CheckBox(id=wxID_CREATENODEDIALOGSAVECONFIG,
2175               label='Save Configuration', name='SaveConfig',
2176               parent=self.MainPanel, pos=wx.Point(256, 216), size=wx.Size(152,
2177               24), style=0)
2178         self.SaveConfig.SetValue(False)
2179         self.SaveConfig.Enable(False)
2180
2181 #        self.StoreEDS = wx.CheckBox(id=wxID_CREATENODEDIALOGSTOREEDS,
2182 #              label='Store EDS', name='StoreEDS', parent=self.MainPanel,
2183 #              pos=wx.Point(256, 240), size=wx.Size(144, 24), style=0)
2184 #        self.StoreEDS.SetValue(False)
2185  
2186         self._init_sizers()
2187
2188     def __init__(self, parent):
2189         self._init_ctrls(parent)
2190         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
2191         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
2192         self.NodeID.SetValue("0x00")
2193         self.Type.Append("master")
2194         self.Type.Append("slave")
2195         self.Type.SetStringSelection("slave")
2196         self.ListProfile = {"None" : ""}
2197         self.Profile.Append("None")
2198         self.Directory = os.path.join(ScriptDirectory, "config")
2199         listfiles = os.listdir(self.Directory)
2200         listfiles.sort()
2201         for item in listfiles:
2202             name, extend = os.path.splitext(item)
2203             if os.path.isfile(os.path.join(self.Directory, item)) and extend == ".prf" and name != "DS-302":
2204                 self.ListProfile[name] = os.path.join(self.Directory, item)
2205                 self.Profile.Append(name)
2206         self.Profile.Append("Other")
2207         self.Profile.SetStringSelection("None")
2208         self.Name.SetFocus()
2209         
2210         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
2211
2212     def OnOK(self, event):
2213         name = self.Name.GetValue()
2214         if name != "":
2215             good = not name[0].isdigit()
2216             for item in name.split("_"):
2217                 good &= item.isalnum()
2218         else:
2219             good = False
2220         if not good:
2221             message = wxMessageDialog(self, "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!", "ERROR", wxOK|wxICON_ERROR)
2222             message.ShowModal()
2223             message.Destroy()
2224             self.Name.SetFocus()
2225         else:
2226             self.EndModal(wxID_OK)
2227
2228     def GetValues(self):
2229         name = self.Name.GetValue()
2230         nodeid = 0
2231         if self.NodeID.GetValue() != "":
2232             nodeid = eval(self.NodeID.GetValue())
2233         type = self.Type.GetStringSelection()
2234         return name, nodeid, type
2235
2236     def GetProfile(self):
2237         name = self.Profile.GetStringSelection()
2238         return name, self.ListProfile[name]
2239
2240     def GetNMTManagement(self):
2241         if self.NMT_None.GetValue():
2242             return "None"
2243         elif self.NMT_NodeGuarding.GetValue():
2244             return "NodeGuarding"
2245         elif self.NMT_Heartbeat.GetValue():
2246             return "Heartbeat"
2247         return None
2248     
2249     def GetOptions(self):
2250         options = []
2251         if self.DS302.GetValue():
2252             options.append("DS302")
2253         if self.GenSYNC.GetValue():
2254             options.append("GenSYNC")
2255         if self.Emergency.GetValue():
2256             options.append("Emergency")
2257         if self.SaveConfig.GetValue():
2258             options.append("SaveConfig")
2259 #        if self.StoreEDS.GetValue():
2260 #            options.append("StoreEDS")
2261         return options
2262
2263     def OnProfileChoice(self, event):
2264         if self.Profile.GetStringSelection() == "Other":
2265             dialog = wxFileDialog(self, "Choose a file", self.Directory, "",  "OD Profile files (*.prf)|*.prf|All files|*.*", wxOPEN|wxCHANGE_DIR)
2266             dialog.ShowModal()
2267             filepath = dialog.GetPath()
2268             dialog.Destroy()
2269             if os.path.isfile(filepath):
2270                 name = os.path.splitext(os.path.basename(filepath))[0]
2271                 self.ListProfile[name] = filepath
2272                 length = self.Profile.GetCount()
2273                 self.Profile.Insert(name, length - 2)
2274                 self.Profile.SetStringSelection(name)
2275             else:
2276                 self.Profile.SetStringSelection("None")
2277         event.Skip()
2278     
2279
2280 #-------------------------------------------------------------------------------
2281 #                               Exception Handler
2282 #-------------------------------------------------------------------------------
2283
2284 Max_Traceback_List_Size = 20
2285
2286 def Display_Exception_Dialog(e_type,e_value,e_tb):
2287     trcbck_lst = []
2288     for i,line in enumerate(traceback.extract_tb(e_tb)):
2289         trcbck = " " + str(i+1) + ". "
2290         if line[0].find(os.getcwd()) == -1:
2291             trcbck += "file : " + str(line[0]) + ",   "
2292         else:
2293             trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ",   "
2294         trcbck += "line : " + str(line[1]) + ",   " + "function : " + str(line[2])
2295         trcbck_lst.append(trcbck)
2296         
2297     # Allow clicking....
2298     cap = wx.Window_GetCapture()
2299     if cap:
2300         cap.ReleaseMouse()
2301
2302     dlg = wx.SingleChoiceDialog(None, 
2303         """
2304 An error happens.
2305
2306 Click on OK for saving an error report.
2307
2308 Please contact LOLITech at:
2309 +33 (0)3 29 52 95 67
2310 bugs_objdictedit@lolitech.fr
2311
2312
2313 Error:
2314 """ +
2315         str(e_type) + " : " + str(e_value), 
2316         "Error",
2317         trcbck_lst)
2318     try:
2319         res = (dlg.ShowModal() == wx.ID_OK)
2320     finally:
2321         dlg.Destroy()
2322
2323     return res
2324
2325 def Display_Error_Dialog(e_value):
2326     message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR)
2327     message.ShowModal()
2328     message.Destroy()
2329
2330 def get_last_traceback(tb):
2331     while tb.tb_next:
2332         tb = tb.tb_next
2333     return tb
2334
2335
2336 def format_namespace(d, indent='    '):
2337     return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
2338
2339
2340 ignored_exceptions = [] # a problem with a line in a module is only reported once per session
2341
2342 def wxAddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]):
2343     
2344     def handle_exception(e_type, e_value, e_traceback):
2345         traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func
2346         last_tb = get_last_traceback(e_traceback)
2347         ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
2348         if str(e_value).startswith("!!!"):
2349             Display_Error_Dialog(e_value)
2350         elif ex not in ignored_exceptions:
2351             ignored_exceptions.append(ex)
2352             result = Display_Exception_Dialog(e_type,e_value,e_traceback)
2353             if result:
2354                 info = {
2355                     'app-title' : wx.GetApp().GetAppName(), # app_title
2356                     'app-version' : app_version,
2357                     'wx-version' : wx.VERSION_STRING,
2358                     'wx-platform' : wx.Platform,
2359                     'python-version' : platform.python_version(), #sys.version.split()[0],
2360                     'platform' : platform.platform(),
2361                     'e-type' : e_type,
2362                     'e-value' : e_value,
2363                     'date' : time.ctime(),
2364                     'cwd' : os.getcwd(),
2365                     }
2366                 if e_traceback:
2367                     info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
2368                     last_tb = get_last_traceback(e_traceback)
2369                     exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred
2370                     info['locals'] = format_namespace(exception_locals)
2371                     if 'self' in exception_locals:
2372                         info['self'] = format_namespace(exception_locals['self'].__dict__)
2373                 
2374                 output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w')
2375                 lst = info.keys()
2376                 lst.sort()
2377                 for a in lst:
2378                     output.write(a+":\n"+str(info[a])+"\n\n")
2379
2380     #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
2381     sys.excepthook = handle_exception
2382
2383 if __name__ == '__main__':
2384     app = wxPySimpleApp()
2385     wxInitAllImageHandlers()
2386     
2387     # Install a exception handle for bug reports
2388     wxAddExceptHook(os.getcwd(),__version__)
2389     
2390     frame = objdictedit(None)
2391
2392     frame.Show()
2393     app.MainLoop()