437 defaultpath = os.getcwd() |
437 defaultpath = os.getcwd() |
438 dialog = wxDirDialog(self , "Choose a project", defaultpath, wxDD_NEW_DIR_BUTTON) |
438 dialog = wxDirDialog(self , "Choose a project", defaultpath, wxDD_NEW_DIR_BUTTON) |
439 if dialog.ShowModal() == wxID_OK: |
439 if dialog.ShowModal() == wxID_OK: |
440 projectpath = dialog.GetPath() |
440 projectpath = dialog.GetPath() |
441 dialog.Destroy() |
441 dialog.Destroy() |
442 if os.path.isdir(projectpath): |
442 try: |
|
443 if os.path.isdir(projectpath): |
|
444 raise Exception |
443 self.BusManagers = {} |
445 self.BusManagers = {} |
444 configpath = os.path.join(projectpath, ".project") |
446 configpath = os.path.join(projectpath, ".project") |
445 if os.path.isfile(configpath): |
447 if not os.path.isfile(configpath): |
446 file = open(configpath, "r") |
448 raise |
447 for bus_id, bus_type, bus_name in [line.strip().split(" ") for line in file.readlines() if line.strip() != ""]: |
449 file = open(configpath, "r") |
448 if bus_type == "CanFestival": |
450 lines = [line.strip() for line in file.readlines() if line.strip() != ""] |
449 id = int(bus_id, 16) |
451 if line[0] != "Beremiz": |
450 manager = NodeManager(os.path.join(base_folder, "CanFestival-3", "objdictgen")) |
452 file.close() |
451 nodelist = NodeList(manager) |
453 raise Exception |
452 result = nodelist.LoadProject(projectpath, bus_name) |
454 for bus_id, bus_type, bus_name in [line.split(" ") for line in lines]: |
453 if not result: |
455 id = int(bus_id, 16) |
454 self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type, "NodeList" : nodelist, "Editor" : None} |
456 if bus_type == "CanFestival": |
455 else: |
457 manager = NodeManager(os.path.join(base_folder, "CanFestival-3", "objdictgen")) |
456 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
458 nodelist = NodeList(manager) |
457 message.ShowModal() |
459 result = nodelist.LoadProject(projectpath, bus_name) |
458 message.Destroy() |
460 if not result: |
|
461 self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type, "NodeList" : nodelist, "Editor" : None} |
459 else: |
462 else: |
460 self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type} |
463 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
461 file.close() |
464 message.ShowModal() |
|
465 message.Destroy() |
|
466 else: |
|
467 self.BusManagers[id] = {"Name" : bus_name, "Type" : bus_type} |
|
468 file.close() |
462 self.PLCManager = PLCControler() |
469 self.PLCManager = PLCControler() |
463 plc_file = os.path.join(projectpath, "plc.xml") |
470 plc_file = os.path.join(projectpath, "plc.xml") |
464 if os.path.isfile(plc_file): |
471 if os.path.isfile(plc_file): |
465 self.PLCManager.OpenXMLFile(plc_file) |
472 self.PLCManager.OpenXMLFile(plc_file) |
466 self.CurrentProjectPath = projectpath |
473 self.CurrentProjectPath = projectpath |
476 self.CurrentProjectPath = projectpath |
483 self.CurrentProjectPath = projectpath |
477 dialog.Destroy() |
484 dialog.Destroy() |
478 self.RefreshBusList() |
485 self.RefreshBusList() |
479 self.RefreshButtons() |
486 self.RefreshButtons() |
480 self.RefreshMainMenu() |
487 self.RefreshMainMenu() |
|
488 except Exception: |
|
489 message = wxMessageDialog(self, "\"%s\" folder is not a valid Beremiz project"%projectpath, "Error", wxOK|wxICON_ERROR) |
|
490 message.ShowModal() |
|
491 message.Destroy() |
481 event.Skip() |
492 event.Skip() |
482 |
493 |
483 def OnCloseProjectMenu(self, event): |
494 def OnCloseProjectMenu(self, event): |
484 self.PLCManager = None |
495 self.PLCManager = None |
485 self.CurrentProjectPath = projectpath |
496 self.CurrentProjectPath = projectpath |