diff -r 2cb34a4ac65a -r 6b5a4c21e061 doc/doxygen/html/networkedit_8py-source.html --- a/doc/doxygen/html/networkedit_8py-source.html Tue Jun 05 17:34:33 2007 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,977 +0,0 @@ - - -CanFestival: /home/epimerde/documents/tc11/CanFestival-3/objdictgen/networkedit.py Source File - - - - -
-
-
-
-

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

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

Generated on Mon Jun 4 16:29:06 2007 for CanFestival by  - -doxygen 1.5.1
- -