Fixed Save As... function in Beremiz
--- a/Beremiz.py Wed Apr 24 10:03:47 2013 +0200
+++ b/Beremiz.py Wed Apr 24 17:27:08 2013 +0200
@@ -980,7 +980,6 @@
self.CTR.SaveProjectAs()
self.RefreshAll()
self._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES)
- event.Skip()
def OnQuitMenu(self, event):
self.Close()
--- a/ConfigTreeNode.py Wed Apr 24 10:03:47 2013 +0200
+++ b/ConfigTreeNode.py Wed Apr 24 17:27:08 2013 +0200
@@ -73,10 +73,12 @@
def ConfNodePath(self):
return os.path.join(self.CTNParent.ConfNodePath(), self.CTNType)
- def CTNPath(self,CTNName=None):
+ def CTNPath(self,CTNName=None,project_path=None):
if not CTNName:
CTNName = self.CTNName()
- return os.path.join(self.CTNParent.CTNPath(),
+ if not project_path:
+ project_path = self.CTNParent.CTNPath()
+ return os.path.join(project_path,
CTNName + NameTypeSeparator + self.CTNType)
def CTNName(self):
@@ -113,7 +115,7 @@
def RemoteExec(self, script, **kwargs):
return self.CTNParent.RemoteExec(script, **kwargs)
- def OnCTNSave(self):
+ def OnCTNSave(self, from_project_path=None):
#Default, do nothing and return success
return True
@@ -155,7 +157,7 @@
def CTNMakeDir(self):
os.mkdir(self.CTNPath())
- def CTNRequestSave(self):
+ def CTNRequestSave(self, from_project_path=None):
if self.GetCTRoot().CheckProjectPathPerm(False):
# If confnode do not have corresponding directory
ctnpath = self.CTNPath()
@@ -178,7 +180,7 @@
XMLFile.close()
# Call the confnode specific OnCTNSave method
- result = self.OnCTNSave()
+ result = self.OnCTNSave(from_project_path)
if not result:
return _("Error while saving \"%s\"\n")%self.CTNPath()
@@ -186,7 +188,8 @@
self.ChangesToSave = False
# go through all children and do the same
for CTNChild in self.IterChildren():
- result = CTNChild.CTNRequestSave()
+ result = CTNChild.CTNRequestSave(
+ CTNChild.CTNPath(project_path=from_project_path))
if result:
return result
return None
--- a/ProjectController.py Wed Apr 24 10:03:47 2013 +0200
+++ b/ProjectController.py Wed Apr 24 17:27:08 2013 +0200
@@ -234,7 +234,9 @@
return True
return False
- def _getProjectFilesPath(self):
+ def _getProjectFilesPath(self, project_path=None):
+ if project_path is not None:
+ return os.path.join(project_path, "project_files")
projectfiles_path = os.path.join(self.GetProjectPath(), "project_files")
if not os.path.exists(projectfiles_path):
os.mkdir(projectfiles_path)
@@ -348,14 +350,19 @@
self.ClearChildren()
self.ResetAppFrame(None)
- def SaveProject(self):
+ def SaveProject(self, from_project_path=None):
if self.CheckProjectPathPerm(False):
+ if from_project_path is not None:
+ old_projectfiles_path = self._getProjectFilesPath(from_project_path)
+ if os.path.isdir(old_projectfiles_path):
+ shutil.copytree(old_projectfiles_path,
+ self._getProjectFilesPath(self.ProjectPath))
self.SaveXMLFile(os.path.join(self.ProjectPath, 'plc.xml'))
- result = self.CTNRequestSave()
+ result = self.CTNRequestSave(from_project_path)
if result:
self.logger.write_error(result)
- def SaveProjectAs(self, dosave=True):
+ def SaveProjectAs(self):
# Ask user to choose a path with write permissions
if wx.Platform == '__WXMSW__':
path = os.getenv("USERPROFILE")
@@ -367,9 +374,8 @@
if answer == wx.ID_OK:
newprojectpath = dirdialog.GetPath()
if os.path.isdir(newprojectpath):
- self.ProjectPath = newprojectpath
- if dosave:
- self.SaveProject()
+ self.ProjectPath, old_project_path = newprojectpath, self.ProjectPath
+ self.SaveProject(old_project_path)
self._setBuildPath(self.BuildPath)
return True
return False
--- a/c_ext/c_ext.py Wed Apr 24 10:03:47 2013 +0200
+++ b/c_ext/c_ext.py Wed Apr 24 17:27:08 2013 +0200
@@ -144,7 +144,7 @@
def CTNTestModified(self):
return self.ChangesToSave or not self.CFileIsSaved()
- def OnCTNSave(self):
+ def OnCTNSave(self, from_project_path=None):
filepath = self.CFileName()
text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
--- a/canfestival/canfestival.py Wed Apr 24 10:03:47 2013 +0200
+++ b/canfestival/canfestival.py Wed Apr 24 17:27:08 2013 +0200
@@ -1,4 +1,4 @@
-import os, sys
+import os, sys, shutil
base_folder = os.path.split(sys.path[0])[0]
CanFestivalPath = os.path.join(base_folder, "CanFestival-3")
@@ -154,7 +154,7 @@
def CTNTestModified(self):
return self.ChangesToSave or self.OneFileHasChanged()
- def OnCTNSave(self):
+ def OnCTNSave(self, from_project_path=None):
return self.SaveCurrentInFile(self.GetSlaveODPath())
def SetParamsAttribute(self, path, value):
@@ -378,8 +378,10 @@
def CTNTestModified(self):
return self.ChangesToSave or self.HasChanged()
- def OnCTNSave(self):
+ def OnCTNSave(self, from_project_path=None):
self.SetRoot(self.CTNPath())
+ shutil.copytree(self.GetEDSFolder(from_project_path),
+ self.GetEDSFolder())
return self.SaveProject() is None
def CTNGenerate_C(self, buildpath, locations):
--- a/py_ext/PythonFileCTNMixin.py Wed Apr 24 10:03:47 2013 +0200
+++ b/py_ext/PythonFileCTNMixin.py Wed Apr 24 17:27:08 2013 +0200
@@ -48,7 +48,7 @@
def CTNTestModified(self):
return self.ChangesToSave or not self.PythonIsSaved()
- def OnCTNSave(self):
+ def OnCTNSave(self, from_project_path=None):
filepath = self.PythonFileName()
text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
--- a/svgui/svgui.py Wed Apr 24 10:03:47 2013 +0200
+++ b/svgui/svgui.py Wed Apr 24 17:27:08 2013 +0200
@@ -5,12 +5,13 @@
from POULibrary import POULibrary
from docutil import open_svg
+from py_ext import PythonFileCTNMixin
class SVGUILibrary(POULibrary):
def GetLibraryPath(self):
return os.path.join(os.path.split(__file__)[0], "pous.xml")
-class SVGUI:
+class SVGUI(PythonFileCTNMixin):
ConfNodeMethods = [
{"bitmap" : "ImportSVG",
@@ -26,13 +27,21 @@
def ConfNodePath(self):
return os.path.join(os.path.dirname(__file__))
- def _getSVGpath(self):
- # define name for IEC raw code file
- return os.path.join(self.CTNPath(), "gui.svg")
+ def _getSVGpath(self, project_path=None):
+ if project_path is None:
+ project_path = self.CTNPath()
+ # define name for SVG file containing gui layout
+ return os.path.join(project_path, "gui.svg")
def _getSVGUIserverpath(self):
return os.path.join(os.path.dirname(__file__), "svgui_server.py")
+ def OnCTNSave(self, from_project_path=None):
+ if from_project_path is not None:
+ shutil.copyfile(self._getSVGpath(from_project_path),
+ self._getSVGpath())
+ return PythonFileCTNMixin.OnCTNSave(self, from_project_path)
+
def CTNGenerate_C(self, buildpath, locations):
"""
Return C code generated by iec2c compiler
--- a/wxglade_hmi/wxglade_hmi.py Wed Apr 24 10:03:47 2013 +0200
+++ b/wxglade_hmi/wxglade_hmi.py Wed Apr 24 17:27:08 2013 +0200
@@ -1,5 +1,5 @@
import wx
-import os, sys
+import os, sys, shutil
from xml.dom import minidom
from py_ext import PythonFileCTNMixin
@@ -16,9 +16,11 @@
def ConfNodePath(self):
return os.path.join(os.path.dirname(__file__))
- def _getWXGLADEpath(self):
- # define name for IEC raw code file
- return os.path.join(self.CTNPath(), "hmi.wxg")
+ def _getWXGLADEpath(self, project_path=None):
+ if project_path is None:
+ project_path = self.CTNPath()
+ # define name for wxGlade gui file
+ return os.path.join(project_path, "hmi.wxg")
def launch_wxglade(self, options, wait=False):
from wxglade import __file__ as fileName
@@ -29,6 +31,11 @@
mode = {False:os.P_NOWAIT, True:os.P_WAIT}[wait]
os.spawnv(mode, sys.executable, ["\"%s\""%sys.executable] + [glade] + options)
+ def OnCTNSave(self, from_project_path=None):
+ if from_project_path is not None:
+ shutil.copyfile(self._getWXGLADEpath(from_project_path),
+ self._getWXGLADEpath())
+ return PythonFileCTNMixin.OnCTNSave(self, from_project_path)
def CTNGenerate_C(self, buildpath, locations):
"""
@@ -128,3 +135,4 @@
if wx.Platform == '__WXMSW__':
wxg_filename = "\"%s\""%wxg_filename
self.launch_wxglade([wxg_filename])
+