lbessard@205: #!/usr/bin/env python lbessard@205: # -*- coding: utf-8 -*- lbessard@205: lbessard@205: #This file is part of CanFestival, a library implementing CanOpen Stack. lbessard@205: # lbessard@205: #Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD lbessard@205: # lbessard@205: #See COPYING file for copyrights details. lbessard@205: # lbessard@205: #This library is free software; you can redistribute it and/or lbessard@205: #modify it under the terms of the GNU Lesser General Public lbessard@205: #License as published by the Free Software Foundation; either lbessard@205: #version 2.1 of the License, or (at your option) any later version. lbessard@205: # lbessard@205: #This library is distributed in the hope that it will be useful, lbessard@205: #but WITHOUT ANY WARRANTY; without even the implied warranty of lbessard@205: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU lbessard@205: #Lesser General Public License for more details. lbessard@205: # lbessard@205: #You should have received a copy of the GNU Lesser General Public lbessard@205: #License along with this library; if not, write to the Free Software lbessard@205: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA lbessard@205: lbessard@205: import wx lbessard@205: import wx.grid lbessard@205: lbessard@205: from types import * lbessard@205: import os, re, platform, sys, time, traceback, getopt lbessard@205: lbessard@205: __version__ = "$Revision$" lbessard@205: lbessard@205: from nodelist import * lbessard@205: from nodemanager import * lbessard@205: from subindextable import * lbessard@205: from commondialogs import * lbessard@205: from doc_index.DS301_index import * lbessard@205: greg@318: ScriptDirectory = os.path.split(os.path.realpath(__file__))[0] lbessard@205: lbessard@205: try: lbessard@254: import wx.html lbessard@254: lbessard@254: EVT_HTML_URL_CLICK = wx.NewId() lbessard@254: lbessard@254: class HtmlWindowUrlClick(wx.PyEvent): lbessard@205: def __init__(self, linkinfo): lbessard@254: wx.PyEvent.__init__(self) lbessard@254: self.SetEventType(EVT_HTML_URL_CLICK) lbessard@205: self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) lbessard@254: lbessard@254: class UrlClickHtmlWindow(wx.html.HtmlWindow): lbessard@205: """ HTML window that generates and OnLinkClicked event. lbessard@205: lbessard@205: Use this to avoid having to override HTMLWindow lbessard@205: """ lbessard@205: def OnLinkClicked(self, linkinfo): lbessard@254: wx.PostEvent(self, HtmlWindowUrlClick(linkinfo)) lbessard@254: lbessard@254: def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY): lbessard@254: if event == HtmlWindowUrlClick: lbessard@254: self.Connect(-1, -1, EVT_HTML_URL_CLICK, handler) lbessard@254: else: lbessard@254: wx.html.HtmlWindow.Bind(event, handler, source=source, id=id, id2=id2) lbessard@205: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Html Frame lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@254: [ID_HTMLFRAME, ID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)] lbessard@205: lbessard@205: class HtmlFrame(wx.Frame): lbessard@205: def _init_ctrls(self, prnt): lbessard@205: # generated method, don't edit lbessard@254: wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame', lbessard@205: parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616), lbessard@205: style=wx.DEFAULT_FRAME_STYLE, title='') lbessard@273: self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) lbessard@205: lbessard@254: self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT, lbessard@205: name='HtmlContent', parent=self, pos=wx.Point(0, 0), lbessard@254: size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO|wx.html.HW_NO_SELECTION) lbessard@254: self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick) lbessard@205: lbessard@205: def __init__(self, parent, opened): lbessard@205: self._init_ctrls(parent) lbessard@205: self.HtmlFrameOpened = opened lbessard@205: lbessard@205: def SetHtmlCode(self, htmlcode): lbessard@205: self.HtmlContent.SetPage(htmlcode) lbessard@205: lbessard@205: def SetHtmlPage(self, htmlpage): lbessard@205: self.HtmlContent.LoadPage(htmlpage) lbessard@205: lbessard@205: def OnCloseFrame(self, event): lbessard@205: self.HtmlFrameOpened.remove(self.GetTitle()) lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnLinkClick(self, event): lbessard@205: url = event.linkinfo[0] lbessard@205: try: lbessard@205: import webbrowser lbessard@205: except ImportError: lbessard@254: wx.MessageBox('Please point your browser at: %s' % url) lbessard@205: else: lbessard@205: webbrowser.open(url) lbessard@205: lbessard@205: Html_Window = True lbessard@205: except: lbessard@205: Html_Window = False lbessard@205: lbessard@205: lbessard@254: [ID_NETWORKEDIT, ID_NETWORKEDITNETWORKNODES, lbessard@254: ID_NETWORKEDITHELPBAR, lbessard@205: ] = [wx.NewId() for _init_ctrls in range(3)] lbessard@205: lbessard@418: [ID_NETWORKEDITNETWORKMENUBUILDMASTER, lbessard@418: ] = [wx.NewId() for _init_coll_AddMenu_Items in range(1)] lbessard@418: lbessard@418: [ID_NETWORKEDITEDITMENUNODEINFOS, ID_NETWORKEDITEDITMENUDS301PROFILE, lbessard@418: ID_NETWORKEDITEDITMENUDS302PROFILE, ID_NETWORKEDITEDITMENUOTHERPROFILE, lbessard@418: ] = [wx.NewId() for _init_coll_EditMenu_Items in range(4)] lbessard@418: lbessard@418: [ID_NETWORKEDITADDMENUSDOSERVER, ID_NETWORKEDITADDMENUSDOCLIENT, lbessard@418: ID_NETWORKEDITADDMENUPDOTRANSMIT, ID_NETWORKEDITADDMENUPDORECEIVE, lbessard@418: ID_NETWORKEDITADDMENUMAPVARIABLE, ID_NETWORKEDITADDMENUUSERTYPE, lbessard@205: ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)] lbessard@205: lbessard@205: class networkedit(wx.Frame): lbessard@418: def _init_coll_MenuBar_Menus(self, parent): lbessard@242: if self.ModeSolo: lbessard@205: parent.Append(menu=self.FileMenu, title='File') lbessard@205: parent.Append(menu=self.NetworkMenu, title='Network') lbessard@205: parent.Append(menu=self.EditMenu, title='Edit') lbessard@205: parent.Append(menu=self.AddMenu, title='Add') lbessard@205: parent.Append(menu=self.HelpMenu, title='Help') lbessard@205: lbessard@418: def _init_coll_FileMenu_Items(self, parent): lbessard@418: parent.Append(help='', id=wx.ID_NEW, lbessard@418: kind=wx.ITEM_NORMAL, text='New\tCTRL+N') lbessard@418: parent.Append(help='', id=wx.ID_OPEN, lbessard@418: kind=wx.ITEM_NORMAL, text='Open\tCTRL+O') lbessard@418: parent.Append(help='', id=wx.ID_CLOSE, lbessard@418: kind=wx.ITEM_NORMAL, text='Close\tCTRL+W') lbessard@418: parent.AppendSeparator() lbessard@418: parent.Append(help='', id=wx.ID_SAVE, lbessard@418: kind=wx.ITEM_NORMAL, text='Save\tCTRL+S') lbessard@418: parent.AppendSeparator() lbessard@418: parent.Append(help='', id=wx.ID_EXIT, lbessard@418: kind=wx.ITEM_NORMAL, text='Exit') lbessard@418: self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW) lbessard@418: self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN) lbessard@418: self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE) lbessard@418: self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) lbessard@418: self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT) lbessard@418: lbessard@418: def _init_coll_NetworkMenu_Items(self, parent): lbessard@418: parent.Append(help='', id=wx.ID_ADD, lbessard@418: kind=wx.ITEM_NORMAL, text='Add Slave Node') lbessard@418: parent.Append(help='', id=wx.ID_DELETE, lbessard@418: kind=wx.ITEM_NORMAL, text='Remove Slave Node') lbessard@418: parent.AppendSeparator() lbessard@418: parent.Append(help='', id=ID_NETWORKEDITNETWORKMENUBUILDMASTER, lbessard@418: kind=wx.ITEM_NORMAL, text='Build Master Dictionary') lbessard@418: self.Bind(wx.EVT_MENU, self.OnAddSlaveMenu, id=wx.ID_ADD) lbessard@418: self.Bind(wx.EVT_MENU, self.OnRemoveSlaveMenu, id=wx.ID_DELETE) lbessard@418: ## self.Bind(wx.EVT_MENU, self.OnBuildMasterMenu, lbessard@418: ## id=ID_NETWORKEDITNETWORKMENUBUILDMASTER) lbessard@418: lbessard@205: def _init_coll_EditMenu_Items(self, parent): lbessard@418: parent.Append(help='', id=wx.ID_REFRESH, lbessard@205: kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R') lbessard@205: parent.AppendSeparator() lbessard@418: parent.Append(help='', id=wx.ID_UNDO, lbessard@205: kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z') lbessard@418: parent.Append(help='', id=wx.ID_REDO, lbessard@205: kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y') lbessard@205: parent.AppendSeparator() lbessard@418: parent.Append(help='', id=ID_NETWORKEDITEDITMENUNODEINFOS, lbessard@205: kind=wx.ITEM_NORMAL, text='Node infos') lbessard@418: parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS301PROFILE, lbessard@205: kind=wx.ITEM_NORMAL, text='DS-301 Profile') lbessard@418: parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS302PROFILE, lbessard@205: kind=wx.ITEM_NORMAL, text='DS-302 Profile') lbessard@418: parent.Append(help='', id=ID_NETWORKEDITEDITMENUOTHERPROFILE, lbessard@205: kind=wx.ITEM_NORMAL, text='Other Profile') lbessard@418: self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH) lbessard@418: self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO) lbessard@418: self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO) lbessard@418: self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu, lbessard@418: id=ID_NETWORKEDITEDITMENUNODEINFOS) lbessard@205: self.Bind(wx.EVT_MENU, self.OnCommunicationMenu, lbessard@418: id=ID_NETWORKEDITEDITMENUDS301PROFILE) lbessard@418: self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu, lbessard@418: id=ID_NETWORKEDITEDITMENUDS302PROFILE) lbessard@205: self.Bind(wx.EVT_MENU, self.OnEditProfileMenu, lbessard@418: id=ID_NETWORKEDITEDITMENUOTHERPROFILE) lbessard@418: lbessard@205: def _init_coll_AddMenu_Items(self, parent): lbessard@418: parent.Append(help='', id=ID_NETWORKEDITADDMENUSDOSERVER, lbessard@205: kind=wx.ITEM_NORMAL, text='SDO Server') lbessard@418: parent.Append(help='', id=ID_NETWORKEDITADDMENUSDOCLIENT, lbessard@205: kind=wx.ITEM_NORMAL, text='SDO Client') lbessard@418: parent.Append(help='', id=ID_NETWORKEDITADDMENUPDOTRANSMIT, lbessard@205: kind=wx.ITEM_NORMAL, text='PDO Transmit') lbessard@418: parent.Append(help='', id=ID_NETWORKEDITADDMENUPDORECEIVE, lbessard@205: kind=wx.ITEM_NORMAL, text='PDO Receive') lbessard@418: parent.Append(help='', id=ID_NETWORKEDITADDMENUMAPVARIABLE, lbessard@205: kind=wx.ITEM_NORMAL, text='Map Variable') lbessard@418: parent.Append(help='', id=ID_NETWORKEDITADDMENUUSERTYPE, lbessard@205: kind=wx.ITEM_NORMAL, text='User Type') lbessard@205: self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu, lbessard@418: id=ID_NETWORKEDITADDMENUSDOSERVER) lbessard@205: self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu, lbessard@418: id=ID_NETWORKEDITADDMENUSDOCLIENT) lbessard@205: self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu, lbessard@418: id=ID_NETWORKEDITADDMENUPDOTRANSMIT) lbessard@205: self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu, lbessard@418: id=ID_NETWORKEDITADDMENUPDORECEIVE) lbessard@205: self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu, lbessard@418: id=ID_NETWORKEDITADDMENUMAPVARIABLE) lbessard@205: self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu, lbessard@418: id=ID_NETWORKEDITADDMENUUSERTYPE) lbessard@418: lbessard@418: def _init_coll_HelpMenu_Items(self, parent): lbessard@418: parent.Append(help='', id=wx.ID_HELP, lbessard@418: kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1') lbessard@418: self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu, id=wx.ID_HELP) lbessard@418: parent.Append(help='', id=wx.ID_HELP_CONTEXT, lbessard@418: kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2') lbessard@418: self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu, id=wx.ID_HELP_CONTEXT) lbessard@418: if Html_Window and self.ModeSolo: lbessard@418: parent.Append(help='', id=wx.ID_ABOUT, lbessard@418: kind=wx.ITEM_NORMAL, text='About') lbessard@418: self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT) lbessard@205: lbessard@205: def _init_coll_HelpBar_Fields(self, parent): lbessard@205: parent.SetFieldsCount(3) lbessard@205: lbessard@205: parent.SetStatusText(number=0, text='') lbessard@205: parent.SetStatusText(number=1, text='') lbessard@205: parent.SetStatusText(number=2, text='') lbessard@205: lbessard@205: parent.SetStatusWidths([100, 110, -1]) lbessard@205: lbessard@205: def _init_utils(self): lbessard@418: self.MenuBar = wx.MenuBar() lbessard@418: self.MenuBar.SetEvtHandlerEnabled(True) lbessard@205: lbessard@242: if self.ModeSolo: lbessard@205: self.FileMenu = wx.Menu(title='') lbessard@205: self.NetworkMenu = wx.Menu(title='') lbessard@205: self.EditMenu = wx.Menu(title='') lbessard@205: self.AddMenu = wx.Menu(title='') lbessard@205: self.HelpMenu = wx.Menu(title='') lbessard@205: lbessard@418: self._init_coll_MenuBar_Menus(self.MenuBar) lbessard@242: if self.ModeSolo: lbessard@205: self._init_coll_FileMenu_Items(self.FileMenu) lbessard@205: self._init_coll_NetworkMenu_Items(self.NetworkMenu) lbessard@205: self._init_coll_EditMenu_Items(self.EditMenu) lbessard@205: self._init_coll_AddMenu_Items(self.AddMenu) lbessard@205: self._init_coll_HelpMenu_Items(self.HelpMenu) lbessard@205: lbessard@205: def _init_ctrls(self, prnt): lbessard@254: wx.Frame.__init__(self, id=ID_NETWORKEDIT, name='networkedit', lbessard@205: parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700), lbessard@205: style=wx.DEFAULT_FRAME_STYLE, title='Networkedit') lbessard@205: self._init_utils() lbessard@205: self.SetClientSize(wx.Size(1000, 700)) lbessard@418: self.SetMenuBar(self.MenuBar) lbessard@273: self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) lbessard@271: if not self.ModeSolo: lbessard@418: self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) lbessard@418: accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, 83, wx.ID_SAVE)]) lbessard@271: self.SetAcceleratorTable(accel) lbessard@254: lbessard@254: self.NetworkNodes = wx.Notebook(id=ID_NETWORKEDITNETWORKNODES, lbessard@205: name='NetworkNodes', parent=self, pos=wx.Point(0, 0), lbessard@254: size=wx.Size(0, 0), style=wx.NB_LEFT) lbessard@205: self.NetworkNodes.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, lbessard@254: self.OnNodeSelectedChanged, id=ID_NETWORKEDITNETWORKNODES) lbessard@254: lbessard@254: self.HelpBar = wx.StatusBar(id=ID_NETWORKEDITHELPBAR, name='HelpBar', lbessard@254: parent=self, style=wx.ST_SIZEGRIP) lbessard@205: self._init_coll_HelpBar_Fields(self.HelpBar) lbessard@205: self.SetStatusBar(self.HelpBar) lbessard@205: lbessard@276: def __init__(self, parent, nodelist = None, projectOpen = None): lbessard@242: self.ModeSolo = nodelist == None lbessard@205: self._init_ctrls(parent) lbessard@205: self.HtmlFrameOpened = [] lbessard@242: self.BusId = None lbessard@205: etisserant@410: icon = wx.Icon(os.path.join(ScriptDirectory,"networkedit.ico"),wx.BITMAP_TYPE_ICO) greg@409: self.SetIcon(icon) etisserant@410: lbessard@242: if self.ModeSolo: lbessard@258: self.Manager = NodeManager() lbessard@205: if projectOpen: lbessard@205: self.NodeList = NodeList(self.Manager) lbessard@205: result = self.NodeList.LoadProject(projectOpen) lbessard@205: if not result: lbessard@205: self.RefreshNetworkNodes() lbessard@205: else: lbessard@205: self.NodeList = None lbessard@205: else: lbessard@205: self.NodeList = nodelist lbessard@205: self.Manager = self.NodeList.GetManager() lbessard@242: self.NodeList.SetCurrentSelected(0) lbessard@242: self.RefreshNetworkNodes() lbessard@242: self.RefreshProfileMenu() lbessard@271: self.NetworkNodes.SetFocus() lbessard@205: lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshTitle() lbessard@205: self.RefreshMainMenu() lbessard@205: lbessard@242: def SetBusId(self, bus_id): lbessard@242: self.BusId = bus_id lbessard@242: lbessard@242: def GetBusId(self): lbessard@242: return self.BusId lbessard@242: lbessard@242: def GetCurrentNodeId(self): lbessard@242: selected = self.NetworkNodes.GetSelection() lbessard@242: # At init selected = -1 lbessard@242: if selected > 0: lbessard@242: window = self.NetworkNodes.GetPage(selected) lbessard@242: return window.GetIndex() lbessard@242: else: lbessard@242: return 0 lbessard@242: lbessard@242: def OnCloseFrame(self, event): lbessard@271: if not self.ModeSolo and getattr(self, "_onclose", None) != None: lbessard@271: self._onclose() lbessard@271: event.Skip() lbessard@271: lbessard@271: def OnChar(self, event): lbessard@271: if event.ControlDown() and event.GetKeyCode() == 83 and getattr(self, "_onsave", None) != None: lbessard@271: self._onsave() lbessard@242: event.Skip() lbessard@242: lbessard@205: def OnQuitMenu(self, event): lbessard@205: self.Close() lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnAddSDOServerMenu(self, event): lbessard@205: self.Manager.AddSDOServerToCurrent() lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshCurrentIndexList() lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnAddSDOClientMenu(self, event): lbessard@205: self.Manager.AddSDOClientToCurrent() lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshCurrentIndexList() lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnAddPDOTransmitMenu(self, event): lbessard@205: self.Manager.AddPDOTransmitToCurrent() lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshCurrentIndexList() lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnAddPDOReceiveMenu(self, event): lbessard@205: self.Manager.AddPDOReceiveToCurrent() lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshCurrentIndexList() lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnAddMapVariableMenu(self, event): lbessard@205: self.AddMapVariable() lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnAddUserTypeMenu(self, event): lbessard@205: self.AddUserType() lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnNodeSelectedChanged(self, event): lbessard@205: selected = event.GetSelection() lbessard@205: # At init selected = -1 lbessard@276: if selected >= 0: lbessard@205: window = self.NetworkNodes.GetPage(selected) lbessard@205: self.NodeList.SetCurrentSelected(window.GetIndex()) lbessard@339: wx.CallAfter(self.RefreshMainMenu) lbessard@339: wx.CallAfter(self.RefreshStatusBar) lbessard@205: event.Skip() lbessard@205: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Load and Save Funtions lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: def OnNewProjectMenu(self, event): lbessard@205: if self.NodeList: lbessard@205: defaultpath = os.path.dirname(self.NodeList.GetRoot()) lbessard@205: else: lbessard@205: defaultpath = os.getcwd() lbessard@254: dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON) lbessard@254: if dialog.ShowModal() == wx.ID_OK: lbessard@205: projectpath = dialog.GetPath() greg@206: if os.path.isdir(projectpath) and len(os.listdir(projectpath)) == 0: lbessard@258: manager = NodeManager() lbessard@205: nodelist = NodeList(manager) lbessard@205: result = nodelist.LoadProject(projectpath) lbessard@205: if not result: lbessard@205: self.Manager = manager lbessard@205: self.NodeList = nodelist lbessard@205: self.NodeList.SetCurrentSelected(0) lbessard@205: lbessard@205: self.RefreshNetworkNodes() lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshTitle() lbessard@205: self.RefreshProfileMenu() lbessard@205: self.RefreshMainMenu() lbessard@205: else: lbessard@254: message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnOpenProjectMenu(self, event): lbessard@205: if self.NodeList: lbessard@205: defaultpath = os.path.dirname(self.NodeList.GetRoot()) lbessard@205: else: lbessard@205: defaultpath = os.getcwd() lbessard@254: dialog = wx.DirDialog(self , "Choose a project", defaultpath, 0) lbessard@254: if dialog.ShowModal() == wx.ID_OK: lbessard@205: projectpath = dialog.GetPath() lbessard@205: if os.path.isdir(projectpath): lbessard@258: manager = NodeManager() lbessard@205: nodelist = NodeList(manager) lbessard@205: result = nodelist.LoadProject(projectpath) lbessard@205: if not result: lbessard@205: self.Manager = manager lbessard@205: self.NodeList = nodelist lbessard@205: self.NodeList.SetCurrentSelected(0) lbessard@205: lbessard@205: self.RefreshNetworkNodes() lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshTitle() lbessard@205: self.RefreshProfileMenu() lbessard@205: self.RefreshMainMenu() lbessard@205: else: lbessard@254: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: dialog.Destroy() lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnSaveProjectMenu(self, event): lbessard@271: if not self.ModeSolo and getattr(self, "_onsave", None) != None: lbessard@271: self._onsave() lbessard@271: else: lbessard@271: result = self.NodeList.SaveProject() lbessard@271: if result: lbessard@271: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) lbessard@271: message.ShowModal() lbessard@271: message.Destroy() lbessard@205: event.Skip() lbessard@205: lbessard@242: def OnCloseProjectMenu(self, event): greg@238: if self.NodeList: lbessard@242: if self.NodeList.HasChanged(): lbessard@254: dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close Project", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) lbessard@242: answer = dialog.ShowModal() greg@238: dialog.Destroy() lbessard@254: if answer == wx.ID_YES: lbessard@242: result = self.NodeList.SaveProject() lbessard@242: if result: lbessard@254: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) lbessard@242: message.ShowModal() lbessard@242: message.Destroy() lbessard@254: elif answer == wx.ID_NO: lbessard@242: self.NodeList.ForceChanged(False) lbessard@242: if not self.NodeList.HasChanged(): lbessard@242: self.Manager = None lbessard@242: self.NodeList = None lbessard@242: self.RefreshNetworkNodes() lbessard@242: self.RefreshTitle() lbessard@242: self.RefreshMainMenu() lbessard@242: event.Skip() greg@238: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Slave Nodes Management lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: def OnAddSlaveMenu(self, event): lbessard@205: dialog = AddSlaveDialog(self) lbessard@205: dialog.SetNodeList(self.NodeList) lbessard@254: if dialog.ShowModal() == wx.ID_OK: lbessard@205: values = dialog.GetValues() lbessard@205: result = self.NodeList.AddSlaveNode(values["slaveName"], values["slaveNodeID"], values["edsFile"]) lbessard@205: if not result: lbessard@299: new_editingpanel = EditingPanel(self.NetworkNodes, self, self.NodeList, False) lbessard@205: new_editingpanel.SetIndex(values["slaveNodeID"]) lbessard@205: idx = self.NodeList.GetOrderNumber(values["slaveNodeID"]) lbessard@205: self.NetworkNodes.InsertPage(idx, new_editingpanel, "") lbessard@205: self.NodeList.SetCurrentSelected(idx) lbessard@205: self.NetworkNodes.SetSelection(idx) lbessard@205: self.RefreshBufferState() lbessard@205: else: lbessard@254: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: dialog.Destroy() lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnRemoveSlaveMenu(self, event): lbessard@205: slavenames = self.NodeList.GetSlaveNames() lbessard@205: slaveids = self.NodeList.GetSlaveIDs() lbessard@254: dialog = wx.SingleChoiceDialog(self, "Choose a slave to remove", "Remove slave", slavenames) lbessard@254: if dialog.ShowModal() == wx.ID_OK: lbessard@205: choice = dialog.GetSelection() lbessard@205: result = self.NodeList.RemoveSlaveNode(slaveids[choice]) lbessard@205: if not result: lbessard@205: slaveids.pop(choice) lbessard@205: current = self.NetworkNodes.GetSelection() lbessard@205: self.NetworkNodes.DeletePage(choice + 1) lbessard@205: if self.NetworkNodes.GetPageCount() > 0: lbessard@205: new_selection = min(current, self.NetworkNodes.GetPageCount() - 1) lbessard@205: self.NetworkNodes.SetSelection(new_selection) lbessard@205: if new_selection > 0: lbessard@205: self.NodeList.SetCurrentSelected(slaveids[new_selection - 1]) lbessard@205: self.RefreshBufferState() lbessard@205: else: lbessard@254: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: event.Skip() lbessard@205: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Refresh Functions lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: def RefreshTitle(self): lbessard@205: if self.NodeList != None: lbessard@205: self.SetTitle("Networkedit - %s"%self.NodeList.GetNetworkName()) lbessard@205: else: lbessard@205: self.SetTitle("Networkedit") lbessard@205: lbessard@205: def OnRefreshMenu(self, event): lbessard@205: self.RefreshCurrentIndexList() lbessard@205: event.Skip() lbessard@205: lbessard@205: def RefreshCurrentIndexList(self): lbessard@205: selected = self.NetworkNodes.GetSelection() lbessard@205: if selected == 0: lbessard@205: window = self.NetworkNodes.GetPage(selected) lbessard@205: window.RefreshIndexList() lbessard@205: else: lbessard@205: pass lbessard@205: lbessard@205: def RefreshNetworkNodes(self): lbessard@205: if self.NetworkNodes.GetPageCount() > 0: lbessard@205: self.NetworkNodes.DeleteAllPages() lbessard@205: if self.NodeList: lbessard@299: new_editingpanel = EditingPanel(self.NetworkNodes, self, self.Manager) lbessard@205: new_editingpanel.SetIndex(0) lbessard@205: self.NetworkNodes.AddPage(new_editingpanel, "") lbessard@205: for idx in self.NodeList.GetSlaveIDs(): lbessard@299: new_editingpanel = EditingPanel(self.NetworkNodes, self, self.NodeList, False) lbessard@205: new_editingpanel.SetIndex(idx) lbessard@205: self.NetworkNodes.AddPage(new_editingpanel, "") lbessard@205: lbessard@205: def RefreshStatusBar(self): lbessard@326: if self: lbessard@326: selected = self.NetworkNodes.GetSelection() lbessard@326: if self.HelpBar and selected >= 0: lbessard@326: window = self.NetworkNodes.GetPage(selected) lbessard@326: selection = window.GetSelection() lbessard@326: if selection: lbessard@326: index, subIndex = selection lbessard@326: if self.NodeList.IsCurrentEntry(index): lbessard@326: self.HelpBar.SetStatusText("Index: 0x%04X"%index, 0) lbessard@326: self.HelpBar.SetStatusText("Subindex: 0x%02X"%subIndex, 1) lbessard@326: entryinfos = self.NodeList.GetEntryInfos(index) lbessard@326: name = entryinfos["name"] lbessard@326: category = "Optional" lbessard@326: if entryinfos["need"]: lbessard@326: category = "Mandatory" lbessard@326: struct = "VAR" lbessard@326: number = "" lbessard@326: if entryinfos["struct"] & OD_IdenticalIndexes: lbessard@326: number = " possibly defined %d times"%entryinfos["nbmax"] lbessard@326: if entryinfos["struct"] & OD_IdenticalSubindexes: lbessard@326: struct = "REC" lbessard@326: elif entryinfos["struct"] & OD_MultipleSubindexes: lbessard@326: struct = "ARRAY" lbessard@326: text = "%s: %s entry of struct %s%s."%(name,category,struct,number) lbessard@326: self.HelpBar.SetStatusText(text, 2) lbessard@326: else: lbessard@326: for i in xrange(3): lbessard@326: self.HelpBar.SetStatusText("", i) lbessard@205: else: lbessard@205: for i in xrange(3): lbessard@205: self.HelpBar.SetStatusText("", i) lbessard@205: lbessard@205: def RefreshMainMenu(self): etisserant@485: if self and self.MenuBar: lbessard@418: self.NetworkMenu.Enable(ID_NETWORKEDITNETWORKMENUBUILDMASTER, False) lbessard@205: if self.NodeList == None: lbessard@242: if self.ModeSolo: lbessard@418: self.MenuBar.EnableTop(1, False) lbessard@418: self.MenuBar.EnableTop(2, False) lbessard@418: self.MenuBar.EnableTop(3, False) lbessard@205: if self.FileMenu: lbessard@418: self.FileMenu.Enable(wx.ID_CLOSE, False) lbessard@418: self.FileMenu.Enable(wx.ID_SAVE, False) lbessard@205: else: lbessard@418: self.MenuBar.EnableTop(0, False) lbessard@418: self.MenuBar.EnableTop(1, False) lbessard@418: self.MenuBar.EnableTop(2, False) lbessard@205: else: lbessard@242: if self.ModeSolo: lbessard@418: self.MenuBar.EnableTop(1, True) lbessard@205: if self.FileMenu: lbessard@418: self.FileMenu.Enable(wx.ID_CLOSE, True) lbessard@418: self.FileMenu.Enable(wx.ID_SAVE, True) lbessard@205: if self.NetworkNodes.GetSelection() == 0: lbessard@418: self.MenuBar.EnableTop(2, True) lbessard@418: self.MenuBar.EnableTop(3, True) lbessard@205: else: lbessard@418: self.MenuBar.EnableTop(2, False) lbessard@418: self.MenuBar.EnableTop(3, False) lbessard@205: else: lbessard@418: self.MenuBar.EnableTop(0, True) lbessard@205: if self.NetworkNodes.GetSelection() == 0: lbessard@418: self.MenuBar.EnableTop(1, True) lbessard@418: self.MenuBar.EnableTop(2, True) lbessard@205: else: lbessard@418: self.MenuBar.EnableTop(1, False) lbessard@418: self.MenuBar.EnableTop(2, False) lbessard@205: lbessard@205: def RefreshProfileMenu(self): lbessard@205: if self.EditMenu: lbessard@205: profile = self.Manager.GetCurrentProfileName() lbessard@418: edititem = self.EditMenu.FindItemById(ID_NETWORKEDITEDITMENUOTHERPROFILE) lbessard@205: if edititem: lbessard@205: length = self.AddMenu.GetMenuItemCount() lbessard@205: for i in xrange(length-6): lbessard@205: additem = self.AddMenu.FindItemByPosition(6) lbessard@205: self.AddMenu.Delete(additem.GetId()) lbessard@205: if profile not in ("None", "DS-301"): lbessard@205: edititem.SetText("%s Profile"%profile) lbessard@205: edititem.Enable(True) lbessard@205: self.AddMenu.AppendSeparator() lbessard@205: for text, indexes in self.Manager.GetCurrentSpecificMenu(): lbessard@205: new_id = wx.NewId() lbessard@205: self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text) lbessard@205: self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id) lbessard@205: else: lbessard@205: edititem.SetText("Other Profile") lbessard@205: edititem.Enable(False) lbessard@205: lbessard@273: def GetProfileCallBack(self, text): lbessard@273: def ProfileCallBack(event): lbessard@273: self.Manager.AddSpecificEntryToCurrent(text) lbessard@273: self.RefreshBufferState() lbessard@273: self.RefreshCurrentIndexList() lbessard@273: event.Skip() lbessard@273: return ProfileCallBack lbessard@273: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Buffer Functions lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: def RefreshBufferState(self): lbessard@205: if self.NodeList: lbessard@205: nodeID = self.Manager.GetCurrentNodeID() lbessard@205: if nodeID != None: lbessard@205: nodename = "0x%2.2X %s"%(nodeID, self.Manager.GetCurrentNodeName()) lbessard@205: else: lbessard@205: nodename = self.Manager.GetCurrentNodeName() lbessard@205: self.NetworkNodes.SetPageText(0, nodename) lbessard@205: for idx, name in enumerate(self.NodeList.GetSlaveNames()): lbessard@205: self.NetworkNodes.SetPageText(idx + 1, name) lbessard@205: self.RefreshTitle() lbessard@205: lbessard@205: def OnUndoMenu(self, event): lbessard@205: self.Manager.LoadCurrentPrevious() lbessard@205: self.RefreshCurrentIndexList() lbessard@205: self.RefreshBufferState() lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnRedoMenu(self, event): lbessard@205: self.Manager.LoadCurrentNext() lbessard@205: self.RefreshCurrentIndexList() lbessard@205: self.RefreshBufferState() lbessard@205: event.Skip() lbessard@205: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Help Method lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: def OnHelpDS301Menu(self, event): lbessard@205: find_index = False lbessard@205: selected = self.NetworkNodes.GetSelection() lbessard@205: if selected >= 0: lbessard@205: window = self.NetworkNodes.GetPage(selected) lbessard@205: result = window.GetSelection() lbessard@205: if result: lbessard@205: find_index = True lbessard@205: index, subIndex = result lbessard@205: result = OpenPDFDocIndex(index, ScriptDirectory) lbessard@205: if type(result) == StringType: lbessard@254: message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: if not find_index: lbessard@205: result = OpenPDFDocIndex(None, ScriptDirectory) lbessard@205: if type(result) == StringType: lbessard@254: message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnHelpCANFestivalMenu(self, event): lbessard@205: #self.OpenHtmlFrame("CAN Festival Reference", os.path.join(ScriptDirectory, "doc/canfestival.html"), wx.Size(1000, 600)) etisserant@386: if wx.Platform == '__WXMSW__': etisserant@386: readerpath = get_acroversion() etisserant@386: readerexepath = os.path.join(readerpath,"AcroRd32.exe") etisserant@386: if(os.path.isfile(readerexepath)): greg@408: os.spawnl(os.P_DETACH, readerexepath, "AcroRd32.exe", '"%s"'%os.path.join(ScriptDirectory, "doc","manual_en.pdf")) etisserant@386: else: etisserant@386: os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16)) lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnAboutMenu(self, event): lbessard@205: self.OpenHtmlFrame("About CAN Festival", os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450)) lbessard@205: event.Skip() lbessard@205: lbessard@205: def OpenHtmlFrame(self, title, file, size): lbessard@205: if title not in self.HtmlFrameOpened: lbessard@205: self.HtmlFrameOpened.append(title) lbessard@205: window = HtmlFrame(self, self.HtmlFrameOpened) lbessard@205: window.SetTitle(title) lbessard@205: window.SetHtmlPage(file) lbessard@205: window.SetClientSize(size) lbessard@205: window.Show() lbessard@205: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Editing Profiles functions lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: def OnCommunicationMenu(self, event): lbessard@205: dictionary,current = self.Manager.GetCurrentCommunicationLists() lbessard@205: self.EditProfile("Edit DS-301 Profile", dictionary, current) lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnOtherCommunicationMenu(self, event): lbessard@205: dictionary,current = self.Manager.GetCurrentDS302Lists() lbessard@205: self.EditProfile("Edit DS-301 Profile", dictionary, current) lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnEditProfileMenu(self, event): lbessard@205: title = "Edit %s Profile"%self.Manager.GetCurrentProfileName() lbessard@205: dictionary,current = self.Manager.GetCurrentProfileLists() lbessard@205: self.EditProfile(title, dictionary, current) lbessard@205: event.Skip() lbessard@205: lbessard@205: def EditProfile(self, title, dictionary, current): lbessard@205: dialog = CommunicationDialog(self) lbessard@205: dialog.SetTitle(title) lbessard@205: dialog.SetIndexDictionary(dictionary) lbessard@205: dialog.SetCurrentList(current) lbessard@205: dialog.RefreshLists() lbessard@254: if dialog.ShowModal() == wx.ID_OK: lbessard@205: new_profile = dialog.GetCurrentList() lbessard@205: addinglist = [] lbessard@205: removinglist = [] lbessard@205: for index in new_profile: lbessard@205: if index not in current: lbessard@205: addinglist.append(index) lbessard@205: for index in current: lbessard@205: if index not in new_profile: lbessard@205: removinglist.append(index) lbessard@205: self.Manager.ManageEntriesOfCurrent(addinglist, removinglist) lbessard@205: self.Manager.BufferCurrentNode() lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshCurrentIndexList() lbessard@205: dialog.Destroy() lbessard@205: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Edit Node informations function lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: def OnNodeInfosMenu(self, event): lbessard@205: dialog = NodeInfosDialog(self) lbessard@205: name, id, type, description = self.Manager.GetCurrentNodeInfos() lbessard@418: defaultstringsize = self.Manager.GetCurrentNodeDefaultStringSize() lbessard@418: dialog.SetValues(name, id, type, description, defaultstringsize) lbessard@254: if dialog.ShowModal() == wx.ID_OK: lbessard@418: name, id, type, description, defaultstringsize = dialog.GetValues() lbessard@205: self.Manager.SetCurrentNodeInfos(name, id, type, description) lbessard@418: self.Manager.SetCurrentNodeDefaultStringSize(defaultstringsize) lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshProfileMenu() lbessard@243: selected = self.NetworkNodes.GetSelection() lbessard@205: if selected >= 0: lbessard@243: window = self.NetworkNodes.GetPage(selected) lbessard@205: window.RefreshTable() lbessard@205: event.Skip() lbessard@205: lbessard@205: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Add User Types and Variables lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: def AddMapVariable(self): lbessard@205: index = self.Manager.GetCurrentNextMapIndex() lbessard@205: if index: lbessard@205: dialog = MapVariableDialog(self) lbessard@205: dialog.SetIndex(index) lbessard@254: if dialog.ShowModal() == wx.ID_OK: lbessard@205: index, name, struct, number = dialog.GetValues() lbessard@205: result = self.Manager.AddMapVariableToCurrent(index, name, struct, number) lbessard@205: if type(result) != StringType: lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshCurrentIndexList() lbessard@205: else: lbessard@254: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: dialog.Destroy() lbessard@205: else: lbessard@254: message = wx.MessageDialog(self, result, "No map variable index left!", wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: lbessard@205: def AddUserType(self): lbessard@205: dialog = UserTypeDialog(self) lbessard@205: dialog.SetTypeList(self.Manager.GetCustomisableTypes()) lbessard@254: if dialog.ShowModal() == wx.ID_OK: lbessard@205: type, min, max, length = dialog.GetValues() lbessard@205: result = self.Manager.AddUserTypeToCurrent(type, min, max, length) lbessard@205: if not IsOfType(result, StringType): lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshCurrentIndexList() lbessard@205: else: lbessard@254: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: dialog.Destroy() lbessard@205: lbessard@327: def OpenMasterDCFDialog(self, node_id): lbessard@327: self.NetworkNodes.SetSelection(0) lbessard@336: self.NetworkNodes.GetPage(0).OpenDCFDialog(node_id) lbessard@327: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Exception Handler lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: Max_Traceback_List_Size = 20 lbessard@205: lbessard@205: def Display_Exception_Dialog(e_type,e_value,e_tb): lbessard@205: trcbck_lst = [] lbessard@205: for i,line in enumerate(traceback.extract_tb(e_tb)): lbessard@205: trcbck = " " + str(i+1) + ". " lbessard@205: if line[0].find(os.getcwd()) == -1: lbessard@205: trcbck += "file : " + str(line[0]) + ", " lbessard@205: else: lbessard@205: trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " lbessard@205: trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) lbessard@205: trcbck_lst.append(trcbck) lbessard@205: lbessard@205: # Allow clicking.... lbessard@205: cap = wx.Window_GetCapture() lbessard@205: if cap: lbessard@205: cap.ReleaseMouse() lbessard@205: lbessard@205: dlg = wx.SingleChoiceDialog(None, lbessard@205: """ lbessard@205: An error happens. lbessard@205: lbessard@205: Click on OK for saving an error report. lbessard@205: lbessard@205: Please contact LOLITech at: lbessard@205: +33 (0)3 29 52 95 67 lbessard@205: bugs_networkedit@lolitech.fr lbessard@205: lbessard@205: lbessard@205: Error: lbessard@205: """ + lbessard@205: str(e_type) + " : " + str(e_value), lbessard@205: "Error", lbessard@205: trcbck_lst) lbessard@205: try: lbessard@205: res = (dlg.ShowModal() == wx.ID_OK) lbessard@205: finally: lbessard@205: dlg.Destroy() lbessard@205: lbessard@205: return res lbessard@205: lbessard@205: def Display_Error_Dialog(e_value): lbessard@254: message = wx.MessageDialog(None, str(e_value), "Error", wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: lbessard@205: def get_last_traceback(tb): lbessard@205: while tb.tb_next: lbessard@205: tb = tb.tb_next lbessard@205: return tb lbessard@205: lbessard@205: lbessard@205: def format_namespace(d, indent=' '): lbessard@205: return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) lbessard@205: lbessard@205: lbessard@205: ignored_exceptions = [] # a problem with a line in a module is only reported once per session lbessard@205: lbessard@254: def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): lbessard@205: lbessard@205: def handle_exception(e_type, e_value, e_traceback): lbessard@205: traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func lbessard@205: last_tb = get_last_traceback(e_traceback) lbessard@205: ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) lbessard@205: if str(e_value).startswith("!!!"): lbessard@205: Display_Error_Dialog(e_value) lbessard@205: elif ex not in ignored_exceptions: lbessard@205: ignored_exceptions.append(ex) lbessard@205: result = Display_Exception_Dialog(e_type,e_value,e_traceback) lbessard@205: if result: lbessard@205: info = { lbessard@205: 'app-title' : wx.GetApp().GetAppName(), # app_title lbessard@205: 'app-version' : app_version, lbessard@205: 'wx-version' : wx.VERSION_STRING, lbessard@205: 'wx-platform' : wx.Platform, lbessard@205: 'python-version' : platform.python_version(), #sys.version.split()[0], lbessard@205: 'platform' : platform.platform(), lbessard@205: 'e-type' : e_type, lbessard@205: 'e-value' : e_value, lbessard@205: 'date' : time.ctime(), lbessard@205: 'cwd' : os.getcwd(), lbessard@205: } lbessard@205: if e_traceback: lbessard@205: info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) lbessard@205: last_tb = get_last_traceback(e_traceback) lbessard@205: exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred lbessard@205: info['locals'] = format_namespace(exception_locals) lbessard@205: if 'self' in exception_locals: lbessard@205: info['self'] = format_namespace(exception_locals['self'].__dict__) lbessard@205: lbessard@205: output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') lbessard@205: lst = info.keys() lbessard@205: lst.sort() lbessard@205: for a in lst: lbessard@205: output.write(a+":\n"+str(info[a])+"\n\n") lbessard@205: lbessard@205: #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) lbessard@205: sys.excepthook = handle_exception lbessard@205: lbessard@205: if __name__ == '__main__': lbessard@276: def usage(): lbessard@276: print "\nUsage of networkedit.py :" lbessard@276: print "\n %s [Projectpath]\n"%sys.argv[0] lbessard@276: lbessard@276: try: lbessard@276: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) lbessard@276: except getopt.GetoptError: lbessard@276: # print help information and exit: lbessard@276: usage() lbessard@276: sys.exit(2) lbessard@276: lbessard@276: for o, a in opts: lbessard@276: if o in ("-h", "--help"): lbessard@276: usage() lbessard@276: sys.exit() lbessard@276: lbessard@276: if len(args) == 0: lbessard@276: projectOpen = None lbessard@276: elif len(args) == 1: lbessard@276: projectOpen = args[0] lbessard@276: else: lbessard@276: usage() lbessard@276: sys.exit(2) lbessard@276: lbessard@254: app = wx.PySimpleApp() lbessard@254: wx.InitAllImageHandlers() lbessard@205: lbessard@205: # Install a exception handle for bug reports lbessard@254: AddExceptHook(os.getcwd(),__version__) lbessard@205: lbessard@276: frame = networkedit(None, projectOpen=projectOpen) lbessard@205: lbessard@205: frame.Show() lbessard@205: app.MainLoop()