396 message = wx.MessageDialog(self, "Folder choosen isn't empty. You can't use it for a new project!", "ERROR", wx.OK|wx.ICON_ERROR) |
399 message = wx.MessageDialog(self, "Folder choosen isn't empty. You can't use it for a new project!", "ERROR", wx.OK|wx.ICON_ERROR) |
397 message.ShowModal() |
400 message.ShowModal() |
398 message.Destroy() |
401 message.Destroy() |
399 event.Skip() |
402 event.Skip() |
400 |
403 |
|
404 def OpenProject(self, projectpath): |
|
405 try: |
|
406 if not os.path.isdir(projectpath): |
|
407 raise Exception |
|
408 self.BusManagers = {} |
|
409 configpath = os.path.join(projectpath, ".project") |
|
410 if not os.path.isfile(configpath): |
|
411 raise Exception |
|
412 file = open(configpath, "r") |
|
413 lines = [line.strip() for line in file.readlines() if line.strip() != ""] |
|
414 if lines[0] != "Beremiz": |
|
415 file.close() |
|
416 raise Exception |
|
417 for bus_id, bus_type, bus_name in [line.split(" ") for line in lines[1:]]: |
|
418 id = int(bus_id, 16) |
|
419 if bus_type == "CanFestival": |
|
420 manager = NodeManager(os.path.join(base_folder, "CanFestival-3", "objdictgen")) |
|
421 nodelist = NodeList(manager) |
|
422 result = nodelist.LoadProject(projectpath, bus_name) |
|
423 if not result: |
|
424 self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type, "NodeList" : nodelist, "Editor" : None} |
|
425 else: |
|
426 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) |
|
427 message.ShowModal() |
|
428 message.Destroy() |
|
429 else: |
|
430 self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type} |
|
431 file.close() |
|
432 self.PLCManager = PLCControler() |
|
433 plc_file = os.path.join(projectpath, "plc.xml") |
|
434 if os.path.isfile(plc_file): |
|
435 self.PLCManager.OpenXMLFile(plc_file) |
|
436 self.CurrentProjectPath = projectpath |
|
437 else: |
|
438 dialog = ProjectDialog(self) |
|
439 if dialog.ShowModal() == wx.ID_OK: |
|
440 values = dialog.GetValues() |
|
441 projectname = values.pop("projectName") |
|
442 values["creationDateTime"] = datetime(*localtime()[:6]) |
|
443 self.PLCManager.CreateNewProject(projectname) |
|
444 self.PLCManager.SetProjectProperties(values) |
|
445 self.PLCManager.SaveXMLFile(plc_file) |
|
446 self.CurrentProjectPath = projectpath |
|
447 dialog.Destroy() |
|
448 self.RefreshBusList() |
|
449 self.RefreshButtons() |
|
450 self.RefreshMainMenu() |
|
451 except Exception: |
|
452 message = wx.MessageDialog(self, "\"%s\" folder is not a valid Beremiz project"%projectpath, "Error", wx.OK|wx.ICON_ERROR) |
|
453 message.ShowModal() |
|
454 message.Destroy() |
|
455 |
401 def OnOpenProjectMenu(self, event): |
456 def OnOpenProjectMenu(self, event): |
402 if self.CurrentProjectPath != "": |
457 if self.CurrentProjectPath != "": |
403 defaultpath = self.CurrentProjectPath |
458 defaultpath = self.CurrentProjectPath |
404 else: |
459 else: |
405 defaultpath = os.getcwd() |
460 defaultpath = os.getcwd() |
406 dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON) |
461 dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON) |
407 if dialog.ShowModal() == wx.ID_OK: |
462 if dialog.ShowModal() == wx.ID_OK: |
408 projectpath = dialog.GetPath() |
463 self.OpenProject(dialog.GetPath()) |
409 dialog.Destroy() |
464 dialog.Destroy() |
410 try: |
|
411 if not os.path.isdir(projectpath): |
|
412 raise Exception |
|
413 self.BusManagers = {} |
|
414 configpath = os.path.join(projectpath, ".project") |
|
415 if not os.path.isfile(configpath): |
|
416 raise Exception |
|
417 file = open(configpath, "r") |
|
418 lines = [line.strip() for line in file.readlines() if line.strip() != ""] |
|
419 if lines[0] != "Beremiz": |
|
420 file.close() |
|
421 raise Exception |
|
422 for bus_id, bus_type, bus_name in [line.split(" ") for line in lines[1:]]: |
|
423 id = int(bus_id, 16) |
|
424 if bus_type == "CanFestival": |
|
425 manager = NodeManager(os.path.join(base_folder, "CanFestival-3", "objdictgen")) |
|
426 nodelist = NodeList(manager) |
|
427 result = nodelist.LoadProject(projectpath, bus_name) |
|
428 if not result: |
|
429 self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type, "NodeList" : nodelist, "Editor" : None} |
|
430 else: |
|
431 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) |
|
432 message.ShowModal() |
|
433 message.Destroy() |
|
434 else: |
|
435 self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type} |
|
436 file.close() |
|
437 self.PLCManager = PLCControler() |
|
438 plc_file = os.path.join(projectpath, "plc.xml") |
|
439 if os.path.isfile(plc_file): |
|
440 self.PLCManager.OpenXMLFile(plc_file) |
|
441 self.CurrentProjectPath = projectpath |
|
442 else: |
|
443 dialog = ProjectDialog(self) |
|
444 if dialog.ShowModal() == wx.ID_OK: |
|
445 values = dialog.GetValues() |
|
446 projectname = values.pop("projectName") |
|
447 values["creationDateTime"] = datetime(*localtime()[:6]) |
|
448 self.PLCManager.CreateNewProject(projectname) |
|
449 self.PLCManager.SetProjectProperties(values) |
|
450 self.PLCManager.SaveXMLFile(plc_file) |
|
451 self.CurrentProjectPath = projectpath |
|
452 dialog.Destroy() |
|
453 self.RefreshBusList() |
|
454 self.RefreshButtons() |
|
455 self.RefreshMainMenu() |
|
456 except Exception: |
|
457 message = wx.MessageDialog(self, "\"%s\" folder is not a valid Beremiz project"%projectpath, "Error", wx.OK|wx.ICON_ERROR) |
|
458 message.ShowModal() |
|
459 message.Destroy() |
|
460 event.Skip() |
465 event.Skip() |
461 |
466 |
462 def OnCloseProjectMenu(self, event): |
467 def OnCloseProjectMenu(self, event): |
463 self.PLCManager = None |
468 self.PLCManager = None |
464 self.CurrentProjectPath = projectpath |
469 self.CurrentProjectPath = projectpath |