Beremiz.py
changeset 791 67b47775ba21
parent 790 52d3a084d2b2
child 793 1b24b970a816
equal deleted inserted replaced
787:f49875b9e946 791:67b47775ba21
   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             try:
   440             if projectOpen == "":
   444                 projectOpen = DecodeFileSystemPath(self.Config.Read("currenteditedproject"))
       
   445                 if projectOpen == "":
       
   446                     projectOpen = None
       
   447             except:
   441                 projectOpen = None
   448                 projectOpen = None
   442         
   449         
   443         if projectOpen is not None and os.path.isdir(projectOpen):
   450         if projectOpen is not None and os.path.isdir(projectOpen):
   444             self.CTR = ProjectController(self, self.Log)
   451             self.CTR = ProjectController(self, self.Log)
   445             self.Controler = self.CTR
   452             self.Controler = self.CTR
   589             
   596             
   590             if self.CTR is not None:
   597             if self.CTR is not None:
   591                 project_path = os.path.realpath(self.CTR.GetProjectPath())
   598                 project_path = os.path.realpath(self.CTR.GetProjectPath())
   592             else:
   599             else:
   593                 project_path = ""
   600                 project_path = ""
   594             self.Config.Write("currenteditedproject", project_path)    
   601             self.Config.Write("currenteditedproject", EncodeFileSystemPath(project_path))    
   595             self.Config.Flush()
   602             self.Config.Flush()
   596             
   603             
   597             event.Skip()
   604             event.Skip()
   598         else:
   605         else:
   599             event.Veto()
   606             event.Veto()
   643             self.FileMenu.Enable(wx.ID_SAVEAS, False)
   650             self.FileMenu.Enable(wx.ID_SAVEAS, False)
   644             MenuToolBar.EnableTool(wx.ID_SAVEAS, False)
   651             MenuToolBar.EnableTool(wx.ID_SAVEAS, False)
   645             self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
   652             self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
   646     
   653     
   647     def RefreshRecentProjectsMenu(self):
   654     def RefreshRecentProjectsMenu(self):
   648         recent_projects = cPickle.loads(str(self.Config.Read("RecentProjects", cPickle.dumps([]))))
   655         recent_projects = map(DecodeFileSystemPath, 
       
   656                               self.GetConfigEntry("RecentProjects", []))
   649         self.FileMenu.Enable(ID_FILEMENURECENTPROJECTS, len(recent_projects) > 0)
   657         self.FileMenu.Enable(ID_FILEMENURECENTPROJECTS, len(recent_projects) > 0)
   650         for idx, projectpath in enumerate(recent_projects):
   658         for idx, projectpath in enumerate(recent_projects):
   651             text = u'%d: %s' % (idx + 1, projectpath)
   659             text = u'%d: %s' % (idx + 1, projectpath)
   652             
   660             
   653             if idx < self.RecentProjectsMenu.GetMenuItemCount():
   661             if idx < self.RecentProjectsMenu.GetMenuItemCount():
   778         self.Log.flush()
   786         self.Log.flush()
   779         if self.EnableDebug:
   787         if self.EnableDebug:
   780             self.DebugVariablePanel.SetDataProducer(None)
   788             self.DebugVariablePanel.SetDataProducer(None)
   781     
   789     
   782     def RefreshConfigRecentProjects(self, projectpath):
   790     def RefreshConfigRecentProjects(self, projectpath):
   783         recent_projects = cPickle.loads(str(self.Config.Read("RecentProjects", cPickle.dumps([]))))
   791         recent_projects = map(DecodeFileSystemPath, 
       
   792                               self.GetConfigEntry("RecentProjects", []))
   784         if projectpath in recent_projects:
   793         if projectpath in recent_projects:
   785             recent_projects.remove(projectpath)
   794             recent_projects.remove(projectpath)
   786         recent_projects.insert(0, projectpath)
   795         recent_projects.insert(0, projectpath)
   787         self.Config.Write("RecentProjects", cPickle.dumps(recent_projects[:MAX_RECENT_PROJECTS]))
   796         self.Config.Write("RecentProjects", cPickle.dumps(
       
   797             map(EncodeFileSystemPath, recent_projects[:MAX_RECENT_PROJECTS])))
   788         self.Config.Flush()
   798         self.Config.Flush()
   789     
   799     
   790     def ResetPerspective(self):
   800     def ResetPerspective(self):
   791         IDEFrame.ResetPerspective(self)
   801         IDEFrame.ResetPerspective(self)
   792         self.RefreshStatusToolBar()
   802         self.RefreshStatusToolBar()
   797     
   807     
   798     def OnNewProjectMenu(self, event):
   808     def OnNewProjectMenu(self, event):
   799         if self.CTR is not None and not self.CheckSaveBeforeClosing():
   809         if self.CTR is not None and not self.CheckSaveBeforeClosing():
   800             return
   810             return
   801         
   811         
   802         if not self.Config.HasEntry("lastopenedfolder"):
   812         try:
       
   813             defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder"))
       
   814         except:
   803             defaultpath = os.path.expanduser("~")
   815             defaultpath = os.path.expanduser("~")
   804         else:
       
   805             defaultpath = self.Config.Read("lastopenedfolder")
       
   806         
   816         
   807         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
   817         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
   808         if dialog.ShowModal() == wx.ID_OK:
   818         if dialog.ShowModal() == wx.ID_OK:
   809             projectpath = dialog.GetPath()
   819             projectpath = dialog.GetPath()
   810             self.Config.Write("lastopenedfolder", os.path.dirname(projectpath))
   820             self.Config.Write("lastopenedfolder", 
       
   821                               EncodeFileSystemPath(os.path.dirname(projectpath)))
   811             self.Config.Flush()
   822             self.Config.Flush()
   812             self.ResetView()
   823             self.ResetView()
   813             ctr = ProjectController(self, self.Log)
   824             ctr = ProjectController(self, self.Log)
   814             result = ctr.NewProject(projectpath)
   825             result = ctr.NewProject(projectpath)
   815             if not result:
   826             if not result:
   831     
   842     
   832     def OnOpenProjectMenu(self, event):
   843     def OnOpenProjectMenu(self, event):
   833         if self.CTR is not None and not self.CheckSaveBeforeClosing():
   844         if self.CTR is not None and not self.CheckSaveBeforeClosing():
   834             return
   845             return
   835         
   846         
   836         if not self.Config.HasEntry("lastopenedfolder"):
   847         try:
       
   848             defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder"))
       
   849         except:
   837             defaultpath = os.path.expanduser("~")
   850             defaultpath = os.path.expanduser("~")
   838         else:
       
   839             defaultpath = self.Config.Read("lastopenedfolder")
       
   840         
   851         
   841         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
   852         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
   842         if dialog.ShowModal() == wx.ID_OK:
   853         if dialog.ShowModal() == wx.ID_OK:
   843             self.OpenProject(dialog.GetPath())
   854             self.OpenProject(dialog.GetPath())
   844         dialog.Destroy()
   855         dialog.Destroy()
   845     
   856     
   846     def OpenProject(self, projectpath):
   857     def OpenProject(self, projectpath):
   847         if os.path.isdir(projectpath):
   858         if os.path.isdir(projectpath):
   848             self.Config.Write("lastopenedfolder", os.path.dirname(projectpath))
   859             self.Config.Write("lastopenedfolder", 
       
   860                               EncodeFileSystemPath(os.path.dirname(projectpath)))
   849             self.Config.Flush()
   861             self.Config.Flush()
   850             self.ResetView()
   862             self.ResetView()
   851             self.CTR = ProjectController(self, self.Log)
   863             self.CTR = ProjectController(self, self.Log)
   852             self.Controler = self.CTR
   864             self.Controler = self.CTR
   853             result = self.CTR.LoadProject(projectpath)
   865             result = self.CTR.LoadProject(projectpath)