Changes merged
authorlaurent
Thu, 10 Dec 2009 12:31:42 +0100
changeset 501 d7bf56b036a8
parent 500 af7c28de4cc7 (diff)
parent 498 c78246f3b85b (current diff)
child 502 5343ae43f6d0
Changes merged
LPCBeremiz.py
--- a/Beremiz.py	Thu Dec 10 10:13:37 2009 +0100
+++ b/Beremiz.py	Thu Dec 10 12:31:42 2009 +0100
@@ -563,7 +563,7 @@
                 self.FileMenu.Enable(wx.ID_PREVIEW, False)
                 self.FileMenu.Enable(wx.ID_PRINT, False)
             self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
-            self.FileMenu.Enable(wx.ID_SAVE, True)
+            self.FileMenu.Enable(wx.ID_SAVE, self.PluginRoot.PlugTestModified())
             self.FileMenu.Enable(wx.ID_SAVEAS, True)
             self.FileMenu.Enable(wx.ID_PROPERTIES, True)
             self.FileMenu.Enable(wx.ID_CLOSE_ALL, True)
--- a/LPCBeremiz.py	Thu Dec 10 10:13:37 2009 +0100
+++ b/LPCBeremiz.py	Thu Dec 10 12:31:42 2009 +0100
@@ -66,7 +66,7 @@
 from plcopen.structures import LOCATIONDATATYPES
 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP,\
                          LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
-from PLCOpenEditor import IDEFrame
+from PLCOpenEditor import IDEFrame, ProjectDialog
 
 #-------------------------------------------------------------------------------
 #                              LPCModule Class
@@ -490,19 +490,29 @@
         """
         if os.path.basename(ProjectPath) == "":
             ProjectPath = os.path.dirname(ProjectPath)
+        
         # Verify that project contains a PLCOpen program
         plc_file = os.path.join(ProjectPath, "plc.xml")
-        if not os.path.isfile(plc_file):
-            return _("Chosen folder doesn't contain a program. It's not a valid project!")
-        # Load PLCOpen file
-        result = self.OpenXMLFile(plc_file)
-        if result:
-            return result
+        if os.path.isfile(plc_file):
+            # Load PLCOpen file
+            result = self.OpenXMLFile(plc_file)
+            if result:
+                return result
+        else:
+            self.CreateNewProject({"companyName": "",
+                                   "productName": "",
+                                   "productVersion": "",
+                                   "projectName": "",
+                                   "pageSize": (0, 0),
+                                   "scaling": {}})
+        
         # Change XSD into class members
         self._AddParamsMembers()
         self.PluggedChilds = {}
+        
         # Keep track of the root plugin (i.e. project path)
         self.ProjectPath = ProjectPath
+        
         self.BuildPath = self._getBuildPath()
         if BuildPath is not None:
             mycopytree(BuildPath, self.BuildPath)
@@ -515,6 +525,10 @@
                 return result
             #Load and init all the childs
             self.LoadChilds()
+        
+        if self.PlugTestModified():
+            self.SaveProject()
+        
         self.RefreshPluginsBlockLists()
 
         return None
@@ -772,6 +786,19 @@
         
         event.Skip()
 
+    def ShowProperties(self):
+        old_values = self.Controler.GetProjectProperties()
+        dialog = ProjectDialog(self ,False)
+        dialog.SetValues(old_values)
+        if dialog.ShowModal() == wx.ID_OK:
+            new_values = dialog.GetValues()
+            new_values["creationDateTime"] = old_values["creationDateTime"]
+            if new_values != old_values:
+                self.Controler.SetProjectProperties(None, new_values)
+                self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, 
+                              TYPESTREE, INSTANCESTREE, SCALING)
+        dialog.Destroy()
+
     def RefreshFileMenu(self):
         if self.PluginRoot is not None:
             selected = self.TabsOpened.GetSelection()
@@ -792,7 +819,7 @@
                 self.FileMenu.Enable(wx.ID_PREVIEW, False)
                 self.FileMenu.Enable(wx.ID_PRINT, False)
             self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
-            self.FileMenu.Enable(wx.ID_SAVE, True)
+            self.FileMenu.Enable(wx.ID_SAVE, self.PluginRoot.PlugTestModified())
             self.FileMenu.Enable(wx.ID_PROPERTIES, True)
         else:
             self.FileMenu.Enable(wx.ID_CLOSE, False)
@@ -1058,8 +1085,13 @@
             else:
                 wx.CallAfter(self.PluginRoot._build)
         
-        def SetProjectName(self, name):
-            self.PluginRoot.SetProjectName(name)
+        def SetProjectProperties(self, projectname, productname, productversion, companyname):
+            properties = self.PluginRoot.GetProjectProperties()
+            properties["projectName"] = projectname
+            properties["productName"] = productname
+            properties["productVersion"] = productversion
+            properties["companyName"] = companyname
+            self.PluginRoot.SetProjectProperties(properties=properties)
             self.RestartTimer()
         
         def SetOnlineMode(self, mode, path=None):
@@ -1287,7 +1319,7 @@
                                        "Refresh": ([], 0),
                                        "Close": ([], 0),
                                        "Compile": ([], 0),
-                                       "SetProjectName": ([str], 0),
+                                       "SetProjectProperties": ([str, str, str, str], 0),
                                        "SetOnlineMode": ([int, str], 1),
                                        "AddBus": ([int, str, str], 1),
                                        "RenameBus": ([int, str], 0),