--- a/Beremiz.py Wed Aug 08 14:54:48 2007 +0200
+++ b/Beremiz.py Thu Aug 09 18:05:09 2007 +0200
@@ -318,6 +318,9 @@
self.Log = LogPseudoFile(self.LogConsole)
+ self.OpenProject(projectOpen) @@ -398,6 +401,58 @@
+ def OpenProject(self, projectpath): + if not os.path.isdir(projectpath): + configpath = os.path.join(projectpath, ".project") + if not os.path.isfile(configpath): + file = open(configpath, "r") + lines = [line.strip() for line in file.readlines() if line.strip() != ""] + if lines[0] != "Beremiz": + for bus_id, bus_type, bus_name in [line.split(" ") for line in lines[1:]]: + if bus_type == "CanFestival": + manager = NodeManager(os.path.join(base_folder, "CanFestival-3", "objdictgen")) + nodelist = NodeList(manager) + result = nodelist.LoadProject(projectpath, bus_name) + self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type, "NodeList" : nodelist, "Editor" : None} + message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) + self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type} + self.PLCManager = PLCControler() + plc_file = os.path.join(projectpath, "plc.xml") + if os.path.isfile(plc_file): + self.PLCManager.OpenXMLFile(plc_file) + self.CurrentProjectPath = projectpath + dialog = ProjectDialog(self) + if dialog.ShowModal() == wx.ID_OK: + values = dialog.GetValues() + projectname = values.pop("projectName") + values["creationDateTime"] = datetime(*localtime()[:6]) + self.PLCManager.CreateNewProject(projectname) + self.PLCManager.SetProjectProperties(values) + self.PLCManager.SaveXMLFile(plc_file) + self.CurrentProjectPath = projectpath + message = wx.MessageDialog(self, "\"%s\" folder is not a valid Beremiz project"%projectpath, "Error", wx.OK|wx.ICON_ERROR) def OnOpenProjectMenu(self, event):
if self.CurrentProjectPath != "":
defaultpath = self.CurrentProjectPath
@@ -405,58 +460,8 @@
defaultpath = os.getcwd()
dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON)
if dialog.ShowModal() == wx.ID_OK:
- projectpath = dialog.GetPath()
+ self.OpenProject(dialog.GetPath())
- if not os.path.isdir(projectpath):
- configpath = os.path.join(projectpath, ".project")
- if not os.path.isfile(configpath):
- file = open(configpath, "r")
- lines = [line.strip() for line in file.readlines() if line.strip() != ""]
- if lines[0] != "Beremiz":
- for bus_id, bus_type, bus_name in [line.split(" ") for line in lines[1:]]:
- if bus_type == "CanFestival":
- manager = NodeManager(os.path.join(base_folder, "CanFestival-3", "objdictgen"))
- nodelist = NodeList(manager)
- result = nodelist.LoadProject(projectpath, bus_name)
- self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type, "NodeList" : nodelist, "Editor" : None}
- message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
- self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type}
- self.PLCManager = PLCControler()
- plc_file = os.path.join(projectpath, "plc.xml")
- if os.path.isfile(plc_file):
- self.PLCManager.OpenXMLFile(plc_file)
- self.CurrentProjectPath = projectpath
- dialog = ProjectDialog(self)
- if dialog.ShowModal() == wx.ID_OK:
- values = dialog.GetValues()
- projectname = values.pop("projectName")
- values["creationDateTime"] = datetime(*localtime()[:6])
- self.PLCManager.CreateNewProject(projectname)
- self.PLCManager.SetProjectProperties(values)
- self.PLCManager.SaveXMLFile(plc_file)
- self.CurrentProjectPath = projectpath
- message = wx.MessageDialog(self, "\"%s\" folder is not a valid Beremiz project"%projectpath, "Error", wx.OK|wx.ICON_ERROR)
def OnCloseProjectMenu(self, event):