Beremiz.py
changeset 788 3cec473bef94
parent 784 a1d970365e41
child 790 52d3a084d2b2
equal deleted inserted replaced
786:aaacf208beb9 788:3cec473bef94
   166 from util.ProcessLogger import ProcessLogger
   166 from util.ProcessLogger import ProcessLogger
   167 
   167 
   168 from docutil import OpenHtmlFrame
   168 from docutil import OpenHtmlFrame
   169 from PLCOpenEditor import IDEFrame, AppendMenu, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES 
   169 from PLCOpenEditor import IDEFrame, AppendMenu, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES 
   170 from PLCOpenEditor import EditorPanel, Viewer, TextViewer, GraphicViewer, ResourceEditor, ConfigurationEditor, DataTypeEditor
   170 from PLCOpenEditor import EditorPanel, Viewer, TextViewer, GraphicViewer, ResourceEditor, ConfigurationEditor, DataTypeEditor
       
   171 from PLCOpenEditor import EncodeFileSystemPath, DecodeFileSystemPath
   171 from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY, ITEM_PROJECT, ITEM_RESOURCE
   172 from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY, ITEM_PROJECT, ITEM_RESOURCE
   172 
   173 
   173 MAX_RECENT_PROJECTS = 10
   174 MAX_RECENT_PROJECTS = 10
   174 
   175 
   175 class GenStaticBitmap(wx.lib.statbmp.GenStaticBitmap):
   176 class GenStaticBitmap(wx.lib.statbmp.GenStaticBitmap):
   433             self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(imgname))
   434             self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(imgname))
   434         
   435         
   435         # Add beremiz's icon in top left corner of the frame
   436         # Add beremiz's icon in top left corner of the frame
   436         self.SetIcon(wx.Icon(Bpath("images", "brz.ico"), wx.BITMAP_TYPE_ICO))
   437         self.SetIcon(wx.Icon(Bpath("images", "brz.ico"), wx.BITMAP_TYPE_ICO))
   437         
   438         
       
   439         if projectOpen is not None:
       
   440             projectOpen = DecodeFileSystemPath(projectOpen, False)
       
   441         
   438         if ctr is None and projectOpen is None and self.Config.HasEntry("currenteditedproject"):
   442         if ctr is None and projectOpen is None and self.Config.HasEntry("currenteditedproject"):
   439             projectOpen = str(self.Config.Read("currenteditedproject"))
   443             projectOpen = DecodeFileSystemPath(self.Config.Read("currenteditedproject"))
   440             if projectOpen == "":
   444             if projectOpen == "":
   441                 projectOpen = None
   445                 projectOpen = None
   442         
   446         
   443         if projectOpen is not None and os.path.isdir(projectOpen):
   447         if projectOpen is not None and os.path.isdir(projectOpen):
   444             self.CTR = ProjectController(self, self.Log)
   448             self.CTR = ProjectController(self, self.Log)
   589             
   593             
   590             if self.CTR is not None:
   594             if self.CTR is not None:
   591                 project_path = os.path.realpath(self.CTR.GetProjectPath())
   595                 project_path = os.path.realpath(self.CTR.GetProjectPath())
   592             else:
   596             else:
   593                 project_path = ""
   597                 project_path = ""
   594             self.Config.Write("currenteditedproject", project_path)    
   598             self.Config.Write("currenteditedproject", EncodeFileSystemPath(project_path))    
   595             self.Config.Flush()
   599             self.Config.Flush()
   596             
   600             
   597             event.Skip()
   601             event.Skip()
   598         else:
   602         else:
   599             event.Veto()
   603             event.Veto()
   643             self.FileMenu.Enable(wx.ID_SAVEAS, False)
   647             self.FileMenu.Enable(wx.ID_SAVEAS, False)
   644             MenuToolBar.EnableTool(wx.ID_SAVEAS, False)
   648             MenuToolBar.EnableTool(wx.ID_SAVEAS, False)
   645             self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
   649             self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
   646     
   650     
   647     def RefreshRecentProjectsMenu(self):
   651     def RefreshRecentProjectsMenu(self):
   648         recent_projects = cPickle.loads(str(self.Config.Read("RecentProjects", cPickle.dumps([]))))
   652         recent_projects = map(DecodeFileSystemPath, 
       
   653                               self.GetConfigEntry("RecentProjects", []))
   649         self.FileMenu.Enable(ID_FILEMENURECENTPROJECTS, len(recent_projects) > 0)
   654         self.FileMenu.Enable(ID_FILEMENURECENTPROJECTS, len(recent_projects) > 0)
   650         for idx, projectpath in enumerate(recent_projects):
   655         for idx, projectpath in enumerate(recent_projects):
   651             text = u'%d: %s' % (idx + 1, projectpath)
   656             text = u'%d: %s' % (idx + 1, projectpath)
   652             
   657             
   653             if idx < self.RecentProjectsMenu.GetMenuItemCount():
   658             if idx < self.RecentProjectsMenu.GetMenuItemCount():
   778         self.Log.flush()
   783         self.Log.flush()
   779         if self.EnableDebug:
   784         if self.EnableDebug:
   780             self.DebugVariablePanel.SetDataProducer(None)
   785             self.DebugVariablePanel.SetDataProducer(None)
   781     
   786     
   782     def RefreshConfigRecentProjects(self, projectpath):
   787     def RefreshConfigRecentProjects(self, projectpath):
   783         recent_projects = cPickle.loads(str(self.Config.Read("RecentProjects", cPickle.dumps([]))))
   788         recent_projects = map(DecodeFileSystemPath, 
       
   789                               self.GetConfigEntry("RecentProjects", []))
   784         if projectpath in recent_projects:
   790         if projectpath in recent_projects:
   785             recent_projects.remove(projectpath)
   791             recent_projects.remove(projectpath)
   786         recent_projects.insert(0, projectpath)
   792         recent_projects.insert(0, projectpath)
   787         self.Config.Write("RecentProjects", cPickle.dumps(recent_projects[:MAX_RECENT_PROJECTS]))
   793         self.Config.Write("RecentProjects", cPickle.dumps(
       
   794             map(EncodeFileSystemPath, recent_projects[:MAX_RECENT_PROJECTS])))
   788         self.Config.Flush()
   795         self.Config.Flush()
   789     
   796     
   790     def ResetPerspective(self):
   797     def ResetPerspective(self):
   791         IDEFrame.ResetPerspective(self)
   798         IDEFrame.ResetPerspective(self)
   792         self.RefreshStatusToolBar()
   799         self.RefreshStatusToolBar()
   800             return
   807             return
   801         
   808         
   802         if not self.Config.HasEntry("lastopenedfolder"):
   809         if not self.Config.HasEntry("lastopenedfolder"):
   803             defaultpath = os.path.expanduser("~")
   810             defaultpath = os.path.expanduser("~")
   804         else:
   811         else:
   805             defaultpath = self.Config.Read("lastopenedfolder")
   812             defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder"))
   806         
   813         
   807         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
   814         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
   808         if dialog.ShowModal() == wx.ID_OK:
   815         if dialog.ShowModal() == wx.ID_OK:
   809             projectpath = dialog.GetPath()
   816             projectpath = dialog.GetPath()
   810             self.Config.Write("lastopenedfolder", os.path.dirname(projectpath))
   817             self.Config.Write("lastopenedfolder", 
       
   818                               EncodeFileSystemPath(os.path.dirname(projectpath)))
   811             self.Config.Flush()
   819             self.Config.Flush()
   812             self.ResetView()
   820             self.ResetView()
   813             ctr = ProjectController(self, self.Log)
   821             ctr = ProjectController(self, self.Log)
   814             result = ctr.NewProject(projectpath)
   822             result = ctr.NewProject(projectpath)
   815             if not result:
   823             if not result:
   834             return
   842             return
   835         
   843         
   836         if not self.Config.HasEntry("lastopenedfolder"):
   844         if not self.Config.HasEntry("lastopenedfolder"):
   837             defaultpath = os.path.expanduser("~")
   845             defaultpath = os.path.expanduser("~")
   838         else:
   846         else:
   839             defaultpath = self.Config.Read("lastopenedfolder")
   847             defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder"))
   840         
   848         
   841         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
   849         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
   842         if dialog.ShowModal() == wx.ID_OK:
   850         if dialog.ShowModal() == wx.ID_OK:
   843             self.OpenProject(dialog.GetPath())
   851             self.OpenProject(dialog.GetPath())
   844         dialog.Destroy()
   852         dialog.Destroy()
   845     
   853     
   846     def OpenProject(self, projectpath):
   854     def OpenProject(self, projectpath):
   847         if os.path.isdir(projectpath):
   855         if os.path.isdir(projectpath):
   848             self.Config.Write("lastopenedfolder", os.path.dirname(projectpath))
   856             self.Config.Write("lastopenedfolder", 
       
   857                               EncodeFileSystemPath(os.path.dirname(projectpath)))
   849             self.Config.Flush()
   858             self.Config.Flush()
   850             self.ResetView()
   859             self.ResetView()
   851             self.CTR = ProjectController(self, self.Log)
   860             self.CTR = ProjectController(self, self.Log)
   852             self.Controler = self.CTR
   861             self.Controler = self.CTR
   853             result = self.CTR.LoadProject(projectpath)
   862             result = self.CTR.LoadProject(projectpath)