nico@207: nico@207: nico@207: CanFestival: /home/epimerde/documents/tc11/CanFestival-3/objdictgen/networkedit.py Source File nico@207: nico@207: nico@207: nico@207: nico@207:
nico@207:
nico@207:
nico@207:
nico@207:

/home/epimerde/documents/tc11/CanFestival-3/objdictgen/networkedit.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
nico@207: 00002 # -*- coding: utf-8 -*-
nico@207: 00003 
nico@207: 00004 #This file is part of CanFestival, a library implementing CanOpen Stack. 
nico@207: 00005 #
nico@207: 00006 #Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD
nico@207: 00007 #
nico@207: 00008 #See COPYING file for copyrights details.
nico@207: 00009 #
nico@207: 00010 #This library is free software; you can redistribute it and/or
nico@207: 00011 #modify it under the terms of the GNU Lesser General Public
nico@207: 00012 #License as published by the Free Software Foundation; either
nico@207: 00013 #version 2.1 of the License, or (at your option) any later version.
nico@207: 00014 #
nico@207: 00015 #This library is distributed in the hope that it will be useful,
nico@207: 00016 #but WITHOUT ANY WARRANTY; without even the implied warranty of
nico@207: 00017 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
nico@207: 00018 #Lesser General Public License for more details.
nico@207: 00019 #
nico@207: 00020 #You should have received a copy of the GNU Lesser General Public
nico@207: 00021 #License along with this library; if not, write to the Free Software
nico@207: 00022 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
nico@207: 00023 
nico@207: 00024 from wxPython.wx import *
nico@207: 00025 from wxPython.grid import *
nico@207: 00026 import wx
nico@207: 00027 from wx.lib.anchors import LayoutAnchors
nico@207: 00028 import wx.grid
nico@207: 00029 
nico@207: 00030 from types import *
nico@207: 00031 import os, re, platform, sys, time, traceback, getopt
nico@207: 00032 
nico@207: 00033 __version__ = "$Revision$"
nico@207: 00034 
nico@207: 00035 from nodelist import *
nico@207: 00036 from nodemanager import *
nico@207: 00037 from subindextable import *
nico@207: 00038 from commondialogs import *
nico@207: 00039 from doc_index.DS301_index import *
nico@207: 00040 
nico@207: 00041 def create(parent):
nico@207: 00042     return networkedit(parent)
nico@207: 00043 
nico@207: 00044 def usage():
nico@207: 00045     print "\nUsage of networkedit.py :"
nico@207: 00046     print "\n   %s [Projectpath]\n"%sys.argv[0]
nico@207: 00047 
nico@207: 00048 try:
nico@207: 00049     opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
nico@207: 00050 except getopt.GetoptError:
nico@207: 00051     # print help information and exit:
nico@207: 00052     usage()
nico@207: 00053     sys.exit(2)
nico@207: 00054 
nico@207: 00055 for o, a in opts:
nico@207: 00056     if o in ("-h", "--help"):
nico@207: 00057         usage()
nico@207: 00058         sys.exit()
nico@207: 00059 
nico@207: 00060 if len(args) == 0:
nico@207: 00061     projectOpen = None 
nico@207: 00062 elif len(args) == 1:
nico@207: 00063     projectOpen = args[0]
nico@207: 00064 else:
nico@207: 00065     usage()
nico@207: 00066     sys.exit(2)
nico@207: 00067 
nico@207: 00068 ScriptDirectory = sys.path[0]
nico@207: 00069 
nico@207: 00070 try:
nico@207: 00071     from wxPython.html import *
nico@207: 00072 
nico@207: 00073     wxEVT_HTML_URL_CLICK = wxNewId()
nico@207: 00074 
nico@207: 00075     def EVT_HTML_URL_CLICK(win, func):
nico@207: 00076         win.Connect(-1, -1, wxEVT_HTML_URL_CLICK, func)
nico@207: 00077 
nico@207: 00078     class wxHtmlWindowUrlClick(wxPyEvent):
nico@207: 00079         def __init__(self, linkinfo):
nico@207: 00080             wxPyEvent.__init__(self)
nico@207: 00081             self.SetEventType(wxEVT_HTML_URL_CLICK)
nico@207: 00082             self.linkinfolinkinfo = (linkinfo.GetHref(), linkinfo.GetTarget())
nico@207: 00083 
nico@207: 00084     class wxUrlClickHtmlWindow(wxHtmlWindow):
nico@207: 00085         """ HTML window that generates and OnLinkClicked event.
nico@207: 00086 
nico@207: 00087         Use this to avoid having to override HTMLWindow
nico@207: 00088         """
nico@207: 00089         def OnLinkClicked(self, linkinfo):
nico@207: 00090             wxPostEvent(self, wxHtmlWindowUrlClick(linkinfo))
nico@207: 00091     
nico@207: 00092 #-------------------------------------------------------------------------------
nico@207: 00093 #                                Html Frame
nico@207: 00094 #-------------------------------------------------------------------------------
nico@207: 00095 
nico@207: 00096     [wxID_HTMLFRAME, wxID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)]
nico@207: 00097 
nico@207: 00098     class HtmlFrame(wx.Frame):
nico@207: 00099         def _init_ctrls(self, prnt):
nico@207: 00100             # generated method, don't edit
nico@207: 00101             wx.Frame.__init__(self, id=wxID_HTMLFRAME, name='HtmlFrame',
nico@207: 00102                   parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616),
nico@207: 00103                   style=wx.DEFAULT_FRAME_STYLE, title='')
nico@207: 00104             self.Bind(wx.EVT_CLOSE, self.OnCloseFrameOnCloseFrame, id=wxID_HTMLFRAME)
nico@207: 00105             
nico@207: 00106             self.HtmlContent = wxUrlClickHtmlWindow(id=wxID_HTMLFRAMEHTMLCONTENT,
nico@207: 00107                   name='HtmlContent', parent=self, pos=wx.Point(0, 0),
nico@207: 00108                   size=wx.Size(-1, -1), style=wxHW_SCROLLBAR_AUTO|wxHW_NO_SELECTION)
nico@207: 00109             EVT_HTML_URL_CLICK(self.HtmlContent, self.OnLinkClickOnLinkClick)
nico@207: 00110 
nico@207: 00111         def __init__(self, parent, opened):
nico@207: 00112             self._init_ctrls_init_ctrls(parent)
nico@207: 00113             self.HtmlFrameOpenedHtmlFrameOpened = opened
nico@207: 00114         
nico@207: 00115         def SetHtmlCode(self, htmlcode):
nico@207: 00116             self.HtmlContent.SetPage(htmlcode)
nico@207: 00117             
nico@207: 00118         def SetHtmlPage(self, htmlpage):
nico@207: 00119             self.HtmlContent.LoadPage(htmlpage)
nico@207: 00120             
nico@207: 00121         def OnCloseFrame(self, event):
nico@207: 00122             self.HtmlFrameOpenedHtmlFrameOpened.remove(self.GetTitle())
nico@207: 00123             event.Skip()
nico@207: 00124         
nico@207: 00125         def OnLinkClick(self, event):
nico@207: 00126             url = event.linkinfo[0]
nico@207: 00127             try:
nico@207: 00128                 import webbrowser
nico@207: 00129             except ImportError:
nico@207: 00130                 wxMessageBox('Please point your browser at: %s' % url)
nico@207: 00131             else:
nico@207: 00132                 webbrowser.open(url)
nico@207: 00133     
nico@207: 00134     Html_Window = True
nico@207: 00135 except:
nico@207: 00136     Html_Window = False
nico@207: 00137 
nico@207: 00138 
nico@207: 00139 [wxID_NETWORKEDIT, wxID_NETWORKEDITNETWORKNODES, 
nico@207: 00140  wxID_NETWORKEDITHELPBAR,
nico@207: 00141 ] = [wx.NewId() for _init_ctrls in range(3)]
nico@207: 00142 
nico@207: 00143 [wxID_NETWORKEDITADDMENUITEMS0, wxID_NETWORKEDITADDMENUITEMS1, 
nico@207: 00144  wxID_NETWORKEDITADDMENUITEMS2, wxID_NETWORKEDITADDMENUITEMS3, 
nico@207: 00145  wxID_NETWORKEDITADDMENUITEMS4, wxID_NETWORKEDITADDMENUITEMS5, 
nico@207: 00146 ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)]
nico@207: 00147 
nico@207: 00148 [wxID_NETWORKEDITFILEMENUITEMS0, wxID_NETWORKEDITFILEMENUITEMS1, 
nico@207: 00149  wxID_NETWORKEDITFILEMENUITEMS2, wxID_NETWORKEDITFILEMENUITEMS4, 
nico@207: 00150  wxID_NETWORKEDITFILEMENUITEMS5, wxID_NETWORKEDITFILEMENUITEMS6,
nico@207: 00151 ] = [wx.NewId() for _init_coll_FileMenu_Items in range(6)]
nico@207: 00152 
nico@207: 00153 [wxID_NETWORKEDITNETWORKMENUITEMS0, wxID_NETWORKEDITNETWORKMENUITEMS1, 
nico@207: 00154  wxID_NETWORKEDITNETWORKMENUITEMS3, 
nico@207: 00155 ] = [wx.NewId() for _init_coll_AddMenu_Items in range(3)]
nico@207: 00156 
nico@207: 00157 
nico@207: 00158 [wxID_NETWORKEDITEDITMENUITEMS0, wxID_NETWORKEDITEDITMENUITEMS1, 
nico@207: 00159  wxID_NETWORKEDITEDITMENUITEMS2, wxID_NETWORKEDITEDITMENUITEMS4, 
nico@207: 00160  wxID_NETWORKEDITEDITMENUITEMS6, wxID_NETWORKEDITEDITMENUITEMS7, 
nico@207: 00161  wxID_NETWORKEDITEDITMENUITEMS8, 
nico@207: 00162 ] = [wx.NewId() for _init_coll_EditMenu_Items in range(7)]
nico@207: 00163 
nico@207: 00164 [wxID_NETWORKEDITHELPMENUITEMS0, wxID_NETWORKEDITHELPMENUITEMS1,
nico@207: 00165  wxID_NETWORKEDITHELPMENUITEMS2,
nico@207: 00166 ] = [wx.NewId() for _init_coll_HelpMenu_Items in range(3)]
nico@207: 00167 
nico@207: 00168 class networkedit(wx.Frame):
nico@207: 00169     def _init_coll_menuBar1_Menus(self, parent):
nico@207: 00170         # generated method, don't edit
nico@207: 00171 
nico@207: 00172         if self.Mode == "solo":
nico@207: 00173             parent.Append(menu=self.FileMenu, title='File')
nico@207: 00174         parent.Append(menu=self.NetworkMenu, title='Network')
nico@207: 00175         parent.Append(menu=self.EditMenu, title='Edit')
nico@207: 00176         parent.Append(menu=self.AddMenu, title='Add')
nico@207: 00177         parent.Append(menu=self.HelpMenu, title='Help')
nico@207: 00178 
nico@207: 00179     def _init_coll_EditMenu_Items(self, parent):
nico@207: 00180         # generated method, don't edit
nico@207: 00181 
nico@207: 00182         parent.Append(help='', id=wxID_NETWORKEDITEDITMENUITEMS4,
nico@207: 00183               kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R')
nico@207: 00184         parent.AppendSeparator()
nico@207: 00185         parent.Append(help='', id=wxID_NETWORKEDITEDITMENUITEMS1,
nico@207: 00186               kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z')
nico@207: 00187         parent.Append(help='', id=wxID_NETWORKEDITEDITMENUITEMS0,
nico@207: 00188               kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y')
nico@207: 00189         parent.AppendSeparator()
nico@207: 00190         parent.Append(help='', id=wxID_NETWORKEDITEDITMENUITEMS6,
nico@207: 00191               kind=wx.ITEM_NORMAL, text='Node infos')
nico@207: 00192         parent.Append(help='', id=wxID_NETWORKEDITEDITMENUITEMS2,
nico@207: 00193               kind=wx.ITEM_NORMAL, text='DS-301 Profile')
nico@207: 00194         parent.Append(help='', id=wxID_NETWORKEDITEDITMENUITEMS8,
nico@207: 00195               kind=wx.ITEM_NORMAL, text='DS-302 Profile')
nico@207: 00196         parent.Append(help='', id=wxID_NETWORKEDITEDITMENUITEMS7,
nico@207: 00197               kind=wx.ITEM_NORMAL, text='Other Profile')
nico@207: 00198         self.Bind(wx.EVT_MENU, self.OnUndoMenu,
nico@207: 00199               id=wxID_NETWORKEDITEDITMENUITEMS1)
nico@207: 00200         self.Bind(wx.EVT_MENU, self.OnRedoMenu,
nico@207: 00201               id=wxID_NETWORKEDITEDITMENUITEMS0)
nico@207: 00202         self.Bind(wx.EVT_MENU, self.OnCommunicationMenu,
nico@207: 00203               id=wxID_NETWORKEDITEDITMENUITEMS2)
nico@207: 00204         self.Bind(wx.EVT_MENU, self.OnRefreshMenu,
nico@207: 00205               id=wxID_NETWORKEDITEDITMENUITEMS4)
nico@207: 00206         self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu,
nico@207: 00207               id=wxID_NETWORKEDITEDITMENUITEMS6)
nico@207: 00208         self.Bind(wx.EVT_MENU, self.OnEditProfileMenu,
nico@207: 00209               id=wxID_NETWORKEDITEDITMENUITEMS7)
nico@207: 00210         self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu,
nico@207: 00211               id=wxID_NETWORKEDITEDITMENUITEMS8)
nico@207: 00212 
nico@207: 00213     def _init_coll_HelpMenu_Items(self, parent):
nico@207: 00214         # generated method, don't edit
nico@207: 00215 
nico@207: 00216         parent.Append(help='', id=wxID_NETWORKEDITHELPMENUITEMS0,
nico@207: 00217               kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1')
nico@207: 00218         self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu,
nico@207: 00219               id=wxID_NETWORKEDITHELPMENUITEMS0)
nico@207: 00220         parent.Append(help='', id=wxID_NETWORKEDITHELPMENUITEMS1,
nico@207: 00221               kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2')
nico@207: 00222         self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu,
nico@207: 00223               id=wxID_NETWORKEDITHELPMENUITEMS1)
nico@207: 00224         if Html_Window and self.Mode == "solo":
nico@207: 00225             parent.Append(help='', id=wxID_NETWORKEDITHELPMENUITEMS2,
nico@207: 00226                   kind=wx.ITEM_NORMAL, text='About')
nico@207: 00227             self.Bind(wx.EVT_MENU, self.OnAboutMenu,
nico@207: 00228                   id=wxID_NETWORKEDITHELPMENUITEMS2)
nico@207: 00229 
nico@207: 00230     def _init_coll_FileMenu_Items(self, parent):
nico@207: 00231         # generated method, don't edit
nico@207: 00232 
nico@207: 00233         parent.Append(help='', id=wxID_NETWORKEDITFILEMENUITEMS5,
nico@207: 00234               kind=wx.ITEM_NORMAL, text='New\tCTRL+N')
nico@207: 00235         parent.Append(help='', id=wxID_NETWORKEDITFILEMENUITEMS0,
nico@207: 00236               kind=wx.ITEM_NORMAL, text='Open\tCTRL+O')
nico@207: 00237         parent.Append(help='', id=wxID_NETWORKEDITFILEMENUITEMS1,
nico@207: 00238               kind=wx.ITEM_NORMAL, text='Save\tCTRL+S')
nico@207: 00239         parent.Append(help='', id=wxID_NETWORKEDITFILEMENUITEMS2,
nico@207: 00240               kind=wx.ITEM_NORMAL, text='Close\tCTRL+W')
nico@207: 00241         parent.AppendSeparator()
nico@207: 00242         parent.Append(help='', id=wxID_NETWORKEDITFILEMENUITEMS4,
nico@207: 00243               kind=wx.ITEM_NORMAL, text='Exit')
nico@207: 00244         self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu,
nico@207: 00245               id=wxID_NETWORKEDITFILEMENUITEMS0)
nico@207: 00246         self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu,
nico@207: 00247               id=wxID_NETWORKEDITFILEMENUITEMS1)
nico@207: 00248 ##        self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu,
nico@207: 00249 ##              id=wxID_NETWORKEDITFILEMENUITEMS2)
nico@207: 00250         self.Bind(wx.EVT_MENU, self.OnQuitMenu,
nico@207: 00251               id=wxID_NETWORKEDITFILEMENUITEMS4)
nico@207: 00252         self.Bind(wx.EVT_MENU, self.OnNewProjectMenu,
nico@207: 00253               id=wxID_NETWORKEDITFILEMENUITEMS5)
nico@207: 00254     
nico@207: 00255     def _init_coll_NetworkMenu_Items(self, parent):
nico@207: 00256         # generated method, don't edit
nico@207: 00257 
nico@207: 00258         parent.Append(help='', id=wxID_NETWORKEDITNETWORKMENUITEMS0,
nico@207: 00259               kind=wx.ITEM_NORMAL, text='Add Slave Node')
nico@207: 00260         parent.Append(help='', id=wxID_NETWORKEDITNETWORKMENUITEMS1,
nico@207: 00261               kind=wx.ITEM_NORMAL, text='Remove Slave Node')
nico@207: 00262         parent.AppendSeparator()
nico@207: 00263         parent.Append(help='', id=wxID_NETWORKEDITNETWORKMENUITEMS3,
nico@207: 00264               kind=wx.ITEM_NORMAL, text='Build Master Dictionary')
nico@207: 00265         self.Bind(wx.EVT_MENU, self.OnAddSlaveMenu,
nico@207: 00266               id=wxID_NETWORKEDITNETWORKMENUITEMS0)
nico@207: 00267         self.Bind(wx.EVT_MENU, self.OnRemoveSlaveMenu,
nico@207: 00268               id=wxID_NETWORKEDITNETWORKMENUITEMS1)
nico@207: 00269 ##        self.Bind(wx.EVT_MENU, self.OnBuildMasterMenu,
nico@207: 00270 ##              id=wxID_NETWORKEDITNETWORKMENUITEMS3)
nico@207: 00271     
nico@207: 00272     def _init_coll_AddMenu_Items(self, parent):
nico@207: 00273         # generated method, don't edit
nico@207: 00274 
nico@207: 00275         parent.Append(help='', id=wxID_NETWORKEDITADDMENUITEMS0,
nico@207: 00276               kind=wx.ITEM_NORMAL, text='SDO Server')
nico@207: 00277         parent.Append(help='', id=wxID_NETWORKEDITADDMENUITEMS1,
nico@207: 00278               kind=wx.ITEM_NORMAL, text='SDO Client')
nico@207: 00279         parent.Append(help='', id=wxID_NETWORKEDITADDMENUITEMS2,
nico@207: 00280               kind=wx.ITEM_NORMAL, text='PDO Transmit')
nico@207: 00281         parent.Append(help='', id=wxID_NETWORKEDITADDMENUITEMS3,
nico@207: 00282               kind=wx.ITEM_NORMAL, text='PDO Receive')
nico@207: 00283         parent.Append(help='', id=wxID_NETWORKEDITADDMENUITEMS4,
nico@207: 00284               kind=wx.ITEM_NORMAL, text='Map Variable')
nico@207: 00285         parent.Append(help='', id=wxID_NETWORKEDITADDMENUITEMS5,
nico@207: 00286               kind=wx.ITEM_NORMAL, text='User Type')
nico@207: 00287         self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu,
nico@207: 00288               id=wxID_NETWORKEDITADDMENUITEMS0)
nico@207: 00289         self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu,
nico@207: 00290               id=wxID_NETWORKEDITADDMENUITEMS1)
nico@207: 00291         self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu,
nico@207: 00292               id=wxID_NETWORKEDITADDMENUITEMS2)
nico@207: 00293         self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu,
nico@207: 00294               id=wxID_NETWORKEDITADDMENUITEMS3)
nico@207: 00295         self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu,
nico@207: 00296               id=wxID_NETWORKEDITADDMENUITEMS4)
nico@207: 00297         self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu,
nico@207: 00298               id=wxID_NETWORKEDITADDMENUITEMS5)
nico@207: 00299 
nico@207: 00300     def _init_coll_HelpBar_Fields(self, parent):
nico@207: 00301         # generated method, don't edit
nico@207: 00302         parent.SetFieldsCount(3)
nico@207: 00303 
nico@207: 00304         parent.SetStatusText(number=0, text='')
nico@207: 00305         parent.SetStatusText(number=1, text='')
nico@207: 00306         parent.SetStatusText(number=2, text='')
nico@207: 00307 
nico@207: 00308         parent.SetStatusWidths([100, 110, -1])
nico@207: 00309 
nico@207: 00310     def _init_utils(self):
nico@207: 00311         # generated method, don't edit
nico@207: 00312         self.menuBar1 = wx.MenuBar()
nico@207: 00313         self.menuBar1.SetEvtHandlerEnabled(True)
nico@207: 00314         
nico@207: 00315         if self.Mode == "solo":
nico@207: 00316             self.FileMenu = wx.Menu(title='')
nico@207: 00317         
nico@207: 00318         self.NetworkMenu = wx.Menu(title='')
nico@207: 00319 
nico@207: 00320         self.EditMenu = wx.Menu(title='')
nico@207: 00321 
nico@207: 00322         self.AddMenu = wx.Menu(title='')
nico@207: 00323 
nico@207: 00324         self.HelpMenu = wx.Menu(title='')
nico@207: 00325 
nico@207: 00326         self._init_coll_menuBar1_Menus(self.menuBar1)
nico@207: 00327         if self.Mode == "solo":
nico@207: 00328             self._init_coll_FileMenu_Items(self.FileMenu)
nico@207: 00329         self._init_coll_NetworkMenu_Items(self.NetworkMenu)
nico@207: 00330         self._init_coll_EditMenu_Items(self.EditMenu)
nico@207: 00331         self._init_coll_AddMenu_Items(self.AddMenu)
nico@207: 00332         self._init_coll_HelpMenu_Items(self.HelpMenu)
nico@207: 00333 
nico@207: 00334     def _init_ctrls(self, prnt):
nico@207: 00335         # generated method, don't edit
nico@207: 00336         wx.Frame.__init__(self, id=wxID_NETWORKEDIT, name='networkedit',
nico@207: 00337               parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700),
nico@207: 00338               style=wx.DEFAULT_FRAME_STYLE, title='Networkedit')
nico@207: 00339         self._init_utils()
nico@207: 00340         self.SetClientSize(wx.Size(1000, 700))
nico@207: 00341         self.SetMenuBar(self.menuBar1)
nico@207: 00342 ##        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=wxID_NETWORKEDIT)
nico@207: 00343 
nico@207: 00344         self.NetworkNodes = wx.Notebook(id=wxID_NETWORKEDITNETWORKNODES,
nico@207: 00345               name='NetworkNodes', parent=self, pos=wx.Point(0, 0),
nico@207: 00346               size=wx.Size(0, 0), style=wxNB_LEFT)
nico@207: 00347         self.NetworkNodes.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
nico@207: 00348               self.OnNodeSelectedChanged, id=wxID_NETWORKEDITNETWORKNODES)
nico@207: 00349 
nico@207: 00350         self.HelpBar = wx.StatusBar(id=wxID_NETWORKEDITHELPBAR, name='HelpBar',
nico@207: 00351               parent=self, style=wxST_SIZEGRIP)
nico@207: 00352         self._init_coll_HelpBar_Fields(self.HelpBar)
nico@207: 00353         self.SetStatusBar(self.HelpBar)
nico@207: 00354 
nico@207: 00355     def __init__(self, parent, mode = "solo", nodelist = None):
nico@207: 00356         self.Mode = mode
nico@207: 00357         self._init_ctrls(parent)
nico@207: 00358         self.HtmlFrameOpened = []
nico@207: 00359         
nico@207: 00360         if self.Mode == "solo":
nico@207: 00361             self.Manager = NodeManager(ScriptDirectory)
nico@207: 00362             if projectOpen:
nico@207: 00363                 self.NodeList = NodeList(self.Manager)
nico@207: 00364                 result = self.NodeList.LoadProject(projectOpen)
nico@207: 00365                 if not result:
nico@207: 00366                     self.RefreshNetworkNodes()
nico@207: 00367             else:
nico@207: 00368                 self.NodeList = None
nico@207: 00369         else:
nico@207: 00370             self.NodeList = nodelist
nico@207: 00371             self.Manager = self.NodeList.GetManager()
nico@207: 00372         
nico@207: 00373         self.RefreshBufferState()
nico@207: 00374         self.RefreshTitle()
nico@207: 00375         self.RefreshMainMenu()
nico@207: 00376 
nico@207: 00377     def GetNoteBook(self):
nico@207: 00378         return self.NetworkNodes
nico@207: 00379 
nico@207: 00380     def OnQuitMenu(self, event):
nico@207: 00381         self.Close()
nico@207: 00382         event.Skip()
nico@207: 00383 
nico@207: 00384     def OnAddSDOServerMenu(self, event):
nico@207: 00385         self.Manager.AddSDOServerToCurrent()
nico@207: 00386         self.RefreshBufferState()
nico@207: 00387         self.RefreshCurrentIndexList()
nico@207: 00388         event.Skip()
nico@207: 00389     
nico@207: 00390     def OnAddSDOClientMenu(self, event):
nico@207: 00391         self.Manager.AddSDOClientToCurrent()
nico@207: 00392         self.RefreshBufferState()
nico@207: 00393         self.RefreshCurrentIndexList()
nico@207: 00394         event.Skip()
nico@207: 00395 
nico@207: 00396     def OnAddPDOTransmitMenu(self, event):
nico@207: 00397         self.Manager.AddPDOTransmitToCurrent()
nico@207: 00398         self.RefreshBufferState()
nico@207: 00399         self.RefreshCurrentIndexList()
nico@207: 00400         event.Skip()
nico@207: 00401 
nico@207: 00402     def OnAddPDOReceiveMenu(self, event):
nico@207: 00403         self.Manager.AddPDOReceiveToCurrent()
nico@207: 00404         self.RefreshBufferState()
nico@207: 00405         self.RefreshCurrentIndexList()
nico@207: 00406         event.Skip()
nico@207: 00407 
nico@207: 00408     def OnAddMapVariableMenu(self, event):
nico@207: 00409         self.AddMapVariable()
nico@207: 00410         event.Skip()
nico@207: 00411 
nico@207: 00412     def OnAddUserTypeMenu(self, event):
nico@207: 00413         self.AddUserType()
nico@207: 00414         event.Skip()
nico@207: 00415 
nico@207: 00416     def OnNodeSelectedChanged(self, event):
nico@207: 00417         selected = event.GetSelection()
nico@207: 00418         # At init selected = -1
nico@207: 00419         if selected > 0:
nico@207: 00420             window = self.NetworkNodes.GetPage(selected)
nico@207: 00421             self.NodeList.SetCurrentSelected(window.GetIndex())
nico@207: 00422         self.RefreshMainMenu()
nico@207: 00423         self.RefreshStatusBar()
nico@207: 00424         event.Skip()
nico@207: 00425 
nico@207: 00426 #-------------------------------------------------------------------------------
nico@207: 00427 #                         Load and Save Funtions
nico@207: 00428 #-------------------------------------------------------------------------------
nico@207: 00429 
nico@207: 00430     def OnNewProjectMenu(self, event):
nico@207: 00431         if self.NodeList:
nico@207: 00432             defaultpath = os.path.dirname(self.NodeList.GetRoot())
nico@207: 00433         else:
nico@207: 00434             defaultpath = os.getcwd()
nico@207: 00435         dialog = wxDirDialog(self , "Choose a project", defaultpath, wxDD_NEW_DIR_BUTTON)
nico@207: 00436         if dialog.ShowModal() == wxID_OK:
nico@207: 00437             projectpath = dialog.GetPath()
nico@207: 00438             if os.path.isdir(projectpath) and len(os.listdir(projectpath)) == 0:
nico@207: 00439                 manager = NodeManager(ScriptDirectory)
nico@207: 00440                 nodelist = NodeList(manager)
nico@207: 00441                 result = nodelist.LoadProject(projectpath)
nico@207: 00442                 if not result:
nico@207: 00443                     self.Manager = manager
nico@207: 00444                     self.NodeList = nodelist
nico@207: 00445                     self.NodeList.SetCurrentSelected(0)
nico@207: 00446                                         
nico@207: 00447                     self.RefreshNetworkNodes()
nico@207: 00448                     self.RefreshBufferState()
nico@207: 00449                     self.RefreshTitle()
nico@207: 00450                     self.RefreshProfileMenu()
nico@207: 00451                     self.RefreshMainMenu()
nico@207: 00452                 else:
nico@207: 00453                     message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR)
nico@207: 00454                     message.ShowModal()
nico@207: 00455                     message.Destroy()
nico@207: 00456         event.Skip()
nico@207: 00457 
nico@207: 00458     def OnOpenProjectMenu(self, event):
nico@207: 00459         if self.NodeList:
nico@207: 00460             defaultpath = os.path.dirname(self.NodeList.GetRoot())
nico@207: 00461         else:
nico@207: 00462             defaultpath = os.getcwd()
nico@207: 00463         dialog = wxDirDialog(self , "Choose a project", defaultpath, 0)
nico@207: 00464         if dialog.ShowModal() == wxID_OK:
nico@207: 00465             projectpath = dialog.GetPath()
nico@207: 00466             if os.path.isdir(projectpath):
nico@207: 00467                 manager = NodeManager(ScriptDirectory)
nico@207: 00468                 nodelist = NodeList(manager)
nico@207: 00469                 result = nodelist.LoadProject(projectpath)
nico@207: 00470                 if not result:
nico@207: 00471                     self.Manager = manager
nico@207: 00472                     self.NodeList = nodelist
nico@207: 00473                     self.NodeList.SetCurrentSelected(0)
nico@207: 00474                     
nico@207: 00475                     self.RefreshNetworkNodes()
nico@207: 00476                     self.RefreshBufferState()
nico@207: 00477                     self.RefreshTitle()
nico@207: 00478                     self.RefreshProfileMenu()
nico@207: 00479                     self.RefreshMainMenu()
nico@207: 00480                 else:
nico@207: 00481                     message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
nico@207: 00482                     message.ShowModal()
nico@207: 00483                     message.Destroy()
nico@207: 00484         dialog.Destroy()
nico@207: 00485         event.Skip()
nico@207: 00486 
nico@207: 00487     def OnSaveProjectMenu(self, event):
nico@207: 00488         result = self.NodeList.SaveProject()
nico@207: 00489         if result:
nico@207: 00490             message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
nico@207: 00491             message.ShowModal()
nico@207: 00492             message.Destroy()
nico@207: 00493         event.Skip()
nico@207: 00494 
nico@207: 00495 #-------------------------------------------------------------------------------
nico@207: 00496 #                             Slave Nodes Management
nico@207: 00497 #-------------------------------------------------------------------------------
nico@207: 00498 
nico@207: 00499     def OnAddSlaveMenu(self, event):
nico@207: 00500         dialog = AddSlaveDialog(self)
nico@207: 00501         dialog.SetNodeList(self.NodeList)
nico@207: 00502         if dialog.ShowModal() == wxID_OK:
nico@207: 00503             values = dialog.GetValues()
nico@207: 00504             result = self.NodeList.AddSlaveNode(values["slaveName"], values["slaveNodeID"], values["edsFile"])
nico@207: 00505             if not result:
nico@207: 00506                 new_editingpanel = EditingPanel(self, self.NodeList, False)
nico@207: 00507                 new_editingpanel.SetIndex(values["slaveNodeID"])
nico@207: 00508                 idx = self.NodeList.GetOrderNumber(values["slaveNodeID"])
nico@207: 00509                 self.NetworkNodes.InsertPage(idx, new_editingpanel, "")
nico@207: 00510                 self.NodeList.SetCurrentSelected(idx)
nico@207: 00511                 self.NetworkNodes.SetSelection(idx)
nico@207: 00512                 self.RefreshBufferState()
nico@207: 00513             else:
nico@207: 00514                 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
nico@207: 00515                 message.ShowModal()
nico@207: 00516                 message.Destroy()
nico@207: 00517         dialog.Destroy()
nico@207: 00518         event.Skip()
nico@207: 00519 
nico@207: 00520     def OnRemoveSlaveMenu(self, event):
nico@207: 00521         slavenames = self.NodeList.GetSlaveNames()
nico@207: 00522         slaveids = self.NodeList.GetSlaveIDs()
nico@207: 00523         dialog = wxSingleChoiceDialog(self, "Choose a slave to remove", "Remove slave", slavenames)
nico@207: 00524         if dialog.ShowModal() == wxID_OK:
nico@207: 00525             choice = dialog.GetSelection()
nico@207: 00526             result = self.NodeList.RemoveSlaveNode(slaveids[choice])
nico@207: 00527             if not result:
nico@207: 00528                 slaveids.pop(choice)
nico@207: 00529                 current = self.NetworkNodes.GetSelection()
nico@207: 00530                 self.NetworkNodes.DeletePage(choice + 1)
nico@207: 00531                 if self.NetworkNodes.GetPageCount() > 0:
nico@207: 00532                     new_selection = min(current, self.NetworkNodes.GetPageCount() - 1)
nico@207: 00533                     self.NetworkNodes.SetSelection(new_selection)
nico@207: 00534                     if new_selection > 0:
nico@207: 00535                         self.NodeList.SetCurrentSelected(slaveids[new_selection - 1])
nico@207: 00536                     self.RefreshBufferState()
nico@207: 00537             else:
nico@207: 00538                 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
nico@207: 00539                 message.ShowModal()
nico@207: 00540                 message.Destroy()
nico@207: 00541         event.Skip()
nico@207: 00542 
nico@207: 00543 #-------------------------------------------------------------------------------
nico@207: 00544 #                             Refresh Functions
nico@207: 00545 #-------------------------------------------------------------------------------
nico@207: 00546 
nico@207: 00547     def RefreshTitle(self):
nico@207: 00548         if self.NodeList != None:
nico@207: 00549             self.SetTitle("Networkedit - %s"%self.NodeList.GetNetworkName())
nico@207: 00550         else:
nico@207: 00551             self.SetTitle("Networkedit")
nico@207: 00552 
nico@207: 00553     def OnRefreshMenu(self, event):
nico@207: 00554         self.RefreshCurrentIndexList()
nico@207: 00555         event.Skip()
nico@207: 00556 
nico@207: 00557     def RefreshCurrentIndexList(self):
nico@207: 00558         selected = self.NetworkNodes.GetSelection()
nico@207: 00559         if selected == 0:
nico@207: 00560             window = self.NetworkNodes.GetPage(selected)
nico@207: 00561             window.RefreshIndexList()
nico@207: 00562         else:
nico@207: 00563             pass
nico@207: 00564 
nico@207: 00565     def RefreshNetworkNodes(self):
nico@207: 00566         if self.NetworkNodes.GetPageCount() > 0:
nico@207: 00567             self.NetworkNodes.DeleteAllPages()
nico@207: 00568         if self.NodeList:
nico@207: 00569             new_editingpanel = EditingPanel(self, self.Manager)
nico@207: 00570             new_editingpanel.SetIndex(0)
nico@207: 00571             self.NetworkNodes.AddPage(new_editingpanel, "")
nico@207: 00572             for idx in self.NodeList.GetSlaveIDs():
nico@207: 00573                 new_editingpanel = EditingPanel(self, self.NodeList, False)
nico@207: 00574                 new_editingpanel.SetIndex(idx)
nico@207: 00575                 self.NetworkNodes.AddPage(new_editingpanel, "")
nico@207: 00576 
nico@207: 00577     def RefreshStatusBar(self):
nico@207: 00578         if self.HelpBar:
nico@207: 00579             window = self.NetworkNodes.GetPage(self.NetworkNodes.GetSelection())
nico@207: 00580             selection = window.GetSelection()
nico@207: 00581             if selection:
nico@207: 00582                 index, subIndex = selection
nico@207: 00583                 if self.NodeList.IsCurrentEntry(index):
nico@207: 00584                     self.HelpBar.SetStatusText("Index: 0x%04X"%index, 0)
nico@207: 00585                     self.HelpBar.SetStatusText("Subindex: 0x%02X"%subIndex, 1)
nico@207: 00586                     entryinfos = self.NodeList.GetEntryInfos(index)
nico@207: 00587                     name = entryinfos["name"]
nico@207: 00588                     category = "Optional"
nico@207: 00589                     if entryinfos["need"]:
nico@207: 00590                         category = "Mandatory"
nico@207: 00591                     struct = "VAR"
nico@207: 00592                     number = ""
nico@207: 00593                     if entryinfos["struct"] & OD_IdenticalIndexes:
nico@207: 00594                         number = " possibly defined %d times"%entryinfos["nbmax"]
nico@207: 00595                     if entryinfos["struct"] & OD_IdenticalSubindexes:
nico@207: 00596                         struct = "REC"
nico@207: 00597                     elif entryinfos["struct"] & OD_MultipleSubindexes:
nico@207: 00598                         struct = "ARRAY"
nico@207: 00599                     text = "%s: %s entry of struct %s%s."%(name,category,struct,number)
nico@207: 00600                     self.HelpBar.SetStatusText(text, 2)
nico@207: 00601                 else:
nico@207: 00602                     for i in xrange(3):
nico@207: 00603                         self.HelpBar.SetStatusText("", i)
nico@207: 00604             else:
nico@207: 00605                 for i in xrange(3):
nico@207: 00606                     self.HelpBar.SetStatusText("", i)
nico@207: 00607 
nico@207: 00608     def RefreshMainMenu(self):
nico@207: 00609         if self.menuBar1:
nico@207: 00610             self.NetworkMenu.Enable(wxID_NETWORKEDITNETWORKMENUITEMS3, False)
nico@207: 00611             if self.NodeList == None:
nico@207: 00612                 if self.Mode == "solo":
nico@207: 00613                     self.menuBar1.EnableTop(1, False)
nico@207: 00614                     self.menuBar1.EnableTop(2, False)
nico@207: 00615                     self.menuBar1.EnableTop(3, False)
nico@207: 00616                     if self.FileMenu:
nico@207: 00617                         self.FileMenu.Enable(wxID_NETWORKEDITFILEMENUITEMS1, False)
nico@207: 00618                         self.FileMenu.Enable(wxID_NETWORKEDITFILEMENUITEMS2, False)
nico@207: 00619                 else:
nico@207: 00620                     self.menuBar1.EnableTop(0, False)
nico@207: 00621                     self.menuBar1.EnableTop(1, False)
nico@207: 00622                     self.menuBar1.EnableTop(2, False)
nico@207: 00623             else:
nico@207: 00624                 if self.Mode == "solo":
nico@207: 00625                     self.menuBar1.EnableTop(1, True)
nico@207: 00626                     if self.FileMenu:
nico@207: 00627                         self.FileMenu.Enable(wxID_NETWORKEDITFILEMENUITEMS1, True)
nico@207: 00628                         self.FileMenu.Enable(wxID_NETWORKEDITFILEMENUITEMS2, False)
nico@207: 00629                     if self.NetworkNodes.GetSelection() == 0:
nico@207: 00630                         self.menuBar1.EnableTop(2, True)
nico@207: 00631                         self.menuBar1.EnableTop(3, True)
nico@207: 00632                     else:
nico@207: 00633                         self.menuBar1.EnableTop(2, False)      
nico@207: 00634                         self.menuBar1.EnableTop(3, False)
nico@207: 00635                 else:
nico@207: 00636                     self.menuBar1.EnableTop(0, True)
nico@207: 00637                     if self.NetworkNodes.GetSelection() == 0:
nico@207: 00638                         self.menuBar1.EnableTop(1, True)
nico@207: 00639                         self.menuBar1.EnableTop(2, True)
nico@207: 00640                     else:
nico@207: 00641                         self.menuBar1.EnableTop(1, False)      
nico@207: 00642                         self.menuBar1.EnableTop(2, False)
nico@207: 00643 
nico@207: 00644     def RefreshProfileMenu(self):
nico@207: 00645         if self.EditMenu:
nico@207: 00646             profile = self.Manager.GetCurrentProfileName()
nico@207: 00647             edititem = self.EditMenu.FindItemById(wxID_NETWORKEDITEDITMENUITEMS7)
nico@207: 00648             if edititem:
nico@207: 00649                 length = self.AddMenu.GetMenuItemCount()
nico@207: 00650                 for i in xrange(length-6):
nico@207: 00651                     additem = self.AddMenu.FindItemByPosition(6)
nico@207: 00652                     self.AddMenu.Delete(additem.GetId())
nico@207: 00653                 if profile not in ("None", "DS-301"):
nico@207: 00654                     edititem.SetText("%s Profile"%profile)
nico@207: 00655                     edititem.Enable(True)
nico@207: 00656                     self.AddMenu.AppendSeparator()
nico@207: 00657                     for text, indexes in self.Manager.GetCurrentSpecificMenu():
nico@207: 00658                         new_id = wx.NewId()
nico@207: 00659                         self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text)
nico@207: 00660                         self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id)
nico@207: 00661                 else:
nico@207: 00662                     edititem.SetText("Other Profile")
nico@207: 00663                     edititem.Enable(False)
nico@207: 00664 
nico@207: 00665 #-------------------------------------------------------------------------------
nico@207: 00666 #                              Buffer Functions
nico@207: 00667 #-------------------------------------------------------------------------------
nico@207: 00668 
nico@207: 00669     def RefreshBufferState(self):
nico@207: 00670         if self.NodeList:
nico@207: 00671             nodeID = self.Manager.GetCurrentNodeID()
nico@207: 00672             if nodeID != None:
nico@207: 00673                 nodename = "0x%2.2X %s"%(nodeID, self.Manager.GetCurrentNodeName())
nico@207: 00674             else:
nico@207: 00675                 nodename = self.Manager.GetCurrentNodeName()
nico@207: 00676             self.NetworkNodes.SetPageText(0, nodename)
nico@207: 00677             for idx, name in enumerate(self.NodeList.GetSlaveNames()):
nico@207: 00678                 self.NetworkNodes.SetPageText(idx + 1, name)
nico@207: 00679             self.RefreshTitle()
nico@207: 00680 
nico@207: 00681     def OnUndoMenu(self, event):
nico@207: 00682         self.Manager.LoadCurrentPrevious()
nico@207: 00683         self.RefreshCurrentIndexList()
nico@207: 00684         self.RefreshBufferState()
nico@207: 00685         event.Skip()
nico@207: 00686 
nico@207: 00687     def OnRedoMenu(self, event):
nico@207: 00688         self.Manager.LoadCurrentNext()
nico@207: 00689         self.RefreshCurrentIndexList()
nico@207: 00690         self.RefreshBufferState()
nico@207: 00691         event.Skip()
nico@207: 00692 
nico@207: 00693 #-------------------------------------------------------------------------------
nico@207: 00694 #                                Help Method
nico@207: 00695 #-------------------------------------------------------------------------------
nico@207: 00696 
nico@207: 00697     def OnHelpDS301Menu(self, event):
nico@207: 00698         find_index = False
nico@207: 00699         selected = self.NetworkNodes.GetSelection()
nico@207: 00700         if selected >= 0:
nico@207: 00701             window = self.NetworkNodes.GetPage(selected)
nico@207: 00702             result = window.GetSelection()
nico@207: 00703             if result:
nico@207: 00704                 find_index = True
nico@207: 00705                 index, subIndex = result
nico@207: 00706                 result = OpenPDFDocIndex(index, ScriptDirectory)
nico@207: 00707                 if type(result) == StringType:
nico@207: 00708                     message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR)
nico@207: 00709                     message.ShowModal()
nico@207: 00710                     message.Destroy()
nico@207: 00711         if not find_index:
nico@207: 00712             result = OpenPDFDocIndex(None, ScriptDirectory)
nico@207: 00713             if type(result) == StringType:
nico@207: 00714                 message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR)
nico@207: 00715                 message.ShowModal()
nico@207: 00716                 message.Destroy()
nico@207: 00717         event.Skip()
nico@207: 00718         
nico@207: 00719     def OnHelpCANFestivalMenu(self, event):
nico@207: 00720         #self.OpenHtmlFrame("CAN Festival Reference", os.path.join(ScriptDirectory, "doc/canfestival.html"), wx.Size(1000, 600))
nico@207: 00721         os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16))
nico@207: 00722         event.Skip()
nico@207: 00723 
nico@207: 00724     def OnAboutMenu(self, event):
nico@207: 00725         self.OpenHtmlFrame("About CAN Festival", os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450))
nico@207: 00726         event.Skip()
nico@207: 00727 
nico@207: 00728     def OpenHtmlFrame(self, title, file, size):
nico@207: 00729         if title not in self.HtmlFrameOpened:
nico@207: 00730             self.HtmlFrameOpened.append(title)
nico@207: 00731             window = HtmlFrame(self, self.HtmlFrameOpened)
nico@207: 00732             window.SetTitle(title)
nico@207: 00733             window.SetHtmlPage(file)
nico@207: 00734             window.SetClientSize(size)
nico@207: 00735             window.Show()
nico@207: 00736 
nico@207: 00737 #-------------------------------------------------------------------------------
nico@207: 00738 #                          Editing Profiles functions
nico@207: 00739 #-------------------------------------------------------------------------------
nico@207: 00740 
nico@207: 00741     def OnCommunicationMenu(self, event):
nico@207: 00742         dictionary,current = self.Manager.GetCurrentCommunicationLists()
nico@207: 00743         self.EditProfile("Edit DS-301 Profile", dictionary, current)
nico@207: 00744         event.Skip()
nico@207: 00745     
nico@207: 00746     def OnOtherCommunicationMenu(self, event):
nico@207: 00747         dictionary,current = self.Manager.GetCurrentDS302Lists()
nico@207: 00748         self.EditProfile("Edit DS-301 Profile", dictionary, current)
nico@207: 00749         event.Skip()
nico@207: 00750     
nico@207: 00751     def OnEditProfileMenu(self, event):
nico@207: 00752         title = "Edit %s Profile"%self.Manager.GetCurrentProfileName()
nico@207: 00753         dictionary,current = self.Manager.GetCurrentProfileLists()
nico@207: 00754         self.EditProfile(title, dictionary, current)
nico@207: 00755         event.Skip()
nico@207: 00756     
nico@207: 00757     def EditProfile(self, title, dictionary, current):
nico@207: 00758         dialog = CommunicationDialog(self)
nico@207: 00759         dialog.SetTitle(title)
nico@207: 00760         dialog.SetIndexDictionary(dictionary)
nico@207: 00761         dialog.SetCurrentList(current)
nico@207: 00762         dialog.RefreshLists()
nico@207: 00763         if dialog.ShowModal() == wxID_OK:
nico@207: 00764             new_profile = dialog.GetCurrentList()
nico@207: 00765             addinglist = []
nico@207: 00766             removinglist = []
nico@207: 00767             for index in new_profile:
nico@207: 00768                 if index not in current:
nico@207: 00769                     addinglist.append(index)
nico@207: 00770             for index in current:
nico@207: 00771                 if index not in new_profile:
nico@207: 00772                     removinglist.append(index)
nico@207: 00773             self.Manager.ManageEntriesOfCurrent(addinglist, removinglist)
nico@207: 00774             self.Manager.GenerateMapList()
nico@207: 00775             self.Manager.BufferCurrentNode()
nico@207: 00776             self.RefreshBufferState()
nico@207: 00777             self.RefreshCurrentIndexList()
nico@207: 00778         dialog.Destroy()
nico@207: 00779 
nico@207: 00780 #-------------------------------------------------------------------------------
nico@207: 00781 #                         Edit Node informations function
nico@207: 00782 #-------------------------------------------------------------------------------
nico@207: 00783 
nico@207: 00784     def OnNodeInfosMenu(self, event):
nico@207: 00785         dialog = NodeInfosDialog(self)
nico@207: 00786         name, id, type, description = self.Manager.GetCurrentNodeInfos()
nico@207: 00787         dialog.SetValues(name, id, type, description)
nico@207: 00788         if dialog.ShowModal() == wxID_OK:
nico@207: 00789             name, id, type, description = dialog.GetValues()
nico@207: 00790             self.Manager.SetCurrentNodeInfos(name, id, type, description)
nico@207: 00791             self.RefreshBufferState()
nico@207: 00792             self.RefreshProfileMenu()
nico@207: 00793             selected = self.FileOpened.GetSelection()
nico@207: 00794             if selected >= 0:
nico@207: 00795                 window = self.FileOpened.GetPage(selected)
nico@207: 00796                 window.RefreshTable()
nico@207: 00797         event.Skip()
nico@207: 00798 
nico@207: 00799 
nico@207: 00800 #-------------------------------------------------------------------------------
nico@207: 00801 #                           Add User Types and Variables
nico@207: 00802 #-------------------------------------------------------------------------------
nico@207: 00803         
nico@207: 00804     def AddMapVariable(self):
nico@207: 00805         index = self.Manager.GetCurrentNextMapIndex()
nico@207: 00806         if index:
nico@207: 00807             dialog = MapVariableDialog(self)
nico@207: 00808             dialog.SetIndex(index)
nico@207: 00809             if dialog.ShowModal() == wxID_OK:
nico@207: 00810                 index, name, struct, number = dialog.GetValues()
nico@207: 00811                 result = self.Manager.AddMapVariableToCurrent(index, name, struct, number)
nico@207: 00812                 if type(result) != StringType:
nico@207: 00813                     self.RefreshBufferState()
nico@207: 00814                     self.RefreshCurrentIndexList()
nico@207: 00815                 else:
nico@207: 00816                     message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
nico@207: 00817                     message.ShowModal()
nico@207: 00818                     message.Destroy()
nico@207: 00819             dialog.Destroy()
nico@207: 00820         else:
nico@207: 00821             message = wxMessageDialog(self, result, "No map variable index left!", wxOK|wxICON_ERROR)
nico@207: 00822             message.ShowModal()
nico@207: 00823             message.Destroy()
nico@207: 00824         
nico@207: 00825     def AddUserType(self):
nico@207: 00826         dialog = UserTypeDialog(self)
nico@207: 00827         dialog.SetTypeList(self.Manager.GetCustomisableTypes())
nico@207: 00828         if dialog.ShowModal() == wxID_OK:
nico@207: 00829             type, min, max, length = dialog.GetValues()
nico@207: 00830             result = self.Manager.AddUserTypeToCurrent(type, min, max, length)
nico@207: 00831             if not IsOfType(result, StringType):
nico@207: 00832                 self.RefreshBufferState()
nico@207: 00833                 self.RefreshCurrentIndexList()
nico@207: 00834             else:
nico@207: 00835                 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
nico@207: 00836                 message.ShowModal()
nico@207: 00837                 message.Destroy()
nico@207: 00838         dialog.Destroy()
nico@207: 00839 
nico@207: 00840 #-------------------------------------------------------------------------------
nico@207: 00841 #                               Exception Handler
nico@207: 00842 #-------------------------------------------------------------------------------
nico@207: 00843 
nico@207: 00844 Max_Traceback_List_Size = 20
nico@207: 00845 
nico@207: 00846 def Display_Exception_Dialog(e_type,e_value,e_tb):
nico@207: 00847     trcbck_lst = []
nico@207: 00848     for i,line in enumerate(traceback.extract_tb(e_tb)):
nico@207: 00849         trcbck = " " + str(i+1) + ". "
nico@207: 00850         if line[0].find(os.getcwd()) == -1:
nico@207: 00851             trcbck += "file : " + str(line[0]) + ",   "
nico@207: 00852         else:
nico@207: 00853             trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ",   "
nico@207: 00854         trcbck += "line : " + str(line[1]) + ",   " + "function : " + str(line[2])
nico@207: 00855         trcbck_lst.append(trcbck)
nico@207: 00856         
nico@207: 00857     # Allow clicking....
nico@207: 00858     cap = wx.Window_GetCapture()
nico@207: 00859     if cap:
nico@207: 00860         cap.ReleaseMouse()
nico@207: 00861 
nico@207: 00862     dlg = wx.SingleChoiceDialog(None, 
nico@207: 00863         """
nico@207: 00864 An error happens.
nico@207: 00865 
nico@207: 00866 Click on OK for saving an error report.
nico@207: 00867 
nico@207: 00868 Please contact LOLITech at:
nico@207: 00869 +33 (0)3 29 52 95 67
nico@207: 00870 bugs_networkedit@lolitech.fr
nico@207: 00871 
nico@207: 00872 
nico@207: 00873 Error:
nico@207: 00874 """ +
nico@207: 00875         str(e_type) + " : " + str(e_value), 
nico@207: 00876         "Error",
nico@207: 00877         trcbck_lst)
nico@207: 00878     try:
nico@207: 00879         res = (dlg.ShowModal() == wx.ID_OK)
nico@207: 00880     finally:
nico@207: 00881         dlg.Destroy()
nico@207: 00882 
nico@207: 00883     return res
nico@207: 00884 
nico@207: 00885 def Display_Error_Dialog(e_value):
nico@207: 00886     message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR)
nico@207: 00887     message.ShowModal()
nico@207: 00888     message.Destroy()
nico@207: 00889 
nico@207: 00890 def get_last_traceback(tb):
nico@207: 00891     while tb.tb_next:
nico@207: 00892         tb = tb.tb_next
nico@207: 00893     return tb
nico@207: 00894 
nico@207: 00895 
nico@207: 00896 def format_namespace(d, indent='    '):
nico@207: 00897     return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
nico@207: 00898 
nico@207: 00899 
nico@207: 00900 ignored_exceptions = [] # a problem with a line in a module is only reported once per session
nico@207: 00901 
nico@207: 00902 def wxAddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]):
nico@207: 00903     
nico@207: 00904     def handle_exception(e_type, e_value, e_traceback):
nico@207: 00905         traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func
nico@207: 00906         last_tb = get_last_traceback(e_traceback)
nico@207: 00907         ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
nico@207: 00908         if str(e_value).startswith("!!!"):
nico@207: 00909             Display_Error_Dialog(e_value)
nico@207: 00910         elif ex not in ignored_exceptions:
nico@207: 00911             ignored_exceptions.append(ex)
nico@207: 00912             result = Display_Exception_Dialog(e_type,e_value,e_traceback)
nico@207: 00913             if result:
nico@207: 00914                 info = {
nico@207: 00915                     'app-title' : wx.GetApp().GetAppName(), # app_title
nico@207: 00916                     'app-version' : app_version,
nico@207: 00917                     'wx-version' : wx.VERSION_STRING,
nico@207: 00918                     'wx-platform' : wx.Platform,
nico@207: 00919                     'python-version' : platform.python_version(), #sys.version.split()[0],
nico@207: 00920                     'platform' : platform.platform(),
nico@207: 00921                     'e-type' : e_type,
nico@207: 00922                     'e-value' : e_value,
nico@207: 00923                     'date' : time.ctime(),
nico@207: 00924                     'cwd' : os.getcwd(),
nico@207: 00925                     }
nico@207: 00926                 if e_traceback:
nico@207: 00927                     info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
nico@207: 00928                     last_tb = get_last_traceback(e_traceback)
nico@207: 00929                     exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred
nico@207: 00930                     info['locals'] = format_namespace(exception_locals)
nico@207: 00931                     if 'self' in exception_locals:
nico@207: 00932                         info['self'] = format_namespace(exception_locals['self'].__dict__)
nico@207: 00933                 
nico@207: 00934                 output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w')
nico@207: 00935                 lst = info.keys()
nico@207: 00936                 lst.sort()
nico@207: 00937                 for a in lst:
nico@207: 00938                     output.write(a+":\n"+str(info[a])+"\n\n")
nico@207: 00939 
nico@207: 00940     #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
nico@207: 00941     sys.excepthook = handle_exception
nico@207: 00942 
nico@207: 00943 if __name__ == '__main__':
nico@207: 00944     app = wxPySimpleApp()
nico@207: 00945     wxInitAllImageHandlers()
nico@207: 00946     
nico@207: 00947     # Install a exception handle for bug reports
nico@207: 00948     wxAddExceptHook(os.getcwd(),__version__)
nico@207: 00949     
nico@207: 00950     frame = networkedit(None)
nico@207: 00951 
nico@207: 00952     frame.Show()
nico@207: 00953     app.MainLoop()
nico@207: 

Generated on Mon Jun 4 16:29:06 2007 for CanFestival by  nico@207: nico@207: doxygen 1.5.1
nico@207: nico@207: