--- a/Beremiz.py Thu Oct 22 17:20:24 2009 +0200
+++ b/Beremiz.py Fri Oct 23 15:41:48 2009 +0200
@@ -293,6 +293,8 @@
kind=wx.ITEM_NORMAL, text=_(u'Open\tCTRL+O'))
AppendMenu(parent, help='', id=wx.ID_SAVE,
kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S'))
+ AppendMenu(parent, help='', id=wx.ID_SAVEAS, + kind=wx.ITEM_NORMAL, text=_(u'Save as\tCTRL+S')) AppendMenu(parent, help='', id=wx.ID_CLOSE,
kind=wx.ITEM_NORMAL, text=_(u'Close Tab\tCTRL+W'))
AppendMenu(parent, help='', id=wx.ID_CLOSE_ALL,
@@ -314,6 +316,7 @@
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
+ self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS) self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL)
self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
@@ -543,6 +546,7 @@
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_SAVEAS, True) self.FileMenu.Enable(wx.ID_PROPERTIES, True)
self.FileMenu.Enable(wx.ID_CLOSE_ALL, True)
@@ -551,6 +555,7 @@
self.FileMenu.Enable(wx.ID_PREVIEW, False)
self.FileMenu.Enable(wx.ID_PRINT, False)
self.FileMenu.Enable(wx.ID_SAVE, False)
+ self.FileMenu.Enable(wx.ID_SAVEAS, False) self.FileMenu.Enable(wx.ID_PROPERTIES, False)
self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
@@ -1370,6 +1375,13 @@
+ def OnSaveProjectAsMenu(self, event): + if self.PluginRoot is not None: + self.PluginRoot.SaveProjectAs() def OnPropertiesMenu(self, event):
@@ -1402,24 +1414,26 @@
return DeleteButtonFunction
def AddPlugin(self, PluginType, plugin):
- dialog = wx.TextEntryDialog(self, _("Please enter a name for plugin:"), _("Add Plugin"), "", wx.OK|wx.CANCEL)
- if dialog.ShowModal() == wx.ID_OK:
- PluginName = dialog.GetValue()
- plugin.PlugAddChild(PluginName, PluginType)
- self.RefreshPluginTree()
- self.PluginRoot.RefreshPluginsBlockLists()
+ if self.PluginRoot.CheckProjectPathPerm(): + dialog = wx.TextEntryDialog(self, _("Please enter a name for plugin:"), _("Add Plugin"), "", wx.OK|wx.CANCEL) + if dialog.ShowModal() == wx.ID_OK: + PluginName = dialog.GetValue() + plugin.PlugAddChild(PluginName, PluginType) + self.RefreshPluginTree() + self.PluginRoot.RefreshPluginsBlockLists() def DeletePlugin(self, plugin):
- dialog = wx.MessageDialog(self, _("Really delete plugin ?"), _("Remove plugin"), wx.YES_NO|wx.NO_DEFAULT)
- if dialog.ShowModal() == wx.ID_YES:
- self.PluginInfos.pop(plugin)
- self.PluginRoot.RefreshPluginsBlockLists()
- self.RefreshPluginTree()
+ if self.PluginRoot.CheckProjectPathPerm(): + dialog = wx.MessageDialog(self, _("Really delete plugin ?"), _("Remove plugin"), wx.YES_NO|wx.NO_DEFAULT) + if dialog.ShowModal() == wx.ID_YES: + self.PluginInfos.pop(plugin) + self.PluginRoot.RefreshPluginsBlockLists() + self.RefreshPluginTree() #-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
--- a/plugger.py Thu Oct 22 17:20:24 2009 +0200
+++ b/plugger.py Fri Oct 23 15:41:48 2009 +0200
@@ -74,7 +74,17 @@
# helper func to get path to images
return os.path.join("images",imgname)
+# helper func to check path write permission +def CheckPathPerm(path): + if path is None or not os.path.isdir(path): + for root, dirs, files in os.walk(path): + if os.access(root, os.W_OK) is not True or os.access(os.path.join(root, name), os.W_OK) is not True: This class is the one that define plugins.
@@ -181,38 +191,39 @@
os.mkdir(self.PlugPath())
def PlugRequestSave(self):
- # If plugin do not have corresponding directory
- plugpath = self.PlugPath()
- if not os.path.isdir(plugpath):
- # generate XML for base XML parameters controller of the plugin
- if self.MandatoryParams:
- BaseXMLFile = open(self.PluginBaseXmlFilePath(),'w')
- BaseXMLFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
- BaseXMLFile.write(self.MandatoryParams[1].generateXMLText(self.MandatoryParams[0], 0))
- # generate XML for XML parameters controller of the plugin
- XMLFile = open(self.PluginXmlFilePath(),'w')
- XMLFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
- XMLFile.write(self.PlugParams[1].generateXMLText(self.PlugParams[0], 0))
- # Call the plugin specific OnPlugSave method
- result = self.OnPlugSave()
- return _("Error while saving \"%s\"\n")%self.PlugPath()
- self.ChangesToSave = False
- # go through all childs and do the same
- for PlugChild in self.IterChilds():
- result = PlugChild.PlugRequestSave()
+ if self.GetPlugRoot().CheckProjectPathPerm(False): + # If plugin do not have corresponding directory + plugpath = self.PlugPath() + if not os.path.isdir(plugpath): + # generate XML for base XML parameters controller of the plugin + if self.MandatoryParams: + BaseXMLFile = open(self.PluginBaseXmlFilePath(),'w') + BaseXMLFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") + BaseXMLFile.write(self.MandatoryParams[1].generateXMLText(self.MandatoryParams[0], 0)) + # generate XML for XML parameters controller of the plugin + XMLFile = open(self.PluginXmlFilePath(),'w') + XMLFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") + XMLFile.write(self.PlugParams[1].generateXMLText(self.PlugParams[0], 0)) + # Call the plugin specific OnPlugSave method + result = self.OnPlugSave() + return _("Error while saving \"%s\"\n")%self.PlugPath() + self.ChangesToSave = False + # go through all childs and do the same + for PlugChild in self.IterChilds(): + result = PlugChild.PlugRequestSave() def PlugImport(self, src_PlugPath):
@@ -690,7 +701,7 @@
from discovery import DiscoveryDialog
@@ -764,7 +775,7 @@
self.PlugType = "Beremiz"
# After __init__ root plugin is not valid
+ self._setBuildPath(None) self.previous_plcstate = None
@@ -852,6 +863,23 @@
if path.startswith("BeremizRoot.TargetType.") and self.BeremizRoot.getTargetType().getcontent() is None:
self.BeremizRoot.setTargetType(self.GetDefaultTarget())
return PlugTemplate.SetParamsAttribute(self, path, value)
+ # helper func to check project path write permission + def CheckProjectPathPerm(self, dosave=True): + if CheckPathPerm(self.ProjectPath): + dialog = wx.MessageDialog(self.AppFrame, + _('You must have write permission to work on the project\nWork on a project copy ?'), + wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) + answer = dialog.ShowModal() + if answer == wx.ID_YES: + if self.SaveProjectAs(): + self.AppFrame.RefreshAll() + self.AppFrame.RefreshTitle() def NewProject(self, ProjectPath, BuildPath=None):
@@ -879,7 +907,7 @@
# Keep track of the root plugin (i.e. project path)
self.ProjectPath = ProjectPath
- self.BuildPath = BuildPath
+ self._setBuildPath(BuildPath) # get plugins bloclist (is that usefull at project creation?)
self.RefreshPluginsBlockLists()
# this will create files base XML files
@@ -906,7 +934,7 @@
# Keep track of the root plugin (i.e. project path)
self.ProjectPath = ProjectPath
- self.BuildPath = BuildPath
+ self._setBuildPath(BuildPath) # If dir have already be made, and file exist
if os.path.isdir(self.PlugPath()) and os.path.isfile(self.PluginXmlFilePath()):
#Load the plugin.xml file into parameters members
@@ -930,11 +958,26 @@
- if not self.SaveXMLFile():
+ if self.CheckProjectPathPerm(False): self.SaveXMLFile(os.path.join(self.ProjectPath, 'plc.xml'))
- result = self.PlugRequestSave()
- self.logger.write_error(result)
+ result = self.PlugRequestSave() + self.logger.write_error(result) + def SaveProjectAs(self, dosave=True): + # Ask user to choose a path with write permissions + dirdialog = wx.DirDialog(self.AppFrame , _("Choose a directory to save project"), os.getenv("HOME"), wx.DD_NEW_DIR_BUTTON) + answer = dirdialog.ShowModal() + newprojectpath = dirdialog.GetPath() + if os.path.isdir(newprojectpath): + self.ProjectPath = newprojectpath + self._setBuildPath(self.BuildPath) # Update PLCOpenEditor Plugin Block types from loaded plugins
def RefreshPluginsBlockLists(self):
@@ -971,10 +1014,33 @@
def ParentsBlockTypesFactory(self):
return self.BlockTypesFactory()
+ def _setBuildPath(self, buildpath): + if CheckPathPerm(buildpath): + self.BuildPath = buildpath + self.BuildPath = buildpath + self.DefaultBuildPath = None + if self._builder is not None: + self._builder.SetBuildPath(self._getBuildPath()) - if self.BuildPath is None:
- return os.path.join(self.ProjectPath, "build")
+ # BuildPath is defined by user + if self.BuildPath is not None: + # BuildPath isn't defined by user but already created by default + if self.DefaultBuildPath is not None: + return self.DefaultBuildPath + # Create a build path in project folder if user has permissions + if CheckPathPerm(self.ProjectPath): + self.DefaultBuildPath = os.path.join(self.ProjectPath, "build") + # Create a build path in temp folder + self.DefaultBuildPath = os.path.join(tempfile.mkdtemp(), os.path.basename(self.ProjectPath), "build") + if not os.path.exists(self.DefaultBuildPath): + os.makedirs(self.DefaultBuildPath) + return self.DefaultBuildPath def _getExtraFilesPath(self):
return os.path.join(self._getBuildPath(), "extra_files")
--- a/plugins/c_ext/CFileEditor.py Thu Oct 22 17:20:24 2009 +0200
+++ b/plugins/c_ext/CFileEditor.py Fri Oct 23 15:41:48 2009 +0200
@@ -908,14 +908,12 @@
selected = self.PartsOpened.GetSelection()
self.PartsOpened.DeletePage(selected)
def OnSaveMenu(self, event):
if getattr(self, "_onsave", None) != None:
#-------------------------------------------------------------------------------
# Notebook Unified Functions
@@ -957,7 +955,6 @@
window = self.PartsOpened.GetPage(selected)
def OnUndoMenu(self, event):
self.Controler.LoadPrevious()
@@ -967,7 +964,6 @@
def OnRedoMenu(self, event):
self.Controler.LoadNext()
@@ -977,7 +973,6 @@
#-------------------------------------------------------------------------------
# CFile Editor Panels Management Functions
--- a/plugins/canfestival/canfestival.py Thu Oct 22 17:20:24 2009 +0200
+++ b/plugins/canfestival/canfestival.py Fri Oct 23 15:41:48 2009 +0200
@@ -100,16 +100,31 @@
- self.GetPlugRoot().SaveProject()
- self._View = objdictedit(self.GetPlugRoot().AppFrame, self)
- # TODO redefine BusId when IEC channel change
- self._View.SetBusId(self.GetCurrentLocation())
- self._View._onclose = _onclose
- self._View._onsave = _onsave
+ open_objdictedit = True + has_permissions = self.GetPlugRoot().CheckProjectPathPerm() + if not has_permissions: + dialog = wx.MessageDialog(self.GetPlugRoot().AppFrame, + _("You don't have write permissions.\nOpen ObjDictEdit anyway ?"), + wx.YES_NO|wx.ICON_QUESTION) + open_objdictedit = dialog.ShowModal() == wx.ID_YES + self.GetPlugRoot().SaveProject() + self._View = objdictedit(self.GetPlugRoot().AppFrame, self) + # TODO redefine BusId when IEC channel change + self._View.SetBusId(self.GetCurrentLocation()) + self._View._onclose = _onclose + self._View._onsave = _onsave {"bitmap" : os.path.join("images", "NetworkEdit"),
@@ -185,16 +200,30 @@
- self.GetPlugRoot().SaveProject()
- self._View = networkedit(self.GetPlugRoot().AppFrame, self)
- # TODO redefine BusId when IEC channel change
- self._View.SetBusId(self.GetCurrentLocation())
- self._View._onclose = _onclose
- self._View._onsave = _onsave
+ open_networkedit = True + has_permissions = self.GetPlugRoot().CheckProjectPathPerm() + if not has_permissions: + dialog = wx.MessageDialog(self.GetPlugRoot().AppFrame, + _("You don't have write permissions.\nOpen NetworkEdit anyway ?"), + wx.YES_NO|wx.ICON_QUESTION) + open_networkedit = dialog.ShowModal() == wx.ID_YES + self.GetPlugRoot().SaveProject() + self._View = networkedit(self.GetPlugRoot().AppFrame, self) + # TODO redefine BusId when IEC channel change + self._View.SetBusId(self.GetCurrentLocation()) + self._View._onclose = _onclose + self._View._onsave = _onsave def _ShowMasterGenerated(self):
buildpath = self._getBuildPath()
--- a/plugins/python/PythonEditor.py Thu Oct 22 17:20:24 2009 +0200
+++ b/plugins/python/PythonEditor.py Fri Oct 23 15:41:48 2009 +0200
@@ -560,7 +560,6 @@
title = _("PythonEditor")
@@ -577,19 +576,17 @@
def OnRefreshMenu(self, event):
self.PythonEdited.RefreshView()
def OnUndoMenu(self, event):
self.Controler.LoadPrevious()
self.PythonEdited.RefreshView()
def OnRedoMenu(self, event):
self.Controler.LoadNext()
self.PythonEdited.RefreshView()
--- a/plugins/python/modules/svgui/svgui.py Thu Oct 22 17:20:24 2009 +0200
+++ b/plugins/python/modules/svgui/svgui.py Fri Oct 23 15:41:48 2009 +0200
@@ -98,6 +98,15 @@
def _StartInkscape(self):
svgfile = self._getSVGpath()
- if not os.path.isfile(svgfile):
+ if not self.GetPlugRoot().CheckProjectPathPerm(): + dialog = wx.MessageDialog(self.GetPlugRoot().AppFrame, + _("You don't have write permissions.\nOpen Inkscape anyway ?"), + wx.YES_NO|wx.ICON_QUESTION) + open_inkscape = dialog.ShowModal() == wx.ID_YES + if not os.path.isfile(svgfile): --- a/targets/toolchain_gcc.py Thu Oct 22 17:20:24 2009 +0200
+++ b/targets/toolchain_gcc.py Fri Oct 23 15:41:48 2009 +0200
@@ -12,11 +12,8 @@
def __init__(self, PluginsRootInstance):
self.PluginsRootInstance = PluginsRootInstance
- self.exe = PluginsRootInstance.GetProjectName() + self.extension
- self.buildpath = PluginsRootInstance._getBuildPath()
- self.exe_path = os.path.join(self.buildpath, self.exe)
+ self.SetBuildPath(self.PluginsRootInstance._getBuildPath()) target = self.PluginsRootInstance.BeremizRoot.getTargetType()
@@ -54,7 +51,15 @@
return open(self._GetMD5FileName(), "r").read()
+ def SetBuildPath(self, buildpath): + if self.buildpath != buildpath: + self.buildpath = buildpath + self.exe = self.PluginsRootInstance.GetProjectName() + self.extension + self.exe_path = os.path.join(self.buildpath, self.exe) def check_and_update_hash_and_deps(self, bn):
# Get latest computed hash and deps
oldhash, deps = self.srcmd5.get(bn,(None,[]))