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.22 $"
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 = []
294 icon = wx.Icon(os.path.join(ScriptDirectory,"networkedit.ico"),wx.BITMAP_TYPE_ICO)
298 self.Manager = NodeManager()
300 self.NodeList = NodeList(self.Manager)
301 result = self.NodeList.LoadProject(projectOpen)
303 self.RefreshNetworkNodes()
307 self.NodeList = nodelist
308 self.Manager = self.NodeList.GetManager()
309 self.NodeList.SetCurrentSelected(0)
310 self.RefreshNetworkNodes()
311 self.RefreshProfileMenu()
312 self.NetworkNodes.SetFocus()
314 self.RefreshBufferState()
316 self.RefreshMainMenu()
318 def SetBusId(self, bus_id):
324 def GetCurrentNodeId(self):
325 selected = self.NetworkNodes.GetSelection()
326 # At init selected = -1
328 window = self.NetworkNodes.GetPage(selected)
329 return window.GetIndex()
333 def OnCloseFrame(self, event):
334 if not self.ModeSolo and getattr(self, "_onclose", None) != None:
338 def OnChar(self, event):
339 if event.ControlDown() and event.GetKeyCode() == 83 and getattr(self, "_onsave", None) != None:
343 def OnQuitMenu(self, event):
347 def OnAddSDOServerMenu(self, event):
348 self.Manager.AddSDOServerToCurrent()
349 self.RefreshBufferState()
350 self.RefreshCurrentIndexList()
353 def OnAddSDOClientMenu(self, event):
354 self.Manager.AddSDOClientToCurrent()
355 self.RefreshBufferState()
356 self.RefreshCurrentIndexList()
359 def OnAddPDOTransmitMenu(self, event):
360 self.Manager.AddPDOTransmitToCurrent()
361 self.RefreshBufferState()
362 self.RefreshCurrentIndexList()
365 def OnAddPDOReceiveMenu(self, event):
366 self.Manager.AddPDOReceiveToCurrent()
367 self.RefreshBufferState()
368 self.RefreshCurrentIndexList()
371 def OnAddMapVariableMenu(self, event):
372 self.AddMapVariable()
375 def OnAddUserTypeMenu(self, event):
379 def OnNodeSelectedChanged(self, event):
380 selected = event.GetSelection()
381 # At init selected = -1
383 window = self.NetworkNodes.GetPage(selected)
384 self.NodeList.SetCurrentSelected(window.GetIndex())
385 wx.CallAfter(self.RefreshMainMenu)
386 wx.CallAfter(self.RefreshStatusBar)
389 #-------------------------------------------------------------------------------
390 # Load and Save Funtions
391 #-------------------------------------------------------------------------------
393 def OnNewProjectMenu(self, event):
395 defaultpath = os.path.dirname(self.NodeList.GetRoot())
397 defaultpath = os.getcwd()
398 dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON)
399 if dialog.ShowModal() == wx.ID_OK:
400 projectpath = dialog.GetPath()
401 if os.path.isdir(projectpath) and len(os.listdir(projectpath)) == 0:
402 manager = NodeManager()
403 nodelist = NodeList(manager)
404 result = nodelist.LoadProject(projectpath)
406 self.Manager = manager
407 self.NodeList = nodelist
408 self.NodeList.SetCurrentSelected(0)
410 self.RefreshNetworkNodes()
411 self.RefreshBufferState()
413 self.RefreshProfileMenu()
414 self.RefreshMainMenu()
416 message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR)
421 def OnOpenProjectMenu(self, event):
423 defaultpath = os.path.dirname(self.NodeList.GetRoot())
425 defaultpath = os.getcwd()
426 dialog = wx.DirDialog(self , "Choose a project", defaultpath, 0)
427 if dialog.ShowModal() == wx.ID_OK:
428 projectpath = dialog.GetPath()
429 if os.path.isdir(projectpath):
430 manager = NodeManager()
431 nodelist = NodeList(manager)
432 result = nodelist.LoadProject(projectpath)
434 self.Manager = manager
435 self.NodeList = nodelist
436 self.NodeList.SetCurrentSelected(0)
438 self.RefreshNetworkNodes()
439 self.RefreshBufferState()
441 self.RefreshProfileMenu()
442 self.RefreshMainMenu()
444 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
450 def OnSaveProjectMenu(self, event):
451 if not self.ModeSolo and getattr(self, "_onsave", None) != None:
454 result = self.NodeList.SaveProject()
456 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
461 def OnCloseProjectMenu(self, event):
463 if self.NodeList.HasChanged():
464 dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close Project", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
465 answer = dialog.ShowModal()
467 if answer == wx.ID_YES:
468 result = self.NodeList.SaveProject()
470 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
473 elif answer == wx.ID_NO:
474 self.NodeList.ForceChanged(False)
475 if not self.NodeList.HasChanged():
478 self.RefreshNetworkNodes()
480 self.RefreshMainMenu()
483 #-------------------------------------------------------------------------------
484 # Slave Nodes Management
485 #-------------------------------------------------------------------------------
487 def OnAddSlaveMenu(self, event):
488 dialog = AddSlaveDialog(self)
489 dialog.SetNodeList(self.NodeList)
490 if dialog.ShowModal() == wx.ID_OK:
491 values = dialog.GetValues()
492 result = self.NodeList.AddSlaveNode(values["slaveName"], values["slaveNodeID"], values["edsFile"])
494 new_editingpanel = EditingPanel(self.NetworkNodes, self, self.NodeList, False)
495 new_editingpanel.SetIndex(values["slaveNodeID"])
496 idx = self.NodeList.GetOrderNumber(values["slaveNodeID"])
497 self.NetworkNodes.InsertPage(idx, new_editingpanel, "")
498 self.NodeList.SetCurrentSelected(idx)
499 self.NetworkNodes.SetSelection(idx)
500 self.RefreshBufferState()
502 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
508 def OnRemoveSlaveMenu(self, event):
509 slavenames = self.NodeList.GetSlaveNames()
510 slaveids = self.NodeList.GetSlaveIDs()
511 dialog = wx.SingleChoiceDialog(self, "Choose a slave to remove", "Remove slave", slavenames)
512 if dialog.ShowModal() == wx.ID_OK:
513 choice = dialog.GetSelection()
514 result = self.NodeList.RemoveSlaveNode(slaveids[choice])
517 current = self.NetworkNodes.GetSelection()
518 self.NetworkNodes.DeletePage(choice + 1)
519 if self.NetworkNodes.GetPageCount() > 0:
520 new_selection = min(current, self.NetworkNodes.GetPageCount() - 1)
521 self.NetworkNodes.SetSelection(new_selection)
522 if new_selection > 0:
523 self.NodeList.SetCurrentSelected(slaveids[new_selection - 1])
524 self.RefreshBufferState()
526 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
531 #-------------------------------------------------------------------------------
533 #-------------------------------------------------------------------------------
535 def RefreshTitle(self):
536 if self.NodeList != None:
537 self.SetTitle("Networkedit - %s"%self.NodeList.GetNetworkName())
539 self.SetTitle("Networkedit")
541 def OnRefreshMenu(self, event):
542 self.RefreshCurrentIndexList()
545 def RefreshCurrentIndexList(self):
546 selected = self.NetworkNodes.GetSelection()
548 window = self.NetworkNodes.GetPage(selected)
549 window.RefreshIndexList()
553 def RefreshNetworkNodes(self):
554 if self.NetworkNodes.GetPageCount() > 0:
555 self.NetworkNodes.DeleteAllPages()
557 new_editingpanel = EditingPanel(self.NetworkNodes, self, self.Manager)
558 new_editingpanel.SetIndex(0)
559 self.NetworkNodes.AddPage(new_editingpanel, "")
560 for idx in self.NodeList.GetSlaveIDs():
561 new_editingpanel = EditingPanel(self.NetworkNodes, self, self.NodeList, False)
562 new_editingpanel.SetIndex(idx)
563 self.NetworkNodes.AddPage(new_editingpanel, "")
565 def RefreshStatusBar(self):
567 selected = self.NetworkNodes.GetSelection()
568 if self.HelpBar and selected >= 0:
569 window = self.NetworkNodes.GetPage(selected)
570 selection = window.GetSelection()
572 index, subIndex = selection
573 if self.NodeList.IsCurrentEntry(index):
574 self.HelpBar.SetStatusText("Index: 0x%04X"%index, 0)
575 self.HelpBar.SetStatusText("Subindex: 0x%02X"%subIndex, 1)
576 entryinfos = self.NodeList.GetEntryInfos(index)
577 name = entryinfos["name"]
578 category = "Optional"
579 if entryinfos["need"]:
580 category = "Mandatory"
583 if entryinfos["struct"] & OD_IdenticalIndexes:
584 number = " possibly defined %d times"%entryinfos["nbmax"]
585 if entryinfos["struct"] & OD_IdenticalSubindexes:
587 elif entryinfos["struct"] & OD_MultipleSubindexes:
589 text = "%s: %s entry of struct %s%s."%(name,category,struct,number)
590 self.HelpBar.SetStatusText(text, 2)
593 self.HelpBar.SetStatusText("", i)
596 self.HelpBar.SetStatusText("", i)
598 def RefreshMainMenu(self):
600 self.NetworkMenu.Enable(ID_NETWORKEDITNETWORKMENUBUILDMASTER, False)
601 if self.NodeList == None:
603 self.MenuBar.EnableTop(1, False)
604 self.MenuBar.EnableTop(2, False)
605 self.MenuBar.EnableTop(3, False)
607 self.FileMenu.Enable(wx.ID_CLOSE, False)
608 self.FileMenu.Enable(wx.ID_SAVE, False)
610 self.MenuBar.EnableTop(0, False)
611 self.MenuBar.EnableTop(1, False)
612 self.MenuBar.EnableTop(2, False)
615 self.MenuBar.EnableTop(1, True)
617 self.FileMenu.Enable(wx.ID_CLOSE, True)
618 self.FileMenu.Enable(wx.ID_SAVE, True)
619 if self.NetworkNodes.GetSelection() == 0:
620 self.MenuBar.EnableTop(2, True)
621 self.MenuBar.EnableTop(3, True)
623 self.MenuBar.EnableTop(2, False)
624 self.MenuBar.EnableTop(3, False)
626 self.MenuBar.EnableTop(0, True)
627 if self.NetworkNodes.GetSelection() == 0:
628 self.MenuBar.EnableTop(1, True)
629 self.MenuBar.EnableTop(2, True)
631 self.MenuBar.EnableTop(1, False)
632 self.MenuBar.EnableTop(2, False)
634 def RefreshProfileMenu(self):
636 profile = self.Manager.GetCurrentProfileName()
637 edititem = self.EditMenu.FindItemById(ID_NETWORKEDITEDITMENUOTHERPROFILE)
639 length = self.AddMenu.GetMenuItemCount()
640 for i in xrange(length-6):
641 additem = self.AddMenu.FindItemByPosition(6)
642 self.AddMenu.Delete(additem.GetId())
643 if profile not in ("None", "DS-301"):
644 edititem.SetText("%s Profile"%profile)
645 edititem.Enable(True)
646 self.AddMenu.AppendSeparator()
647 for text, indexes in self.Manager.GetCurrentSpecificMenu():
649 self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text)
650 self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id)
652 edititem.SetText("Other Profile")
653 edititem.Enable(False)
655 def GetProfileCallBack(self, text):
656 def ProfileCallBack(event):
657 self.Manager.AddSpecificEntryToCurrent(text)
658 self.RefreshBufferState()
659 self.RefreshCurrentIndexList()
661 return ProfileCallBack
663 #-------------------------------------------------------------------------------
665 #-------------------------------------------------------------------------------
667 def RefreshBufferState(self):
669 nodeID = self.Manager.GetCurrentNodeID()
671 nodename = "0x%2.2X %s"%(nodeID, self.Manager.GetCurrentNodeName())
673 nodename = self.Manager.GetCurrentNodeName()
674 self.NetworkNodes.SetPageText(0, nodename)
675 for idx, name in enumerate(self.NodeList.GetSlaveNames()):
676 self.NetworkNodes.SetPageText(idx + 1, name)
679 def OnUndoMenu(self, event):
680 self.Manager.LoadCurrentPrevious()
681 self.RefreshCurrentIndexList()
682 self.RefreshBufferState()
685 def OnRedoMenu(self, event):
686 self.Manager.LoadCurrentNext()
687 self.RefreshCurrentIndexList()
688 self.RefreshBufferState()
691 #-------------------------------------------------------------------------------
693 #-------------------------------------------------------------------------------
695 def OnHelpDS301Menu(self, event):
697 selected = self.NetworkNodes.GetSelection()
699 window = self.NetworkNodes.GetPage(selected)
700 result = window.GetSelection()
703 index, subIndex = result
704 result = OpenPDFDocIndex(index, ScriptDirectory)
705 if type(result) == StringType:
706 message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR)
710 result = OpenPDFDocIndex(None, ScriptDirectory)
711 if type(result) == StringType:
712 message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR)
717 def OnHelpCANFestivalMenu(self, event):
718 #self.OpenHtmlFrame("CAN Festival Reference", os.path.join(ScriptDirectory, "doc/canfestival.html"), wx.Size(1000, 600))
719 if wx.Platform == '__WXMSW__':
720 readerpath = get_acroversion()
721 readerexepath = os.path.join(readerpath,"AcroRd32.exe")
722 if(os.path.isfile(readerexepath)):
723 os.spawnl(os.P_DETACH, readerexepath, "AcroRd32.exe", '"%s"'%os.path.join(ScriptDirectory, "doc","manual_en.pdf"))
725 os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16))
728 def OnAboutMenu(self, event):
729 self.OpenHtmlFrame("About CAN Festival", os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450))
732 def OpenHtmlFrame(self, title, file, size):
733 if title not in self.HtmlFrameOpened:
734 self.HtmlFrameOpened.append(title)
735 window = HtmlFrame(self, self.HtmlFrameOpened)
736 window.SetTitle(title)
737 window.SetHtmlPage(file)
738 window.SetClientSize(size)
741 #-------------------------------------------------------------------------------
742 # Editing Profiles functions
743 #-------------------------------------------------------------------------------
745 def OnCommunicationMenu(self, event):
746 dictionary,current = self.Manager.GetCurrentCommunicationLists()
747 self.EditProfile("Edit DS-301 Profile", dictionary, current)
750 def OnOtherCommunicationMenu(self, event):
751 dictionary,current = self.Manager.GetCurrentDS302Lists()
752 self.EditProfile("Edit DS-301 Profile", dictionary, current)
755 def OnEditProfileMenu(self, event):
756 title = "Edit %s Profile"%self.Manager.GetCurrentProfileName()
757 dictionary,current = self.Manager.GetCurrentProfileLists()
758 self.EditProfile(title, dictionary, current)
761 def EditProfile(self, title, dictionary, current):
762 dialog = CommunicationDialog(self)
763 dialog.SetTitle(title)
764 dialog.SetIndexDictionary(dictionary)
765 dialog.SetCurrentList(current)
766 dialog.RefreshLists()
767 if dialog.ShowModal() == wx.ID_OK:
768 new_profile = dialog.GetCurrentList()
771 for index in new_profile:
772 if index not in current:
773 addinglist.append(index)
774 for index in current:
775 if index not in new_profile:
776 removinglist.append(index)
777 self.Manager.ManageEntriesOfCurrent(addinglist, removinglist)
778 self.Manager.BufferCurrentNode()
779 self.RefreshBufferState()
780 self.RefreshCurrentIndexList()
783 #-------------------------------------------------------------------------------
784 # Edit Node informations function
785 #-------------------------------------------------------------------------------
787 def OnNodeInfosMenu(self, event):
788 dialog = NodeInfosDialog(self)
789 name, id, type, description = self.Manager.GetCurrentNodeInfos()
790 defaultstringsize = self.Manager.GetCurrentNodeDefaultStringSize()
791 dialog.SetValues(name, id, type, description, defaultstringsize)
792 if dialog.ShowModal() == wx.ID_OK:
793 name, id, type, description, defaultstringsize = dialog.GetValues()
794 self.Manager.SetCurrentNodeInfos(name, id, type, description)
795 self.Manager.SetCurrentNodeDefaultStringSize(defaultstringsize)
796 self.RefreshBufferState()
797 self.RefreshProfileMenu()
798 selected = self.NetworkNodes.GetSelection()
800 window = self.NetworkNodes.GetPage(selected)
801 window.RefreshTable()
805 #-------------------------------------------------------------------------------
806 # Add User Types and Variables
807 #-------------------------------------------------------------------------------
809 def AddMapVariable(self):
810 index = self.Manager.GetCurrentNextMapIndex()
812 dialog = MapVariableDialog(self)
813 dialog.SetIndex(index)
814 if dialog.ShowModal() == wx.ID_OK:
815 index, name, struct, number = dialog.GetValues()
816 result = self.Manager.AddMapVariableToCurrent(index, name, struct, number)
817 if type(result) != StringType:
818 self.RefreshBufferState()
819 self.RefreshCurrentIndexList()
821 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
826 message = wx.MessageDialog(self, result, "No map variable index left!", wx.OK|wx.ICON_ERROR)
830 def AddUserType(self):
831 dialog = UserTypeDialog(self)
832 dialog.SetTypeList(self.Manager.GetCustomisableTypes())
833 if dialog.ShowModal() == wx.ID_OK:
834 type, min, max, length = dialog.GetValues()
835 result = self.Manager.AddUserTypeToCurrent(type, min, max, length)
836 if not IsOfType(result, StringType):
837 self.RefreshBufferState()
838 self.RefreshCurrentIndexList()
840 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
845 def OpenMasterDCFDialog(self, node_id):
846 self.NetworkNodes.SetSelection(0)
847 self.NetworkNodes.GetPage(0).OpenDCFDialog(node_id)
849 #-------------------------------------------------------------------------------
851 #-------------------------------------------------------------------------------
853 Max_Traceback_List_Size = 20
855 def Display_Exception_Dialog(e_type,e_value,e_tb):
857 for i,line in enumerate(traceback.extract_tb(e_tb)):
858 trcbck = " " + str(i+1) + ". "
859 if line[0].find(os.getcwd()) == -1:
860 trcbck += "file : " + str(line[0]) + ", "
862 trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", "
863 trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2])
864 trcbck_lst.append(trcbck)
867 cap = wx.Window_GetCapture()
871 dlg = wx.SingleChoiceDialog(None,
875 Click on OK for saving an error report.
877 Please contact LOLITech at:
879 bugs_networkedit@lolitech.fr
884 str(e_type) + " : " + str(e_value),
888 res = (dlg.ShowModal() == wx.ID_OK)
894 def Display_Error_Dialog(e_value):
895 message = wx.MessageDialog(None, str(e_value), "Error", wx.OK|wx.ICON_ERROR)
899 def get_last_traceback(tb):
905 def format_namespace(d, indent=' '):
906 return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
909 ignored_exceptions = [] # a problem with a line in a module is only reported once per session
911 def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]):
913 def handle_exception(e_type, e_value, e_traceback):
914 traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func
915 last_tb = get_last_traceback(e_traceback)
916 ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
917 if str(e_value).startswith("!!!"):
918 Display_Error_Dialog(e_value)
919 elif ex not in ignored_exceptions:
920 ignored_exceptions.append(ex)
921 result = Display_Exception_Dialog(e_type,e_value,e_traceback)
924 'app-title' : wx.GetApp().GetAppName(), # app_title
925 'app-version' : app_version,
926 'wx-version' : wx.VERSION_STRING,
927 'wx-platform' : wx.Platform,
928 'python-version' : platform.python_version(), #sys.version.split()[0],
929 'platform' : platform.platform(),
932 'date' : time.ctime(),
936 info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
937 last_tb = get_last_traceback(e_traceback)
938 exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred
939 info['locals'] = format_namespace(exception_locals)
940 if 'self' in exception_locals:
941 info['self'] = format_namespace(exception_locals['self'].__dict__)
943 output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w')
947 output.write(a+":\n"+str(info[a])+"\n\n")
949 #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
950 sys.excepthook = handle_exception
952 if __name__ == '__main__':
954 print "\nUsage of networkedit.py :"
955 print "\n %s [Projectpath]\n"%sys.argv[0]
958 opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
959 except getopt.GetoptError:
960 # print help information and exit:
965 if o in ("-h", "--help"):
972 projectOpen = args[0]
977 app = wx.PySimpleApp()
978 wx.InitAllImageHandlers()
980 # Install a exception handle for bug reports
981 AddExceptHook(os.getcwd(),__version__)
983 frame = networkedit(None, projectOpen=projectOpen)