Beremiz.py
changeset 361 331d698e1118
parent 356 e9698d0ee5f3
child 382 37f870528def
equal deleted inserted replaced
360:32339ad7d9ae 361:331d698e1118
    27 import os, sys, getopt, wx
    27 import os, sys, getopt, wx
    28 import tempfile
    28 import tempfile
    29 import shutil
    29 import shutil
    30 import random
    30 import random
    31 
    31 
    32 _local_path = os.path.split(os.path.realpath(__file__))[0]
    32 CWD = os.path.split(os.path.realpath(__file__))[0]
       
    33 
    33 def Bpath(*args):
    34 def Bpath(*args):
    34     return os.path.join(_local_path,*args)
    35     return os.path.join(CWD,*args)
    35 
    36 
    36 if __name__ == '__main__':
    37 if __name__ == '__main__':
    37     def usage():
    38     def usage():
    38         print "\nUsage of Beremiz.py :"
    39         print "\nUsage of Beremiz.py :"
    39         print "\n   %s [Projectpath] [Buildpath]\n"%sys.argv[0]
    40         print "\n   %s [Projectpath] [Buildpath]\n"%sys.argv[0]
    69     wx.InitAllImageHandlers()
    70     wx.InitAllImageHandlers()
    70     
    71     
    71     bmp = wx.Image(Bpath("images","splash.png")).ConvertToBitmap()
    72     bmp = wx.Image(Bpath("images","splash.png")).ConvertToBitmap()
    72     splash=wx.SplashScreen(bmp,wx.SPLASH_CENTRE_ON_SCREEN, 1000, None)
    73     splash=wx.SplashScreen(bmp,wx.SPLASH_CENTRE_ON_SCREEN, 1000, None)
    73     wx.Yield()
    74     wx.Yield()
       
    75 
       
    76 # Import module for internationalization
       
    77 import gettext
       
    78 import __builtin__
       
    79 
       
    80 # Get folder containing translation files
       
    81 localedir = os.path.join(CWD,"locale")
       
    82 # Get the default language
       
    83 langid = wx.LANGUAGE_DEFAULT
       
    84 # Define translation domain (name of translation files)
       
    85 domain = "Beremiz"
       
    86 
       
    87 # Define locale for wx
       
    88 loc = __builtin__.__dict__.get('loc', None)
       
    89 if loc is None:
       
    90     loc = wx.Locale(langid)
       
    91     __builtin__.__dict__['loc'] = loc
       
    92 # Define location for searching translation files
       
    93 loc.AddCatalogLookupPathPrefix(localedir)
       
    94 # Define locale domain
       
    95 loc.AddCatalog(domain)
       
    96 
       
    97 def unicode_translation(message):
       
    98     return wx.GetTranslation(message).encode("utf-8")
       
    99 
       
   100 if __name__ == '__main__':
       
   101     __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation
    74 
   102 
    75 import wx.lib.buttons, wx.lib.statbmp
   103 import wx.lib.buttons, wx.lib.statbmp
    76 import TextCtrlAutoComplete, cPickle
   104 import TextCtrlAutoComplete, cPickle
    77 import types, time, re, platform, time, traceback, commands
   105 import types, time, re, platform, time, traceback, commands
    78 from plugger import PluginsRoot, MATIEC_ERROR_MODEL
   106 from plugger import PluginsRoot, MATIEC_ERROR_MODEL
   253 
   281 
   254 class Beremiz(wx.Frame):
   282 class Beremiz(wx.Frame):
   255 	
   283 	
   256     def _init_coll_FileMenu_Items(self, parent):
   284     def _init_coll_FileMenu_Items(self, parent):
   257         parent.Append(help='', id=wx.ID_NEW,
   285         parent.Append(help='', id=wx.ID_NEW,
   258               kind=wx.ITEM_NORMAL, text=u'New\tCTRL+N')
   286               kind=wx.ITEM_NORMAL, text=_(u'New\tCTRL+N'))
   259         parent.Append(help='', id=wx.ID_OPEN,
   287         parent.Append(help='', id=wx.ID_OPEN,
   260               kind=wx.ITEM_NORMAL, text=u'Open\tCTRL+O')
   288               kind=wx.ITEM_NORMAL, text=_(u'Open\tCTRL+O'))
   261         parent.Append(help='', id=wx.ID_SAVE,
   289         parent.Append(help='', id=wx.ID_SAVE,
   262               kind=wx.ITEM_NORMAL, text=u'Save\tCTRL+S')
   290               kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S'))
   263         parent.Append(help='', id=wx.ID_CLOSE_ALL,
   291         parent.Append(help='', id=wx.ID_CLOSE_ALL,
   264               kind=wx.ITEM_NORMAL, text=u'Close Project')
   292               kind=wx.ITEM_NORMAL, text=_(u'Close Project'))
   265         parent.AppendSeparator()
   293         parent.AppendSeparator()
   266         parent.Append(help='', id=wx.ID_PROPERTIES,
   294         parent.Append(help='', id=wx.ID_PROPERTIES,
   267               kind=wx.ITEM_NORMAL, text=u'Properties')
   295               kind=wx.ITEM_NORMAL, text=_(u'Properties'))
   268         parent.AppendSeparator()
   296         parent.AppendSeparator()
   269         parent.Append(help='', id=wx.ID_EXIT,
   297         parent.Append(help='', id=wx.ID_EXIT,
   270               kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q')
   298               kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q'))
   271         self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
   299         self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
   272         self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
   300         self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
   273         self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
   301         self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
   274         self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL)
   302         self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL)
   275         self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
   303         self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
   276         self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
   304         self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
   277         
   305         
   278     def _init_coll_EditMenu_Items(self, parent):
   306     def _init_coll_EditMenu_Items(self, parent):
   279         parent.Append(help='', id=wx.ID_EDIT,
   307         parent.Append(help='', id=wx.ID_EDIT,
   280               kind=wx.ITEM_NORMAL, text=u'Edit PLC\tCTRL+R')
   308               kind=wx.ITEM_NORMAL, text=_(u'Edit PLC\tCTRL+R'))
   281         parent.AppendSeparator()
   309         parent.AppendSeparator()
   282         parent.Append(help='', id=wx.ID_ADD,
   310         parent.Append(help='', id=wx.ID_ADD,
   283               kind=wx.ITEM_NORMAL, text=u'Add Plugin')
   311               kind=wx.ITEM_NORMAL, text=_(u'Add Plugin'))
   284         parent.Append(help='', id=wx.ID_DELETE,
   312         parent.Append(help='', id=wx.ID_DELETE,
   285               kind=wx.ITEM_NORMAL, text=u'Delete Plugin')
   313               kind=wx.ITEM_NORMAL, text=_(u'Delete Plugin'))
   286         self.Bind(wx.EVT_MENU, self.OnEditPLCMenu, id=wx.ID_EDIT)
   314         self.Bind(wx.EVT_MENU, self.OnEditPLCMenu, id=wx.ID_EDIT)
   287         self.Bind(wx.EVT_MENU, self.OnAddMenu, id=wx.ID_ADD)
   315         self.Bind(wx.EVT_MENU, self.OnAddMenu, id=wx.ID_ADD)
   288         self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=wx.ID_DELETE)
   316         self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=wx.ID_DELETE)
   289     
   317     
   290     def _init_coll_RunMenu_Items(self, parent):
   318     def _init_coll_RunMenu_Items(self, parent):
   291         parent.Append(help='', id=ID_BEREMIZRUNMENUBUILD,
   319         parent.Append(help='', id=ID_BEREMIZRUNMENUBUILD,
   292               kind=wx.ITEM_NORMAL, text=u'Build\tCTRL+R')
   320               kind=wx.ITEM_NORMAL, text=_(u'Build\tCTRL+R'))
   293         parent.AppendSeparator()
   321         parent.AppendSeparator()
   294         parent.Append(help='', id=ID_BEREMIZRUNMENUSIMULATE,
   322         parent.Append(help='', id=ID_BEREMIZRUNMENUSIMULATE,
   295               kind=wx.ITEM_NORMAL, text=u'Simulate')
   323               kind=wx.ITEM_NORMAL, text=_(u'Simulate'))
   296         parent.Append(help='', id=ID_BEREMIZRUNMENURUN,
   324         parent.Append(help='', id=ID_BEREMIZRUNMENURUN,
   297               kind=wx.ITEM_NORMAL, text=u'Run')
   325               kind=wx.ITEM_NORMAL, text=_(u'Run'))
   298         parent.AppendSeparator()
   326         parent.AppendSeparator()
   299         parent.Append(help='', id=ID_BEREMIZRUNMENUSAVELOG,
   327         parent.Append(help='', id=ID_BEREMIZRUNMENUSAVELOG,
   300               kind=wx.ITEM_NORMAL, text=u'Save Log')
   328               kind=wx.ITEM_NORMAL, text=_(u'Save Log'))
   301         self.Bind(wx.EVT_MENU, self.OnBuildMenu,
   329         self.Bind(wx.EVT_MENU, self.OnBuildMenu,
   302               id=ID_BEREMIZRUNMENUBUILD)
   330               id=ID_BEREMIZRUNMENUBUILD)
   303         self.Bind(wx.EVT_MENU, self.OnSimulateMenu,
   331         self.Bind(wx.EVT_MENU, self.OnSimulateMenu,
   304               id=ID_BEREMIZRUNMENUSIMULATE)
   332               id=ID_BEREMIZRUNMENUSIMULATE)
   305         self.Bind(wx.EVT_MENU, self.OnRunMenu,
   333         self.Bind(wx.EVT_MENU, self.OnRunMenu,
   307         self.Bind(wx.EVT_MENU, self.OnSaveLogMenu,
   335         self.Bind(wx.EVT_MENU, self.OnSaveLogMenu,
   308               id=ID_BEREMIZRUNMENUSAVELOG)
   336               id=ID_BEREMIZRUNMENUSAVELOG)
   309     
   337     
   310     def _init_coll_HelpMenu_Items(self, parent):
   338     def _init_coll_HelpMenu_Items(self, parent):
   311         parent.Append(help='', id=wx.ID_HELP,
   339         parent.Append(help='', id=wx.ID_HELP,
   312               kind=wx.ITEM_NORMAL, text=u'Beremiz\tF1')
   340               kind=wx.ITEM_NORMAL, text=_(u'Beremiz\tF1'))
   313         parent.Append(help='', id=wx.ID_ABOUT,
   341         parent.Append(help='', id=wx.ID_ABOUT,
   314               kind=wx.ITEM_NORMAL, text=u'About')
   342               kind=wx.ITEM_NORMAL, text=_(u'About'))
   315         self.Bind(wx.EVT_MENU, self.OnBeremizMenu, id=wx.ID_HELP)
   343         self.Bind(wx.EVT_MENU, self.OnBeremizMenu, id=wx.ID_HELP)
   316         self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
   344         self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
   317     
   345     
   318     def _init_coll_MenuBar_Menus(self, parent):
   346     def _init_coll_MenuBar_Menus(self, parent):
   319         parent.Append(menu=self.FileMenu, title=u'File')
   347         parent.Append(menu=self.FileMenu, title=_(u'File'))
   320         #parent.Append(menu=self.EditMenu, title=u'Edit')
   348         #parent.Append(menu=self.EditMenu, title=u'Edit')
   321         #parent.Append(menu=self.RunMenu, title=u'Run')
   349         #parent.Append(menu=self.RunMenu, title=u'Run')
   322         parent.Append(menu=self.HelpMenu, title=u'Help')
   350         parent.Append(menu=self.HelpMenu, title=_(u'Help'))
   323     
   351     
   324     def _init_utils(self):
   352     def _init_utils(self):
   325         self.MenuBar = wx.MenuBar()
   353         self.MenuBar = wx.MenuBar()
   326         self.FileMenu = wx.Menu(title=u'')
   354         self.FileMenu = wx.Menu(title=u'')
   327         #self.EditMenu = wx.Menu(title=u'')
   355         #self.EditMenu = wx.Menu(title=u'')
   359         self.PLCConfig.SetSizer(self.PLCConfigMainSizer)
   387         self.PLCConfig.SetSizer(self.PLCConfigMainSizer)
   360         
   388         
   361     def _init_ctrls(self, prnt):
   389     def _init_ctrls(self, prnt):
   362         wx.Frame.__init__(self, id=ID_BEREMIZ, name=u'Beremiz',
   390         wx.Frame.__init__(self, id=ID_BEREMIZ, name=u'Beremiz',
   363               parent=prnt, pos=wx.Point(0, 0), size=wx.Size(1000, 600),
   391               parent=prnt, pos=wx.Point(0, 0), size=wx.Size(1000, 600),
   364               style=wx.DEFAULT_FRAME_STYLE|wx.CLIP_CHILDREN, title=u'Beremiz')
   392               style=wx.DEFAULT_FRAME_STYLE|wx.CLIP_CHILDREN, title=_(u'Beremiz'))
   365         self._init_utils()
   393         self._init_utils()
   366         self.SetClientSize(wx.Size(1000, 600))
   394         self.SetClientSize(wx.Size(1000, 600))
   367         self.SetMenuBar(self.MenuBar)
   395         self.SetMenuBar(self.MenuBar)
   368         self.Bind(wx.EVT_ACTIVATE, self.OnFrameActivated)
   396         self.Bind(wx.EVT_ACTIVATE, self.OnFrameActivated)
   369         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
   397         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
   402             self.AUIManager.SetDockSizeConstraint(0.5, 0.5)
   430             self.AUIManager.SetDockSizeConstraint(0.5, 0.5)
   403             
   431             
   404             self.AUIManager.AddPane(self.PLCConfig, wx.aui.AuiPaneInfo().CenterPane())
   432             self.AUIManager.AddPane(self.PLCConfig, wx.aui.AuiPaneInfo().CenterPane())
   405             
   433             
   406             self.AUIManager.AddPane(self.LogConsole, wx.aui.AuiPaneInfo().
   434             self.AUIManager.AddPane(self.LogConsole, wx.aui.AuiPaneInfo().
   407                 Caption("Log Console").Bottom().Layer(1).
   435                 Caption(_("Log Console")).Bottom().Layer(1).
   408                 BestSize(wx.Size(800, 200)).CloseButton(False))
   436                 BestSize(wx.Size(800, 200)).CloseButton(False))
   409         
   437         
   410             self.AUIManager.Update()
   438             self.AUIManager.Update()
   411 
   439 
   412         self._init_sizers()
   440         self._init_sizers()
   490 		
   518 		
   491     def OnCloseFrame(self, event):
   519     def OnCloseFrame(self, event):
   492         if self.PluginRoot is not None:
   520         if self.PluginRoot is not None:
   493             if self.PluginRoot.ProjectTestModified():
   521             if self.PluginRoot.ProjectTestModified():
   494                 dialog = wx.MessageDialog(self,
   522                 dialog = wx.MessageDialog(self,
   495                                           "Save changes ?",
   523                                           _("Save changes ?"),
   496                                           "Close Application", 
   524                                           _("Close Application"), 
   497                                           wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
   525                                           wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
   498                 answer = dialog.ShowModal()
   526                 answer = dialog.ShowModal()
   499                 dialog.Destroy()
   527                 dialog.Destroy()
   500                 if answer == wx.ID_YES:
   528                 if answer == wx.ID_YES:
   501                     self.PluginRoot.SaveProject()
   529                     self.PluginRoot.SaveProject()
   579             
   607             
   580             addbutton_id = wx.NewId()
   608             addbutton_id = wx.NewId()
   581             addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Add.png')),
   609             addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Add.png')),
   582                   name='AddPluginButton', parent=plcwindow, pos=wx.Point(0, 0),
   610                   name='AddPluginButton', parent=plcwindow, pos=wx.Point(0, 0),
   583                   size=wx.Size(16, 16), style=wx.NO_BORDER)
   611                   size=wx.Size(16, 16), style=wx.NO_BORDER)
   584             addbutton.SetToolTipString("Add a sub plugin")
   612             addbutton.SetToolTipString(_("Add a sub plugin"))
   585             addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddPluginMenu(self.PluginRoot), id=addbutton_id)
   613             addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddPluginMenu(self.PluginRoot), id=addbutton_id)
   586             plcwindowsizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
   614             plcwindowsizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
   587     
   615     
   588             plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL)
   616             plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL)
   589             plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL)
   617             plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL)
   675         else:
   703         else:
   676             msizer = wx.FlexGridSizer(cols=1)
   704             msizer = wx.FlexGridSizer(cols=1)
   677         for plugin_method in plugin.PluginMethods:
   705         for plugin_method in plugin.PluginMethods:
   678             if "method" in plugin_method and plugin_method.get("shown",True):
   706             if "method" in plugin_method and plugin_method.get("shown",True):
   679                 id = wx.NewId()
   707                 id = wx.NewId()
   680                 label=plugin_method["name"]
   708                 label = plugin_method["name"]
   681                 button = GenBitmapTextButton(id=id, parent=parent,
   709                 button = GenBitmapTextButton(id=id, parent=parent,
   682                     bitmap=wx.Bitmap(Bpath( "%s.png"%plugin_method.get("bitmap", os.path.join("images", "Unknown")))), label=label, 
   710                     bitmap=wx.Bitmap(Bpath( "%s.png"%plugin_method.get("bitmap", os.path.join("images", "Unknown")))), label=label, 
   683                     name=label, pos=wx.DefaultPosition, style=wx.NO_BORDER)
   711                     name=label, pos=wx.DefaultPosition, style=wx.NO_BORDER)
   684                 button.SetFont(self.normal_bt_font)
   712                 button.SetFont(self.normal_bt_font)
   685                 button.SetToolTipString(plugin_method["tooltip"])
   713                 button.SetToolTipString(plugin_method["tooltip"])
   782         leftsizer.AddSizer(rolesizer, 0, border=0, flag=wx.GROW|wx.RIGHT)
   810         leftsizer.AddSizer(rolesizer, 0, border=0, flag=wx.GROW|wx.RIGHT)
   783 
   811 
   784         enablebutton_id = wx.NewId()
   812         enablebutton_id = wx.NewId()
   785         enablebutton = wx.lib.buttons.GenBitmapToggleButton(id=enablebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Disabled.png')),
   813         enablebutton = wx.lib.buttons.GenBitmapToggleButton(id=enablebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Disabled.png')),
   786               name='EnableButton', parent=leftwindow, size=wx.Size(16, 16), pos=wx.Point(0, 0), style=0)#wx.NO_BORDER)
   814               name='EnableButton', parent=leftwindow, size=wx.Size(16, 16), pos=wx.Point(0, 0), style=0)#wx.NO_BORDER)
   787         enablebutton.SetToolTipString("Enable/Disable this plugin")
   815         enablebutton.SetToolTipString(_("Enable/Disable this plugin"))
   788         make_genbitmaptogglebutton_flat(enablebutton)
   816         make_genbitmaptogglebutton_flat(enablebutton)
   789         enablebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Enabled.png')))
   817         enablebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Enabled.png')))
   790         enablebutton.SetToggle(plugin.MandatoryParams[1].getEnabled())
   818         enablebutton.SetToggle(plugin.MandatoryParams[1].getEnabled())
   791         def toggleenablebutton(event):
   819         def toggleenablebutton(event):
   792             res = self.SetPluginParamsAttribute(plugin, "BaseParams.Enabled", enablebutton.GetToggle())
   820             res = self.SetPluginParamsAttribute(plugin, "BaseParams.Enabled", enablebutton.GetToggle())
   832 
   860 
   833         deletebutton_id = wx.NewId()
   861         deletebutton_id = wx.NewId()
   834         deletebutton = wx.lib.buttons.GenBitmapButton(id=deletebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Delete.png')),
   862         deletebutton = wx.lib.buttons.GenBitmapButton(id=deletebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Delete.png')),
   835               name='DeletePluginButton', parent=leftwindow, pos=wx.Point(0, 0),
   863               name='DeletePluginButton', parent=leftwindow, pos=wx.Point(0, 0),
   836               size=wx.Size(16, 16), style=wx.NO_BORDER)
   864               size=wx.Size(16, 16), style=wx.NO_BORDER)
   837         deletebutton.SetToolTipString("Delete this plugin")
   865         deletebutton.SetToolTipString(_("Delete this plugin"))
   838         deletebutton.Bind(wx.EVT_BUTTON, self.GetDeleteButtonFunction(plugin), id=deletebutton_id)
   866         deletebutton.Bind(wx.EVT_BUTTON, self.GetDeleteButtonFunction(plugin), id=deletebutton_id)
   839         adddeletesizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
   867         adddeletesizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
   840 
   868 
   841         if len(plugin.PlugChildsTypes) > 0:
   869         if len(plugin.PlugChildsTypes) > 0:
   842             addbutton_id = wx.NewId()
   870             addbutton_id = wx.NewId()
   843             addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Add.png')),
   871             addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Add.png')),
   844                   name='AddPluginButton', parent=leftwindow, pos=wx.Point(0, 0),
   872                   name='AddPluginButton', parent=leftwindow, pos=wx.Point(0, 0),
   845                   size=wx.Size(16, 16), style=wx.NO_BORDER)
   873                   size=wx.Size(16, 16), style=wx.NO_BORDER)
   846             addbutton.SetToolTipString("Add a sub plugin")
   874             addbutton.SetToolTipString(_("Add a sub plugin"))
   847             addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddPluginMenu(plugin), id=addbutton_id)
   875             addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddPluginMenu(plugin), id=addbutton_id)
   848             adddeletesizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
   876             adddeletesizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
   849         
   877         
   850         expandbutton_id = wx.NewId()
   878         expandbutton_id = wx.NewId()
   851         expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'plus.png')),
   879         expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'plus.png')),
  1023         def AddPluginMenu(event):
  1051         def AddPluginMenu(event):
  1024             main_menu = wx.Menu(title='')
  1052             main_menu = wx.Menu(title='')
  1025             if len(plugin.PlugChildsTypes) > 0:
  1053             if len(plugin.PlugChildsTypes) > 0:
  1026                 for name, XSDClass, help in plugin.PlugChildsTypes:
  1054                 for name, XSDClass, help in plugin.PlugChildsTypes:
  1027                     new_id = wx.NewId()
  1055                     new_id = wx.NewId()
  1028                     main_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text="Append "+help)
  1056                     main_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=_("Append ")+help)
  1029                     self.Bind(wx.EVT_MENU, self._GetAddPluginFunction(name, plugin), id=new_id)
  1057                     self.Bind(wx.EVT_MENU, self._GetAddPluginFunction(name, plugin), id=new_id)
  1030             self.PopupMenuXY(main_menu)
  1058             self.PopupMenuXY(main_menu)
  1031             event.Skip()
  1059             event.Skip()
  1032         return AddPluginMenu
  1060         return AddPluginMenu
  1033     
  1061     
  1108             if path:
  1136             if path:
  1109                 element_path = "%s.%s"%(path, element_infos["name"])
  1137                 element_path = "%s.%s"%(path, element_infos["name"])
  1110             else:
  1138             else:
  1111                 element_path = element_infos["name"]
  1139                 element_path = element_infos["name"]
  1112             if element_infos["type"] == "element":
  1140             if element_infos["type"] == "element":
  1113                 staticbox = wx.StaticBox(id=-1, label=element_infos["name"], 
  1141                 label = element_infos["name"]
       
  1142                 staticbox = wx.StaticBox(id=-1, label=_(label), 
  1114                     name='%s_staticbox'%element_infos["name"], parent=parent,
  1143                     name='%s_staticbox'%element_infos["name"], parent=parent,
  1115                     pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0)
  1144                     pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0)
  1116                 staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
  1145                 staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
  1117                 if first:
  1146                 if first:
  1118                     sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW|wx.TOP)
  1147                     sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW|wx.TOP)
  1128                     sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
  1157                     sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
  1129                 staticbitmap = GenStaticBitmap(ID=-1, bitmapname="%s.png"%element_infos["name"],
  1158                 staticbitmap = GenStaticBitmap(ID=-1, bitmapname="%s.png"%element_infos["name"],
  1130                     name="%s_bitmap"%element_infos["name"], parent=parent,
  1159                     name="%s_bitmap"%element_infos["name"], parent=parent,
  1131                     pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
  1160                     pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
  1132                 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT)
  1161                 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT)
  1133                 statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], 
  1162                 label = element_infos["name"]
       
  1163                 statictext = wx.StaticText(id=-1, label="%s:"%_(label), 
  1134                     name="%s_label"%element_infos["name"], parent=parent, 
  1164                     name="%s_label"%element_infos["name"], parent=parent, 
  1135                     pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0)
  1165                     pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
  1136                 boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP)
  1166                 boxsizer.AddWindow(statictext, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.RIGHT)
  1137                 id = wx.NewId()
  1167                 id = wx.NewId()
  1138                 if isinstance(element_infos["type"], types.ListType):
  1168                 if isinstance(element_infos["type"], types.ListType):
  1139                     combobox = wx.ComboBox(id=id, name=element_infos["name"], parent=parent, 
  1169                     combobox = wx.ComboBox(id=id, name=element_infos["name"], parent=parent, 
  1140                         pos=wx.Point(0, 0), size=wx.Size(150, 28), style=wx.CB_READONLY)
  1170                         pos=wx.Point(0, 0), size=wx.Size(150, 28), style=wx.CB_READONLY)
  1141                     boxsizer.AddWindow(combobox, 0, border=0, flag=0)
  1171                     boxsizer.AddWindow(combobox, 0, border=0, flag=0)
  1142                     if element_infos["use"] == "optional":
  1172                     if element_infos["use"] == "optional":
  1143                         combobox.Append("")
  1173                         combobox.Append("")
  1144                     if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType):
  1174                     if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType):
  1145                         for choice, xsdclass in element_infos["type"]:
  1175                         for choice, xsdclass in element_infos["type"]:
  1146                             combobox.Append(choice)
  1176                             combobox.Append(choice)
  1147                         staticbox = wx.StaticBox(id=-1, label="%(name)s - %(value)s"%element_infos, 
  1177                         name = element_infos["name"]
       
  1178                         value = element_infos["value"]
       
  1179                         staticbox = wx.StaticBox(id=-1, label="%s - %s"%(_(name), _(value)), 
  1148                             name='%s_staticbox'%element_infos["name"], parent=parent,
  1180                             name='%s_staticbox'%element_infos["name"], parent=parent,
  1149                             pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0)
  1181                             pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0)
  1150                         staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
  1182                         staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
  1151                         sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM)
  1183                         sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM)
  1152                         self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path)
  1184                         self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path)
  1212         if not config.HasEntry("lastopenedfolder"):
  1244         if not config.HasEntry("lastopenedfolder"):
  1213             defaultpath = os.path.expanduser("~")
  1245             defaultpath = os.path.expanduser("~")
  1214         else:
  1246         else:
  1215             defaultpath = config.Read("lastopenedfolder")
  1247             defaultpath = config.Read("lastopenedfolder")
  1216         
  1248         
  1217         dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON)
  1249         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
  1218         if dialog.ShowModal() == wx.ID_OK:
  1250         if dialog.ShowModal() == wx.ID_OK:
  1219             projectpath = dialog.GetPath()
  1251             projectpath = dialog.GetPath()
  1220             dialog.Destroy()
  1252             dialog.Destroy()
  1221             config.Write("lastopenedfolder", os.path.dirname(projectpath))
  1253             config.Write("lastopenedfolder", os.path.dirname(projectpath))
  1222             config.Flush()
  1254             config.Flush()
  1224             res = self.PluginRoot.NewProject(projectpath)
  1256             res = self.PluginRoot.NewProject(projectpath)
  1225             if not res :
  1257             if not res :
  1226                 self.RefreshAll()
  1258                 self.RefreshAll()
  1227                 self.RefreshMainMenu()
  1259                 self.RefreshMainMenu()
  1228             else:
  1260             else:
  1229                 message = wx.MessageDialog(self, res, "ERROR", wx.OK|wx.ICON_ERROR)
  1261                 message = wx.MessageDialog(self, res, _("ERROR"), wx.OK|wx.ICON_ERROR)
  1230                 message.ShowModal()
  1262                 message.ShowModal()
  1231                 message.Destroy()
  1263                 message.Destroy()
  1232         event.Skip()
  1264         event.Skip()
  1233     
  1265     
  1234     def OnOpenProjectMenu(self, event):
  1266     def OnOpenProjectMenu(self, event):
  1235         if not config.HasEntry("lastopenedfolder"):
  1267         if not config.HasEntry("lastopenedfolder"):
  1236             defaultpath = os.path.expanduser("~")
  1268             defaultpath = os.path.expanduser("~")
  1237         else:
  1269         else:
  1238             defaultpath = config.Read("lastopenedfolder")
  1270             defaultpath = config.Read("lastopenedfolder")
  1239         
  1271         
  1240         dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON)
  1272         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
  1241         if dialog.ShowModal() == wx.ID_OK:
  1273         if dialog.ShowModal() == wx.ID_OK:
  1242             projectpath = dialog.GetPath()
  1274             projectpath = dialog.GetPath()
  1243             if os.path.isdir(projectpath):
  1275             if os.path.isdir(projectpath):
  1244                 config.Write("lastopenedfolder", os.path.dirname(projectpath))
  1276                 config.Write("lastopenedfolder", os.path.dirname(projectpath))
  1245                 config.Flush()
  1277                 config.Flush()
  1247                 result = self.PluginRoot.LoadProject(projectpath)
  1279                 result = self.PluginRoot.LoadProject(projectpath)
  1248                 if not result:
  1280                 if not result:
  1249                     self.RefreshAll()
  1281                     self.RefreshAll()
  1250                     self.RefreshMainMenu()
  1282                     self.RefreshMainMenu()
  1251                 else:
  1283                 else:
  1252                     message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
  1284                     message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
  1253                     message.ShowModal()
  1285                     message.ShowModal()
  1254                     message.Destroy()
  1286                     message.Destroy()
  1255             else:
  1287             else:
  1256                 message = wx.MessageDialog(self, "\"%s\" folder is not a valid Beremiz project\n"%projectpath, "Error", wx.OK|wx.ICON_ERROR)
  1288                 message = wx.MessageDialog(self, _("\"%s\" folder is not a valid Beremiz project\n")%projectpath, _("Error"), wx.OK|wx.ICON_ERROR)
  1257                 message.ShowModal()
  1289                 message.ShowModal()
  1258                 message.Destroy()
  1290                 message.Destroy()
  1259             dialog.Destroy()
  1291             dialog.Destroy()
  1260         event.Skip()
  1292         event.Skip()
  1261     
  1293     
  1262     def OnCloseProjectMenu(self, event):
  1294     def OnCloseProjectMenu(self, event):
  1263         if self.PluginRoot is not None:
  1295         if self.PluginRoot is not None:
  1264             if self.PluginRoot.ProjectTestModified():
  1296             if self.PluginRoot.ProjectTestModified():
  1265                 dialog = wx.MessageDialog(self,
  1297                 dialog = wx.MessageDialog(self,
  1266                                           "Save changes ?",
  1298                                           _("Save changes ?"),
  1267                                           "Close Application", 
  1299                                           _("Close Application"), 
  1268                                           wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
  1300                                           wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
  1269                 answer = dialog.ShowModal()
  1301                 answer = dialog.ShowModal()
  1270                 dialog.Destroy()
  1302                 dialog.Destroy()
  1271                 if answer == wx.ID_YES:
  1303                 if answer == wx.ID_YES:
  1272                     self.PluginRoot.SaveProject()
  1304                     self.PluginRoot.SaveProject()
  1320     def OnBeremizMenu(self, event):
  1352     def OnBeremizMenu(self, event):
  1321         open_pdf(Bpath( "doc", "manual_beremiz.pdf"))
  1353         open_pdf(Bpath( "doc", "manual_beremiz.pdf"))
  1322         event.Skip()
  1354         event.Skip()
  1323     
  1355     
  1324     def OnAboutMenu(self, event):
  1356     def OnAboutMenu(self, event):
  1325         OpenHtmlFrame(self,"About Beremiz", Bpath("doc","about.html"), wx.Size(550, 500))
  1357         OpenHtmlFrame(self,_("About Beremiz"), Bpath("doc","about.html"), wx.Size(550, 500))
  1326         event.Skip()
  1358         event.Skip()
  1327     
  1359     
  1328     def OnAddButton(self, event):
  1360     def OnAddButton(self, event):
  1329         PluginType = self.PluginChilds.GetStringSelection()
  1361         PluginType = self.PluginChilds.GetStringSelection()
  1330         if PluginType != "":
  1362         if PluginType != "":
  1353             wx.CallAfter(self.DeletePlugin, plugin)
  1385             wx.CallAfter(self.DeletePlugin, plugin)
  1354             event.Skip()
  1386             event.Skip()
  1355         return DeleteButtonFunction
  1387         return DeleteButtonFunction
  1356     
  1388     
  1357     def AddPlugin(self, PluginType, plugin):
  1389     def AddPlugin(self, PluginType, plugin):
  1358         dialog = wx.TextEntryDialog(self, "Please enter a name for plugin:", "Add Plugin", "", wx.OK|wx.CANCEL)
  1390         dialog = wx.TextEntryDialog(self, _("Please enter a name for plugin:"), _("Add Plugin"), "", wx.OK|wx.CANCEL)
  1359         if dialog.ShowModal() == wx.ID_OK:
  1391         if dialog.ShowModal() == wx.ID_OK:
  1360             PluginName = dialog.GetValue()
  1392             PluginName = dialog.GetValue()
  1361             plugin.PlugAddChild(PluginName, PluginType)
  1393             plugin.PlugAddChild(PluginName, PluginType)
  1362             self.RefreshPluginTree()
  1394             self.RefreshPluginTree()
  1363         dialog.Destroy()
  1395         dialog.Destroy()
  1364     
  1396     
  1365     def DeletePlugin(self, plugin):
  1397     def DeletePlugin(self, plugin):
  1366         dialog = wx.MessageDialog(self, "Really delete plugin ?", "Remove plugin", wx.YES_NO|wx.NO_DEFAULT)
  1398         dialog = wx.MessageDialog(self, _("Really delete plugin ?"), _("Remove plugin"), wx.YES_NO|wx.NO_DEFAULT)
  1367         if dialog.ShowModal() == wx.ID_YES:
  1399         if dialog.ShowModal() == wx.ID_YES:
  1368             self.PluginInfos.pop(plugin)
  1400             self.PluginInfos.pop(plugin)
  1369             plugin.PlugRemove()
  1401             plugin.PlugRemove()
  1370             del plugin
  1402             del plugin
  1371             self.RefreshPluginTree()
  1403             self.RefreshPluginTree()
  1378 Max_Traceback_List_Size = 20
  1410 Max_Traceback_List_Size = 20
  1379 
  1411 
  1380 def Display_Exception_Dialog(e_type, e_value, e_tb, bug_report_path):
  1412 def Display_Exception_Dialog(e_type, e_value, e_tb, bug_report_path):
  1381     trcbck_lst = []
  1413     trcbck_lst = []
  1382     for i,line in enumerate(traceback.extract_tb(e_tb)):
  1414     for i,line in enumerate(traceback.extract_tb(e_tb)):
  1383         trcbck = " " + str(i+1) + ". "
  1415         trcbck = " " + str(i+1) + _(". ")
  1384         if line[0].find(os.getcwd()) == -1:
  1416         if line[0].find(os.getcwd()) == -1:
  1385             trcbck += "file : " + str(line[0]) + ",   "
  1417             trcbck += _("file : ") + str(line[0]) + _(",   ")
  1386         else:
  1418         else:
  1387             trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ",   "
  1419             trcbck += _("file : ") + str(line[0][len(os.getcwd()):]) + _(",   ")
  1388         trcbck += "line : " + str(line[1]) + ",   " + "function : " + str(line[2])
  1420         trcbck += _("line : ") + str(line[1]) + _(",   ") + _("function : ") + str(line[2])
  1389         trcbck_lst.append(trcbck)
  1421         trcbck_lst.append(trcbck)
  1390         
  1422         
  1391     # Allow clicking....
  1423     # Allow clicking....
  1392     cap = wx.Window_GetCapture()
  1424     cap = wx.Window_GetCapture()
  1393     if cap:
  1425     if cap:
  1394         cap.ReleaseMouse()
  1426         cap.ReleaseMouse()
  1395 
  1427 
  1396     dlg = wx.SingleChoiceDialog(None, 
  1428     dlg = wx.SingleChoiceDialog(None, 
  1397         """
  1429         _("""
  1398 An unhandled exception (bug) occured. Bug report saved at :
  1430 An unhandled exception (bug) occured. Bug report saved at :
  1399 (%s)
  1431 (%s)
  1400 
  1432 
  1401 Please contact LOLITech at:
  1433 Please contact LOLITech at:
  1402 +33 (0)3 29 57 60 42
  1434 +33 (0)3 29 57 60 42
  1404 bugs_beremiz@lolitech.fr
  1436 bugs_beremiz@lolitech.fr
  1405 
  1437 
  1406 You should now restart Beremiz.
  1438 You should now restart Beremiz.
  1407 
  1439 
  1408 Traceback:
  1440 Traceback:
  1409 """ % bug_report_path +
  1441 """) % bug_report_path +
  1410         str(e_type) + " : " + str(e_value), 
  1442         str(e_type) + " : " + str(e_value), 
  1411         "Error",
  1443         _("Error"),
  1412         trcbck_lst)
  1444         trcbck_lst)
  1413     try:
  1445     try:
  1414         res = (dlg.ShowModal() == wx.ID_OK)
  1446         res = (dlg.ShowModal() == wx.ID_OK)
  1415     finally:
  1447     finally:
  1416         dlg.Destroy()
  1448         dlg.Destroy()
  1417 
  1449 
  1418     return res
  1450     return res
  1419 
  1451 
  1420 def Display_Error_Dialog(e_value):
  1452 def Display_Error_Dialog(e_value):
  1421     message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR)
  1453     message = wxMessageDialog(None, str(e_value), _("Error"), wxOK|wxICON_ERROR)
  1422     message.ShowModal()
  1454     message.ShowModal()
  1423     message.Destroy()
  1455     message.Destroy()
  1424 
  1456 
  1425 def get_last_traceback(tb):
  1457 def get_last_traceback(tb):
  1426     while tb.tb_next:
  1458     while tb.tb_next: