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: laurent@580: __version__ = "$Revision: 1.27 $" laurent@580: laurent@580: if __name__ == '__main__': laurent@580: def usage(): laurent@580: print _("\nUsage of networkedit.py :") laurent@580: print "\n %s [Projectpath]\n"%sys.argv[0] laurent@580: laurent@580: try: laurent@580: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) laurent@580: except getopt.GetoptError: laurent@580: # print help information and exit: laurent@580: usage() laurent@580: sys.exit(2) laurent@580: laurent@580: for o, a in opts: laurent@580: if o in ("-h", "--help"): laurent@580: usage() laurent@580: sys.exit() laurent@580: laurent@580: if len(args) == 0: laurent@580: projectOpen = None laurent@580: elif len(args) == 1: laurent@580: projectOpen = args[0] laurent@580: else: laurent@580: usage() laurent@580: sys.exit(2) laurent@580: laurent@580: app = wx.PySimpleApp() laurent@580: laurent@580: ScriptDirectory = os.path.split(os.path.realpath(__file__))[0] laurent@580: laurent@580: # Import module for internationalization laurent@580: import gettext laurent@580: import __builtin__ laurent@580: laurent@580: # Get folder containing translation files laurent@580: localedir = os.path.join(ScriptDirectory,"locale") laurent@580: # Get the default language laurent@580: langid = wx.LANGUAGE_DEFAULT laurent@580: # Define translation domain (name of translation files) laurent@580: domain = "objdictgen" laurent@580: laurent@580: # Define locale for wx laurent@580: loc = __builtin__.__dict__.get('loc', None) laurent@580: if loc is None: laurent@580: loc = wx.Locale(langid) laurent@580: __builtin__.__dict__['loc'] = loc laurent@580: # Define location for searching translation files laurent@580: loc.AddCatalogLookupPathPrefix(localedir) laurent@580: # Define locale domain laurent@580: loc.AddCatalog(domain) laurent@580: laurent@580: if __name__ == '__main__': laurent@580: __builtin__.__dict__['_'] = wx.GetTranslation 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: 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: laurent@580: 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: laurent@580: parent.Append(menu=self.FileMenu, title=_('File')) laurent@580: parent.Append(menu=self.NetworkMenu, title=_('Network')) laurent@580: parent.Append(menu=self.EditMenu, title=_('Edit')) laurent@580: parent.Append(menu=self.AddMenu, title=_('Add')) laurent@580: 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, laurent@580: kind=wx.ITEM_NORMAL, text=_('New\tCTRL+N')) lbessard@418: parent.Append(help='', id=wx.ID_OPEN, laurent@580: kind=wx.ITEM_NORMAL, text=_('Open\tCTRL+O')) lbessard@418: parent.Append(help='', id=wx.ID_CLOSE, laurent@580: kind=wx.ITEM_NORMAL, text=_('Close\tCTRL+W')) lbessard@418: parent.AppendSeparator() lbessard@418: parent.Append(help='', id=wx.ID_SAVE, laurent@580: kind=wx.ITEM_NORMAL, text=_('Save\tCTRL+S')) lbessard@418: parent.AppendSeparator() lbessard@418: parent.Append(help='', id=wx.ID_EXIT, laurent@580: 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, laurent@580: kind=wx.ITEM_NORMAL, text=_('Add Slave Node')) lbessard@418: parent.Append(help='', id=wx.ID_DELETE, laurent@580: kind=wx.ITEM_NORMAL, text=_('Remove Slave Node')) lbessard@418: parent.AppendSeparator() lbessard@418: parent.Append(help='', id=ID_NETWORKEDITNETWORKMENUBUILDMASTER, laurent@580: 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, laurent@580: kind=wx.ITEM_NORMAL, text=_('Refresh\tCTRL+R')) lbessard@205: parent.AppendSeparator() lbessard@418: parent.Append(help='', id=wx.ID_UNDO, laurent@580: kind=wx.ITEM_NORMAL, text=_('Undo\tCTRL+Z')) lbessard@418: parent.Append(help='', id=wx.ID_REDO, laurent@580: kind=wx.ITEM_NORMAL, text=_('Redo\tCTRL+Y')) lbessard@205: parent.AppendSeparator() lbessard@418: parent.Append(help='', id=ID_NETWORKEDITEDITMENUNODEINFOS, laurent@580: kind=wx.ITEM_NORMAL, text=_('Node infos')) lbessard@418: parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS301PROFILE, laurent@580: kind=wx.ITEM_NORMAL, text=_('DS-301 Profile')) lbessard@418: parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS302PROFILE, laurent@580: kind=wx.ITEM_NORMAL, text=_('DS-302 Profile')) lbessard@418: parent.Append(help='', id=ID_NETWORKEDITEDITMENUOTHERPROFILE, laurent@580: 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, laurent@580: kind=wx.ITEM_NORMAL, text=_('SDO Server')) lbessard@418: parent.Append(help='', id=ID_NETWORKEDITADDMENUSDOCLIENT, laurent@580: kind=wx.ITEM_NORMAL, text=_('SDO Client')) lbessard@418: parent.Append(help='', id=ID_NETWORKEDITADDMENUPDOTRANSMIT, laurent@580: kind=wx.ITEM_NORMAL, text=_('PDO Transmit')) lbessard@418: parent.Append(help='', id=ID_NETWORKEDITADDMENUPDORECEIVE, laurent@580: kind=wx.ITEM_NORMAL, text=_('PDO Receive')) lbessard@418: parent.Append(help='', id=ID_NETWORKEDITADDMENUMAPVARIABLE, laurent@580: kind=wx.ITEM_NORMAL, text=_('Map Variable')) lbessard@418: parent.Append(help='', id=ID_NETWORKEDITADDMENUUSERTYPE, laurent@580: 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, laurent@580: 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, laurent@580: 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, laurent@580: 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), laurent@580: 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@491: self.Closing = False 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@491: def IsClosing(self): lbessard@491: return self.Closing lbessard@491: 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@491: self.Closing = True 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() greg@612: #event.Skip() lbessard@242: lbessard@205: def OnQuitMenu(self, event): lbessard@205: self.Close() laurent@608: lbessard@205: def OnAddSDOServerMenu(self, event): lbessard@205: self.Manager.AddSDOServerToCurrent() lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshCurrentIndexList() laurent@608: lbessard@205: def OnAddSDOClientMenu(self, event): lbessard@205: self.Manager.AddSDOClientToCurrent() lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshCurrentIndexList() laurent@608: lbessard@205: def OnAddPDOTransmitMenu(self, event): lbessard@205: self.Manager.AddPDOTransmitToCurrent() lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshCurrentIndexList() laurent@608: lbessard@205: def OnAddPDOReceiveMenu(self, event): lbessard@205: self.Manager.AddPDOReceiveToCurrent() lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshCurrentIndexList() laurent@608: lbessard@205: def OnAddMapVariableMenu(self, event): lbessard@205: self.AddMapVariable() laurent@608: lbessard@205: def OnAddUserTypeMenu(self, event): lbessard@205: self.AddUserType() laurent@608: lbessard@205: def OnNodeSelectedChanged(self, event): lbessard@491: if not self.Closing: lbessard@491: selected = event.GetSelection() lbessard@491: # At init selected = -1 lbessard@491: if selected >= 0: lbessard@491: window = self.NetworkNodes.GetPage(selected) lbessard@491: self.NodeList.SetCurrentSelected(window.GetIndex()) lbessard@491: wx.CallAfter(self.RefreshMainMenu) lbessard@491: 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() laurent@580: 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: laurent@580: message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() laurent@608: 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() laurent@580: 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: laurent@580: message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: dialog.Destroy() laurent@608: 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: laurent@580: message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) lbessard@271: message.ShowModal() lbessard@271: message.Destroy() laurent@608: lbessard@242: def OnCloseProjectMenu(self, event): greg@238: if self.NodeList: lbessard@242: if self.NodeList.HasChanged(): laurent@580: 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: laurent@580: 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() laurent@608: 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: laurent@580: message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: dialog.Destroy() laurent@608: lbessard@205: def OnRemoveSlaveMenu(self, event): lbessard@205: slavenames = self.NodeList.GetSlaveNames() lbessard@205: slaveids = self.NodeList.GetSlaveIDs() laurent@580: 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: laurent@580: message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() laurent@608: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Refresh Functions lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: def RefreshTitle(self): lbessard@205: if self.NodeList != None: laurent@580: self.SetTitle(_("Networkedit - %s")%self.NodeList.GetNetworkName()) lbessard@205: else: laurent@580: self.SetTitle(_("Networkedit")) lbessard@205: lbessard@205: def OnRefreshMenu(self, event): lbessard@205: self.RefreshCurrentIndexList() laurent@608: 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@491: selected = self.NetworkNodes.GetSelection() lbessard@491: if self.HelpBar and selected >= 0: lbessard@491: window = self.NetworkNodes.GetPage(selected) lbessard@491: selection = window.GetSelection() lbessard@491: if selection: lbessard@491: index, subIndex = selection lbessard@491: if self.NodeList.IsCurrentEntry(index): laurent@580: self.HelpBar.SetStatusText(_("Index: 0x%04X")%index, 0) laurent@580: self.HelpBar.SetStatusText(_("Subindex: 0x%02X")%subIndex, 1) lbessard@491: entryinfos = self.NodeList.GetEntryInfos(index) lbessard@491: name = entryinfos["name"] laurent@580: category = _("Optional") lbessard@491: if entryinfos["need"]: laurent@580: category = _("Mandatory") lbessard@491: struct = "VAR" lbessard@491: number = "" lbessard@491: if entryinfos["struct"] & OD_IdenticalIndexes: laurent@580: number = _(" possibly defined %d times")%entryinfos["nbmax"] lbessard@491: if entryinfos["struct"] & OD_IdenticalSubindexes: lbessard@491: struct = "REC" lbessard@491: elif entryinfos["struct"] & OD_MultipleSubindexes: lbessard@491: struct = "ARRAY" laurent@580: text = _("%s: %s entry of struct %s%s.")%(name,category,struct,number) lbessard@491: self.HelpBar.SetStatusText(text, 2) lbessard@205: else: lbessard@205: for i in xrange(3): lbessard@205: self.HelpBar.SetStatusText("", i) lbessard@491: else: lbessard@491: for i in xrange(3): lbessard@491: self.HelpBar.SetStatusText("", i) lbessard@205: lbessard@205: def RefreshMainMenu(self): lbessard@491: self.NetworkMenu.Enable(ID_NETWORKEDITNETWORKMENUBUILDMASTER, False) lbessard@491: if self.NodeList == None: lbessard@491: if self.ModeSolo: lbessard@491: self.MenuBar.EnableTop(1, False) lbessard@491: self.MenuBar.EnableTop(2, False) lbessard@491: self.MenuBar.EnableTop(3, False) lbessard@491: if self.FileMenu: lbessard@491: self.FileMenu.Enable(wx.ID_CLOSE, False) lbessard@491: self.FileMenu.Enable(wx.ID_SAVE, False) lbessard@491: else: lbessard@491: self.MenuBar.EnableTop(0, False) lbessard@491: self.MenuBar.EnableTop(1, False) lbessard@491: self.MenuBar.EnableTop(2, False) lbessard@491: else: lbessard@491: if self.ModeSolo: lbessard@491: self.MenuBar.EnableTop(1, True) lbessard@491: if self.FileMenu: lbessard@491: self.FileMenu.Enable(wx.ID_CLOSE, True) lbessard@491: self.FileMenu.Enable(wx.ID_SAVE, True) lbessard@491: if self.NetworkNodes.GetSelection() == 0: lbessard@491: self.MenuBar.EnableTop(2, True) lbessard@491: self.MenuBar.EnableTop(3, True) lbessard@491: else: lbessard@491: self.MenuBar.EnableTop(2, False) lbessard@491: self.MenuBar.EnableTop(3, False) lbessard@491: else: lbessard@491: self.MenuBar.EnableTop(0, True) lbessard@491: if self.NetworkNodes.GetSelection() == 0: lbessard@491: self.MenuBar.EnableTop(1, True) lbessard@491: self.MenuBar.EnableTop(2, True) lbessard@491: else: lbessard@491: self.MenuBar.EnableTop(1, False) lbessard@418: self.MenuBar.EnableTop(2, False) lbessard@205: lbessard@205: def RefreshProfileMenu(self): lbessard@491: profile = self.Manager.GetCurrentProfileName() lbessard@491: edititem = self.EditMenu.FindItemById(ID_NETWORKEDITEDITMENUOTHERPROFILE) lbessard@491: if edititem: lbessard@491: length = self.AddMenu.GetMenuItemCount() lbessard@491: for i in xrange(length-6): lbessard@491: additem = self.AddMenu.FindItemByPosition(6) lbessard@491: self.AddMenu.Delete(additem.GetId()) lbessard@491: if profile not in ("None", "DS-301"): laurent@580: edititem.SetText(_("%s Profile")%profile) lbessard@491: edititem.Enable(True) lbessard@491: self.AddMenu.AppendSeparator() lbessard@491: for text, indexes in self.Manager.GetCurrentSpecificMenu(): lbessard@491: new_id = wx.NewId() lbessard@491: self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text) lbessard@491: self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id) lbessard@491: else: laurent@580: edititem.SetText(_("Other Profile")) lbessard@491: 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: return ProfileCallBack lbessard@273: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Buffer Functions lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: def RefreshBufferState(self): lbessard@491: if self.NodeList is not None: 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: lbessard@205: def OnRedoMenu(self, event): lbessard@205: self.Manager.LoadCurrentNext() lbessard@205: self.RefreshCurrentIndexList() lbessard@205: self.RefreshBufferState() 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@512: if isinstance(result, (StringType, UnicodeType)): laurent@580: 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@512: if isinstance(result, (StringType, UnicodeType)): laurent@580: message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() 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: lbessard@205: def OnAboutMenu(self, event): laurent@580: self.OpenHtmlFrame(_("About CAN Festival"), os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450)) 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() laurent@580: self.EditProfile(_("Edit DS-301 Profile"), dictionary, current) lbessard@205: lbessard@205: def OnOtherCommunicationMenu(self, event): lbessard@205: dictionary,current = self.Manager.GetCurrentDS302Lists() laurent@580: self.EditProfile(_("Edit DS-302 Profile"), dictionary, current) lbessard@205: lbessard@205: def OnEditProfileMenu(self, event): laurent@580: title = _("Edit %s Profile")%self.Manager.GetCurrentProfileName() lbessard@205: dictionary,current = self.Manager.GetCurrentProfileLists() lbessard@205: self.EditProfile(title, dictionary, current) 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: 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@512: if not isinstance(result, (StringType, UnicodeType)): lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshCurrentIndexList() lbessard@205: else: laurent@580: 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: laurent@580: 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: laurent@580: 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)): laurent@580: trcbck = " " + str(i+1) + _(". ") lbessard@205: if line[0].find(os.getcwd()) == -1: laurent@580: trcbck += _("file : ") + str(line[0]) + _(", ") lbessard@205: else: laurent@580: trcbck += _("file : ") + str(line[0][len(os.getcwd()):]) + _(", ") laurent@580: 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, laurent@580: _(""" lbessard@205: An error happens. lbessard@205: lbessard@205: Click on OK for saving an error report. lbessard@205: greg@614: Please be kind enough to send this file to: greg@614: edouard.tisserant@gmail.com lbessard@205: lbessard@205: lbessard@205: Error: laurent@580: """) + laurent@580: str(e_type) + _(" : ") + str(e_value), laurent@580: _("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): laurent@580: 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@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()