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