64 from Beremiz import * |
64 from Beremiz import * |
65 from plugger import PluginsRoot, PlugTemplate, opjimg, connectors |
65 from plugger import PluginsRoot, PlugTemplate, opjimg, connectors |
66 from plcopen.structures import LOCATIONDATATYPES |
66 from plcopen.structures import LOCATIONDATATYPES |
67 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP,\ |
67 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP,\ |
68 LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY |
68 LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY |
69 from PLCOpenEditor import IDEFrame |
69 from PLCOpenEditor import IDEFrame, ProjectDialog |
70 |
70 |
71 #------------------------------------------------------------------------------- |
71 #------------------------------------------------------------------------------- |
72 # LPCModule Class |
72 # LPCModule Class |
73 #------------------------------------------------------------------------------- |
73 #------------------------------------------------------------------------------- |
74 |
74 |
487 Load a project contained in a folder |
487 Load a project contained in a folder |
488 @param ProjectPath: path of the project folder |
488 @param ProjectPath: path of the project folder |
489 """ |
489 """ |
490 if os.path.basename(ProjectPath) == "": |
490 if os.path.basename(ProjectPath) == "": |
491 ProjectPath = os.path.dirname(ProjectPath) |
491 ProjectPath = os.path.dirname(ProjectPath) |
|
492 |
492 # Verify that project contains a PLCOpen program |
493 # Verify that project contains a PLCOpen program |
493 plc_file = os.path.join(ProjectPath, "plc.xml") |
494 plc_file = os.path.join(ProjectPath, "plc.xml") |
494 if not os.path.isfile(plc_file): |
495 if os.path.isfile(plc_file): |
495 return _("Chosen folder doesn't contain a program. It's not a valid project!") |
496 # Load PLCOpen file |
496 # Load PLCOpen file |
497 result = self.OpenXMLFile(plc_file) |
497 result = self.OpenXMLFile(plc_file) |
498 if result: |
498 if result: |
499 return result |
499 return result |
500 else: |
|
501 self.CreateNewProject({"companyName": "", |
|
502 "productName": "", |
|
503 "productVersion": "", |
|
504 "projectName": "", |
|
505 "pageSize": (0, 0), |
|
506 "scaling": {}}) |
|
507 |
500 # Change XSD into class members |
508 # Change XSD into class members |
501 self._AddParamsMembers() |
509 self._AddParamsMembers() |
502 self.PluggedChilds = {} |
510 self.PluggedChilds = {} |
|
511 |
503 # Keep track of the root plugin (i.e. project path) |
512 # Keep track of the root plugin (i.e. project path) |
504 self.ProjectPath = ProjectPath |
513 self.ProjectPath = ProjectPath |
|
514 |
505 self.BuildPath = self._getBuildPath() |
515 self.BuildPath = self._getBuildPath() |
506 if BuildPath is not None: |
516 if BuildPath is not None: |
507 mycopytree(BuildPath, self.BuildPath) |
517 mycopytree(BuildPath, self.BuildPath) |
508 |
518 |
509 # If dir have already be made, and file exist |
519 # If dir have already be made, and file exist |
769 self.PluginRoot.KillDebugThread() |
783 self.PluginRoot.KillDebugThread() |
770 self.KillLocalRuntime() |
784 self.KillLocalRuntime() |
771 |
785 |
772 event.Skip() |
786 event.Skip() |
773 |
787 |
|
788 def ShowProperties(self): |
|
789 old_values = self.Controler.GetProjectProperties() |
|
790 dialog = ProjectDialog(self ,False) |
|
791 dialog.SetValues(old_values) |
|
792 if dialog.ShowModal() == wx.ID_OK: |
|
793 new_values = dialog.GetValues() |
|
794 new_values["creationDateTime"] = old_values["creationDateTime"] |
|
795 if new_values != old_values: |
|
796 self.Controler.SetProjectProperties(None, new_values) |
|
797 self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, |
|
798 TYPESTREE, INSTANCESTREE, SCALING) |
|
799 dialog.Destroy() |
|
800 |
774 def RefreshFileMenu(self): |
801 def RefreshFileMenu(self): |
775 if self.PluginRoot is not None: |
802 if self.PluginRoot is not None: |
776 selected = self.TabsOpened.GetSelection() |
803 selected = self.TabsOpened.GetSelection() |
777 if selected >= 0: |
804 if selected >= 0: |
778 graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer) |
805 graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer) |
789 else: |
816 else: |
790 self.FileMenu.Enable(wx.ID_CLOSE, False) |
817 self.FileMenu.Enable(wx.ID_CLOSE, False) |
791 self.FileMenu.Enable(wx.ID_PREVIEW, False) |
818 self.FileMenu.Enable(wx.ID_PREVIEW, False) |
792 self.FileMenu.Enable(wx.ID_PRINT, False) |
819 self.FileMenu.Enable(wx.ID_PRINT, False) |
793 self.FileMenu.Enable(wx.ID_PAGE_SETUP, True) |
820 self.FileMenu.Enable(wx.ID_PAGE_SETUP, True) |
794 self.FileMenu.Enable(wx.ID_SAVE, True) |
821 self.FileMenu.Enable(wx.ID_SAVE, self.PluginRoot.PlugTestModified()) |
795 self.FileMenu.Enable(wx.ID_PROPERTIES, True) |
822 self.FileMenu.Enable(wx.ID_PROPERTIES, True) |
796 else: |
823 else: |
797 self.FileMenu.Enable(wx.ID_CLOSE, False) |
824 self.FileMenu.Enable(wx.ID_CLOSE, False) |
798 self.FileMenu.Enable(wx.ID_PAGE_SETUP, False) |
825 self.FileMenu.Enable(wx.ID_PAGE_SETUP, False) |
799 self.FileMenu.Enable(wx.ID_PREVIEW, False) |
826 self.FileMenu.Enable(wx.ID_PREVIEW, False) |
1055 if wx.GetApp() is None: |
1082 if wx.GetApp() is None: |
1056 self.PluginRoot._build() |
1083 self.PluginRoot._build() |
1057 else: |
1084 else: |
1058 wx.CallAfter(self.PluginRoot._build) |
1085 wx.CallAfter(self.PluginRoot._build) |
1059 |
1086 |
1060 def SetProjectName(self, name): |
1087 def SetProjectProperties(self, projectname, productname, productversion, companyname): |
1061 self.PluginRoot.SetProjectName(name) |
1088 properties = self.PluginRoot.GetProjectProperties() |
|
1089 properties["projectName"] = projectname |
|
1090 properties["productName"] = productname |
|
1091 properties["productVersion"] = productversion |
|
1092 properties["companyName"] = companyname |
|
1093 self.PluginRoot.SetProjectProperties(properties=properties) |
1062 self.RestartTimer() |
1094 self.RestartTimer() |
1063 |
1095 |
1064 def SetOnlineMode(self, mode, path=None): |
1096 def SetOnlineMode(self, mode, path=None): |
1065 self.PluginRoot.SetOnlineMode(mode, path) |
1097 self.PluginRoot.SetOnlineMode(mode, path) |
1066 self.RestartTimer() |
1098 self.RestartTimer() |
1284 for function, (arg_types, opt) in {"Exit": ([], 0), |
1316 for function, (arg_types, opt) in {"Exit": ([], 0), |
1285 "Show": ([], 0), |
1317 "Show": ([], 0), |
1286 "Refresh": ([], 0), |
1318 "Refresh": ([], 0), |
1287 "Close": ([], 0), |
1319 "Close": ([], 0), |
1288 "Compile": ([], 0), |
1320 "Compile": ([], 0), |
1289 "SetProjectName": ([str], 0), |
1321 "SetProjectProperties": ([str, str, str, str], 0), |
1290 "SetOnlineMode": ([int, str], 1), |
1322 "SetOnlineMode": ([int, str], 1), |
1291 "AddBus": ([int, str, str], 1), |
1323 "AddBus": ([int, str, str], 1), |
1292 "RenameBus": ([int, str], 0), |
1324 "RenameBus": ([int, str], 0), |
1293 "ChangeBusIECChannel": ([int, int], 0), |
1325 "ChangeBusIECChannel": ([int, int], 0), |
1294 "RemoveBus": ([int], 0), |
1326 "RemoveBus": ([int], 0), |