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: from wxPython.wx import * lbessard@205: from wxPython.grid import * lbessard@205: import wx lbessard@205: from wx.lib.anchors import LayoutAnchors 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 * greg@238: from config_utils import * lbessard@205: lbessard@205: def create(parent): lbessard@205: return networkedit(parent) lbessard@205: lbessard@205: def usage(): lbessard@205: print "\nUsage of networkedit.py :" lbessard@205: print "\n %s [Projectpath]\n"%sys.argv[0] lbessard@205: lbessard@205: try: lbessard@205: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) lbessard@205: except getopt.GetoptError: lbessard@205: # print help information and exit: lbessard@205: usage() lbessard@205: sys.exit(2) lbessard@205: lbessard@205: for o, a in opts: lbessard@205: if o in ("-h", "--help"): lbessard@205: usage() lbessard@205: sys.exit() lbessard@205: lbessard@205: if len(args) == 0: lbessard@205: projectOpen = None lbessard@205: elif len(args) == 1: lbessard@205: projectOpen = args[0] lbessard@205: else: lbessard@205: usage() lbessard@205: sys.exit(2) lbessard@205: lbessard@205: ScriptDirectory = sys.path[0] lbessard@205: lbessard@205: try: lbessard@205: from wxPython.html import * lbessard@205: lbessard@205: wxEVT_HTML_URL_CLICK = wxNewId() lbessard@205: lbessard@205: def EVT_HTML_URL_CLICK(win, func): lbessard@205: win.Connect(-1, -1, wxEVT_HTML_URL_CLICK, func) lbessard@205: lbessard@205: class wxHtmlWindowUrlClick(wxPyEvent): lbessard@205: def __init__(self, linkinfo): lbessard@205: wxPyEvent.__init__(self) lbessard@205: self.SetEventType(wxEVT_HTML_URL_CLICK) lbessard@205: self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) lbessard@205: lbessard@205: class wxUrlClickHtmlWindow(wxHtmlWindow): 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@205: wxPostEvent(self, wxHtmlWindowUrlClick(linkinfo)) lbessard@205: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Html Frame lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: [wxID_HTMLFRAME, wxID_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@205: wx.Frame.__init__(self, id=wxID_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@205: self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=wxID_HTMLFRAME) lbessard@205: lbessard@205: self.HtmlContent = wxUrlClickHtmlWindow(id=wxID_HTMLFRAMEHTMLCONTENT, lbessard@205: name='HtmlContent', parent=self, pos=wx.Point(0, 0), lbessard@205: size=wx.Size(-1, -1), style=wxHW_SCROLLBAR_AUTO|wxHW_NO_SELECTION) lbessard@205: EVT_HTML_URL_CLICK(self.HtmlContent, 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@205: wxMessageBox('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@205: [wxID_NETWORKEDIT, wxID_NETWORKEDITNETWORKNODES, lbessard@205: wxID_NETWORKEDITHELPBAR, lbessard@205: ] = [wx.NewId() for _init_ctrls in range(3)] lbessard@205: lbessard@205: [wxID_NETWORKEDITADDMENUITEMS0, wxID_NETWORKEDITADDMENUITEMS1, lbessard@205: wxID_NETWORKEDITADDMENUITEMS2, wxID_NETWORKEDITADDMENUITEMS3, lbessard@205: wxID_NETWORKEDITADDMENUITEMS4, wxID_NETWORKEDITADDMENUITEMS5, lbessard@205: ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)] lbessard@205: lbessard@205: [wxID_NETWORKEDITFILEMENUITEMS0, wxID_NETWORKEDITFILEMENUITEMS1, lbessard@205: wxID_NETWORKEDITFILEMENUITEMS2, wxID_NETWORKEDITFILEMENUITEMS4, lbessard@205: wxID_NETWORKEDITFILEMENUITEMS5, wxID_NETWORKEDITFILEMENUITEMS6, lbessard@205: ] = [wx.NewId() for _init_coll_FileMenu_Items in range(6)] lbessard@205: lbessard@205: [wxID_NETWORKEDITNETWORKMENUITEMS0, wxID_NETWORKEDITNETWORKMENUITEMS1, lbessard@205: wxID_NETWORKEDITNETWORKMENUITEMS3, lbessard@205: ] = [wx.NewId() for _init_coll_AddMenu_Items in range(3)] lbessard@205: lbessard@205: lbessard@205: [wxID_NETWORKEDITEDITMENUITEMS0, wxID_NETWORKEDITEDITMENUITEMS1, lbessard@205: wxID_NETWORKEDITEDITMENUITEMS2, wxID_NETWORKEDITEDITMENUITEMS4, lbessard@205: wxID_NETWORKEDITEDITMENUITEMS6, wxID_NETWORKEDITEDITMENUITEMS7, lbessard@205: wxID_NETWORKEDITEDITMENUITEMS8, lbessard@205: ] = [wx.NewId() for _init_coll_EditMenu_Items in range(7)] lbessard@205: lbessard@205: [wxID_NETWORKEDITHELPMENUITEMS0, wxID_NETWORKEDITHELPMENUITEMS1, lbessard@205: wxID_NETWORKEDITHELPMENUITEMS2, lbessard@205: ] = [wx.NewId() for _init_coll_HelpMenu_Items in range(3)] lbessard@205: lbessard@205: class networkedit(wx.Frame): lbessard@205: def _init_coll_menuBar1_Menus(self, parent): lbessard@205: # generated method, don't edit lbessard@205: lbessard@205: if self.Mode == "solo": 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@205: def _init_coll_EditMenu_Items(self, parent): lbessard@205: # generated method, don't edit lbessard@205: lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITEDITMENUITEMS4, lbessard@205: kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R') lbessard@205: parent.AppendSeparator() lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITEDITMENUITEMS1, lbessard@205: kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z') lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITEDITMENUITEMS0, lbessard@205: kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y') lbessard@205: parent.AppendSeparator() lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITEDITMENUITEMS6, lbessard@205: kind=wx.ITEM_NORMAL, text='Node infos') lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITEDITMENUITEMS2, lbessard@205: kind=wx.ITEM_NORMAL, text='DS-301 Profile') lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITEDITMENUITEMS8, lbessard@205: kind=wx.ITEM_NORMAL, text='DS-302 Profile') lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITEDITMENUITEMS7, lbessard@205: kind=wx.ITEM_NORMAL, text='Other Profile') lbessard@205: self.Bind(wx.EVT_MENU, self.OnUndoMenu, lbessard@205: id=wxID_NETWORKEDITEDITMENUITEMS1) lbessard@205: self.Bind(wx.EVT_MENU, self.OnRedoMenu, lbessard@205: id=wxID_NETWORKEDITEDITMENUITEMS0) lbessard@205: self.Bind(wx.EVT_MENU, self.OnCommunicationMenu, lbessard@205: id=wxID_NETWORKEDITEDITMENUITEMS2) lbessard@205: self.Bind(wx.EVT_MENU, self.OnRefreshMenu, lbessard@205: id=wxID_NETWORKEDITEDITMENUITEMS4) lbessard@205: self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu, lbessard@205: id=wxID_NETWORKEDITEDITMENUITEMS6) lbessard@205: self.Bind(wx.EVT_MENU, self.OnEditProfileMenu, lbessard@205: id=wxID_NETWORKEDITEDITMENUITEMS7) lbessard@205: self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu, lbessard@205: id=wxID_NETWORKEDITEDITMENUITEMS8) lbessard@205: lbessard@205: def _init_coll_HelpMenu_Items(self, parent): lbessard@205: # generated method, don't edit lbessard@205: lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITHELPMENUITEMS0, lbessard@205: kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1') lbessard@205: self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu, lbessard@205: id=wxID_NETWORKEDITHELPMENUITEMS0) lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITHELPMENUITEMS1, lbessard@205: kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2') lbessard@205: self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu, lbessard@205: id=wxID_NETWORKEDITHELPMENUITEMS1) lbessard@205: if Html_Window and self.Mode == "solo": lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITHELPMENUITEMS2, lbessard@205: kind=wx.ITEM_NORMAL, text='About') lbessard@205: self.Bind(wx.EVT_MENU, self.OnAboutMenu, lbessard@205: id=wxID_NETWORKEDITHELPMENUITEMS2) lbessard@205: lbessard@205: def _init_coll_FileMenu_Items(self, parent): lbessard@205: # generated method, don't edit lbessard@205: lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITFILEMENUITEMS5, lbessard@205: kind=wx.ITEM_NORMAL, text='New\tCTRL+N') lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITFILEMENUITEMS0, lbessard@205: kind=wx.ITEM_NORMAL, text='Open\tCTRL+O') lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITFILEMENUITEMS1, lbessard@205: kind=wx.ITEM_NORMAL, text='Save\tCTRL+S') lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITFILEMENUITEMS2, lbessard@205: kind=wx.ITEM_NORMAL, text='Close\tCTRL+W') lbessard@205: parent.AppendSeparator() lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITFILEMENUITEMS4, lbessard@205: kind=wx.ITEM_NORMAL, text='Exit') lbessard@205: self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, lbessard@205: id=wxID_NETWORKEDITFILEMENUITEMS0) lbessard@205: self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, lbessard@205: id=wxID_NETWORKEDITFILEMENUITEMS1) lbessard@205: ## self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, lbessard@205: ## id=wxID_NETWORKEDITFILEMENUITEMS2) lbessard@205: self.Bind(wx.EVT_MENU, self.OnQuitMenu, lbessard@205: id=wxID_NETWORKEDITFILEMENUITEMS4) lbessard@205: self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, lbessard@205: id=wxID_NETWORKEDITFILEMENUITEMS5) lbessard@205: lbessard@205: def _init_coll_NetworkMenu_Items(self, parent): lbessard@205: # generated method, don't edit lbessard@205: lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITNETWORKMENUITEMS0, lbessard@205: kind=wx.ITEM_NORMAL, text='Add Slave Node') lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITNETWORKMENUITEMS1, lbessard@205: kind=wx.ITEM_NORMAL, text='Remove Slave Node') lbessard@205: parent.AppendSeparator() lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITNETWORKMENUITEMS3, lbessard@205: kind=wx.ITEM_NORMAL, text='Build Master Dictionary') lbessard@205: self.Bind(wx.EVT_MENU, self.OnAddSlaveMenu, lbessard@205: id=wxID_NETWORKEDITNETWORKMENUITEMS0) lbessard@205: self.Bind(wx.EVT_MENU, self.OnRemoveSlaveMenu, lbessard@205: id=wxID_NETWORKEDITNETWORKMENUITEMS1) greg@238: self.Bind(wx.EVT_MENU, self.OnBuildMasterMenu, greg@238: id=wxID_NETWORKEDITNETWORKMENUITEMS3) lbessard@205: lbessard@205: def _init_coll_AddMenu_Items(self, parent): lbessard@205: # generated method, don't edit lbessard@205: lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITADDMENUITEMS0, lbessard@205: kind=wx.ITEM_NORMAL, text='SDO Server') lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITADDMENUITEMS1, lbessard@205: kind=wx.ITEM_NORMAL, text='SDO Client') lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITADDMENUITEMS2, lbessard@205: kind=wx.ITEM_NORMAL, text='PDO Transmit') lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITADDMENUITEMS3, lbessard@205: kind=wx.ITEM_NORMAL, text='PDO Receive') lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITADDMENUITEMS4, lbessard@205: kind=wx.ITEM_NORMAL, text='Map Variable') lbessard@205: parent.Append(help='', id=wxID_NETWORKEDITADDMENUITEMS5, lbessard@205: kind=wx.ITEM_NORMAL, text='User Type') lbessard@205: self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu, lbessard@205: id=wxID_NETWORKEDITADDMENUITEMS0) lbessard@205: self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu, lbessard@205: id=wxID_NETWORKEDITADDMENUITEMS1) lbessard@205: self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu, lbessard@205: id=wxID_NETWORKEDITADDMENUITEMS2) lbessard@205: self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu, lbessard@205: id=wxID_NETWORKEDITADDMENUITEMS3) lbessard@205: self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu, lbessard@205: id=wxID_NETWORKEDITADDMENUITEMS4) lbessard@205: self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu, lbessard@205: id=wxID_NETWORKEDITADDMENUITEMS5) lbessard@205: lbessard@205: def _init_coll_HelpBar_Fields(self, parent): lbessard@205: # generated method, don't edit 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@205: # generated method, don't edit lbessard@205: self.menuBar1 = wx.MenuBar() lbessard@205: self.menuBar1.SetEvtHandlerEnabled(True) lbessard@205: lbessard@205: if self.Mode == "solo": lbessard@205: self.FileMenu = wx.Menu(title='') lbessard@205: lbessard@205: self.NetworkMenu = wx.Menu(title='') lbessard@205: lbessard@205: self.EditMenu = wx.Menu(title='') lbessard@205: lbessard@205: self.AddMenu = wx.Menu(title='') lbessard@205: lbessard@205: self.HelpMenu = wx.Menu(title='') lbessard@205: lbessard@205: self._init_coll_menuBar1_Menus(self.menuBar1) lbessard@205: if self.Mode == "solo": 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@205: # generated method, don't edit lbessard@205: wx.Frame.__init__(self, id=wxID_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@205: self.SetMenuBar(self.menuBar1) lbessard@205: ## self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=wxID_NETWORKEDIT) lbessard@205: lbessard@205: self.NetworkNodes = wx.Notebook(id=wxID_NETWORKEDITNETWORKNODES, lbessard@205: name='NetworkNodes', parent=self, pos=wx.Point(0, 0), lbessard@205: size=wx.Size(0, 0), style=wxNB_LEFT) lbessard@205: self.NetworkNodes.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, lbessard@205: self.OnNodeSelectedChanged, id=wxID_NETWORKEDITNETWORKNODES) lbessard@205: lbessard@205: self.HelpBar = wx.StatusBar(id=wxID_NETWORKEDITHELPBAR, name='HelpBar', lbessard@205: parent=self, style=wxST_SIZEGRIP) lbessard@205: self._init_coll_HelpBar_Fields(self.HelpBar) lbessard@205: self.SetStatusBar(self.HelpBar) lbessard@205: lbessard@205: def __init__(self, parent, mode = "solo", nodelist = None): lbessard@205: self.Mode = mode lbessard@205: self._init_ctrls(parent) lbessard@205: self.HtmlFrameOpened = [] lbessard@205: lbessard@205: if self.Mode == "solo": lbessard@205: self.Manager = NodeManager(ScriptDirectory) 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@205: lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshTitle() lbessard@205: self.RefreshMainMenu() lbessard@205: lbessard@205: def GetNoteBook(self): lbessard@205: return self.NetworkNodes lbessard@205: 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@205: if selected > 0: lbessard@205: window = self.NetworkNodes.GetPage(selected) lbessard@205: self.NodeList.SetCurrentSelected(window.GetIndex()) lbessard@205: self.RefreshMainMenu() lbessard@205: 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@205: dialog = wxDirDialog(self , "Choose a project", defaultpath, wxDD_NEW_DIR_BUTTON) lbessard@205: if dialog.ShowModal() == wxID_OK: lbessard@205: projectpath = dialog.GetPath() greg@206: if os.path.isdir(projectpath) and len(os.listdir(projectpath)) == 0: lbessard@205: manager = NodeManager(ScriptDirectory) 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@205: message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_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@205: dialog = wxDirDialog(self , "Choose a project", defaultpath, 0) lbessard@205: if dialog.ShowModal() == wxID_OK: lbessard@205: projectpath = dialog.GetPath() lbessard@205: if os.path.isdir(projectpath): lbessard@205: manager = NodeManager(ScriptDirectory) 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@205: message = wxMessageDialog(self, result, "Error", wxOK|wxICON_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@205: result = self.NodeList.SaveProject() lbessard@205: if result: lbessard@205: message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: event.Skip() lbessard@205: greg@238: def OnBuildMasterMenu(self, event): greg@238: if self.NodeList: greg@238: dialog = wxFileDialog(self, "Choose a locations file", os.getcwd(), "", "text files (*.txt)|*.od|All files|*.*", wxOPEN|wxCHANGE_DIR) greg@238: if dialog.ShowModal() == wxID_OK: greg@238: filepath = dialog.GetPath() greg@238: dialog.Destroy() greg@238: if os.path.isfile(filepath): greg@238: dialog = wxTextEntryDialog(self, "Busname selection", "Please enter the bus number", "", wxOK|wxCANCEL) greg@238: if dialog.ShowModal() == wxID_OK: greg@238: busname = None greg@238: try: greg@238: busname = int(dialog.GetValue()) greg@238: except: greg@238: pass greg@238: if busname: greg@238: file = open(filepath, "r") greg@238: locations = [(elements[0], elements[1]) for elements in [line.strip().split(" ") for line in file.readlines()]] greg@238: GenerateConciseDCF(locations, busname, self.NodeList) greg@238: message = wxMessageDialog(self, "Master node generation successful!", "Error", wxOK|wxICON_ERROR) greg@238: message.ShowModal() greg@238: message.Destroy() greg@238: else: greg@238: message = wxMessageDialog(self, "Busname must be a number!", "Error", wxOK|wxICON_ERROR) greg@238: message.ShowModal() greg@238: message.Destroy() greg@238: else: greg@238: message = wxMessageDialog(self, "\"%s\" isn't a valid file!"%filepath, "Error", wxOK|wxICON_ERROR) greg@238: message.ShowModal() greg@238: message.Destroy() greg@238: event.Skip() greg@238: 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@205: if dialog.ShowModal() == wxID_OK: lbessard@205: values = dialog.GetValues() lbessard@205: result = self.NodeList.AddSlaveNode(values["slaveName"], values["slaveNodeID"], values["edsFile"]) lbessard@205: if not result: lbessard@205: new_editingpanel = EditingPanel(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@205: message = wxMessageDialog(self, result, "Error", wxOK|wxICON_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@205: dialog = wxSingleChoiceDialog(self, "Choose a slave to remove", "Remove slave", slavenames) lbessard@205: if dialog.ShowModal() == wxID_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@205: message = wxMessageDialog(self, result, "Error", wxOK|wxICON_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@205: new_editingpanel = EditingPanel(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@205: new_editingpanel = EditingPanel(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@205: if self.HelpBar: lbessard@205: window = self.NetworkNodes.GetPage(self.NetworkNodes.GetSelection()) lbessard@205: selection = window.GetSelection() lbessard@205: if selection: lbessard@205: index, subIndex = selection lbessard@205: if self.NodeList.IsCurrentEntry(index): lbessard@205: self.HelpBar.SetStatusText("Index: 0x%04X"%index, 0) lbessard@205: self.HelpBar.SetStatusText("Subindex: 0x%02X"%subIndex, 1) lbessard@205: entryinfos = self.NodeList.GetEntryInfos(index) lbessard@205: name = entryinfos["name"] lbessard@205: category = "Optional" lbessard@205: if entryinfos["need"]: lbessard@205: category = "Mandatory" lbessard@205: struct = "VAR" lbessard@205: number = "" lbessard@205: if entryinfos["struct"] & OD_IdenticalIndexes: lbessard@205: number = " possibly defined %d times"%entryinfos["nbmax"] lbessard@205: if entryinfos["struct"] & OD_IdenticalSubindexes: lbessard@205: struct = "REC" lbessard@205: elif entryinfos["struct"] & OD_MultipleSubindexes: lbessard@205: struct = "ARRAY" lbessard@205: text = "%s: %s entry of struct %s%s."%(name,category,struct,number) lbessard@205: self.HelpBar.SetStatusText(text, 2) lbessard@205: else: lbessard@205: for i in xrange(3): lbessard@205: 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): lbessard@205: if self.menuBar1: lbessard@205: if self.NodeList == None: greg@238: self.NetworkMenu.Enable(wxID_NETWORKEDITNETWORKMENUITEMS3, False) lbessard@205: if self.Mode == "solo": lbessard@205: self.menuBar1.EnableTop(1, False) lbessard@205: self.menuBar1.EnableTop(2, False) lbessard@205: self.menuBar1.EnableTop(3, False) lbessard@205: if self.FileMenu: lbessard@205: self.FileMenu.Enable(wxID_NETWORKEDITFILEMENUITEMS1, False) lbessard@205: self.FileMenu.Enable(wxID_NETWORKEDITFILEMENUITEMS2, False) lbessard@205: else: lbessard@205: self.menuBar1.EnableTop(0, False) lbessard@205: self.menuBar1.EnableTop(1, False) lbessard@205: self.menuBar1.EnableTop(2, False) lbessard@205: else: greg@238: self.NetworkMenu.Enable(wxID_NETWORKEDITNETWORKMENUITEMS3, True) lbessard@205: if self.Mode == "solo": lbessard@205: self.menuBar1.EnableTop(1, True) lbessard@205: if self.FileMenu: lbessard@205: self.FileMenu.Enable(wxID_NETWORKEDITFILEMENUITEMS1, True) greg@238: self.FileMenu.Enable(wxID_NETWORKEDITFILEMENUITEMS2, True) lbessard@205: if self.NetworkNodes.GetSelection() == 0: lbessard@205: self.menuBar1.EnableTop(2, True) lbessard@205: self.menuBar1.EnableTop(3, True) lbessard@205: else: lbessard@205: self.menuBar1.EnableTop(2, False) lbessard@205: self.menuBar1.EnableTop(3, False) lbessard@205: else: lbessard@205: self.menuBar1.EnableTop(0, True) lbessard@205: if self.NetworkNodes.GetSelection() == 0: lbessard@205: self.menuBar1.EnableTop(1, True) lbessard@205: self.menuBar1.EnableTop(2, True) lbessard@205: else: lbessard@205: self.menuBar1.EnableTop(1, False) lbessard@205: self.menuBar1.EnableTop(2, False) lbessard@205: lbessard@205: def RefreshProfileMenu(self): lbessard@205: if self.EditMenu: lbessard@205: profile = self.Manager.GetCurrentProfileName() lbessard@205: edititem = self.EditMenu.FindItemById(wxID_NETWORKEDITEDITMENUITEMS7) 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: greg@238: def GetProfileCallBack(self, text): greg@238: def ProfileCallBack(event): greg@238: self.Manager.AddSpecificEntryToCurrent(text) greg@238: self.RefreshBufferState() greg@238: self.RefreshCurrentIndexList() greg@238: event.Skip() greg@238: return ProfileCallBack greg@238: 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@205: message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_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@205: message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_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)) lbessard@205: 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@205: if dialog.ShowModal() == wxID_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.GenerateMapList() 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@205: dialog.SetValues(name, id, type, description) lbessard@205: if dialog.ShowModal() == wxID_OK: lbessard@205: name, id, type, description = dialog.GetValues() lbessard@205: self.Manager.SetCurrentNodeInfos(name, id, type, description) lbessard@205: self.RefreshBufferState() lbessard@205: self.RefreshProfileMenu() lbessard@205: selected = self.FileOpened.GetSelection() lbessard@205: if selected >= 0: lbessard@205: window = self.FileOpened.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@205: if dialog.ShowModal() == wxID_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@205: message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: dialog.Destroy() lbessard@205: else: lbessard@205: message = wxMessageDialog(self, result, "No map variable index left!", wxOK|wxICON_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@205: if dialog.ShowModal() == wxID_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@205: message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: dialog.Destroy() lbessard@205: 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@205: message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_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@205: def wxAddExceptHook(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@205: app = wxPySimpleApp() lbessard@205: wxInitAllImageHandlers() lbessard@205: lbessard@205: # Install a exception handle for bug reports lbessard@205: wxAddExceptHook(os.getcwd(),__version__) lbessard@205: lbessard@205: frame = networkedit(None) lbessard@205: lbessard@205: frame.Show() lbessard@205: app.MainLoop()