objdictgen/networkedit.py
changeset 580 2ae92a99ac10
parent 548 ecb8b7c6cf17
child 608 daa1e1c3fba4
equal deleted inserted replaced
577:0bb82be64630 580:2ae92a99ac10
    25 import wx.grid
    25 import wx.grid
    26 
    26 
    27 from types import *
    27 from types import *
    28 import os, re, platform, sys, time, traceback, getopt
    28 import os, re, platform, sys, time, traceback, getopt
    29 
    29 
    30 __version__ = "$Revision$"
    30 __version__ = "$Revision: 1.27 $"
       
    31 
       
    32 if __name__ == '__main__':
       
    33     def usage():
       
    34         print _("\nUsage of networkedit.py :")
       
    35         print "\n   %s [Projectpath]\n"%sys.argv[0]
       
    36 
       
    37     try:
       
    38         opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
       
    39     except getopt.GetoptError:
       
    40         # print help information and exit:
       
    41         usage()
       
    42         sys.exit(2)
       
    43 
       
    44     for o, a in opts:
       
    45         if o in ("-h", "--help"):
       
    46             usage()
       
    47             sys.exit()
       
    48 
       
    49     if len(args) == 0:
       
    50         projectOpen = None 
       
    51     elif len(args) == 1:
       
    52         projectOpen = args[0]
       
    53     else:
       
    54         usage()
       
    55         sys.exit(2)
       
    56     
       
    57     app = wx.PySimpleApp()
       
    58 
       
    59 ScriptDirectory = os.path.split(os.path.realpath(__file__))[0]
       
    60 
       
    61 # Import module for internationalization
       
    62 import gettext
       
    63 import __builtin__
       
    64 
       
    65 # Get folder containing translation files
       
    66 localedir = os.path.join(ScriptDirectory,"locale")
       
    67 # Get the default language
       
    68 langid = wx.LANGUAGE_DEFAULT
       
    69 # Define translation domain (name of translation files)
       
    70 domain = "objdictgen"
       
    71 
       
    72 # Define locale for wx
       
    73 loc = __builtin__.__dict__.get('loc', None)
       
    74 if loc is None:
       
    75     loc = wx.Locale(langid)
       
    76     __builtin__.__dict__['loc'] = loc
       
    77 # Define location for searching translation files
       
    78 loc.AddCatalogLookupPathPrefix(localedir)
       
    79 # Define locale domain
       
    80 loc.AddCatalog(domain)
       
    81 
       
    82 if __name__ == '__main__':
       
    83     __builtin__.__dict__['_'] = wx.GetTranslation
    31 
    84 
    32 from nodelist import *
    85 from nodelist import *
    33 from nodemanager import *
    86 from nodemanager import *
    34 from subindextable import *
    87 from subindextable import *
    35 from commondialogs import *
    88 from commondialogs import *
    36 from doc_index.DS301_index import *
    89 from doc_index.DS301_index import *
    37 
       
    38 ScriptDirectory = os.path.split(os.path.realpath(__file__))[0]
       
    39 
    90 
    40 try:
    91 try:
    41     import wx.html
    92     import wx.html
    42 
    93 
    43     EVT_HTML_URL_CLICK = wx.NewId()
    94     EVT_HTML_URL_CLICK = wx.NewId()
    98         def OnLinkClick(self, event):
   149         def OnLinkClick(self, event):
    99             url = event.linkinfo[0]
   150             url = event.linkinfo[0]
   100             try:
   151             try:
   101                 import webbrowser
   152                 import webbrowser
   102             except ImportError:
   153             except ImportError:
   103                 wx.MessageBox('Please point your browser at: %s' % url)
   154                 wx.MessageBox(_('Please point your browser at: %s') % url)
   104             else:
   155             else:
   105                 webbrowser.open(url)
   156                 webbrowser.open(url)
   106     
   157     
   107     Html_Window = True
   158     Html_Window = True
   108 except:
   159 except:
   126 ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)]
   177 ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)]
   127 
   178 
   128 class networkedit(wx.Frame):
   179 class networkedit(wx.Frame):
   129     def _init_coll_MenuBar_Menus(self, parent):
   180     def _init_coll_MenuBar_Menus(self, parent):
   130         if self.ModeSolo:
   181         if self.ModeSolo:
   131             parent.Append(menu=self.FileMenu, title='File')
   182             parent.Append(menu=self.FileMenu, title=_('File'))
   132         parent.Append(menu=self.NetworkMenu, title='Network')
   183         parent.Append(menu=self.NetworkMenu, title=_('Network'))
   133         parent.Append(menu=self.EditMenu, title='Edit')
   184         parent.Append(menu=self.EditMenu, title=_('Edit'))
   134         parent.Append(menu=self.AddMenu, title='Add')
   185         parent.Append(menu=self.AddMenu, title=_('Add'))
   135         parent.Append(menu=self.HelpMenu, title='Help')
   186         parent.Append(menu=self.HelpMenu, title=_('Help'))
   136 
   187 
   137     def _init_coll_FileMenu_Items(self, parent):
   188     def _init_coll_FileMenu_Items(self, parent):
   138         parent.Append(help='', id=wx.ID_NEW,
   189         parent.Append(help='', id=wx.ID_NEW,
   139               kind=wx.ITEM_NORMAL, text='New\tCTRL+N')
   190               kind=wx.ITEM_NORMAL, text=_('New\tCTRL+N'))
   140         parent.Append(help='', id=wx.ID_OPEN,
   191         parent.Append(help='', id=wx.ID_OPEN,
   141               kind=wx.ITEM_NORMAL, text='Open\tCTRL+O')
   192               kind=wx.ITEM_NORMAL, text=_('Open\tCTRL+O'))
   142         parent.Append(help='', id=wx.ID_CLOSE,
   193         parent.Append(help='', id=wx.ID_CLOSE,
   143               kind=wx.ITEM_NORMAL, text='Close\tCTRL+W')
   194               kind=wx.ITEM_NORMAL, text=_('Close\tCTRL+W'))
   144         parent.AppendSeparator()
   195         parent.AppendSeparator()
   145         parent.Append(help='', id=wx.ID_SAVE,
   196         parent.Append(help='', id=wx.ID_SAVE,
   146               kind=wx.ITEM_NORMAL, text='Save\tCTRL+S')
   197               kind=wx.ITEM_NORMAL, text=_('Save\tCTRL+S'))
   147         parent.AppendSeparator()
   198         parent.AppendSeparator()
   148         parent.Append(help='', id=wx.ID_EXIT,
   199         parent.Append(help='', id=wx.ID_EXIT,
   149               kind=wx.ITEM_NORMAL, text='Exit')
   200               kind=wx.ITEM_NORMAL, text=_('Exit'))
   150         self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
   201         self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
   151         self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
   202         self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
   152         self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE)
   203         self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE)
   153         self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
   204         self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
   154         self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
   205         self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
   155 
   206 
   156     def _init_coll_NetworkMenu_Items(self, parent):
   207     def _init_coll_NetworkMenu_Items(self, parent):
   157         parent.Append(help='', id=wx.ID_ADD,
   208         parent.Append(help='', id=wx.ID_ADD,
   158               kind=wx.ITEM_NORMAL, text='Add Slave Node')
   209               kind=wx.ITEM_NORMAL, text=_('Add Slave Node'))
   159         parent.Append(help='', id=wx.ID_DELETE,
   210         parent.Append(help='', id=wx.ID_DELETE,
   160               kind=wx.ITEM_NORMAL, text='Remove Slave Node')
   211               kind=wx.ITEM_NORMAL, text=_('Remove Slave Node'))
   161         parent.AppendSeparator()
   212         parent.AppendSeparator()
   162         parent.Append(help='', id=ID_NETWORKEDITNETWORKMENUBUILDMASTER,
   213         parent.Append(help='', id=ID_NETWORKEDITNETWORKMENUBUILDMASTER,
   163               kind=wx.ITEM_NORMAL, text='Build Master Dictionary')
   214               kind=wx.ITEM_NORMAL, text=_('Build Master Dictionary'))
   164         self.Bind(wx.EVT_MENU, self.OnAddSlaveMenu, id=wx.ID_ADD)
   215         self.Bind(wx.EVT_MENU, self.OnAddSlaveMenu, id=wx.ID_ADD)
   165         self.Bind(wx.EVT_MENU, self.OnRemoveSlaveMenu, id=wx.ID_DELETE)
   216         self.Bind(wx.EVT_MENU, self.OnRemoveSlaveMenu, id=wx.ID_DELETE)
   166 ##        self.Bind(wx.EVT_MENU, self.OnBuildMasterMenu,
   217 ##        self.Bind(wx.EVT_MENU, self.OnBuildMasterMenu,
   167 ##              id=ID_NETWORKEDITNETWORKMENUBUILDMASTER)
   218 ##              id=ID_NETWORKEDITNETWORKMENUBUILDMASTER)
   168 
   219 
   169     def _init_coll_EditMenu_Items(self, parent):
   220     def _init_coll_EditMenu_Items(self, parent):
   170         parent.Append(help='', id=wx.ID_REFRESH,
   221         parent.Append(help='', id=wx.ID_REFRESH,
   171               kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R')
   222               kind=wx.ITEM_NORMAL, text=_('Refresh\tCTRL+R'))
   172         parent.AppendSeparator()
   223         parent.AppendSeparator()
   173         parent.Append(help='', id=wx.ID_UNDO,
   224         parent.Append(help='', id=wx.ID_UNDO,
   174               kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z')
   225               kind=wx.ITEM_NORMAL, text=_('Undo\tCTRL+Z'))
   175         parent.Append(help='', id=wx.ID_REDO,
   226         parent.Append(help='', id=wx.ID_REDO,
   176               kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y')
   227               kind=wx.ITEM_NORMAL, text=_('Redo\tCTRL+Y'))
   177         parent.AppendSeparator()
   228         parent.AppendSeparator()
   178         parent.Append(help='', id=ID_NETWORKEDITEDITMENUNODEINFOS,
   229         parent.Append(help='', id=ID_NETWORKEDITEDITMENUNODEINFOS,
   179               kind=wx.ITEM_NORMAL, text='Node infos')
   230               kind=wx.ITEM_NORMAL, text=_('Node infos'))
   180         parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS301PROFILE,
   231         parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS301PROFILE,
   181               kind=wx.ITEM_NORMAL, text='DS-301 Profile')
   232               kind=wx.ITEM_NORMAL, text=_('DS-301 Profile'))
   182         parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS302PROFILE,
   233         parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS302PROFILE,
   183               kind=wx.ITEM_NORMAL, text='DS-302 Profile')
   234               kind=wx.ITEM_NORMAL, text=_('DS-302 Profile'))
   184         parent.Append(help='', id=ID_NETWORKEDITEDITMENUOTHERPROFILE,
   235         parent.Append(help='', id=ID_NETWORKEDITEDITMENUOTHERPROFILE,
   185               kind=wx.ITEM_NORMAL, text='Other Profile')
   236               kind=wx.ITEM_NORMAL, text=_('Other Profile'))
   186         self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH)
   237         self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH)
   187         self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO)
   238         self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO)
   188         self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO)
   239         self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO)
   189         self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu,
   240         self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu,
   190               id=ID_NETWORKEDITEDITMENUNODEINFOS)
   241               id=ID_NETWORKEDITEDITMENUNODEINFOS)
   195         self.Bind(wx.EVT_MENU, self.OnEditProfileMenu,
   246         self.Bind(wx.EVT_MENU, self.OnEditProfileMenu,
   196               id=ID_NETWORKEDITEDITMENUOTHERPROFILE)
   247               id=ID_NETWORKEDITEDITMENUOTHERPROFILE)
   197 
   248 
   198     def _init_coll_AddMenu_Items(self, parent):
   249     def _init_coll_AddMenu_Items(self, parent):
   199         parent.Append(help='', id=ID_NETWORKEDITADDMENUSDOSERVER,
   250         parent.Append(help='', id=ID_NETWORKEDITADDMENUSDOSERVER,
   200               kind=wx.ITEM_NORMAL, text='SDO Server')
   251               kind=wx.ITEM_NORMAL, text=_('SDO Server'))
   201         parent.Append(help='', id=ID_NETWORKEDITADDMENUSDOCLIENT,
   252         parent.Append(help='', id=ID_NETWORKEDITADDMENUSDOCLIENT,
   202               kind=wx.ITEM_NORMAL, text='SDO Client')
   253               kind=wx.ITEM_NORMAL, text=_('SDO Client'))
   203         parent.Append(help='', id=ID_NETWORKEDITADDMENUPDOTRANSMIT,
   254         parent.Append(help='', id=ID_NETWORKEDITADDMENUPDOTRANSMIT,
   204               kind=wx.ITEM_NORMAL, text='PDO Transmit')
   255               kind=wx.ITEM_NORMAL, text=_('PDO Transmit'))
   205         parent.Append(help='', id=ID_NETWORKEDITADDMENUPDORECEIVE,
   256         parent.Append(help='', id=ID_NETWORKEDITADDMENUPDORECEIVE,
   206               kind=wx.ITEM_NORMAL, text='PDO Receive')
   257               kind=wx.ITEM_NORMAL, text=_('PDO Receive'))
   207         parent.Append(help='', id=ID_NETWORKEDITADDMENUMAPVARIABLE,
   258         parent.Append(help='', id=ID_NETWORKEDITADDMENUMAPVARIABLE,
   208               kind=wx.ITEM_NORMAL, text='Map Variable')
   259               kind=wx.ITEM_NORMAL, text=_('Map Variable'))
   209         parent.Append(help='', id=ID_NETWORKEDITADDMENUUSERTYPE,
   260         parent.Append(help='', id=ID_NETWORKEDITADDMENUUSERTYPE,
   210               kind=wx.ITEM_NORMAL, text='User Type')
   261               kind=wx.ITEM_NORMAL, text=_('User Type'))
   211         self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu,
   262         self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu,
   212               id=ID_NETWORKEDITADDMENUSDOSERVER)
   263               id=ID_NETWORKEDITADDMENUSDOSERVER)
   213         self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu,
   264         self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu,
   214               id=ID_NETWORKEDITADDMENUSDOCLIENT)
   265               id=ID_NETWORKEDITADDMENUSDOCLIENT)
   215         self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu,
   266         self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu,
   221         self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu,
   272         self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu,
   222               id=ID_NETWORKEDITADDMENUUSERTYPE)
   273               id=ID_NETWORKEDITADDMENUUSERTYPE)
   223 
   274 
   224     def _init_coll_HelpMenu_Items(self, parent):
   275     def _init_coll_HelpMenu_Items(self, parent):
   225         parent.Append(help='', id=wx.ID_HELP,
   276         parent.Append(help='', id=wx.ID_HELP,
   226               kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1')
   277               kind=wx.ITEM_NORMAL, text=_('DS-301 Standard\tF1'))
   227         self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu, id=wx.ID_HELP)
   278         self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu, id=wx.ID_HELP)
   228         parent.Append(help='', id=wx.ID_HELP_CONTEXT,
   279         parent.Append(help='', id=wx.ID_HELP_CONTEXT,
   229               kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2')
   280               kind=wx.ITEM_NORMAL, text=_('CAN Festival Docs\tF2'))
   230         self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu, id=wx.ID_HELP_CONTEXT)
   281         self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu, id=wx.ID_HELP_CONTEXT)
   231         if Html_Window and self.ModeSolo:
   282         if Html_Window and self.ModeSolo:
   232             parent.Append(help='', id=wx.ID_ABOUT,
   283             parent.Append(help='', id=wx.ID_ABOUT,
   233                   kind=wx.ITEM_NORMAL, text='About')
   284                   kind=wx.ITEM_NORMAL, text=_('About'))
   234             self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
   285             self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
   235 
   286 
   236     def _init_coll_HelpBar_Fields(self, parent):
   287     def _init_coll_HelpBar_Fields(self, parent):
   237         parent.SetFieldsCount(3)
   288         parent.SetFieldsCount(3)
   238 
   289 
   262         self._init_coll_HelpMenu_Items(self.HelpMenu)
   313         self._init_coll_HelpMenu_Items(self.HelpMenu)
   263 
   314 
   264     def _init_ctrls(self, prnt):
   315     def _init_ctrls(self, prnt):
   265         wx.Frame.__init__(self, id=ID_NETWORKEDIT, name='networkedit',
   316         wx.Frame.__init__(self, id=ID_NETWORKEDIT, name='networkedit',
   266               parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700),
   317               parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700),
   267               style=wx.DEFAULT_FRAME_STYLE, title='Networkedit')
   318               style=wx.DEFAULT_FRAME_STYLE, title=_('Networkedit'))
   268         self._init_utils()
   319         self._init_utils()
   269         self.SetClientSize(wx.Size(1000, 700))
   320         self.SetClientSize(wx.Size(1000, 700))
   270         self.SetMenuBar(self.MenuBar)
   321         self.SetMenuBar(self.MenuBar)
   271         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
   322         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
   272         if not self.ModeSolo:
   323         if not self.ModeSolo:
   399     def OnNewProjectMenu(self, event):
   450     def OnNewProjectMenu(self, event):
   400         if self.NodeList:
   451         if self.NodeList:
   401             defaultpath = os.path.dirname(self.NodeList.GetRoot())
   452             defaultpath = os.path.dirname(self.NodeList.GetRoot())
   402         else:
   453         else:
   403             defaultpath = os.getcwd()
   454             defaultpath = os.getcwd()
   404         dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON)
   455         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
   405         if dialog.ShowModal() == wx.ID_OK:
   456         if dialog.ShowModal() == wx.ID_OK:
   406             projectpath = dialog.GetPath()
   457             projectpath = dialog.GetPath()
   407             if os.path.isdir(projectpath) and len(os.listdir(projectpath)) == 0:
   458             if os.path.isdir(projectpath) and len(os.listdir(projectpath)) == 0:
   408                 manager = NodeManager()
   459                 manager = NodeManager()
   409                 nodelist = NodeList(manager)
   460                 nodelist = NodeList(manager)
   417                     self.RefreshBufferState()
   468                     self.RefreshBufferState()
   418                     self.RefreshTitle()
   469                     self.RefreshTitle()
   419                     self.RefreshProfileMenu()
   470                     self.RefreshProfileMenu()
   420                     self.RefreshMainMenu()
   471                     self.RefreshMainMenu()
   421                 else:
   472                 else:
   422                     message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR)
   473                     message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR)
   423                     message.ShowModal()
   474                     message.ShowModal()
   424                     message.Destroy()
   475                     message.Destroy()
   425         event.Skip()
   476         event.Skip()
   426 
   477 
   427     def OnOpenProjectMenu(self, event):
   478     def OnOpenProjectMenu(self, event):
   428         if self.NodeList:
   479         if self.NodeList:
   429             defaultpath = os.path.dirname(self.NodeList.GetRoot())
   480             defaultpath = os.path.dirname(self.NodeList.GetRoot())
   430         else:
   481         else:
   431             defaultpath = os.getcwd()
   482             defaultpath = os.getcwd()
   432         dialog = wx.DirDialog(self , "Choose a project", defaultpath, 0)
   483         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, 0)
   433         if dialog.ShowModal() == wx.ID_OK:
   484         if dialog.ShowModal() == wx.ID_OK:
   434             projectpath = dialog.GetPath()
   485             projectpath = dialog.GetPath()
   435             if os.path.isdir(projectpath):
   486             if os.path.isdir(projectpath):
   436                 manager = NodeManager()
   487                 manager = NodeManager()
   437                 nodelist = NodeList(manager)
   488                 nodelist = NodeList(manager)
   445                     self.RefreshBufferState()
   496                     self.RefreshBufferState()
   446                     self.RefreshTitle()
   497                     self.RefreshTitle()
   447                     self.RefreshProfileMenu()
   498                     self.RefreshProfileMenu()
   448                     self.RefreshMainMenu()
   499                     self.RefreshMainMenu()
   449                 else:
   500                 else:
   450                     message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
   501                     message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
   451                     message.ShowModal()
   502                     message.ShowModal()
   452                     message.Destroy()
   503                     message.Destroy()
   453         dialog.Destroy()
   504         dialog.Destroy()
   454         event.Skip()
   505         event.Skip()
   455 
   506 
   457         if not self.ModeSolo and getattr(self, "_onsave", None) != None:
   508         if not self.ModeSolo and getattr(self, "_onsave", None) != None:
   458             self._onsave()
   509             self._onsave()
   459         else:
   510         else:
   460             result = self.NodeList.SaveProject()
   511             result = self.NodeList.SaveProject()
   461             if result:
   512             if result:
   462                 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
   513                 message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
   463                 message.ShowModal()
   514                 message.ShowModal()
   464                 message.Destroy()
   515                 message.Destroy()
   465         event.Skip()
   516         event.Skip()
   466 
   517 
   467     def OnCloseProjectMenu(self, event):
   518     def OnCloseProjectMenu(self, event):
   468         if self.NodeList:
   519         if self.NodeList:
   469             if self.NodeList.HasChanged():
   520             if self.NodeList.HasChanged():
   470                 dialog = wx.MessageDialog(self, "There are changes, do you want to save?",  "Close Project", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
   521                 dialog = wx.MessageDialog(self, _("There are changes, do you want to save?"), _("Close Project"), wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
   471                 answer = dialog.ShowModal()
   522                 answer = dialog.ShowModal()
   472                 dialog.Destroy()
   523                 dialog.Destroy()
   473                 if answer == wx.ID_YES:
   524                 if answer == wx.ID_YES:
   474                     result = self.NodeList.SaveProject()
   525                     result = self.NodeList.SaveProject()
   475                     if result:
   526                     if result:
   476                         message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
   527                         message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
   477                         message.ShowModal()
   528                         message.ShowModal()
   478                         message.Destroy()
   529                         message.Destroy()
   479                 elif answer == wx.ID_NO:
   530                 elif answer == wx.ID_NO:
   480                     self.NodeList.ForceChanged(False)
   531                     self.NodeList.ForceChanged(False)
   481             if not self.NodeList.HasChanged():
   532             if not self.NodeList.HasChanged():
   503                 self.NetworkNodes.InsertPage(idx, new_editingpanel, "")
   554                 self.NetworkNodes.InsertPage(idx, new_editingpanel, "")
   504                 self.NodeList.SetCurrentSelected(idx)
   555                 self.NodeList.SetCurrentSelected(idx)
   505                 self.NetworkNodes.SetSelection(idx)
   556                 self.NetworkNodes.SetSelection(idx)
   506                 self.RefreshBufferState()
   557                 self.RefreshBufferState()
   507             else:
   558             else:
   508                 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
   559                 message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
   509                 message.ShowModal()
   560                 message.ShowModal()
   510                 message.Destroy()
   561                 message.Destroy()
   511         dialog.Destroy()
   562         dialog.Destroy()
   512         event.Skip()
   563         event.Skip()
   513 
   564 
   514     def OnRemoveSlaveMenu(self, event):
   565     def OnRemoveSlaveMenu(self, event):
   515         slavenames = self.NodeList.GetSlaveNames()
   566         slavenames = self.NodeList.GetSlaveNames()
   516         slaveids = self.NodeList.GetSlaveIDs()
   567         slaveids = self.NodeList.GetSlaveIDs()
   517         dialog = wx.SingleChoiceDialog(self, "Choose a slave to remove", "Remove slave", slavenames)
   568         dialog = wx.SingleChoiceDialog(self, _("Choose a slave to remove"), _("Remove slave"), slavenames)
   518         if dialog.ShowModal() == wx.ID_OK:
   569         if dialog.ShowModal() == wx.ID_OK:
   519             choice = dialog.GetSelection()
   570             choice = dialog.GetSelection()
   520             result = self.NodeList.RemoveSlaveNode(slaveids[choice])
   571             result = self.NodeList.RemoveSlaveNode(slaveids[choice])
   521             if not result:
   572             if not result:
   522                 slaveids.pop(choice)
   573                 slaveids.pop(choice)
   527                     self.NetworkNodes.SetSelection(new_selection)
   578                     self.NetworkNodes.SetSelection(new_selection)
   528                     if new_selection > 0:
   579                     if new_selection > 0:
   529                         self.NodeList.SetCurrentSelected(slaveids[new_selection - 1])
   580                         self.NodeList.SetCurrentSelected(slaveids[new_selection - 1])
   530                     self.RefreshBufferState()
   581                     self.RefreshBufferState()
   531             else:
   582             else:
   532                 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
   583                 message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
   533                 message.ShowModal()
   584                 message.ShowModal()
   534                 message.Destroy()
   585                 message.Destroy()
   535         event.Skip()
   586         event.Skip()
   536 
   587 
   537 #-------------------------------------------------------------------------------
   588 #-------------------------------------------------------------------------------
   538 #                             Refresh Functions
   589 #                             Refresh Functions
   539 #-------------------------------------------------------------------------------
   590 #-------------------------------------------------------------------------------
   540 
   591 
   541     def RefreshTitle(self):
   592     def RefreshTitle(self):
   542         if self.NodeList != None:
   593         if self.NodeList != None:
   543             self.SetTitle("Networkedit - %s"%self.NodeList.GetNetworkName())
   594             self.SetTitle(_("Networkedit - %s")%self.NodeList.GetNetworkName())
   544         else:
   595         else:
   545             self.SetTitle("Networkedit")
   596             self.SetTitle(_("Networkedit"))
   546 
   597 
   547     def OnRefreshMenu(self, event):
   598     def OnRefreshMenu(self, event):
   548         self.RefreshCurrentIndexList()
   599         self.RefreshCurrentIndexList()
   549         event.Skip()
   600         event.Skip()
   550 
   601 
   574             window = self.NetworkNodes.GetPage(selected)
   625             window = self.NetworkNodes.GetPage(selected)
   575             selection = window.GetSelection()
   626             selection = window.GetSelection()
   576             if selection:
   627             if selection:
   577                 index, subIndex = selection
   628                 index, subIndex = selection
   578                 if self.NodeList.IsCurrentEntry(index):
   629                 if self.NodeList.IsCurrentEntry(index):
   579                     self.HelpBar.SetStatusText("Index: 0x%04X"%index, 0)
   630                     self.HelpBar.SetStatusText(_("Index: 0x%04X")%index, 0)
   580                     self.HelpBar.SetStatusText("Subindex: 0x%02X"%subIndex, 1)
   631                     self.HelpBar.SetStatusText(_("Subindex: 0x%02X")%subIndex, 1)
   581                     entryinfos = self.NodeList.GetEntryInfos(index)
   632                     entryinfos = self.NodeList.GetEntryInfos(index)
   582                     name = entryinfos["name"]
   633                     name = entryinfos["name"]
   583                     category = "Optional"
   634                     category = _("Optional")
   584                     if entryinfos["need"]:
   635                     if entryinfos["need"]:
   585                         category = "Mandatory"
   636                         category = _("Mandatory")
   586                     struct = "VAR"
   637                     struct = "VAR"
   587                     number = ""
   638                     number = ""
   588                     if entryinfos["struct"] & OD_IdenticalIndexes:
   639                     if entryinfos["struct"] & OD_IdenticalIndexes:
   589                         number = " possibly defined %d times"%entryinfos["nbmax"]
   640                         number = _(" possibly defined %d times")%entryinfos["nbmax"]
   590                     if entryinfos["struct"] & OD_IdenticalSubindexes:
   641                     if entryinfos["struct"] & OD_IdenticalSubindexes:
   591                         struct = "REC"
   642                         struct = "REC"
   592                     elif entryinfos["struct"] & OD_MultipleSubindexes:
   643                     elif entryinfos["struct"] & OD_MultipleSubindexes:
   593                         struct = "ARRAY"
   644                         struct = "ARRAY"
   594                     text = "%s: %s entry of struct %s%s."%(name,category,struct,number)
   645                     text = _("%s: %s entry of struct %s%s.")%(name,category,struct,number)
   595                     self.HelpBar.SetStatusText(text, 2)
   646                     self.HelpBar.SetStatusText(text, 2)
   596                 else:
   647                 else:
   597                     for i in xrange(3):
   648                     for i in xrange(3):
   598                         self.HelpBar.SetStatusText("", i)
   649                         self.HelpBar.SetStatusText("", i)
   599             else:
   650             else:
   642             length = self.AddMenu.GetMenuItemCount()
   693             length = self.AddMenu.GetMenuItemCount()
   643             for i in xrange(length-6):
   694             for i in xrange(length-6):
   644                 additem = self.AddMenu.FindItemByPosition(6)
   695                 additem = self.AddMenu.FindItemByPosition(6)
   645                 self.AddMenu.Delete(additem.GetId())
   696                 self.AddMenu.Delete(additem.GetId())
   646             if profile not in ("None", "DS-301"):
   697             if profile not in ("None", "DS-301"):
   647                 edititem.SetText("%s Profile"%profile)
   698                 edititem.SetText(_("%s Profile")%profile)
   648                 edititem.Enable(True)
   699                 edititem.Enable(True)
   649                 self.AddMenu.AppendSeparator()
   700                 self.AddMenu.AppendSeparator()
   650                 for text, indexes in self.Manager.GetCurrentSpecificMenu():
   701                 for text, indexes in self.Manager.GetCurrentSpecificMenu():
   651                     new_id = wx.NewId()
   702                     new_id = wx.NewId()
   652                     self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text)
   703                     self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text)
   653                     self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id)
   704                     self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id)
   654             else:
   705             else:
   655                 edititem.SetText("Other Profile")
   706                 edititem.SetText(_("Other Profile"))
   656                 edititem.Enable(False)
   707                 edititem.Enable(False)
   657 
   708 
   658     def GetProfileCallBack(self, text):
   709     def GetProfileCallBack(self, text):
   659         def ProfileCallBack(event):
   710         def ProfileCallBack(event):
   660             self.Manager.AddSpecificEntryToCurrent(text)
   711             self.Manager.AddSpecificEntryToCurrent(text)
   704             if result:
   755             if result:
   705                 find_index = True
   756                 find_index = True
   706                 index, subIndex = result
   757                 index, subIndex = result
   707                 result = OpenPDFDocIndex(index, ScriptDirectory)
   758                 result = OpenPDFDocIndex(index, ScriptDirectory)
   708                 if isinstance(result, (StringType, UnicodeType)):
   759                 if isinstance(result, (StringType, UnicodeType)):
   709                     message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR)
   760                     message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR)
   710                     message.ShowModal()
   761                     message.ShowModal()
   711                     message.Destroy()
   762                     message.Destroy()
   712         if not find_index:
   763         if not find_index:
   713             result = OpenPDFDocIndex(None, ScriptDirectory)
   764             result = OpenPDFDocIndex(None, ScriptDirectory)
   714             if isinstance(result, (StringType, UnicodeType)):
   765             if isinstance(result, (StringType, UnicodeType)):
   715                 message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR)
   766                 message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR)
   716                 message.ShowModal()
   767                 message.ShowModal()
   717                 message.Destroy()
   768                 message.Destroy()
   718         event.Skip()
   769         event.Skip()
   719         
   770         
   720     def OnHelpCANFestivalMenu(self, event):
   771     def OnHelpCANFestivalMenu(self, event):
   727         else:
   778         else:
   728             os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16))
   779             os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16))
   729         event.Skip()
   780         event.Skip()
   730 
   781 
   731     def OnAboutMenu(self, event):
   782     def OnAboutMenu(self, event):
   732         self.OpenHtmlFrame("About CAN Festival", os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450))
   783         self.OpenHtmlFrame(_("About CAN Festival"), os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450))
   733         event.Skip()
   784         event.Skip()
   734 
   785 
   735     def OpenHtmlFrame(self, title, file, size):
   786     def OpenHtmlFrame(self, title, file, size):
   736         if title not in self.HtmlFrameOpened:
   787         if title not in self.HtmlFrameOpened:
   737             self.HtmlFrameOpened.append(title)
   788             self.HtmlFrameOpened.append(title)
   745 #                          Editing Profiles functions
   796 #                          Editing Profiles functions
   746 #-------------------------------------------------------------------------------
   797 #-------------------------------------------------------------------------------
   747 
   798 
   748     def OnCommunicationMenu(self, event):
   799     def OnCommunicationMenu(self, event):
   749         dictionary,current = self.Manager.GetCurrentCommunicationLists()
   800         dictionary,current = self.Manager.GetCurrentCommunicationLists()
   750         self.EditProfile("Edit DS-301 Profile", dictionary, current)
   801         self.EditProfile(_("Edit DS-301 Profile"), dictionary, current)
   751         event.Skip()
   802         event.Skip()
   752     
   803     
   753     def OnOtherCommunicationMenu(self, event):
   804     def OnOtherCommunicationMenu(self, event):
   754         dictionary,current = self.Manager.GetCurrentDS302Lists()
   805         dictionary,current = self.Manager.GetCurrentDS302Lists()
   755         self.EditProfile("Edit DS-302 Profile", dictionary, current)
   806         self.EditProfile(_("Edit DS-302 Profile"), dictionary, current)
   756         event.Skip()
   807         event.Skip()
   757     
   808     
   758     def OnEditProfileMenu(self, event):
   809     def OnEditProfileMenu(self, event):
   759         title = "Edit %s Profile"%self.Manager.GetCurrentProfileName()
   810         title = _("Edit %s Profile")%self.Manager.GetCurrentProfileName()
   760         dictionary,current = self.Manager.GetCurrentProfileLists()
   811         dictionary,current = self.Manager.GetCurrentProfileLists()
   761         self.EditProfile(title, dictionary, current)
   812         self.EditProfile(title, dictionary, current)
   762         event.Skip()
   813         event.Skip()
   763     
   814     
   764     def EditProfile(self, title, dictionary, current):
   815     def EditProfile(self, title, dictionary, current):
   819                 result = self.Manager.AddMapVariableToCurrent(index, name, struct, number)
   870                 result = self.Manager.AddMapVariableToCurrent(index, name, struct, number)
   820                 if not isinstance(result, (StringType, UnicodeType)):
   871                 if not isinstance(result, (StringType, UnicodeType)):
   821                     self.RefreshBufferState()
   872                     self.RefreshBufferState()
   822                     self.RefreshCurrentIndexList()
   873                     self.RefreshCurrentIndexList()
   823                 else:
   874                 else:
   824                     message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
   875                     message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
   825                     message.ShowModal()
   876                     message.ShowModal()
   826                     message.Destroy()
   877                     message.Destroy()
   827             dialog.Destroy()
   878             dialog.Destroy()
   828         else:
   879         else:
   829             message = wx.MessageDialog(self, result, "No map variable index left!", wx.OK|wx.ICON_ERROR)
   880             message = wx.MessageDialog(self, result, _("No map variable index left!"), wx.OK|wx.ICON_ERROR)
   830             message.ShowModal()
   881             message.ShowModal()
   831             message.Destroy()
   882             message.Destroy()
   832         
   883         
   833     def AddUserType(self):
   884     def AddUserType(self):
   834         dialog = UserTypeDialog(self)
   885         dialog = UserTypeDialog(self)
   838             result = self.Manager.AddUserTypeToCurrent(type, min, max, length)
   889             result = self.Manager.AddUserTypeToCurrent(type, min, max, length)
   839             if not IsOfType(result, StringType):
   890             if not IsOfType(result, StringType):
   840                 self.RefreshBufferState()
   891                 self.RefreshBufferState()
   841                 self.RefreshCurrentIndexList()
   892                 self.RefreshCurrentIndexList()
   842             else:
   893             else:
   843                 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
   894                 message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
   844                 message.ShowModal()
   895                 message.ShowModal()
   845                 message.Destroy()
   896                 message.Destroy()
   846         dialog.Destroy()
   897         dialog.Destroy()
   847 
   898 
   848     def OpenMasterDCFDialog(self, node_id):
   899     def OpenMasterDCFDialog(self, node_id):
   856 Max_Traceback_List_Size = 20
   907 Max_Traceback_List_Size = 20
   857 
   908 
   858 def Display_Exception_Dialog(e_type,e_value,e_tb):
   909 def Display_Exception_Dialog(e_type,e_value,e_tb):
   859     trcbck_lst = []
   910     trcbck_lst = []
   860     for i,line in enumerate(traceback.extract_tb(e_tb)):
   911     for i,line in enumerate(traceback.extract_tb(e_tb)):
   861         trcbck = " " + str(i+1) + ". "
   912         trcbck = " " + str(i+1) + _(". ")
   862         if line[0].find(os.getcwd()) == -1:
   913         if line[0].find(os.getcwd()) == -1:
   863             trcbck += "file : " + str(line[0]) + ",   "
   914             trcbck += _("file : ") + str(line[0]) + _(",   ")
   864         else:
   915         else:
   865             trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ",   "
   916             trcbck += _("file : ") + str(line[0][len(os.getcwd()):]) + _(",   ")
   866         trcbck += "line : " + str(line[1]) + ",   " + "function : " + str(line[2])
   917         trcbck += _("line : ") + str(line[1]) + _(",   ") + _("function : ") + str(line[2])
   867         trcbck_lst.append(trcbck)
   918         trcbck_lst.append(trcbck)
   868         
   919         
   869     # Allow clicking....
   920     # Allow clicking....
   870     cap = wx.Window_GetCapture()
   921     cap = wx.Window_GetCapture()
   871     if cap:
   922     if cap:
   872         cap.ReleaseMouse()
   923         cap.ReleaseMouse()
   873 
   924 
   874     dlg = wx.SingleChoiceDialog(None, 
   925     dlg = wx.SingleChoiceDialog(None, 
   875         """
   926         _("""
   876 An error happens.
   927 An error happens.
   877 
   928 
   878 Click on OK for saving an error report.
   929 Click on OK for saving an error report.
   879 
   930 
   880 Please contact LOLITech at:
   931 Please contact LOLITech at:
   881 +33 (0)3 29 57 60 42
   932 +33 (0)3 29 57 60 42
   882 bugs_networkedit@lolitech.fr
   933 bugs_networkedit@lolitech.fr
   883 
   934 
   884 
   935 
   885 Error:
   936 Error:
   886 """ +
   937 """) +
   887         str(e_type) + " : " + str(e_value), 
   938         str(e_type) + _(" : ") + str(e_value), 
   888         "Error",
   939         _("Error"),
   889         trcbck_lst)
   940         trcbck_lst)
   890     try:
   941     try:
   891         res = (dlg.ShowModal() == wx.ID_OK)
   942         res = (dlg.ShowModal() == wx.ID_OK)
   892     finally:
   943     finally:
   893         dlg.Destroy()
   944         dlg.Destroy()
   894 
   945 
   895     return res
   946     return res
   896 
   947 
   897 def Display_Error_Dialog(e_value):
   948 def Display_Error_Dialog(e_value):
   898     message = wx.MessageDialog(None, str(e_value), "Error", wx.OK|wx.ICON_ERROR)
   949     message = wx.MessageDialog(None, str(e_value), _("Error"), wx.OK|wx.ICON_ERROR)
   899     message.ShowModal()
   950     message.ShowModal()
   900     message.Destroy()
   951     message.Destroy()
   901 
   952 
   902 def get_last_traceback(tb):
   953 def get_last_traceback(tb):
   903     while tb.tb_next:
   954     while tb.tb_next:
   951 
  1002 
   952     #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
  1003     #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
   953     sys.excepthook = handle_exception
  1004     sys.excepthook = handle_exception
   954 
  1005 
   955 if __name__ == '__main__':
  1006 if __name__ == '__main__':
   956     def usage():
       
   957         print "\nUsage of networkedit.py :"
       
   958         print "\n   %s [Projectpath]\n"%sys.argv[0]
       
   959 
       
   960     try:
       
   961         opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
       
   962     except getopt.GetoptError:
       
   963         # print help information and exit:
       
   964         usage()
       
   965         sys.exit(2)
       
   966 
       
   967     for o, a in opts:
       
   968         if o in ("-h", "--help"):
       
   969             usage()
       
   970             sys.exit()
       
   971 
       
   972     if len(args) == 0:
       
   973         projectOpen = None 
       
   974     elif len(args) == 1:
       
   975         projectOpen = args[0]
       
   976     else:
       
   977         usage()
       
   978         sys.exit(2)
       
   979     
       
   980     app = wx.PySimpleApp()
       
   981     wx.InitAllImageHandlers()
  1007     wx.InitAllImageHandlers()
   982     
  1008     
   983     # Install a exception handle for bug reports
  1009     # Install a exception handle for bug reports
   984     AddExceptHook(os.getcwd(),__version__)
  1010     AddExceptHook(os.getcwd(),__version__)
   985     
  1011