--- a/Beremiz.py Mon Jul 20 16:28:56 2009 +0200
+++ b/Beremiz.py Tue Jul 28 17:43:19 2009 +0200
@@ -29,9 +29,10 @@
-_local_path = os.path.split(os.path.realpath(__file__))[0]
+CWD = os.path.split(os.path.realpath(__file__))[0] - return os.path.join(_local_path,*args)
+ return os.path.join(CWD,*args) if __name__ == '__main__':
@@ -72,6 +73,33 @@
splash=wx.SplashScreen(bmp,wx.SPLASH_CENTRE_ON_SCREEN, 1000, None)
+# Import module for internationalization +# Get folder containing translation files +localedir = os.path.join(CWD,"locale") +# Get the default language +langid = wx.LANGUAGE_DEFAULT +# Define translation domain (name of translation files) +loc = __builtin__.__dict__.get('loc', None) + loc = wx.Locale(langid) + __builtin__.__dict__['loc'] = loc +# Define location for searching translation files +loc.AddCatalogLookupPathPrefix(localedir) +def unicode_translation(message): + return wx.GetTranslation(message).encode("utf-8") +if __name__ == '__main__': + __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation import wx.lib.buttons, wx.lib.statbmp
import TextCtrlAutoComplete, cPickle
import types, time, re, platform, time, traceback, commands
@@ -255,19 +283,19 @@
def _init_coll_FileMenu_Items(self, parent):
parent.Append(help='', id=wx.ID_NEW,
- kind=wx.ITEM_NORMAL, text=u'New\tCTRL+N')
+ kind=wx.ITEM_NORMAL, text=_(u'New\tCTRL+N')) parent.Append(help='', id=wx.ID_OPEN,
- kind=wx.ITEM_NORMAL, text=u'Open\tCTRL+O')
+ kind=wx.ITEM_NORMAL, text=_(u'Open\tCTRL+O')) parent.Append(help='', id=wx.ID_SAVE,
- kind=wx.ITEM_NORMAL, text=u'Save\tCTRL+S')
+ kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S')) parent.Append(help='', id=wx.ID_CLOSE_ALL,
- kind=wx.ITEM_NORMAL, text=u'Close Project')
+ kind=wx.ITEM_NORMAL, text=_(u'Close Project')) parent.Append(help='', id=wx.ID_PROPERTIES,
- kind=wx.ITEM_NORMAL, text=u'Properties')
+ kind=wx.ITEM_NORMAL, text=_(u'Properties')) parent.Append(help='', id=wx.ID_EXIT,
- kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q')
+ kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q')) 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.OnSaveProjectMenu, id=wx.ID_SAVE)
@@ -277,27 +305,27 @@
def _init_coll_EditMenu_Items(self, parent):
parent.Append(help='', id=wx.ID_EDIT,
- kind=wx.ITEM_NORMAL, text=u'Edit PLC\tCTRL+R')
+ kind=wx.ITEM_NORMAL, text=_(u'Edit PLC\tCTRL+R')) parent.Append(help='', id=wx.ID_ADD,
- kind=wx.ITEM_NORMAL, text=u'Add Plugin')
+ kind=wx.ITEM_NORMAL, text=_(u'Add Plugin')) parent.Append(help='', id=wx.ID_DELETE,
- kind=wx.ITEM_NORMAL, text=u'Delete Plugin')
+ kind=wx.ITEM_NORMAL, text=_(u'Delete Plugin')) self.Bind(wx.EVT_MENU, self.OnEditPLCMenu, id=wx.ID_EDIT)
self.Bind(wx.EVT_MENU, self.OnAddMenu, id=wx.ID_ADD)
self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=wx.ID_DELETE)
def _init_coll_RunMenu_Items(self, parent):
parent.Append(help='', id=ID_BEREMIZRUNMENUBUILD,
- kind=wx.ITEM_NORMAL, text=u'Build\tCTRL+R')
+ kind=wx.ITEM_NORMAL, text=_(u'Build\tCTRL+R')) parent.Append(help='', id=ID_BEREMIZRUNMENUSIMULATE,
- kind=wx.ITEM_NORMAL, text=u'Simulate')
+ kind=wx.ITEM_NORMAL, text=_(u'Simulate')) parent.Append(help='', id=ID_BEREMIZRUNMENURUN,
- kind=wx.ITEM_NORMAL, text=u'Run')
+ kind=wx.ITEM_NORMAL, text=_(u'Run')) parent.Append(help='', id=ID_BEREMIZRUNMENUSAVELOG,
- kind=wx.ITEM_NORMAL, text=u'Save Log')
+ kind=wx.ITEM_NORMAL, text=_(u'Save Log')) self.Bind(wx.EVT_MENU, self.OnBuildMenu,
id=ID_BEREMIZRUNMENUBUILD)
self.Bind(wx.EVT_MENU, self.OnSimulateMenu,
@@ -309,17 +337,17 @@
def _init_coll_HelpMenu_Items(self, parent):
parent.Append(help='', id=wx.ID_HELP,
- kind=wx.ITEM_NORMAL, text=u'Beremiz\tF1')
+ kind=wx.ITEM_NORMAL, text=_(u'Beremiz\tF1')) parent.Append(help='', id=wx.ID_ABOUT,
- kind=wx.ITEM_NORMAL, text=u'About')
+ kind=wx.ITEM_NORMAL, text=_(u'About')) self.Bind(wx.EVT_MENU, self.OnBeremizMenu, id=wx.ID_HELP)
self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
def _init_coll_MenuBar_Menus(self, parent):
- parent.Append(menu=self.FileMenu, title=u'File')
+ parent.Append(menu=self.FileMenu, title=_(u'File')) #parent.Append(menu=self.EditMenu, title=u'Edit')
#parent.Append(menu=self.RunMenu, title=u'Run')
- parent.Append(menu=self.HelpMenu, title=u'Help')
+ parent.Append(menu=self.HelpMenu, title=_(u'Help')) self.MenuBar = wx.MenuBar()
@@ -361,7 +389,7 @@
def _init_ctrls(self, prnt):
wx.Frame.__init__(self, id=ID_BEREMIZ, name=u'Beremiz',
parent=prnt, pos=wx.Point(0, 0), size=wx.Size(1000, 600),
- style=wx.DEFAULT_FRAME_STYLE|wx.CLIP_CHILDREN, title=u'Beremiz')
+ style=wx.DEFAULT_FRAME_STYLE|wx.CLIP_CHILDREN, title=_(u'Beremiz')) self.SetClientSize(wx.Size(1000, 600))
self.SetMenuBar(self.MenuBar)
@@ -404,7 +432,7 @@
self.AUIManager.AddPane(self.PLCConfig, wx.aui.AuiPaneInfo().CenterPane())
self.AUIManager.AddPane(self.LogConsole, wx.aui.AuiPaneInfo().
- Caption("Log Console").Bottom().Layer(1).
+ Caption(_("Log Console")).Bottom().Layer(1). BestSize(wx.Size(800, 200)).CloseButton(False))
@@ -492,8 +520,8 @@
if self.PluginRoot is not None:
if self.PluginRoot.ProjectTestModified():
dialog = wx.MessageDialog(self,
+ _("Close Application"), wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
answer = dialog.ShowModal()
@@ -581,7 +609,7 @@
addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Add.png')),
name='AddPluginButton', parent=plcwindow, pos=wx.Point(0, 0),
size=wx.Size(16, 16), style=wx.NO_BORDER)
- addbutton.SetToolTipString("Add a sub plugin")
+ addbutton.SetToolTipString(_("Add a sub plugin")) addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddPluginMenu(self.PluginRoot), id=addbutton_id)
plcwindowsizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
@@ -677,7 +705,7 @@
for plugin_method in plugin.PluginMethods:
if "method" in plugin_method and plugin_method.get("shown",True):
- label=plugin_method["name"]
+ label = plugin_method["name"] button = GenBitmapTextButton(id=id, parent=parent,
bitmap=wx.Bitmap(Bpath( "%s.png"%plugin_method.get("bitmap", os.path.join("images", "Unknown")))), label=label,
name=label, pos=wx.DefaultPosition, style=wx.NO_BORDER)
@@ -784,7 +812,7 @@
enablebutton_id = wx.NewId()
enablebutton = wx.lib.buttons.GenBitmapToggleButton(id=enablebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Disabled.png')),
name='EnableButton', parent=leftwindow, size=wx.Size(16, 16), pos=wx.Point(0, 0), style=0)#wx.NO_BORDER)
- enablebutton.SetToolTipString("Enable/Disable this plugin")
+ enablebutton.SetToolTipString(_("Enable/Disable this plugin")) make_genbitmaptogglebutton_flat(enablebutton)
enablebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Enabled.png')))
enablebutton.SetToggle(plugin.MandatoryParams[1].getEnabled())
@@ -834,7 +862,7 @@
deletebutton = wx.lib.buttons.GenBitmapButton(id=deletebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Delete.png')),
name='DeletePluginButton', parent=leftwindow, pos=wx.Point(0, 0),
size=wx.Size(16, 16), style=wx.NO_BORDER)
- deletebutton.SetToolTipString("Delete this plugin")
+ deletebutton.SetToolTipString(_("Delete this plugin")) deletebutton.Bind(wx.EVT_BUTTON, self.GetDeleteButtonFunction(plugin), id=deletebutton_id)
adddeletesizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
@@ -843,7 +871,7 @@
addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Add.png')),
name='AddPluginButton', parent=leftwindow, pos=wx.Point(0, 0),
size=wx.Size(16, 16), style=wx.NO_BORDER)
- addbutton.SetToolTipString("Add a sub plugin")
+ addbutton.SetToolTipString(_("Add a sub plugin")) addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddPluginMenu(plugin), id=addbutton_id)
adddeletesizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
@@ -1025,7 +1053,7 @@
if len(plugin.PlugChildsTypes) > 0:
for name, XSDClass, help in plugin.PlugChildsTypes:
- main_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text="Append "+help)
+ main_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=_("Append ")+help) self.Bind(wx.EVT_MENU, self._GetAddPluginFunction(name, plugin), id=new_id)
self.PopupMenuXY(main_menu)
@@ -1110,7 +1138,8 @@
element_path = element_infos["name"]
if element_infos["type"] == "element":
- staticbox = wx.StaticBox(id=-1, label=element_infos["name"],
+ label = element_infos["name"] + staticbox = wx.StaticBox(id=-1, label=_(label), name='%s_staticbox'%element_infos["name"], parent=parent,
pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0)
staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
@@ -1130,10 +1159,11 @@
name="%s_bitmap"%element_infos["name"], parent=parent,
pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT)
- statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"],
+ label = element_infos["name"] + statictext = wx.StaticText(id=-1, label="%s:"%_(label), name="%s_label"%element_infos["name"], parent=parent,
- pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0)
- boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP)
+ pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) + boxsizer.AddWindow(statictext, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.RIGHT) if isinstance(element_infos["type"], types.ListType):
combobox = wx.ComboBox(id=id, name=element_infos["name"], parent=parent,
@@ -1144,7 +1174,9 @@
if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType):
for choice, xsdclass in element_infos["type"]:
- staticbox = wx.StaticBox(id=-1, label="%(name)s - %(value)s"%element_infos,
+ name = element_infos["name"] + value = element_infos["value"] + staticbox = wx.StaticBox(id=-1, label="%s - %s"%(_(name), _(value)), name='%s_staticbox'%element_infos["name"], parent=parent,
pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0)
staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
@@ -1214,7 +1246,7 @@
defaultpath = config.Read("lastopenedfolder")
- 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()
@@ -1226,7 +1258,7 @@
- message = wx.MessageDialog(self, res, "ERROR", wx.OK|wx.ICON_ERROR)
+ message = wx.MessageDialog(self, res, _("ERROR"), wx.OK|wx.ICON_ERROR) @@ -1237,7 +1269,7 @@
defaultpath = config.Read("lastopenedfolder")
- 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):
@@ -1249,11 +1281,11 @@
- message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
+ message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) - message = wx.MessageDialog(self, "\"%s\" folder is not a valid Beremiz project\n"%projectpath, "Error", wx.OK|wx.ICON_ERROR)
+ message = wx.MessageDialog(self, _("\"%s\" folder is not a valid Beremiz project\n")%projectpath, _("Error"), wx.OK|wx.ICON_ERROR) @@ -1263,8 +1295,8 @@
if self.PluginRoot is not None:
if self.PluginRoot.ProjectTestModified():
dialog = wx.MessageDialog(self,
+ _("Close Application"), wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
answer = dialog.ShowModal()
@@ -1322,7 +1354,7 @@
def OnAboutMenu(self, event):
- OpenHtmlFrame(self,"About Beremiz", Bpath("doc","about.html"), wx.Size(550, 500))
+ OpenHtmlFrame(self,_("About Beremiz"), Bpath("doc","about.html"), wx.Size(550, 500)) def OnAddButton(self, event):
@@ -1355,7 +1387,7 @@
return DeleteButtonFunction
def AddPlugin(self, PluginType, plugin):
- dialog = wx.TextEntryDialog(self, "Please enter a name for plugin:", "Add Plugin", "", wx.OK|wx.CANCEL)
+ dialog = wx.TextEntryDialog(self, _("Please enter a name for plugin:"), _("Add Plugin"), "", wx.OK|wx.CANCEL) if dialog.ShowModal() == wx.ID_OK:
PluginName = dialog.GetValue()
plugin.PlugAddChild(PluginName, PluginType)
@@ -1363,7 +1395,7 @@
def DeletePlugin(self, plugin):
- dialog = wx.MessageDialog(self, "Really delete plugin ?", "Remove plugin", wx.YES_NO|wx.NO_DEFAULT)
+ dialog = wx.MessageDialog(self, _("Really delete plugin ?"), _("Remove plugin"), wx.YES_NO|wx.NO_DEFAULT) if dialog.ShowModal() == wx.ID_YES:
self.PluginInfos.pop(plugin)
@@ -1380,12 +1412,12 @@
def Display_Exception_Dialog(e_type, e_value, e_tb, bug_report_path):
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]) + _(", ") - 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)
@@ -1394,7 +1426,7 @@
dlg = wx.SingleChoiceDialog(None,
An unhandled exception (bug) occured. Bug report saved at :
@@ -1406,9 +1438,9 @@
You should now restart Beremiz.
+""") % bug_report_path + str(e_type) + " : " + str(e_value),
res = (dlg.ShowModal() == wx.ID_OK)
@@ -1418,7 +1450,7 @@
def Display_Error_Dialog(e_value):
- message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR)
+ message = wxMessageDialog(None, str(e_value), _("Error"), wxOK|wxICON_ERROR) --- a/plugger.py Mon Jul 20 16:28:56 2009 +0200
+++ b/plugger.py Tue Jul 28 17:43:19 2009 +0200
@@ -199,7 +199,7 @@
# Call the plugin specific OnPlugSave method
result = self.OnPlugSave()
- return "Error while saving \"%s\"\n"%self.PlugPath()
+ return _("Error while saving \"%s\"\n")%self.PlugPath() self.ChangesToSave = False
@@ -235,7 +235,7 @@
gen_result = self.PlugGenerate_C(buildpath, locations)
PlugCFilesAndCFLAGS, PlugLDFLAGS, DoCalls = gen_result[:3]
extra_files = gen_result[3:]
- # if some files heve been generated put them in the list with their location
+ # if some files have been generated put them in the list with their location LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), PlugCFilesAndCFLAGS, DoCalls)]
@@ -392,7 +392,7 @@
shutil.move(oldname, self.PlugPath())
# warn user he has two left hands
- self.logger.write_warning("A child names \"%s\" already exist -> \"%s\"\n"%(DesiredName,res))
+ self.logger.write_warning(_("A child names \"%s\" already exist -> \"%s\"\n")%(DesiredName,res)) def FindNewIEC_Channel(self, DesiredChannel):
@@ -417,14 +417,14 @@
if res < CurrentChannel: # Want to go down ?
- self.logger.write_warning("Cannot find lower free IEC channel than %d\n"%CurrentChannel)
+ self.logger.write_warning(_("Cannot find lower free IEC channel than %d\n")%CurrentChannel) return CurrentChannel # Can't go bellow 0, do nothing
# Finally set IEC Channel
self.BaseParams.setIEC_Channel(res)
if DesiredChannel != res:
- self.logger.write_warning("A child with IEC channel %d already exist -> %d\n"%(DesiredChannel,res))
+ self.logger.write_warning(_("A child with IEC channel %d already exist -> %d\n")%(DesiredChannel,res)) @@ -462,7 +462,7 @@
PlugClass, PlugHelp = PlugChildsTypes[PlugType]
- raise Exception, "Cannot create child %s of type %s "%(PlugName, PlugType)
+ raise Exception, _("Cannot create child %s of type %s ")%(PlugName, PlugType) # if PlugClass is a class factory, call it. (prevent unneeded imports)
if type(PlugClass) == types.FunctionType:
@@ -472,7 +472,7 @@
PluggedChildsWithSameClass = self.PluggedChilds.setdefault(PlugType, list())
if getattr(PlugClass, "PlugMaxCount", None) and len(PluggedChildsWithSameClass) >= PlugClass.PlugMaxCount:
- raise Exception, "Max count (%d) reached for this plugin of type %s "%(PlugClass.PlugMaxCount, PlugType)
+ raise Exception, _("Max count (%d) reached for this plugin of type %s ")%(PlugClass.PlugMaxCount, PlugType) # create the final class, derived of provided plugin and template
class FinalPlugClass(PlugClass, PlugTemplate):
@@ -500,7 +500,7 @@
_self.LoadXMLParams(NewPlugName)
# Basic check. Better to fail immediately.
if (_self.BaseParams.getName() != NewPlugName):
- raise Exception, "Project tree layout do not match plugin.xml %s!=%s "%(NewPlugName, _self.BaseParams.getName())
+ raise Exception, _("Project tree layout do not match plugin.xml %s!=%s ")%(NewPlugName, _self.BaseParams.getName()) # Now, self.PlugPath() should be OK
@@ -555,7 +555,7 @@
self.MandatoryParams[1].loadXMLTree(basetree.childNodes[0])
- self.logger.write_error("Couldn't load plugin base parameters %s :\n %s" % (PlugName, str(exc)))
+ self.logger.write_error(_("Couldn't load plugin base parameters %s :\n %s") % (PlugName, str(exc))) self.logger.write_error(traceback.format_exc())
@@ -566,7 +566,7 @@
self.PlugParams[1].loadXMLTree(tree.childNodes[0])
- self.logger.write_error("Couldn't load plugin parameters %s :\n %s" % (PlugName, str(exc)))
+ self.logger.write_error(_("Couldn't load plugin parameters %s :\n %s") % (PlugName, str(exc))) self.logger.write_error(traceback.format_exc())
@@ -578,7 +578,7 @@
self.PlugAddChild(pname, ptype)
- self.logger.write_error("Could not add child \"%s\", type %s :\n%s\n"%(pname, ptype, str(exc)))
+ self.logger.write_error(_("Could not add child \"%s\", type %s :\n%s\n")%(pname, ptype, str(exc))) self.logger.write_error(traceback.format_exc())
def EnableMethod(self, method, value):
@@ -777,7 +777,7 @@
# Verify that choosen folder is empty
if not os.path.isdir(ProjectPath) or len(os.listdir(ProjectPath)) > 0:
- return "Folder choosen isn't empty. You can't use it for a new project!"
+ return _("Folder choosen isn't empty. You can't use it for a new project!") dialog = ProjectDialog(self.AppFrame)
if dialog.ShowModal() == wx.ID_OK:
@@ -786,7 +786,7 @@
- return "Project not created"
+ return _("Project not created") self.CreateNewProject(values)
@@ -812,7 +812,7 @@
# Verify that project contains a PLCOpen program
plc_file = os.path.join(ProjectPath, "plc.xml")
if not os.path.isfile(plc_file):
- return "Folder choosen doesn't contain a program. It's not a valid project!"
+ return _("Folder choosen doesn't contain a program. It's not a valid project!") result = self.OpenXMLFile(plc_file)
@@ -928,17 +928,17 @@
# Update PLCOpenEditor Plugin Block types before generate ST code
self.RefreshPluginsBlockLists()
- self.logger.write("Generating SoftPLC IEC-61131 ST/IL/SFC code...\n")
+ self.logger.write(_("Generating SoftPLC IEC-61131 ST/IL/SFC code...\n")) buildpath = self._getBuildPath()
# ask PLCOpenEditor controller to write ST/IL/SFC code file
program, errors, warnings = self.GenerateProgram(self._getIECgeneratedcodepath())
- self.logger.write_warning("Warnings in ST/IL/SFC code generator :\n")
+ self.logger.write_warning(_("Warnings in ST/IL/SFC code generator :\n")) self.logger.write_warning("%s\n"%warning)
- self.logger.write_error("Error in ST/IL/SFC code generator :\n%s\n"%errors[0])
+ self.logger.write_error(_("Error in ST/IL/SFC code generator :\n%s\n")%errors[0]) plc_file = open(self._getIECcodepath(), "w")
if getattr(self, "PluggedChilds", None) is not None:
@@ -960,7 +960,7 @@
plc_file = open(self._getIECcodepath(), "a")
plc_file.write(open(self._getIECgeneratedcodepath(), "r").read())
- self.logger.write("Compiling IEC Program in to C code...\n")
+ self.logger.write(_("Compiling IEC Program in to C code...\n")) # Now compile IEC code into many C files
# files are listed to stdout, and errors to stderr.
status, result, err_result = ProcessLogger(
@@ -999,7 +999,7 @@
- self.logger.write_error("Error : IEC to C compiler returned %d\n"%status)
+ self.logger.write_error(_("Error : IEC to C compiler returned %d\n")%status) # Now extract C files of stdout
@@ -1007,11 +1007,11 @@
# remove those that are not to be compiled because included by others
- self.logger.write_error("Error : At least one configuration and one ressource must be declared in PLC !\n")
+ self.logger.write_error(_("Error : At least one configuration and one ressource must be declared in PLC !\n")) # transform those base names to full names with path
C_files = map(lambda filename:os.path.join(buildpath, filename), C_files)
- self.logger.write("Extracting Located Variables...\n")
+ self.logger.write(_("Extracting Located Variables...\n")) # Keep track of generated located variables for later use by self._Generate_C
self.PLCGeneratedLocatedVars = self.GetLocations()
# Keep track of generated C files for later use by self.PlugGenerate_C
@@ -1034,7 +1034,7 @@
targetmodule = getattr(__import__(modulename), targetname)
- self.logger.write_error("Can't find module for target %s!\n"%targetname)
+ self.logger.write_error(_("Can't find module for target %s!\n")%targetname) self.logger.write_error(str(msg))
@@ -1158,7 +1158,7 @@
self._IECPathToIdx[IEC_path]=Idx
- self.logger.write_error("Cannot open/parse VARIABLES.csv!\n")
+ self.logger.write_error(_("Cannot open/parse VARIABLES.csv!\n")) self.logger.write_error(traceback.format_exc())
self.ResetIECProgramsAndVariables()
@@ -1270,7 +1270,7 @@
self.EnableMethod("_Clean", True)
- self.logger.write("Start build in %s\n" % buildpath)
+ self.logger.write(_("Start build in %s\n") % buildpath) # Generate SoftPLC IEC code
IECGenRes = self._Generate_SoftPLC()
@@ -1278,7 +1278,7 @@
# If IEC code gen fail, bail out.
- self.logger.write_error("IEC-61131-3 code generation failed !\n")
+ self.logger.write_error(_("IEC-61131-3 code generation failed !\n")) # Reset variable and program list that are parsed from
@@ -1286,17 +1286,17 @@
self.ResetIECProgramsAndVariables()
# Generate C code and compilation params from plugin hierarchy
- self.logger.write("Generating plugins C code\n")
+ self.logger.write(_("Generating plugins C code\n")) self.LocationCFilesAndCFLAGS, self.LDFLAGS, ExtraFiles = self._Generate_C(
self.PLCGeneratedLocatedVars)
- self.logger.write_error("Plugins code generation failed !\n")
+ self.logger.write_error(_("Plugins code generation failed !\n")) self.logger.write_error(traceback.format_exc())
- # Get temprary directory path
+ # Get temporary directory path extrafilespath = self._getExtraFilesPath()
if os.path.exists(extrafilespath):
@@ -1329,25 +1329,25 @@
# Insert this file as first file to be compiled at root plugin
self.LocationCFilesAndCFLAGS[0][1].insert(0,(code_path, self.plcCFLAGS))
- self.logger.write_error(name+" generation failed !\n")
+ self.logger.write_error(name+_(" generation failed !\n")) self.logger.write_error(traceback.format_exc())
- self.logger.write("C code generated successfully.\n")
+ self.logger.write(_("C code generated successfully.\n")) # Get current or fresh builder
builder = self.GetBuilder()
- self.logger.write_error("Fatal : cannot get builder.\n")
+ self.logger.write_error(_("Fatal : cannot get builder.\n")) - self.logger.write_error("C Build failed.\n")
+ self.logger.write_error(_("C Build failed.\n")) - self.logger.write_error("C Build crashed !\n")
+ self.logger.write_error(_("C Build crashed !\n")) self.logger.write_error(traceback.format_exc())
@@ -1428,10 +1428,10 @@
if os.path.isdir(os.path.join(self._getBuildPath())):
- self.logger.write("Cleaning the build directory\n")
+ self.logger.write(_("Cleaning the build directory\n")) shutil.rmtree(os.path.join(self._getBuildPath()))
- self.logger.write_error("Build directory already clean\n")
+ self.logger.write_error(_("Build directory already clean\n")) self.ShowMethod("_showIECcode", False)
self.EnableMethod("_Clean", False)
@@ -1446,28 +1446,29 @@
status = self._connector.GetPLCstatus()
- "Started":[("_Run", False),
- "Stopped":[("_Run", True),
- "Empty": [("_Run", False),
- "Dirty": [("_Run", True),
- "Broken": [("_Run", True),
- "Disconnected": [("_Run", False),
- ("_Disconnect", False)],
+ _("Started"): [("_Run", False), + _("Stopped"): [("_Run", True), + _("Empty"): [("_Run", False), + _("Dirty"): [("_Run", True), + _("Broken"): [("_Run", True), + _("Disconnected"):[("_Run", False), + ("_Disconnect", False)], @@ -1478,7 +1479,11 @@
current_status = self.UpdateMethodsFromPLCStatus()
if current_status != self.previous_plcstate:
self.previous_plcstate = current_status
- self.StatusPrint.get(current_status, self.logger.write)("PLC is %s\n"%current_status)
+ if current_status is not None: + status = _(current_status) + self.StatusPrint.get(current_status, self.logger.write)(_("PLC is %s\n")%status) self.AppFrame.RefreshAll()
@@ -1509,7 +1514,7 @@
self.TracedIECPath.append(IECPath)
- self.logger.write_warning("Debug : Unknown variable %s\n"%IECPath)
+ self.logger.write_warning(_("Debug : Unknown variable %s\n")%IECPath) for IECPathToPop in IECPathsToPop:
self.IECdebug_datas.pop(IECPathToPop)
@@ -1604,12 +1609,12 @@
self.CallWeakcallables("__tick__", "NewDataAvailable")
elif debug_vars is not None:
wx.CallAfter(self.logger.write_warning,
- "Debug data not coherent %d != %d\n"%(len(debug_vars), len(self.TracedIECPath)))
+ _("Debug data not coherent %d != %d\n")%(len(debug_vars), len(self.TracedIECPath))) #wx.CallAfter(self.logger.write, "Debugger unavailable\n")
- wx.CallAfter(self.logger.write, "Debugger disabled\n")
+ wx.CallAfter(self.logger.write, _("Debugger disabled\n")) self.IECdebug_lock.release()
@@ -1617,7 +1622,7 @@
self.DebugThread.join(timeout=1)
if self.DebugThread.isAlive():
- self.logger.write_warning("Debug Thread couldn't be killed")
+ self.logger.write_warning(_("Debug Thread couldn't be killed")) @@ -1626,7 +1631,7 @@
if self.GetIECProgramsAndVariables():
self._connector.StartPLC(debug=True)
- self.logger.write("Starting PLC (debug mode)\n")
+ self.logger.write(_("Starting PLC (debug mode)\n")) if self.PLCDebug is None:
self.RefreshPluginsBlockLists()
@@ -1639,7 +1644,7 @@
self.DebugThread = Thread(target=self.DebugThreadProc)
- self.logger.write_error("Couldn't start PLC debug !\n")
+ self.logger.write_error(_("Couldn't start PLC debug !\n")) self.UpdateMethodsFromPLCStatus()
@@ -1665,17 +1670,17 @@
if self.DebugThread is not None:
- self.logger.write("Stopping debug\n")
+ self.logger.write(_("Stopping debug\n")) if not self._connector.StopPLC():
- self.logger.write_error("Couldn't stop PLC !\n")
+ self.logger.write_error(_("Couldn't stop PLC !\n")) self.UpdateMethodsFromPLCStatus()
# don't accept re-connetion is already connected
if self._connector is not None:
- self.logger.write_error("Already connected. Please disconnect\n")
+ self.logger.write_error(_("Already connected. Please disconnect\n")) @@ -1702,13 +1707,13 @@
self._connector = connectors.ConnectorFactory(uri, self)
- self.logger.write_error("Exception while connecting %s!\n"%uri)
+ self.logger.write_error(_("Exception while connecting %s!\n")%uri) self.logger.write_error(traceback.format_exc())
# Did connection success ?
if self._connector is None:
- self.logger.write_error("Connection failed to %s!\n"%uri)
+ self.logger.write_error(_("Connection failed to %s!\n")%uri) self.ShowMethod("_Connect", False)
self.ShowMethod("_Disconnect", True)
@@ -1718,7 +1723,11 @@
# Init with actual PLC status and print it
self.previous_plcstate = self.UpdateMethodsFromPLCStatus()
- self.logger.write("PLC is %s\n"%self.previous_plcstate)
+ if self.previous_plcstate is not None: + status = _(self.previous_plcstate) + self.logger.write(_("PLC is %s\n")%status) self.StatusTimer.Start(milliseconds=500, oneShot=False)
@@ -1732,16 +1741,16 @@
if not self._connector.MatchMD5(MD5):
self.logger.write_warning(
- "Latest build do not match with target, please transfer.\n")
+ _("Latest build do not match with target, please transfer.\n")) self.EnableMethod("_Transfer", True)
- "Latest build match target, no transfer needed.\n")
+ _("Latest build match target, no transfer needed.\n")) self.EnableMethod("_Transfer", True)
#self.EnableMethod("_Transfer", False)
self.logger.write_warning(
- "Cannot compare latest build to target. Please build.\n")
+ _("Cannot compare latest build to target. Please build.\n")) self.EnableMethod("_Transfer", False)
@@ -1756,13 +1765,13 @@
# Check if md5 file is empty : ask user to build PLC
- self.logger.write_error("Failed : Must build before transfer.\n")
+ self.logger.write_error(_("Failed : Must build before transfer.\n")) # Compare PLC project with PLC on target
if self._connector.MatchMD5(MD5):
- "Latest build already match current target. Transfering anyway...\n")
+ _("Latest build already match current target. Transfering anyway...\n")) # Get temprary directory path
extrafilespath = self._getExtraFilesPath()
@@ -1782,68 +1791,68 @@
self.UnsubscribeAllDebugIECVariable()
self.ProgramTransferred()
- self.logger.write("Transfer completed successfully.\n")
+ self.logger.write(_("Transfer completed successfully.\n")) - self.logger.write_error("Transfer failed\n")
+ self.logger.write_error(_("Transfer failed\n")) - self.logger.write_error("No PLC to transfer (did build success ?)\n")
+ self.logger.write_error(_("No PLC to transfer (did build success ?)\n")) self.UpdateMethodsFromPLCStatus()
{"bitmap" : opjimg("editPLC"),
- "tooltip" : "Edit PLC program with PLCOpenEditor",
+ "name" : _("Edit PLC"), + "tooltip" : _("Edit PLC program with PLCOpenEditor"), {"bitmap" : opjimg("Build"),
- "tooltip" : "Build project into build folder",
+ "tooltip" : _("Build project into build folder"), {"bitmap" : opjimg("Clean"),
- "tooltip" : "Clean project build folder",
+ "tooltip" : _("Clean project build folder"), {"bitmap" : opjimg("Run"),
- "tooltip" : "Start PLC",
+ "tooltip" : _("Start PLC"), {"bitmap" : opjimg("Debug"),
- "tooltip" : "Start PLC (debug mode)",
+ "tooltip" : _("Start PLC (debug mode)"), # {"bitmap" : opjimg("Debug"),
# "name" : "Do_Test_Debug",
# "tooltip" : "Test debug mode)",
# "method" : "_Do_Test_Debug"},
{"bitmap" : opjimg("Stop"),
- "tooltip" : "Stop Running PLC",
+ "tooltip" : _("Stop Running PLC"), {"bitmap" : opjimg("Connect"),
- "tooltip" : "Connect to the target PLC",
+ "tooltip" : _("Connect to the target PLC"), {"bitmap" : opjimg("Transfer"),
+ "name" : _("Transfer"), - "tooltip" : "Transfer PLC",
+ "tooltip" : _("Transfer PLC"), {"bitmap" : opjimg("Disconnect"),
+ "name" : _("Disconnect"), - "tooltip" : "Disconnect from PLC",
+ "tooltip" : _("Disconnect from PLC"), "method" : "_Disconnect"},
{"bitmap" : opjimg("ShowIECcode"),
+ "name" : _("Show code"), - "tooltip" : "Show IEC code generated by PLCGenerator",
+ "tooltip" : _("Show IEC code generated by PLCGenerator"), "method" : "_showIECcode"},
{"bitmap" : opjimg("editIECrawcode"),
- "name" : "Raw IEC code",
- "tooltip" : "Edit raw IEC code added to code generated by PLCGenerator",
+ "name" : _("Raw IEC code"), + "tooltip" : _("Edit raw IEC code added to code generated by PLCGenerator"), "method" : "_editIECrawcode"},
{"bitmap" : opjimg("editPYTHONcode"),
--- a/plugins/canfestival/config_utils.py Mon Jul 20 16:28:56 2009 +0200
+++ b/plugins/canfestival/config_utils.py Tue Jul 28 17:43:19 2009 +0200
@@ -332,13 +332,13 @@
if name in self.IECLocations:
if self.IECLocations[name]["type"] != COlocationtype:
- raise PDOmappingException, "Conflict type for location \"%s\"" % name
+ raise PDOmappingException, _("Conflict type for location \"%s\"") % name # Get only the part of the location that concern this node
loc = location["LOC"][len(current_location):]
# loc correspond to (ID, INDEX, SUBINDEX [,BIT])
if len(loc) not in (2, 3, 4):
- raise PDOmappingException, "Bad location size : %s"%str(loc)
+ raise PDOmappingException, _("Bad location size : %s") % str(loc) @@ -351,14 +351,14 @@
# Check Id is in slave node list
if nodeid not in self.NodeList.SlaveNodes.keys():
- raise PDOmappingException, "Non existing node ID : %d (variable %s)" % (nodeid,name)
+ raise PDOmappingException, _("Non existing node ID : %d (variable %s)") % (nodeid,name) # Get the model for this node (made from EDS)
node = self.NodeList.SlaveNodes[nodeid]["Node"]
# Extract and check index and subindex
if not node.IsEntry(index, subindex):
- raise PDOmappingException, "No such index/subindex (%x,%x) in ID : %d (variable %s)" % (index,subindex,nodeid,name)
+ raise PDOmappingException, _("No such index/subindex (%x,%x) in ID : %d (variable %s)") % (index,subindex,nodeid,name) subentry_infos = node.GetSubentryInfos(index, subindex)
@@ -368,19 +368,19 @@
if sizelocation == "X" and len(loc) > 3:
elif sizelocation != "X" and len(loc) > 3:
- raise PDOmappingException, "Cannot set bit offset for non bool '%s' variable (ID:%d,Idx:%x,sIdx:%x))" % (name,nodeid,index,subindex)
+ raise PDOmappingException, _("Cannot set bit offset for non bool '%s' variable (ID:%d,Idx:%x,sIdx:%x))") % (name,nodeid,index,subindex) if location["IEC_TYPE"] != "BOOL" and subentry_infos["type"] != COlocationtype:
- raise PDOmappingException, "Invalid type \"%s\"-> %d != %d for location\"%s\"" % (location["IEC_TYPE"], COlocationtype, subentry_infos["type"] , name)
+ raise PDOmappingException, _("Invalid type \"%s\"-> %d != %d for location\"%s\"") % (location["IEC_TYPE"], COlocationtype, subentry_infos["type"] , name) typeinfos = node.GetEntryInfos(COlocationtype)
self.IECLocations[name] = {"type":COlocationtype, "pdotype":SlavePDOType[direction],
"nodeid": nodeid, "index": index,"subindex": subindex,
"bit": numbit, "size": typeinfos["size"], "sizelocation": sizelocation}
- raise PDOmappingException, "Not PDO mappable variable : '%s' (ID:%d,Idx:%x,sIdx:%x))" % (name,nodeid,index,subindex)
+ raise PDOmappingException, _("Not PDO mappable variable : '%s' (ID:%d,Idx:%x,sIdx:%x))") % (name,nodeid,index,subindex) #-------------------------------------------------------------------------------
# Search for locations already mapped
@@ -452,7 +452,7 @@
result = self.GetEmptyPDO(nodeid, pdotype)
- raise PDOmappingException, "Impossible to define PDO mapping for node %02x"%nodeid
+ raise PDOmappingException, _("Impossible to define PDO mapping for node %02x") % nodeid pdoindex, pdocobid, pdonbparams = result
for name, loc_infos in locations[pdotype]:
pdosize += loc_infos["size"]
@@ -466,7 +466,7 @@
pdomapping = [(name, loc_infos)]
result = self.GetEmptyPDO(nodeid, pdotype, pdoindex + 1)
- raise PDOmappingException, "Impossible to define PDO mapping for node %02x"%nodeid
+ raise PDOmappingException, _("Impossible to define PDO mapping for node %02x") % nodeid pdoindex, pdocobid, pdonbparams = result
pdomapping.append((name, loc_infos))
@@ -614,13 +614,13 @@
if IECLocations[name] != COlocationtype:
- raise PDOmappingException, "Conflict type for location \"%s\"" % name
+ raise PDOmappingException, _("Conflict type for location \"%s\"") % name # Get only the part of the location that concern this node
loc = location["LOC"][len(current_location):]
# loc correspond to (ID, INDEX, SUBINDEX [,BIT])
if len(loc) not in (2, 3, 4):
- raise PDOmappingException, "Bad location size : %s"%str(loc)
+ raise PDOmappingException, _("Bad location size : %s") % str(loc) @@ -629,12 +629,12 @@
# Extract and check index and subindex
if not slave.IsEntry(index, subindex):
- raise PDOmappingException, "No such index/subindex (%x,%x) (variable %s)" % (index, subindex, name)
+ raise PDOmappingException, _("No such index/subindex (%x,%x) (variable %s)") % (index, subindex, name) subentry_infos = slave.GetSubentryInfos(index, subindex)
if subentry_infos["type"] != COlocationtype:
- raise PDOmappingException, "Invalid type \"%s\"-> %d != %d for location\"%s\"" % (location["IEC_TYPE"], COlocationtype, subentry_infos["type"] , name)
+ raise PDOmappingException, _("Invalid type \"%s\"-> %d != %d for location\"%s\"") % (location["IEC_TYPE"], COlocationtype, subentry_infos["type"] , name) IECLocations[name] = COlocationtype
pointers[(index, subindex)] = name