Beremiz.py
changeset 256 1da137b99948
parent 249 a770187273e9
child 257 a4b01f57069a
equal deleted inserted replaced
255:1f660bed2ab1 256:1da137b99948
    34     return os.path.join(_local_path,*args)
    34     return os.path.join(_local_path,*args)
    35 
    35 
    36 if __name__ == '__main__':
    36 if __name__ == '__main__':
    37     def usage():
    37     def usage():
    38         print "\nUsage of Beremiz.py :"
    38         print "\nUsage of Beremiz.py :"
    39         print "\n   %s [Projectpath]\n"%sys.argv[0]
    39         print "\n   %s [Projectpath] [Buildpath]\n"%sys.argv[0]
    40     
    40     
    41     try:
    41     try:
    42         opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
    42         opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
    43     except getopt.GetoptError:
    43     except getopt.GetoptError:
    44         # print help information and exit:
    44         # print help information and exit:
    48     for o, a in opts:
    48     for o, a in opts:
    49         if o in ("-h", "--help"):
    49         if o in ("-h", "--help"):
    50             usage()
    50             usage()
    51             sys.exit()
    51             sys.exit()
    52     
    52     
    53     if len(args) > 1:
    53     if len(args) > 2:
    54         usage()
    54         usage()
    55         sys.exit()
    55         sys.exit()
    56     elif len(args) == 1:
    56     elif len(args) == 1:
    57         projectOpen = args[0]
    57         projectOpen = args[0]
       
    58     elif len(args) == 2:
       
    59         projectOpen = args[0]
       
    60         buildpath = args[1]
    58     else:
    61     else:
    59         projectOpen = None
    62         projectOpen = None
       
    63         buildpath = None
    60     
    64     
    61     app = wx.PySimpleApp()
    65     app = wx.PySimpleApp()
    62     wx.InitAllImageHandlers()
    66     wx.InitAllImageHandlers()
    63     
    67     
    64     bmp = wx.Image(Bpath("images","splash.png")).ConvertToBitmap()
    68     bmp = wx.Image(Bpath("images","splash.png")).ConvertToBitmap()
   402         
   406         
   403             self.AUIManager.Update()
   407             self.AUIManager.Update()
   404 
   408 
   405         self._init_sizers()
   409         self._init_sizers()
   406 
   410 
   407     def __init__(self, parent, projectOpen):
   411     def __init__(self, parent, projectOpen, buildpath):
   408         self._init_ctrls(parent)
   412         self._init_ctrls(parent)
   409         
   413         
   410         self.Log = LogPseudoFile(self.LogConsole)
   414         self.Log = LogPseudoFile(self.LogConsole)
   411         
   415         
   412         # create temporary directory for runtime working directory
   416         # create temporary directory for runtime working directory
   428         
   432         
   429         self.PluginInfos = {}
   433         self.PluginInfos = {}
   430         
   434         
   431         if projectOpen:
   435         if projectOpen:
   432             self.PluginRoot = PluginsRoot(self, self.Log, self.runtime_port)
   436             self.PluginRoot = PluginsRoot(self, self.Log, self.runtime_port)
   433             self.PluginRoot.LoadProject(projectOpen)
   437             self.PluginRoot.LoadProject(projectOpen, buildpath)
   434             self.RefreshPLCParams()
   438             self.RefreshPLCParams()
   435             self.RefreshPluginTree()
   439             self.RefreshPluginTree()
   436         else:
   440         else:
   437             self.PluginRoot = None
   441             self.PluginRoot = None
   438         
   442         
  1171                         textctrl.ChangeValue(str(element_infos["value"]))
  1175                         textctrl.ChangeValue(str(element_infos["value"]))
  1172                         textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path))
  1176                         textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path))
  1173             first = False
  1177             first = False
  1174     
  1178     
  1175     def OnNewProjectMenu(self, event):
  1179     def OnNewProjectMenu(self, event):
  1176         defaultpath = ""
  1180         defaultpath = config.Read("workspacedir")
  1177         if self.PluginRoot is not None:
  1181         if self.PluginRoot is not None:
  1178             defaultpath = self.PluginRoot.GetProjectPath()
  1182             defaultpath = self.PluginRoot.GetProjectPath()
  1179         if not defaultpath:
  1183         
  1180             defaultpath = os.getcwd()
       
  1181         dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON)
  1184         dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON)
  1182         if dialog.ShowModal() == wx.ID_OK:
  1185         if dialog.ShowModal() == wx.ID_OK:
  1183             projectpath = dialog.GetPath()
  1186             projectpath = dialog.GetPath()
  1184             dialog.Destroy()
  1187             dialog.Destroy()
  1185             self.PluginRoot = PluginsRoot(self, self.Log, self.runtime_port)
  1188             self.PluginRoot = PluginsRoot(self, self.Log, self.runtime_port)
  1193                 message.ShowModal()
  1196                 message.ShowModal()
  1194                 message.Destroy()
  1197                 message.Destroy()
  1195         event.Skip()
  1198         event.Skip()
  1196     
  1199     
  1197     def OnOpenProjectMenu(self, event):
  1200     def OnOpenProjectMenu(self, event):
  1198         defaultpath = ""
  1201         defaultpath = config.Read("workspacedir")
  1199         if self.PluginRoot is not None:
  1202         if self.PluginRoot is not None:
  1200             defaultpath = self.PluginRoot.GetProjectPath()
  1203             defaultpath = self.PluginRoot.GetProjectPath()
  1201         if not defaultpath:
  1204         
  1202             defaultpath = os.getcwd()
       
  1203         dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON)
  1205         dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON)
  1204         if dialog.ShowModal() == wx.ID_OK:
  1206         if dialog.ShowModal() == wx.ID_OK:
  1205             projectpath = dialog.GetPath()
  1207             projectpath = dialog.GetPath()
  1206             if os.path.isdir(projectpath):
  1208             if os.path.isdir(projectpath):
  1207                 self.PluginRoot = PluginsRoot(self, self.Log, self.runtime_port)
  1209                 self.PluginRoot = PluginsRoot(self, self.Log, self.runtime_port)
  1440 
  1442 
  1441 if __name__ == '__main__':
  1443 if __name__ == '__main__':
  1442     # Install a exception handle for bug reports
  1444     # Install a exception handle for bug reports
  1443     AddExceptHook(os.getcwd(),__version__)
  1445     AddExceptHook(os.getcwd(),__version__)
  1444     
  1446     
  1445     frame = Beremiz(None, projectOpen)
  1447     frame = Beremiz(None, projectOpen, buildpath)
  1446     frame.Show()
  1448     frame.Show()
  1447     splash.Close()
  1449     splash.Close()
  1448 
  1450     config = wx.ConfigBase.Get()
       
  1451     if not config.HasEntry("workspacedir"):
       
  1452         defaultpath = os.path.expanduser("~")
       
  1453         dialog = wx.DirDialog(frame, "Select a Workspace", defaultpath, wx.DD_NEW_DIR_BUTTON)
       
  1454         if dialog.ShowModal() == wx.ID_OK:
       
  1455             defaultpath = dialog.GetPath()
       
  1456             dialog.Destroy()        
       
  1457         config.Write("workspacedir", defaultpath)
       
  1458         config.Flush()
  1449     app.MainLoop()
  1459     app.MainLoop()