diff -r 0bb82be64630 -r 2ae92a99ac10 objdictgen/networkedit.py --- a/objdictgen/networkedit.py Mon Jul 20 16:11:20 2009 +0200 +++ b/objdictgen/networkedit.py Mon Jul 27 16:29:59 2009 +0200 @@ -27,7 +27,60 @@ from types import * import os, re, platform, sys, time, traceback, getopt -__version__ = "$Revision$" +__version__ = "$Revision: 1.27 $" + +if __name__ == '__main__': + def usage(): + print _("\nUsage of networkedit.py :") + print "\n %s [Projectpath]\n"%sys.argv[0] + + try: + opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) + except getopt.GetoptError: + # print help information and exit: + usage() + sys.exit(2) + + for o, a in opts: + if o in ("-h", "--help"): + usage() + sys.exit() + + if len(args) == 0: + projectOpen = None + elif len(args) == 1: + projectOpen = args[0] + else: + usage() + sys.exit(2) + + app = wx.PySimpleApp() + +ScriptDirectory = os.path.split(os.path.realpath(__file__))[0] + +# Import module for internationalization +import gettext +import __builtin__ + +# Get folder containing translation files +localedir = os.path.join(ScriptDirectory,"locale") +# Get the default language +langid = wx.LANGUAGE_DEFAULT +# Define translation domain (name of translation files) +domain = "objdictgen" + +# Define locale for wx +loc = __builtin__.__dict__.get('loc', None) +if loc is None: + loc = wx.Locale(langid) + __builtin__.__dict__['loc'] = loc +# Define location for searching translation files +loc.AddCatalogLookupPathPrefix(localedir) +# Define locale domain +loc.AddCatalog(domain) + +if __name__ == '__main__': + __builtin__.__dict__['_'] = wx.GetTranslation from nodelist import * from nodemanager import * @@ -35,8 +88,6 @@ from commondialogs import * from doc_index.DS301_index import * -ScriptDirectory = os.path.split(os.path.realpath(__file__))[0] - try: import wx.html @@ -100,7 +151,7 @@ try: import webbrowser except ImportError: - wx.MessageBox('Please point your browser at: %s' % url) + wx.MessageBox(_('Please point your browser at: %s') % url) else: webbrowser.open(url) @@ -128,25 +179,25 @@ class networkedit(wx.Frame): def _init_coll_MenuBar_Menus(self, parent): if self.ModeSolo: - parent.Append(menu=self.FileMenu, title='File') - parent.Append(menu=self.NetworkMenu, title='Network') - parent.Append(menu=self.EditMenu, title='Edit') - parent.Append(menu=self.AddMenu, title='Add') - parent.Append(menu=self.HelpMenu, title='Help') + parent.Append(menu=self.FileMenu, title=_('File')) + parent.Append(menu=self.NetworkMenu, title=_('Network')) + parent.Append(menu=self.EditMenu, title=_('Edit')) + parent.Append(menu=self.AddMenu, title=_('Add')) + parent.Append(menu=self.HelpMenu, title=_('Help')) def _init_coll_FileMenu_Items(self, parent): parent.Append(help='', id=wx.ID_NEW, - kind=wx.ITEM_NORMAL, text='New\tCTRL+N') + kind=wx.ITEM_NORMAL, text=_('New\tCTRL+N')) parent.Append(help='', id=wx.ID_OPEN, - kind=wx.ITEM_NORMAL, text='Open\tCTRL+O') + kind=wx.ITEM_NORMAL, text=_('Open\tCTRL+O')) parent.Append(help='', id=wx.ID_CLOSE, - kind=wx.ITEM_NORMAL, text='Close\tCTRL+W') + kind=wx.ITEM_NORMAL, text=_('Close\tCTRL+W')) parent.AppendSeparator() parent.Append(help='', id=wx.ID_SAVE, - kind=wx.ITEM_NORMAL, text='Save\tCTRL+S') + kind=wx.ITEM_NORMAL, text=_('Save\tCTRL+S')) parent.AppendSeparator() parent.Append(help='', id=wx.ID_EXIT, - kind=wx.ITEM_NORMAL, text='Exit') + kind=wx.ITEM_NORMAL, text=_('Exit')) self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW) self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN) self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE) @@ -155,12 +206,12 @@ def _init_coll_NetworkMenu_Items(self, parent): parent.Append(help='', id=wx.ID_ADD, - kind=wx.ITEM_NORMAL, text='Add Slave Node') + kind=wx.ITEM_NORMAL, text=_('Add Slave Node')) parent.Append(help='', id=wx.ID_DELETE, - kind=wx.ITEM_NORMAL, text='Remove Slave Node') + kind=wx.ITEM_NORMAL, text=_('Remove Slave Node')) parent.AppendSeparator() parent.Append(help='', id=ID_NETWORKEDITNETWORKMENUBUILDMASTER, - kind=wx.ITEM_NORMAL, text='Build Master Dictionary') + kind=wx.ITEM_NORMAL, text=_('Build Master Dictionary')) self.Bind(wx.EVT_MENU, self.OnAddSlaveMenu, id=wx.ID_ADD) self.Bind(wx.EVT_MENU, self.OnRemoveSlaveMenu, id=wx.ID_DELETE) ## self.Bind(wx.EVT_MENU, self.OnBuildMasterMenu, @@ -168,21 +219,21 @@ def _init_coll_EditMenu_Items(self, parent): parent.Append(help='', id=wx.ID_REFRESH, - kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R') + kind=wx.ITEM_NORMAL, text=_('Refresh\tCTRL+R')) parent.AppendSeparator() parent.Append(help='', id=wx.ID_UNDO, - kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z') + kind=wx.ITEM_NORMAL, text=_('Undo\tCTRL+Z')) parent.Append(help='', id=wx.ID_REDO, - kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y') + kind=wx.ITEM_NORMAL, text=_('Redo\tCTRL+Y')) parent.AppendSeparator() parent.Append(help='', id=ID_NETWORKEDITEDITMENUNODEINFOS, - kind=wx.ITEM_NORMAL, text='Node infos') + kind=wx.ITEM_NORMAL, text=_('Node infos')) parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS301PROFILE, - kind=wx.ITEM_NORMAL, text='DS-301 Profile') + kind=wx.ITEM_NORMAL, text=_('DS-301 Profile')) parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS302PROFILE, - kind=wx.ITEM_NORMAL, text='DS-302 Profile') + kind=wx.ITEM_NORMAL, text=_('DS-302 Profile')) parent.Append(help='', id=ID_NETWORKEDITEDITMENUOTHERPROFILE, - kind=wx.ITEM_NORMAL, text='Other Profile') + kind=wx.ITEM_NORMAL, text=_('Other Profile')) self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH) self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO) self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO) @@ -197,17 +248,17 @@ def _init_coll_AddMenu_Items(self, parent): parent.Append(help='', id=ID_NETWORKEDITADDMENUSDOSERVER, - kind=wx.ITEM_NORMAL, text='SDO Server') + kind=wx.ITEM_NORMAL, text=_('SDO Server')) parent.Append(help='', id=ID_NETWORKEDITADDMENUSDOCLIENT, - kind=wx.ITEM_NORMAL, text='SDO Client') + kind=wx.ITEM_NORMAL, text=_('SDO Client')) parent.Append(help='', id=ID_NETWORKEDITADDMENUPDOTRANSMIT, - kind=wx.ITEM_NORMAL, text='PDO Transmit') + kind=wx.ITEM_NORMAL, text=_('PDO Transmit')) parent.Append(help='', id=ID_NETWORKEDITADDMENUPDORECEIVE, - kind=wx.ITEM_NORMAL, text='PDO Receive') + kind=wx.ITEM_NORMAL, text=_('PDO Receive')) parent.Append(help='', id=ID_NETWORKEDITADDMENUMAPVARIABLE, - kind=wx.ITEM_NORMAL, text='Map Variable') + kind=wx.ITEM_NORMAL, text=_('Map Variable')) parent.Append(help='', id=ID_NETWORKEDITADDMENUUSERTYPE, - kind=wx.ITEM_NORMAL, text='User Type') + kind=wx.ITEM_NORMAL, text=_('User Type')) self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu, id=ID_NETWORKEDITADDMENUSDOSERVER) self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu, @@ -223,14 +274,14 @@ def _init_coll_HelpMenu_Items(self, parent): parent.Append(help='', id=wx.ID_HELP, - kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1') + kind=wx.ITEM_NORMAL, text=_('DS-301 Standard\tF1')) self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu, id=wx.ID_HELP) parent.Append(help='', id=wx.ID_HELP_CONTEXT, - kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2') + kind=wx.ITEM_NORMAL, text=_('CAN Festival Docs\tF2')) self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu, id=wx.ID_HELP_CONTEXT) if Html_Window and self.ModeSolo: parent.Append(help='', id=wx.ID_ABOUT, - kind=wx.ITEM_NORMAL, text='About') + kind=wx.ITEM_NORMAL, text=_('About')) self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT) def _init_coll_HelpBar_Fields(self, parent): @@ -264,7 +315,7 @@ def _init_ctrls(self, prnt): wx.Frame.__init__(self, id=ID_NETWORKEDIT, name='networkedit', parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700), - style=wx.DEFAULT_FRAME_STYLE, title='Networkedit') + style=wx.DEFAULT_FRAME_STYLE, title=_('Networkedit')) self._init_utils() self.SetClientSize(wx.Size(1000, 700)) self.SetMenuBar(self.MenuBar) @@ -401,7 +452,7 @@ defaultpath = os.path.dirname(self.NodeList.GetRoot()) else: defaultpath = os.getcwd() - dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON) + dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON) if dialog.ShowModal() == wx.ID_OK: projectpath = dialog.GetPath() if os.path.isdir(projectpath) and len(os.listdir(projectpath)) == 0: @@ -419,7 +470,7 @@ self.RefreshProfileMenu() self.RefreshMainMenu() else: - message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) + message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() event.Skip() @@ -429,7 +480,7 @@ defaultpath = os.path.dirname(self.NodeList.GetRoot()) else: defaultpath = os.getcwd() - dialog = wx.DirDialog(self , "Choose a project", defaultpath, 0) + dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, 0) if dialog.ShowModal() == wx.ID_OK: projectpath = dialog.GetPath() if os.path.isdir(projectpath): @@ -447,7 +498,7 @@ self.RefreshProfileMenu() self.RefreshMainMenu() else: - message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) + message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() dialog.Destroy() @@ -459,7 +510,7 @@ else: result = self.NodeList.SaveProject() if result: - message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) + message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() event.Skip() @@ -467,13 +518,13 @@ def OnCloseProjectMenu(self, event): if self.NodeList: if self.NodeList.HasChanged(): - dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close Project", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) + dialog = wx.MessageDialog(self, _("There are changes, do you want to save?"), _("Close Project"), wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) answer = dialog.ShowModal() dialog.Destroy() if answer == wx.ID_YES: result = self.NodeList.SaveProject() if result: - message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) + message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() elif answer == wx.ID_NO: @@ -505,7 +556,7 @@ self.NetworkNodes.SetSelection(idx) self.RefreshBufferState() else: - message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) + message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() dialog.Destroy() @@ -514,7 +565,7 @@ def OnRemoveSlaveMenu(self, event): slavenames = self.NodeList.GetSlaveNames() slaveids = self.NodeList.GetSlaveIDs() - dialog = wx.SingleChoiceDialog(self, "Choose a slave to remove", "Remove slave", slavenames) + dialog = wx.SingleChoiceDialog(self, _("Choose a slave to remove"), _("Remove slave"), slavenames) if dialog.ShowModal() == wx.ID_OK: choice = dialog.GetSelection() result = self.NodeList.RemoveSlaveNode(slaveids[choice]) @@ -529,7 +580,7 @@ self.NodeList.SetCurrentSelected(slaveids[new_selection - 1]) self.RefreshBufferState() else: - message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) + message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() event.Skip() @@ -540,9 +591,9 @@ def RefreshTitle(self): if self.NodeList != None: - self.SetTitle("Networkedit - %s"%self.NodeList.GetNetworkName()) + self.SetTitle(_("Networkedit - %s")%self.NodeList.GetNetworkName()) else: - self.SetTitle("Networkedit") + self.SetTitle(_("Networkedit")) def OnRefreshMenu(self, event): self.RefreshCurrentIndexList() @@ -576,22 +627,22 @@ if selection: index, subIndex = selection if self.NodeList.IsCurrentEntry(index): - self.HelpBar.SetStatusText("Index: 0x%04X"%index, 0) - self.HelpBar.SetStatusText("Subindex: 0x%02X"%subIndex, 1) + self.HelpBar.SetStatusText(_("Index: 0x%04X")%index, 0) + self.HelpBar.SetStatusText(_("Subindex: 0x%02X")%subIndex, 1) entryinfos = self.NodeList.GetEntryInfos(index) name = entryinfos["name"] - category = "Optional" + category = _("Optional") if entryinfos["need"]: - category = "Mandatory" + category = _("Mandatory") struct = "VAR" number = "" if entryinfos["struct"] & OD_IdenticalIndexes: - number = " possibly defined %d times"%entryinfos["nbmax"] + number = _(" possibly defined %d times")%entryinfos["nbmax"] if entryinfos["struct"] & OD_IdenticalSubindexes: struct = "REC" elif entryinfos["struct"] & OD_MultipleSubindexes: struct = "ARRAY" - text = "%s: %s entry of struct %s%s."%(name,category,struct,number) + text = _("%s: %s entry of struct %s%s.")%(name,category,struct,number) self.HelpBar.SetStatusText(text, 2) else: for i in xrange(3): @@ -644,7 +695,7 @@ additem = self.AddMenu.FindItemByPosition(6) self.AddMenu.Delete(additem.GetId()) if profile not in ("None", "DS-301"): - edititem.SetText("%s Profile"%profile) + edititem.SetText(_("%s Profile")%profile) edititem.Enable(True) self.AddMenu.AppendSeparator() for text, indexes in self.Manager.GetCurrentSpecificMenu(): @@ -652,7 +703,7 @@ self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text) self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id) else: - edititem.SetText("Other Profile") + edititem.SetText(_("Other Profile")) edititem.Enable(False) def GetProfileCallBack(self, text): @@ -706,13 +757,13 @@ index, subIndex = result result = OpenPDFDocIndex(index, ScriptDirectory) if isinstance(result, (StringType, UnicodeType)): - message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) + message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() if not find_index: result = OpenPDFDocIndex(None, ScriptDirectory) if isinstance(result, (StringType, UnicodeType)): - message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) + message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() event.Skip() @@ -729,7 +780,7 @@ event.Skip() def OnAboutMenu(self, event): - self.OpenHtmlFrame("About CAN Festival", os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450)) + self.OpenHtmlFrame(_("About CAN Festival"), os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450)) event.Skip() def OpenHtmlFrame(self, title, file, size): @@ -747,16 +798,16 @@ def OnCommunicationMenu(self, event): dictionary,current = self.Manager.GetCurrentCommunicationLists() - self.EditProfile("Edit DS-301 Profile", dictionary, current) + self.EditProfile(_("Edit DS-301 Profile"), dictionary, current) event.Skip() def OnOtherCommunicationMenu(self, event): dictionary,current = self.Manager.GetCurrentDS302Lists() - self.EditProfile("Edit DS-302 Profile", dictionary, current) + self.EditProfile(_("Edit DS-302 Profile"), dictionary, current) event.Skip() def OnEditProfileMenu(self, event): - title = "Edit %s Profile"%self.Manager.GetCurrentProfileName() + title = _("Edit %s Profile")%self.Manager.GetCurrentProfileName() dictionary,current = self.Manager.GetCurrentProfileLists() self.EditProfile(title, dictionary, current) event.Skip() @@ -821,12 +872,12 @@ self.RefreshBufferState() self.RefreshCurrentIndexList() else: - message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) + message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() dialog.Destroy() else: - message = wx.MessageDialog(self, result, "No map variable index left!", wx.OK|wx.ICON_ERROR) + message = wx.MessageDialog(self, result, _("No map variable index left!"), wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() @@ -840,7 +891,7 @@ self.RefreshBufferState() self.RefreshCurrentIndexList() else: - message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) + message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() dialog.Destroy() @@ -858,12 +909,12 @@ def Display_Exception_Dialog(e_type,e_value,e_tb): trcbck_lst = [] for i,line in enumerate(traceback.extract_tb(e_tb)): - trcbck = " " + str(i+1) + ". " + trcbck = " " + str(i+1) + _(". ") if line[0].find(os.getcwd()) == -1: - trcbck += "file : " + str(line[0]) + ", " + trcbck += _("file : ") + str(line[0]) + _(", ") else: - trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " - trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) + trcbck += _("file : ") + str(line[0][len(os.getcwd()):]) + _(", ") + trcbck += _("line : ") + str(line[1]) + _(", ") + _("function : ") + str(line[2]) trcbck_lst.append(trcbck) # Allow clicking.... @@ -872,7 +923,7 @@ cap.ReleaseMouse() dlg = wx.SingleChoiceDialog(None, - """ + _(""" An error happens. Click on OK for saving an error report. @@ -883,9 +934,9 @@ Error: -""" + - str(e_type) + " : " + str(e_value), - "Error", +""") + + str(e_type) + _(" : ") + str(e_value), + _("Error"), trcbck_lst) try: res = (dlg.ShowModal() == wx.ID_OK) @@ -895,7 +946,7 @@ return res def Display_Error_Dialog(e_value): - message = wx.MessageDialog(None, str(e_value), "Error", wx.OK|wx.ICON_ERROR) + message = wx.MessageDialog(None, str(e_value), _("Error"), wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() @@ -953,31 +1004,6 @@ sys.excepthook = handle_exception if __name__ == '__main__': - def usage(): - print "\nUsage of networkedit.py :" - print "\n %s [Projectpath]\n"%sys.argv[0] - - try: - opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) - except getopt.GetoptError: - # print help information and exit: - usage() - sys.exit(2) - - for o, a in opts: - if o in ("-h", "--help"): - usage() - sys.exit() - - if len(args) == 0: - projectOpen = None - elif len(args) == 1: - projectOpen = args[0] - else: - usage() - sys.exit(2) - - app = wx.PySimpleApp() wx.InitAllImageHandlers() # Install a exception handle for bug reports