2 # -*- coding: utf-8 -*-
4 #This file is part of CanFestival, a library implementing CanOpen Stack.
6 #Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD
8 #See COPYING file for copyrights details.
10 #This library is free software; you can redistribute it and/or
11 #modify it under the terms of the GNU Lesser General Public
12 #License as published by the Free Software Foundation; either
13 #version 2.1 of the License, or (at your option) any later version.
15 #This library is distributed in the hope that it will be useful,
16 #but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 #Lesser General Public License for more details.
20 #You should have received a copy of the GNU Lesser General Public
21 #License along with this library; if not, write to the Free Software
22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 import os, re, platform, sys, time, traceback, getopt
30 __version__ = "$Revision: 1.25 $"
32 from nodelist import *
33 from nodemanager import *
34 from subindextable import *
35 from commondialogs import *
36 from doc_index.DS301_index import *
38 ScriptDirectory = os.path.split(os.path.realpath(__file__))[0]
43 EVT_HTML_URL_CLICK = wx.NewId()
45 class HtmlWindowUrlClick(wx.PyEvent):
46 def __init__(self, linkinfo):
47 wx.PyEvent.__init__(self)
48 self.SetEventType(EVT_HTML_URL_CLICK)
49 self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget())
51 class UrlClickHtmlWindow(wx.html.HtmlWindow):
52 """ HTML window that generates and OnLinkClicked event.
54 Use this to avoid having to override HTMLWindow
56 def OnLinkClicked(self, linkinfo):
57 wx.PostEvent(self, HtmlWindowUrlClick(linkinfo))
59 def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY):
60 if event == HtmlWindowUrlClick:
61 self.Connect(-1, -1, EVT_HTML_URL_CLICK, handler)
63 wx.html.HtmlWindow.Bind(event, handler, source=source, id=id, id2=id2)
65 #-------------------------------------------------------------------------------
67 #-------------------------------------------------------------------------------
69 [ID_HTMLFRAME, ID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)]
71 class HtmlFrame(wx.Frame):
72 def _init_ctrls(self, prnt):
73 # generated method, don't edit
74 wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame',
75 parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616),
76 style=wx.DEFAULT_FRAME_STYLE, title='')
77 self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
79 self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT,
80 name='HtmlContent', parent=self, pos=wx.Point(0, 0),
81 size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO|wx.html.HW_NO_SELECTION)
82 self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick)
84 def __init__(self, parent, opened):
85 self._init_ctrls(parent)
86 self.HtmlFrameOpened = opened
88 def SetHtmlCode(self, htmlcode):
89 self.HtmlContent.SetPage(htmlcode)
91 def SetHtmlPage(self, htmlpage):
92 self.HtmlContent.LoadPage(htmlpage)
94 def OnCloseFrame(self, event):
95 self.HtmlFrameOpened.remove(self.GetTitle())
98 def OnLinkClick(self, event):
99 url = event.linkinfo[0]
103 wx.MessageBox('Please point your browser at: %s' % url)
112 [ID_NETWORKEDIT, ID_NETWORKEDITNETWORKNODES,
113 ID_NETWORKEDITHELPBAR,
114 ] = [wx.NewId() for _init_ctrls in range(3)]
116 [ID_NETWORKEDITNETWORKMENUBUILDMASTER,
117 ] = [wx.NewId() for _init_coll_AddMenu_Items in range(1)]
119 [ID_NETWORKEDITEDITMENUNODEINFOS, ID_NETWORKEDITEDITMENUDS301PROFILE,
120 ID_NETWORKEDITEDITMENUDS302PROFILE, ID_NETWORKEDITEDITMENUOTHERPROFILE,
121 ] = [wx.NewId() for _init_coll_EditMenu_Items in range(4)]
123 [ID_NETWORKEDITADDMENUSDOSERVER, ID_NETWORKEDITADDMENUSDOCLIENT,
124 ID_NETWORKEDITADDMENUPDOTRANSMIT, ID_NETWORKEDITADDMENUPDORECEIVE,
125 ID_NETWORKEDITADDMENUMAPVARIABLE, ID_NETWORKEDITADDMENUUSERTYPE,
126 ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)]
128 class networkedit(wx.Frame):
129 def _init_coll_MenuBar_Menus(self, parent):
131 parent.Append(menu=self.FileMenu, title='File')
132 parent.Append(menu=self.NetworkMenu, title='Network')
133 parent.Append(menu=self.EditMenu, title='Edit')
134 parent.Append(menu=self.AddMenu, title='Add')
135 parent.Append(menu=self.HelpMenu, title='Help')
137 def _init_coll_FileMenu_Items(self, parent):
138 parent.Append(help='', id=wx.ID_NEW,
139 kind=wx.ITEM_NORMAL, text='New\tCTRL+N')
140 parent.Append(help='', id=wx.ID_OPEN,
141 kind=wx.ITEM_NORMAL, text='Open\tCTRL+O')
142 parent.Append(help='', id=wx.ID_CLOSE,
143 kind=wx.ITEM_NORMAL, text='Close\tCTRL+W')
144 parent.AppendSeparator()
145 parent.Append(help='', id=wx.ID_SAVE,
146 kind=wx.ITEM_NORMAL, text='Save\tCTRL+S')
147 parent.AppendSeparator()
148 parent.Append(help='', id=wx.ID_EXIT,
149 kind=wx.ITEM_NORMAL, text='Exit')
150 self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
151 self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
152 self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE)
153 self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
154 self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
156 def _init_coll_NetworkMenu_Items(self, parent):
157 parent.Append(help='', id=wx.ID_ADD,
158 kind=wx.ITEM_NORMAL, text='Add Slave Node')
159 parent.Append(help='', id=wx.ID_DELETE,
160 kind=wx.ITEM_NORMAL, text='Remove Slave Node')
161 parent.AppendSeparator()
162 parent.Append(help='', id=ID_NETWORKEDITNETWORKMENUBUILDMASTER,
163 kind=wx.ITEM_NORMAL, text='Build Master Dictionary')
164 self.Bind(wx.EVT_MENU, self.OnAddSlaveMenu, id=wx.ID_ADD)
165 self.Bind(wx.EVT_MENU, self.OnRemoveSlaveMenu, id=wx.ID_DELETE)
166 ## self.Bind(wx.EVT_MENU, self.OnBuildMasterMenu,
167 ## id=ID_NETWORKEDITNETWORKMENUBUILDMASTER)
169 def _init_coll_EditMenu_Items(self, parent):
170 parent.Append(help='', id=wx.ID_REFRESH,
171 kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R')
172 parent.AppendSeparator()
173 parent.Append(help='', id=wx.ID_UNDO,
174 kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z')
175 parent.Append(help='', id=wx.ID_REDO,
176 kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y')
177 parent.AppendSeparator()
178 parent.Append(help='', id=ID_NETWORKEDITEDITMENUNODEINFOS,
179 kind=wx.ITEM_NORMAL, text='Node infos')
180 parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS301PROFILE,
181 kind=wx.ITEM_NORMAL, text='DS-301 Profile')
182 parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS302PROFILE,
183 kind=wx.ITEM_NORMAL, text='DS-302 Profile')
184 parent.Append(help='', id=ID_NETWORKEDITEDITMENUOTHERPROFILE,
185 kind=wx.ITEM_NORMAL, text='Other Profile')
186 self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH)
187 self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO)
188 self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO)
189 self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu,
190 id=ID_NETWORKEDITEDITMENUNODEINFOS)
191 self.Bind(wx.EVT_MENU, self.OnCommunicationMenu,
192 id=ID_NETWORKEDITEDITMENUDS301PROFILE)
193 self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu,
194 id=ID_NETWORKEDITEDITMENUDS302PROFILE)
195 self.Bind(wx.EVT_MENU, self.OnEditProfileMenu,
196 id=ID_NETWORKEDITEDITMENUOTHERPROFILE)
198 def _init_coll_AddMenu_Items(self, parent):
199 parent.Append(help='', id=ID_NETWORKEDITADDMENUSDOSERVER,
200 kind=wx.ITEM_NORMAL, text='SDO Server')
201 parent.Append(help='', id=ID_NETWORKEDITADDMENUSDOCLIENT,
202 kind=wx.ITEM_NORMAL, text='SDO Client')
203 parent.Append(help='', id=ID_NETWORKEDITADDMENUPDOTRANSMIT,
204 kind=wx.ITEM_NORMAL, text='PDO Transmit')
205 parent.Append(help='', id=ID_NETWORKEDITADDMENUPDORECEIVE,
206 kind=wx.ITEM_NORMAL, text='PDO Receive')
207 parent.Append(help='', id=ID_NETWORKEDITADDMENUMAPVARIABLE,
208 kind=wx.ITEM_NORMAL, text='Map Variable')
209 parent.Append(help='', id=ID_NETWORKEDITADDMENUUSERTYPE,
210 kind=wx.ITEM_NORMAL, text='User Type')
211 self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu,
212 id=ID_NETWORKEDITADDMENUSDOSERVER)
213 self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu,
214 id=ID_NETWORKEDITADDMENUSDOCLIENT)
215 self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu,
216 id=ID_NETWORKEDITADDMENUPDOTRANSMIT)
217 self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu,
218 id=ID_NETWORKEDITADDMENUPDORECEIVE)
219 self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu,
220 id=ID_NETWORKEDITADDMENUMAPVARIABLE)
221 self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu,
222 id=ID_NETWORKEDITADDMENUUSERTYPE)
224 def _init_coll_HelpMenu_Items(self, parent):
225 parent.Append(help='', id=wx.ID_HELP,
226 kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1')
227 self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu, id=wx.ID_HELP)
228 parent.Append(help='', id=wx.ID_HELP_CONTEXT,
229 kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2')
230 self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu, id=wx.ID_HELP_CONTEXT)
231 if Html_Window and self.ModeSolo:
232 parent.Append(help='', id=wx.ID_ABOUT,
233 kind=wx.ITEM_NORMAL, text='About')
234 self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
236 def _init_coll_HelpBar_Fields(self, parent):
237 parent.SetFieldsCount(3)
239 parent.SetStatusText(number=0, text='')
240 parent.SetStatusText(number=1, text='')
241 parent.SetStatusText(number=2, text='')
243 parent.SetStatusWidths([100, 110, -1])
245 def _init_utils(self):
246 self.MenuBar = wx.MenuBar()
247 self.MenuBar.SetEvtHandlerEnabled(True)
250 self.FileMenu = wx.Menu(title='')
251 self.NetworkMenu = wx.Menu(title='')
252 self.EditMenu = wx.Menu(title='')
253 self.AddMenu = wx.Menu(title='')
254 self.HelpMenu = wx.Menu(title='')
256 self._init_coll_MenuBar_Menus(self.MenuBar)
258 self._init_coll_FileMenu_Items(self.FileMenu)
259 self._init_coll_NetworkMenu_Items(self.NetworkMenu)
260 self._init_coll_EditMenu_Items(self.EditMenu)
261 self._init_coll_AddMenu_Items(self.AddMenu)
262 self._init_coll_HelpMenu_Items(self.HelpMenu)
264 def _init_ctrls(self, prnt):
265 wx.Frame.__init__(self, id=ID_NETWORKEDIT, name='networkedit',
266 parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700),
267 style=wx.DEFAULT_FRAME_STYLE, title='Networkedit')
269 self.SetClientSize(wx.Size(1000, 700))
270 self.SetMenuBar(self.MenuBar)
271 self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
272 if not self.ModeSolo:
273 self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
274 accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, 83, wx.ID_SAVE)])
275 self.SetAcceleratorTable(accel)
277 self.NetworkNodes = wx.Notebook(id=ID_NETWORKEDITNETWORKNODES,
278 name='NetworkNodes', parent=self, pos=wx.Point(0, 0),
279 size=wx.Size(0, 0), style=wx.NB_LEFT)
280 self.NetworkNodes.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
281 self.OnNodeSelectedChanged, id=ID_NETWORKEDITNETWORKNODES)
283 self.HelpBar = wx.StatusBar(id=ID_NETWORKEDITHELPBAR, name='HelpBar',
284 parent=self, style=wx.ST_SIZEGRIP)
285 self._init_coll_HelpBar_Fields(self.HelpBar)
286 self.SetStatusBar(self.HelpBar)
288 def __init__(self, parent, nodelist = None, projectOpen = None):
289 self.ModeSolo = nodelist == None
290 self._init_ctrls(parent)
291 self.HtmlFrameOpened = []
295 icon = wx.Icon(os.path.join(ScriptDirectory,"networkedit.ico"),wx.BITMAP_TYPE_ICO)
299 self.Manager = NodeManager()
301 self.NodeList = NodeList(self.Manager)
302 result = self.NodeList.LoadProject(projectOpen)
304 self.RefreshNetworkNodes()
308 self.NodeList = nodelist
309 self.Manager = self.NodeList.GetManager()
310 self.NodeList.SetCurrentSelected(0)
311 self.RefreshNetworkNodes()
312 self.RefreshProfileMenu()
313 self.NetworkNodes.SetFocus()
315 self.RefreshBufferState()
317 self.RefreshMainMenu()
319 def SetBusId(self, bus_id):
328 def GetCurrentNodeId(self):
329 selected = self.NetworkNodes.GetSelection()
330 # At init selected = -1
332 window = self.NetworkNodes.GetPage(selected)
333 return window.GetIndex()
337 def OnCloseFrame(self, event):
339 if not self.ModeSolo and getattr(self, "_onclose", None) != None:
343 def OnChar(self, event):
344 if event.ControlDown() and event.GetKeyCode() == 83 and getattr(self, "_onsave", None) != None:
348 def OnQuitMenu(self, event):
352 def OnAddSDOServerMenu(self, event):
353 self.Manager.AddSDOServerToCurrent()
354 self.RefreshBufferState()
355 self.RefreshCurrentIndexList()
358 def OnAddSDOClientMenu(self, event):
359 self.Manager.AddSDOClientToCurrent()
360 self.RefreshBufferState()
361 self.RefreshCurrentIndexList()
364 def OnAddPDOTransmitMenu(self, event):
365 self.Manager.AddPDOTransmitToCurrent()
366 self.RefreshBufferState()
367 self.RefreshCurrentIndexList()
370 def OnAddPDOReceiveMenu(self, event):
371 self.Manager.AddPDOReceiveToCurrent()
372 self.RefreshBufferState()
373 self.RefreshCurrentIndexList()
376 def OnAddMapVariableMenu(self, event):
377 self.AddMapVariable()
380 def OnAddUserTypeMenu(self, event):
384 def OnNodeSelectedChanged(self, event):
386 selected = event.GetSelection()
387 # At init selected = -1
389 window = self.NetworkNodes.GetPage(selected)
390 self.NodeList.SetCurrentSelected(window.GetIndex())
391 wx.CallAfter(self.RefreshMainMenu)
392 wx.CallAfter(self.RefreshStatusBar)
395 #-------------------------------------------------------------------------------
396 # Load and Save Funtions
397 #-------------------------------------------------------------------------------
399 def OnNewProjectMenu(self, event):
401 defaultpath = os.path.dirname(self.NodeList.GetRoot())
403 defaultpath = os.getcwd()
404 dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON)
405 if dialog.ShowModal() == wx.ID_OK:
406 projectpath = dialog.GetPath()
407 if os.path.isdir(projectpath) and len(os.listdir(projectpath)) == 0:
408 manager = NodeManager()
409 nodelist = NodeList(manager)
410 result = nodelist.LoadProject(projectpath)
412 self.Manager = manager
413 self.NodeList = nodelist
414 self.NodeList.SetCurrentSelected(0)
416 self.RefreshNetworkNodes()
417 self.RefreshBufferState()
419 self.RefreshProfileMenu()
420 self.RefreshMainMenu()
422 message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR)
427 def OnOpenProjectMenu(self, event):
429 defaultpath = os.path.dirname(self.NodeList.GetRoot())
431 defaultpath = os.getcwd()
432 dialog = wx.DirDialog(self , "Choose a project", defaultpath, 0)
433 if dialog.ShowModal() == wx.ID_OK:
434 projectpath = dialog.GetPath()
435 if os.path.isdir(projectpath):
436 manager = NodeManager()
437 nodelist = NodeList(manager)
438 result = nodelist.LoadProject(projectpath)
440 self.Manager = manager
441 self.NodeList = nodelist
442 self.NodeList.SetCurrentSelected(0)
444 self.RefreshNetworkNodes()
445 self.RefreshBufferState()
447 self.RefreshProfileMenu()
448 self.RefreshMainMenu()
450 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
456 def OnSaveProjectMenu(self, event):
457 if not self.ModeSolo and getattr(self, "_onsave", None) != None:
460 result = self.NodeList.SaveProject()
462 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
467 def OnCloseProjectMenu(self, event):
469 if self.NodeList.HasChanged():
470 dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close Project", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
471 answer = dialog.ShowModal()
473 if answer == wx.ID_YES:
474 result = self.NodeList.SaveProject()
476 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
479 elif answer == wx.ID_NO:
480 self.NodeList.ForceChanged(False)
481 if not self.NodeList.HasChanged():
484 self.RefreshNetworkNodes()
486 self.RefreshMainMenu()
489 #-------------------------------------------------------------------------------
490 # Slave Nodes Management
491 #-------------------------------------------------------------------------------
493 def OnAddSlaveMenu(self, event):
494 dialog = AddSlaveDialog(self)
495 dialog.SetNodeList(self.NodeList)
496 if dialog.ShowModal() == wx.ID_OK:
497 values = dialog.GetValues()
498 result = self.NodeList.AddSlaveNode(values["slaveName"], values["slaveNodeID"], values["edsFile"])
500 new_editingpanel = EditingPanel(self.NetworkNodes, self, self.NodeList, False)
501 new_editingpanel.SetIndex(values["slaveNodeID"])
502 idx = self.NodeList.GetOrderNumber(values["slaveNodeID"])
503 self.NetworkNodes.InsertPage(idx, new_editingpanel, "")
504 self.NodeList.SetCurrentSelected(idx)
505 self.NetworkNodes.SetSelection(idx)
506 self.RefreshBufferState()
508 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
514 def OnRemoveSlaveMenu(self, event):
515 slavenames = self.NodeList.GetSlaveNames()
516 slaveids = self.NodeList.GetSlaveIDs()
517 dialog = wx.SingleChoiceDialog(self, "Choose a slave to remove", "Remove slave", slavenames)
518 if dialog.ShowModal() == wx.ID_OK:
519 choice = dialog.GetSelection()
520 result = self.NodeList.RemoveSlaveNode(slaveids[choice])
523 current = self.NetworkNodes.GetSelection()
524 self.NetworkNodes.DeletePage(choice + 1)
525 if self.NetworkNodes.GetPageCount() > 0:
526 new_selection = min(current, self.NetworkNodes.GetPageCount() - 1)
527 self.NetworkNodes.SetSelection(new_selection)
528 if new_selection > 0:
529 self.NodeList.SetCurrentSelected(slaveids[new_selection - 1])
530 self.RefreshBufferState()
532 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
537 #-------------------------------------------------------------------------------
539 #-------------------------------------------------------------------------------
541 def RefreshTitle(self):
542 if self.NodeList != None:
543 self.SetTitle("Networkedit - %s"%self.NodeList.GetNetworkName())
545 self.SetTitle("Networkedit")
547 def OnRefreshMenu(self, event):
548 self.RefreshCurrentIndexList()
551 def RefreshCurrentIndexList(self):
552 selected = self.NetworkNodes.GetSelection()
554 window = self.NetworkNodes.GetPage(selected)
555 window.RefreshIndexList()
559 def RefreshNetworkNodes(self):
560 if self.NetworkNodes.GetPageCount() > 0:
561 self.NetworkNodes.DeleteAllPages()
563 new_editingpanel = EditingPanel(self.NetworkNodes, self, self.Manager)
564 new_editingpanel.SetIndex(0)
565 self.NetworkNodes.AddPage(new_editingpanel, "")
566 for idx in self.NodeList.GetSlaveIDs():
567 new_editingpanel = EditingPanel(self.NetworkNodes, self, self.NodeList, False)
568 new_editingpanel.SetIndex(idx)
569 self.NetworkNodes.AddPage(new_editingpanel, "")
571 def RefreshStatusBar(self):
572 selected = self.NetworkNodes.GetSelection()
573 if self.HelpBar and selected >= 0:
574 window = self.NetworkNodes.GetPage(selected)
575 selection = window.GetSelection()
577 index, subIndex = selection
578 if self.NodeList.IsCurrentEntry(index):
579 self.HelpBar.SetStatusText("Index: 0x%04X"%index, 0)
580 self.HelpBar.SetStatusText("Subindex: 0x%02X"%subIndex, 1)
581 entryinfos = self.NodeList.GetEntryInfos(index)
582 name = entryinfos["name"]
583 category = "Optional"
584 if entryinfos["need"]:
585 category = "Mandatory"
588 if entryinfos["struct"] & OD_IdenticalIndexes:
589 number = " possibly defined %d times"%entryinfos["nbmax"]
590 if entryinfos["struct"] & OD_IdenticalSubindexes:
592 elif entryinfos["struct"] & OD_MultipleSubindexes:
594 text = "%s: %s entry of struct %s%s."%(name,category,struct,number)
595 self.HelpBar.SetStatusText(text, 2)
598 self.HelpBar.SetStatusText("", i)
601 self.HelpBar.SetStatusText("", i)
603 def RefreshMainMenu(self):
604 self.NetworkMenu.Enable(ID_NETWORKEDITNETWORKMENUBUILDMASTER, False)
605 if self.NodeList == None:
607 self.MenuBar.EnableTop(1, False)
608 self.MenuBar.EnableTop(2, False)
609 self.MenuBar.EnableTop(3, False)
611 self.FileMenu.Enable(wx.ID_CLOSE, False)
612 self.FileMenu.Enable(wx.ID_SAVE, False)
614 self.MenuBar.EnableTop(0, False)
615 self.MenuBar.EnableTop(1, False)
616 self.MenuBar.EnableTop(2, False)
619 self.MenuBar.EnableTop(1, True)
621 self.FileMenu.Enable(wx.ID_CLOSE, True)
622 self.FileMenu.Enable(wx.ID_SAVE, True)
623 if self.NetworkNodes.GetSelection() == 0:
624 self.MenuBar.EnableTop(2, True)
625 self.MenuBar.EnableTop(3, True)
627 self.MenuBar.EnableTop(2, False)
628 self.MenuBar.EnableTop(3, False)
630 self.MenuBar.EnableTop(0, True)
631 if self.NetworkNodes.GetSelection() == 0:
632 self.MenuBar.EnableTop(1, True)
633 self.MenuBar.EnableTop(2, True)
635 self.MenuBar.EnableTop(1, False)
636 self.MenuBar.EnableTop(2, False)
638 def RefreshProfileMenu(self):
639 profile = self.Manager.GetCurrentProfileName()
640 edititem = self.EditMenu.FindItemById(ID_NETWORKEDITEDITMENUOTHERPROFILE)
642 length = self.AddMenu.GetMenuItemCount()
643 for i in xrange(length-6):
644 additem = self.AddMenu.FindItemByPosition(6)
645 self.AddMenu.Delete(additem.GetId())
646 if profile not in ("None", "DS-301"):
647 edititem.SetText("%s Profile"%profile)
648 edititem.Enable(True)
649 self.AddMenu.AppendSeparator()
650 for text, indexes in self.Manager.GetCurrentSpecificMenu():
652 self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text)
653 self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id)
655 edititem.SetText("Other Profile")
656 edititem.Enable(False)
658 def GetProfileCallBack(self, text):
659 def ProfileCallBack(event):
660 self.Manager.AddSpecificEntryToCurrent(text)
661 self.RefreshBufferState()
662 self.RefreshCurrentIndexList()
664 return ProfileCallBack
666 #-------------------------------------------------------------------------------
668 #-------------------------------------------------------------------------------
670 def RefreshBufferState(self):
671 if self.NodeList is not None:
672 nodeID = self.Manager.GetCurrentNodeID()
674 nodename = "0x%2.2X %s"%(nodeID, self.Manager.GetCurrentNodeName())
676 nodename = self.Manager.GetCurrentNodeName()
677 self.NetworkNodes.SetPageText(0, nodename)
678 for idx, name in enumerate(self.NodeList.GetSlaveNames()):
679 self.NetworkNodes.SetPageText(idx + 1, name)
682 def OnUndoMenu(self, event):
683 self.Manager.LoadCurrentPrevious()
684 self.RefreshCurrentIndexList()
685 self.RefreshBufferState()
688 def OnRedoMenu(self, event):
689 self.Manager.LoadCurrentNext()
690 self.RefreshCurrentIndexList()
691 self.RefreshBufferState()
694 #-------------------------------------------------------------------------------
696 #-------------------------------------------------------------------------------
698 def OnHelpDS301Menu(self, event):
700 selected = self.NetworkNodes.GetSelection()
702 window = self.NetworkNodes.GetPage(selected)
703 result = window.GetSelection()
706 index, subIndex = result
707 result = OpenPDFDocIndex(index, ScriptDirectory)
708 if isinstance(result, (StringType, UnicodeType)):
709 message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR)
713 result = OpenPDFDocIndex(None, ScriptDirectory)
714 if isinstance(result, (StringType, UnicodeType)):
715 message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR)
720 def OnHelpCANFestivalMenu(self, event):
721 #self.OpenHtmlFrame("CAN Festival Reference", os.path.join(ScriptDirectory, "doc/canfestival.html"), wx.Size(1000, 600))
722 if wx.Platform == '__WXMSW__':
723 readerpath = get_acroversion()
724 readerexepath = os.path.join(readerpath,"AcroRd32.exe")
725 if(os.path.isfile(readerexepath)):
726 os.spawnl(os.P_DETACH, readerexepath, "AcroRd32.exe", '"%s"'%os.path.join(ScriptDirectory, "doc","manual_en.pdf"))
728 os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16))
731 def OnAboutMenu(self, event):
732 self.OpenHtmlFrame("About CAN Festival", os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450))
735 def OpenHtmlFrame(self, title, file, size):
736 if title not in self.HtmlFrameOpened:
737 self.HtmlFrameOpened.append(title)
738 window = HtmlFrame(self, self.HtmlFrameOpened)
739 window.SetTitle(title)
740 window.SetHtmlPage(file)
741 window.SetClientSize(size)
744 #-------------------------------------------------------------------------------
745 # Editing Profiles functions
746 #-------------------------------------------------------------------------------
748 def OnCommunicationMenu(self, event):
749 dictionary,current = self.Manager.GetCurrentCommunicationLists()
750 self.EditProfile("Edit DS-301 Profile", dictionary, current)
753 def OnOtherCommunicationMenu(self, event):
754 dictionary,current = self.Manager.GetCurrentDS302Lists()
755 self.EditProfile("Edit DS-301 Profile", dictionary, current)
758 def OnEditProfileMenu(self, event):
759 title = "Edit %s Profile"%self.Manager.GetCurrentProfileName()
760 dictionary,current = self.Manager.GetCurrentProfileLists()
761 self.EditProfile(title, dictionary, current)
764 def EditProfile(self, title, dictionary, current):
765 dialog = CommunicationDialog(self)
766 dialog.SetTitle(title)
767 dialog.SetIndexDictionary(dictionary)
768 dialog.SetCurrentList(current)
769 dialog.RefreshLists()
770 if dialog.ShowModal() == wx.ID_OK:
771 new_profile = dialog.GetCurrentList()
774 for index in new_profile:
775 if index not in current:
776 addinglist.append(index)
777 for index in current:
778 if index not in new_profile:
779 removinglist.append(index)
780 self.Manager.ManageEntriesOfCurrent(addinglist, removinglist)
781 self.Manager.BufferCurrentNode()
782 self.RefreshBufferState()
783 self.RefreshCurrentIndexList()
786 #-------------------------------------------------------------------------------
787 # Edit Node informations function
788 #-------------------------------------------------------------------------------
790 def OnNodeInfosMenu(self, event):
791 dialog = NodeInfosDialog(self)
792 name, id, type, description = self.Manager.GetCurrentNodeInfos()
793 defaultstringsize = self.Manager.GetCurrentNodeDefaultStringSize()
794 dialog.SetValues(name, id, type, description, defaultstringsize)
795 if dialog.ShowModal() == wx.ID_OK:
796 name, id, type, description, defaultstringsize = dialog.GetValues()
797 self.Manager.SetCurrentNodeInfos(name, id, type, description)
798 self.Manager.SetCurrentNodeDefaultStringSize(defaultstringsize)
799 self.RefreshBufferState()
800 self.RefreshProfileMenu()
801 selected = self.NetworkNodes.GetSelection()
803 window = self.NetworkNodes.GetPage(selected)
804 window.RefreshTable()
808 #-------------------------------------------------------------------------------
809 # Add User Types and Variables
810 #-------------------------------------------------------------------------------
812 def AddMapVariable(self):
813 index = self.Manager.GetCurrentNextMapIndex()
815 dialog = MapVariableDialog(self)
816 dialog.SetIndex(index)
817 if dialog.ShowModal() == wx.ID_OK:
818 index, name, struct, number = dialog.GetValues()
819 result = self.Manager.AddMapVariableToCurrent(index, name, struct, number)
820 if not isinstance(result, (StringType, UnicodeType)):
821 self.RefreshBufferState()
822 self.RefreshCurrentIndexList()
824 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
829 message = wx.MessageDialog(self, result, "No map variable index left!", wx.OK|wx.ICON_ERROR)
833 def AddUserType(self):
834 dialog = UserTypeDialog(self)
835 dialog.SetTypeList(self.Manager.GetCustomisableTypes())
836 if dialog.ShowModal() == wx.ID_OK:
837 type, min, max, length = dialog.GetValues()
838 result = self.Manager.AddUserTypeToCurrent(type, min, max, length)
839 if not IsOfType(result, StringType):
840 self.RefreshBufferState()
841 self.RefreshCurrentIndexList()
843 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
848 def OpenMasterDCFDialog(self, node_id):
849 self.NetworkNodes.SetSelection(0)
850 self.NetworkNodes.GetPage(0).OpenDCFDialog(node_id)
852 #-------------------------------------------------------------------------------
854 #-------------------------------------------------------------------------------
856 Max_Traceback_List_Size = 20
858 def Display_Exception_Dialog(e_type,e_value,e_tb):
860 for i,line in enumerate(traceback.extract_tb(e_tb)):
861 trcbck = " " + str(i+1) + ". "
862 if line[0].find(os.getcwd()) == -1:
863 trcbck += "file : " + str(line[0]) + ", "
865 trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", "
866 trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2])
867 trcbck_lst.append(trcbck)
870 cap = wx.Window_GetCapture()
874 dlg = wx.SingleChoiceDialog(None,
878 Click on OK for saving an error report.
880 Please contact LOLITech at:
882 bugs_networkedit@lolitech.fr
887 str(e_type) + " : " + str(e_value),
891 res = (dlg.ShowModal() == wx.ID_OK)
897 def Display_Error_Dialog(e_value):
898 message = wx.MessageDialog(None, str(e_value), "Error", wx.OK|wx.ICON_ERROR)
902 def get_last_traceback(tb):
908 def format_namespace(d, indent=' '):
909 return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
912 ignored_exceptions = [] # a problem with a line in a module is only reported once per session
914 def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]):
916 def handle_exception(e_type, e_value, e_traceback):
917 traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func
918 last_tb = get_last_traceback(e_traceback)
919 ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
920 if str(e_value).startswith("!!!"):
921 Display_Error_Dialog(e_value)
922 elif ex not in ignored_exceptions:
923 ignored_exceptions.append(ex)
924 result = Display_Exception_Dialog(e_type,e_value,e_traceback)
927 'app-title' : wx.GetApp().GetAppName(), # app_title
928 'app-version' : app_version,
929 'wx-version' : wx.VERSION_STRING,
930 'wx-platform' : wx.Platform,
931 'python-version' : platform.python_version(), #sys.version.split()[0],
932 'platform' : platform.platform(),
935 'date' : time.ctime(),
939 info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
940 last_tb = get_last_traceback(e_traceback)
941 exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred
942 info['locals'] = format_namespace(exception_locals)
943 if 'self' in exception_locals:
944 info['self'] = format_namespace(exception_locals['self'].__dict__)
946 output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w')
950 output.write(a+":\n"+str(info[a])+"\n\n")
952 #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
953 sys.excepthook = handle_exception
955 if __name__ == '__main__':
957 print "\nUsage of networkedit.py :"
958 print "\n %s [Projectpath]\n"%sys.argv[0]
961 opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
962 except getopt.GetoptError:
963 # print help information and exit:
968 if o in ("-h", "--help"):
975 projectOpen = args[0]
980 app = wx.PySimpleApp()
981 wx.InitAllImageHandlers()
983 # Install a exception handle for bug reports
984 AddExceptHook(os.getcwd(),__version__)
986 frame = networkedit(None, projectOpen=projectOpen)