260 |
260 |
261 #------------------------------------------------------------------------------- |
261 #------------------------------------------------------------------------------- |
262 # Helper Functions |
262 # Helper Functions |
263 #------------------------------------------------------------------------------- |
263 #------------------------------------------------------------------------------- |
264 |
264 |
|
265 import base64 |
|
266 |
|
267 def EncodeFileSystemPath(path, use_base64=True): |
|
268 path = path.encode(sys.getfilesystemencoding()) |
|
269 if use_base64: |
|
270 return base64.encodestring(path) |
|
271 return path |
|
272 |
|
273 def DecodeFileSystemPath(path, is_base64=True): |
|
274 if is_base64: |
|
275 path = base64.decodestring(path) |
|
276 return unicode(path, sys.getfilesystemencoding()) |
|
277 |
265 # Compatibility function for wx versions < 2.6 |
278 # Compatibility function for wx versions < 2.6 |
266 def AppendMenu(parent, help, id, kind, text): |
279 def AppendMenu(parent, help, id, kind, text): |
267 if wx.VERSION >= (2, 6, 0): |
280 if wx.VERSION >= (2, 6, 0): |
268 parent.Append(help=help, id=id, kind=kind, text=text) |
281 parent.Append(help=help, id=id, kind=kind, text=text) |
269 else: |
282 else: |
781 |
794 |
782 def GetProjectConfiguration(self): |
795 def GetProjectConfiguration(self): |
783 projects = {} |
796 projects = {} |
784 try: |
797 try: |
785 if self.Config.HasEntry("projects"): |
798 if self.Config.HasEntry("projects"): |
786 projects = cPickle.loads(str(self.Config.Read("projects"))) |
799 projects = cPickle.loads(self.Config.Read("projects")) |
787 except: |
800 except: |
788 pass |
801 pass |
789 |
802 |
790 return projects.get(os.path.realpath(self.Controler.GetFilePath()), {}) |
803 return projects.get( |
|
804 EncodeFileSystemPath(os.path.realpath(self.Controler.GetFilePath())), {}) |
791 |
805 |
792 def SavePageState(self, page): |
806 def SavePageState(self, page): |
793 state = page.GetState() |
807 state = page.GetState() |
794 if state is not None: |
808 if state is not None: |
795 if self.Config.HasEntry("projects"): |
809 if self.Config.HasEntry("projects"): |
796 projects = cPickle.loads(str(self.Config.Read("projects"))) |
810 projects = cPickle.loads(self.Config.Read("projects")) |
797 else: |
811 else: |
798 projects = {} |
812 projects = {} |
799 |
813 |
800 project_infos = projects.setdefault(os.path.realpath(self.Controler.GetFilePath()), {}) |
814 project_infos = projects.setdefault( |
|
815 EncodeFileSystemPath(os.path.realpath(self.Controler.GetFilePath())), {}) |
801 editors_state = project_infos.setdefault("editors_state", {}) |
816 editors_state = project_infos.setdefault("editors_state", {}) |
802 |
817 |
803 if page.IsDebugging(): |
818 if page.IsDebugging(): |
804 editors_state[page.GetInstancePath()] = state |
819 editors_state[page.GetInstancePath()] = state |
805 else: |
820 else: |
979 tabs = [] |
994 tabs = [] |
980 |
995 |
981 projects = {} |
996 projects = {} |
982 try: |
997 try: |
983 if self.Config.HasEntry("projects"): |
998 if self.Config.HasEntry("projects"): |
984 projects = cPickle.loads(str(self.Config.Read("projects"))) |
999 projects = cPickle.loads(self.Config.Read("projects")) |
985 except: |
1000 except: |
986 pass |
1001 pass |
987 |
1002 |
988 project_infos = projects.setdefault(os.path.realpath(self.Controler.GetFilePath()), {}) |
1003 project_infos = projects.setdefault( |
|
1004 EncodeFileSystemPath(os.path.realpath(self.Controler.GetFilePath())), {}) |
989 project_infos["tabs"] = self.SaveTabLayout(self.TabsOpened) |
1005 project_infos["tabs"] = self.SaveTabLayout(self.TabsOpened) |
990 if self.EnableDebug: |
1006 if self.EnableDebug: |
991 project_infos["debug_vars"] = self.DebugVariablePanel.GetDebugVariables() |
1007 project_infos["debug_vars"] = self.DebugVariablePanel.GetDebugVariables() |
992 |
1008 |
993 self.Config.Write("projects", cPickle.dumps(projects)) |
1009 self.Config.Write("projects", cPickle.dumps(projects)) |
2665 IDEFrame.__init__(self, parent) |
2681 IDEFrame.__init__(self, parent) |
2666 |
2682 |
2667 result = None |
2683 result = None |
2668 |
2684 |
2669 # Open the filepath if defined |
2685 # Open the filepath if defined |
2670 if fileOpen is not None and os.path.isfile(fileOpen): |
2686 if fileOpen is not None: |
2671 # Create a new controller |
2687 fileOpen = DecodeFileSystemPath(fileOpen, False) |
2672 controler = PLCControler() |
2688 if os.path.isfile(fileOpen): |
2673 result = controler.OpenXMLFile(fileOpen) |
2689 # Create a new controller |
2674 if result is None: |
2690 controler = PLCControler() |
2675 self.Controler = controler |
2691 result = controler.OpenXMLFile(fileOpen) |
2676 self.LibraryPanel.SetController(controler) |
2692 if result is None: |
2677 self.ProjectTree.Enable(True) |
2693 self.Controler = controler |
2678 self.PouInstanceVariablesPanel.SetController(controler) |
2694 self.LibraryPanel.SetController(controler) |
2679 self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
2695 self.ProjectTree.Enable(True) |
|
2696 self.PouInstanceVariablesPanel.SetController(controler) |
|
2697 self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
2680 |
2698 |
2681 # Define PLCOpenEditor icon |
2699 # Define PLCOpenEditor icon |
2682 self.SetIcon(wx.Icon(os.path.join(CWD, "Images", "poe.ico"),wx.BITMAP_TYPE_ICO)) |
2700 self.SetIcon(wx.Icon(os.path.join(CWD, "Images", "poe.ico"),wx.BITMAP_TYPE_ICO)) |
2683 |
2701 |
2684 self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
2702 self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |