Beremiz.py
changeset 1601 37271c24ce45
parent 1600 481a71c864d4
child 1602 95ecb26fdc4e
equal deleted inserted replaced
1600:481a71c864d4 1601:37271c24ce45
   755         try:
   755         try:
   756             recent_projects = map(DecodeFileSystemPath,
   756             recent_projects = map(DecodeFileSystemPath,
   757                                   self.GetConfigEntry("RecentProjects", []))
   757                                   self.GetConfigEntry("RecentProjects", []))
   758         except:
   758         except:
   759             recent_projects = []
   759             recent_projects = []
       
   760 
       
   761         while self.RecentProjectsMenu.GetMenuItemCount() > len(recent_projects):
       
   762             item = self.RecentProjectsMenu.FindItemByPosition(0)
       
   763             self.RecentProjectsMenu.RemoveItem(item)
       
   764 
   760         self.FileMenu.Enable(ID_FILEMENURECENTPROJECTS, len(recent_projects) > 0)
   765         self.FileMenu.Enable(ID_FILEMENURECENTPROJECTS, len(recent_projects) > 0)
   761         for idx, projectpath in enumerate(recent_projects):
   766         for idx, projectpath in enumerate(recent_projects):
   762             text = u'%d: %s' % (idx + 1, projectpath)
   767             text = u'%d: %s' % (idx + 1, projectpath)
   763 
   768 
   764             if idx < self.RecentProjectsMenu.GetMenuItemCount():
   769             if idx < self.RecentProjectsMenu.GetMenuItemCount():
   894         self.Log.flush()
   899         self.Log.flush()
   895         if self.EnableDebug:
   900         if self.EnableDebug:
   896             self.DebugVariablePanel.SetDataProducer(None)
   901             self.DebugVariablePanel.SetDataProducer(None)
   897             self.ResetConnectionStatusBar()
   902             self.ResetConnectionStatusBar()
   898 
   903 
   899     def RefreshConfigRecentProjects(self, projectpath):
   904     def RefreshConfigRecentProjects(self, projectpath, err=False):
   900         try:
   905         try:
   901             recent_projects = map(DecodeFileSystemPath,
   906             recent_projects = map(DecodeFileSystemPath,
   902                                   self.GetConfigEntry("RecentProjects", []))
   907                                   self.GetConfigEntry("RecentProjects", []))
   903         except:
   908         except:
   904             recent_projects = []
   909             recent_projects = []
   905         if projectpath in recent_projects:
   910         if projectpath in recent_projects:
   906             recent_projects.remove(projectpath)
   911             recent_projects.remove(projectpath)
   907         recent_projects.insert(0, projectpath)
   912         if not err:
       
   913             recent_projects.insert(0, projectpath)
   908         self.Config.Write("RecentProjects", cPickle.dumps(
   914         self.Config.Write("RecentProjects", cPickle.dumps(
   909             map(EncodeFileSystemPath, recent_projects[:MAX_RECENT_PROJECTS])))
   915             map(EncodeFileSystemPath, recent_projects[:MAX_RECENT_PROJECTS])))
   910         self.Config.Flush()
   916         self.Config.Flush()
   911 
   917 
   912     def ResetPerspective(self):
   918     def ResetPerspective(self):
   965 
   971 
   966     def OpenProject(self, projectpath):
   972     def OpenProject(self, projectpath):
   967         if os.path.isdir(projectpath):
   973         if os.path.isdir(projectpath):
   968             self.Config.Write("lastopenedfolder",
   974             self.Config.Write("lastopenedfolder",
   969                               EncodeFileSystemPath(os.path.dirname(projectpath)))
   975                               EncodeFileSystemPath(os.path.dirname(projectpath)))
       
   976             err = False
   970             self.Config.Flush()
   977             self.Config.Flush()
   971             self.ResetView()
   978             self.ResetView()
   972             self.CTR = ProjectController(self, self.Log)
   979             self.CTR = ProjectController(self, self.Log)
   973             self.Controler = self.CTR
   980             self.Controler = self.CTR
   974             result = self.CTR.LoadProject(projectpath)
   981             result = self.CTR.LoadProject(projectpath)
   975             if not result:
   982             if not result:
   976                 self.LibraryPanel.SetController(self.Controler)
   983                 self.LibraryPanel.SetController(self.Controler)
   977                 self.ProjectTree.Enable(True)
   984                 self.ProjectTree.Enable(True)
   978                 self.PouInstanceVariablesPanel.SetController(self.Controler)
   985                 self.PouInstanceVariablesPanel.SetController(self.Controler)
   979                 self.RefreshConfigRecentProjects(projectpath)
       
   980                 if self.EnableDebug:
   986                 if self.EnableDebug:
   981                     self.DebugVariablePanel.SetDataProducer(self.CTR)
   987                     self.DebugVariablePanel.SetDataProducer(self.CTR)
   982                 self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
   988                 self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
   983             else:
   989             else:
   984                 self.ResetView()
   990                 self.ResetView()
   985                 self.ShowErrorMessage(result)
   991                 self.ShowErrorMessage(result)
   986             self.RefreshAll()
   992             self.RefreshAll()
   987         else:
   993         else:
   988             self.ShowErrorMessage(_("\"%s\" folder is not a valid Beremiz project\n") % projectpath)
   994             self.ShowErrorMessage(_("\"%s\" folder is not a valid Beremiz project\n") % projectpath)
       
   995             err = True
       
   996         self.RefreshConfigRecentProjects(projectpath, err)
   989         self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
   997         self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
   990 
   998 
   991     def OnCloseProjectMenu(self, event):
   999     def OnCloseProjectMenu(self, event):
   992         if self.CTR is not None and not self.CheckSaveBeforeClosing():
  1000         if self.CTR is not None and not self.CheckSaveBeforeClosing():
   993             return
  1001             return