# HG changeset patch # User laurent # Date 1342568028 -7200 # Node ID 67b47775ba2117dd0d1c5a7130da54dc6191df26 # Parent f49875b9e946420de2ca1f25db0048df23706411# Parent 52d3a084d2b2bfeacee4781808b311dc4a500938 Merged diff -r f49875b9e946 -r 67b47775ba21 Beremiz.py --- a/Beremiz.py Fri Jul 06 21:00:43 2012 +0200 +++ b/Beremiz.py Wed Jul 18 01:33:48 2012 +0200 @@ -168,6 +168,7 @@ from docutil import OpenHtmlFrame from PLCOpenEditor import IDEFrame, AppendMenu, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES from PLCOpenEditor import EditorPanel, Viewer, TextViewer, GraphicViewer, ResourceEditor, ConfigurationEditor, DataTypeEditor +from PLCOpenEditor import EncodeFileSystemPath, DecodeFileSystemPath from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY, ITEM_PROJECT, ITEM_RESOURCE MAX_RECENT_PROJECTS = 10 @@ -435,9 +436,15 @@ # Add beremiz's icon in top left corner of the frame self.SetIcon(wx.Icon(Bpath("images", "brz.ico"), wx.BITMAP_TYPE_ICO)) + if projectOpen is not None: + projectOpen = DecodeFileSystemPath(projectOpen, False) + if ctr is None and projectOpen is None and self.Config.HasEntry("currenteditedproject"): - projectOpen = str(self.Config.Read("currenteditedproject")) - if projectOpen == "": + try: + projectOpen = DecodeFileSystemPath(self.Config.Read("currenteditedproject")) + if projectOpen == "": + projectOpen = None + except: projectOpen = None if projectOpen is not None and os.path.isdir(projectOpen): @@ -591,7 +598,7 @@ project_path = os.path.realpath(self.CTR.GetProjectPath()) else: project_path = "" - self.Config.Write("currenteditedproject", project_path) + self.Config.Write("currenteditedproject", EncodeFileSystemPath(project_path)) self.Config.Flush() event.Skip() @@ -645,7 +652,8 @@ self.FileMenu.Enable(wx.ID_CLOSE_ALL, False) def RefreshRecentProjectsMenu(self): - recent_projects = cPickle.loads(str(self.Config.Read("RecentProjects", cPickle.dumps([])))) + recent_projects = map(DecodeFileSystemPath, + self.GetConfigEntry("RecentProjects", [])) self.FileMenu.Enable(ID_FILEMENURECENTPROJECTS, len(recent_projects) > 0) for idx, projectpath in enumerate(recent_projects): text = u'%d: %s' % (idx + 1, projectpath) @@ -780,11 +788,13 @@ self.DebugVariablePanel.SetDataProducer(None) def RefreshConfigRecentProjects(self, projectpath): - recent_projects = cPickle.loads(str(self.Config.Read("RecentProjects", cPickle.dumps([])))) + recent_projects = map(DecodeFileSystemPath, + self.GetConfigEntry("RecentProjects", [])) if projectpath in recent_projects: recent_projects.remove(projectpath) recent_projects.insert(0, projectpath) - self.Config.Write("RecentProjects", cPickle.dumps(recent_projects[:MAX_RECENT_PROJECTS])) + self.Config.Write("RecentProjects", cPickle.dumps( + map(EncodeFileSystemPath, recent_projects[:MAX_RECENT_PROJECTS]))) self.Config.Flush() def ResetPerspective(self): @@ -799,15 +809,16 @@ if self.CTR is not None and not self.CheckSaveBeforeClosing(): return - if not self.Config.HasEntry("lastopenedfolder"): + try: + defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder")) + except: defaultpath = os.path.expanduser("~") - else: - defaultpath = self.Config.Read("lastopenedfolder") dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON) if dialog.ShowModal() == wx.ID_OK: projectpath = dialog.GetPath() - self.Config.Write("lastopenedfolder", os.path.dirname(projectpath)) + self.Config.Write("lastopenedfolder", + EncodeFileSystemPath(os.path.dirname(projectpath))) self.Config.Flush() self.ResetView() ctr = ProjectController(self, self.Log) @@ -833,10 +844,10 @@ if self.CTR is not None and not self.CheckSaveBeforeClosing(): return - if not self.Config.HasEntry("lastopenedfolder"): + try: + defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder")) + except: defaultpath = os.path.expanduser("~") - else: - defaultpath = self.Config.Read("lastopenedfolder") dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON) if dialog.ShowModal() == wx.ID_OK: @@ -845,7 +856,8 @@ def OpenProject(self, projectpath): if os.path.isdir(projectpath): - self.Config.Write("lastopenedfolder", os.path.dirname(projectpath)) + self.Config.Write("lastopenedfolder", + EncodeFileSystemPath(os.path.dirname(projectpath))) self.Config.Flush() self.ResetView() self.CTR = ProjectController(self, self.Log) diff -r f49875b9e946 -r 67b47775ba21 ProjectController.py --- a/ProjectController.py Fri Jul 06 21:00:43 2012 +0200 +++ b/ProjectController.py Wed Jul 18 01:33:48 2012 +0200 @@ -995,35 +995,40 @@ return self._ProjectFilesView - elif name is not None and os.path.isfile(name): - if not self._FileEditors.has_key(name): - file_extension = os.path.splitext(name)[1] + elif name is not None and name.find("::") != -1: + filepath, editor_name = name.split("::") + if not self._FileEditors.has_key(filepath): + if os.path.isfile(filepath): + file_extension = os.path.splitext(filepath)[1] + + editors = dict([(editor_name, editor) + for extension, editor_name, editor in features.file_editors + if extension == file_extension]) + + if editor_name == "": + if len(editors) == 1: + editor_name = editors.keys()[0] + elif len(editors) > 0: + names = editors.keys() + dialog = wx.SingleChoiceDialog(self.AppFrame, + _("Select an editor:"), _("Editor selection"), + names, wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) + if dialog.ShowModal() == wx.ID_OK: + editor_name = names[dialog.GetSelection()] + dialog.Destroy() + + if editor_name != "": + name = "::".join([filepath, editor_name]) + + editor = editors[editor_name]() + self._FileEditors[filepath] = editor(self.AppFrame.TabsOpened, self, name, self.AppFrame) + self._FileEditors[filepath].SetIcon(GetBitmap("FILE")) + + if self._FileEditors.has_key(filepath): + editor = self._FileEditors[filepath] + self.AppFrame.EditProjectElement(editor, editor.GetTagName()) - editors = dict([(editor_name, editor) - for extension, editor_name, editor in features.file_editors - if extension == file_extension]) - - editor_name = None - if len(editors) == 1: - editor_name = editors.keys()[0] - elif len(editors) > 0: - names = editors.keys() - dialog = wx.SingleChoiceDialog(self.ParentWindow, - _("Select an editor:"), _("Editor selection"), - names, wx.OK|wx.CANCEL) - if dialog.ShowModal() == wx.ID_OK: - editor_name = names[dialog.GetSelection()] - dialog.Destroy() - - if editor_name is not None: - editor = editors[editor_name]() - self._FileEditors[name] = editor(self.AppFrame.TabsOpened, self, name, self.AppFrame) - self._FileEditors[name].SetIcon(GetBitmap("FILE")) - - if self._FileEditors.has_key(name): - self.AppFrame.EditProjectElement(self._FileEditors[name], name) - - return self._FileEditors[name] + return self._FileEditors.get(filepath) else: return ConfigTreeNode._OpenView(self, self.CTNName(), onlyopened) @@ -1361,6 +1366,7 @@ self.ChangesToSave = True if self._View is not None: self._View.RefreshView() + if self.AppFrame is not None: self.AppFrame.RefreshTitle() self.AppFrame.RefreshFileMenu() self.AppFrame.RefreshEditMenu() diff -r f49875b9e946 -r 67b47775ba21 util/FileManagementPanel.py --- a/util/FileManagementPanel.py Fri Jul 06 21:00:43 2012 +0200 +++ b/util/FileManagementPanel.py Wed Jul 18 01:33:48 2012 +0200 @@ -369,7 +369,7 @@ filepath = self.ManagedDir.GetPath() if (os.path.isfile(filepath) and os.path.splitext(filepath)[1] in self.EditableFileExtensions): - self.Controler._OpenView(filepath) + self.Controler._OpenView(filepath + "::") event.Skip() def CopyFile(self, src, dst): diff -r f49875b9e946 -r 67b47775ba21 util/ProcessLogger.py --- a/util/ProcessLogger.py Fri Jul 06 21:00:43 2012 +0200 +++ b/util/ProcessLogger.py Wed Jul 18 01:33:48 2012 +0200 @@ -27,7 +27,7 @@ import wx import subprocess, ctypes from threading import Timer, Lock, Thread, Semaphore -import os +import os, sys if os.name == 'posix': from signal import SIGTERM, SIGKILL @@ -86,7 +86,10 @@ else: self.Command = Command self.Command_str = subprocess.list2cmdline(self.Command) - + + self.Command = map(lambda x: x.encode(sys.getfilesystemencoding()), + self.Command) + self.finish_callback = finish_callback self.no_stdout = no_stdout self.no_stderr = no_stderr