Beremiz.py
changeset 679 d72f3a42f440
parent 678 92a1ec3c6fdd
child 683 57aa9da845d5
equal deleted inserted replaced
678:92a1ec3c6fdd 679:d72f3a42f440
   476         self.ScrollingEnabled = True
   476         self.ScrollingEnabled = True
   477         
   477         
   478         self.LastPanelSelected = None
   478         self.LastPanelSelected = None
   479         
   479         
   480         self.PluginInfos = {}
   480         self.PluginInfos = {}
   481         self.PluginRoot = None
       
   482         
   481         
   483         # Define Tree item icon list
   482         # Define Tree item icon list
   484         self.LocationImageList = wx.ImageList(16, 16)
   483         self.LocationImageList = wx.ImageList(16, 16)
   485         self.LocationImageDict = {}
   484         self.LocationImageDict = {}
   486         
   485         
   496         
   495         
   497         # Add beremiz's icon in top left corner of the frame
   496         # Add beremiz's icon in top left corner of the frame
   498         self.SetIcon(wx.Icon(Bpath( "images", "brz.ico"), wx.BITMAP_TYPE_ICO))
   497         self.SetIcon(wx.Icon(Bpath( "images", "brz.ico"), wx.BITMAP_TYPE_ICO))
   499         
   498         
   500         if projectOpen is not None and os.path.isdir(projectOpen):
   499         if projectOpen is not None and os.path.isdir(projectOpen):
   501             self.OpenProject(os.path.abspath(projectOpen))
   500             self.PluginRoot = PluginsRoot(self, self.Log)
       
   501             self.Controler = self.PluginRoot
       
   502             result = self.PluginRoot.LoadProject(projectOpen, buildpath)
       
   503             if not result:
       
   504                 self.RefreshConfigRecentProjects(os.path.abspath(projectOpen))
       
   505                 self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
       
   506                 self.RefreshAll()
       
   507             else:
       
   508                 self.ResetView()
       
   509                 self.ShowErrorMessage(result)
   502         else:
   510         else:
   503             self.PluginRoot = plugin_root
   511             self.PluginRoot = plugin_root
   504             self.Controler = plugin_root
   512             self.Controler = plugin_root
   505             if plugin_root is not None:
   513             if plugin_root is not None:
   506                 self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
   514                 self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
   507                 self.RefreshAll()
   515                 self.RefreshAll()
   508             self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
       
   509         if self.EnableDebug:
   516         if self.EnableDebug:
   510             self.DebugVariablePanel.SetDataProducer(self.PluginRoot)
   517             self.DebugVariablePanel.SetDataProducer(self.PluginRoot)
   511         
   518         
   512         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
   519         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
   513         
   520         
       
   521         self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
   514         self.RefreshPluginMenu()
   522         self.RefreshPluginMenu()
   515         self.LogConsole.SetFocus()
   523         self.LogConsole.SetFocus()
   516 
   524 
   517     def RiseLogConsole(self):
   525     def RiseLogConsole(self):
   518         self.BottomNoteBook.SetSelection(self.BottomNoteBook.GetPageIndex(self.LogConsole))
   526         self.BottomNoteBook.SetSelection(self.BottomNoteBook.GetPageIndex(self.LogConsole))
  1502         self.PluginRoot = None
  1510         self.PluginRoot = None
  1503         self.Log.flush()
  1511         self.Log.flush()
  1504         if self.EnableDebug:
  1512         if self.EnableDebug:
  1505             self.DebugVariablePanel.SetDataProducer(None)
  1513             self.DebugVariablePanel.SetDataProducer(None)
  1506     
  1514     
       
  1515     def RefreshConfigRecentProjects(self, projectpath):
       
  1516         recent_projects = cPickle.loads(str(self.Config.Read("RecentProjects", cPickle.dumps([]))))
       
  1517         if projectpath in recent_projects:
       
  1518             recent_projects.remove(projectpath)
       
  1519         recent_projects.insert(0, projectpath)
       
  1520         self.Config.Write("RecentProjects", cPickle.dumps(recent_projects[:MAX_RECENT_PROJECTS]))
       
  1521         self.Config.Flush()
       
  1522     
  1507     def OnNewProjectMenu(self, event):
  1523     def OnNewProjectMenu(self, event):
  1508         if self.PluginRoot is not None and not self.CheckSaveBeforeClosing():
  1524         if self.PluginRoot is not None and not self.CheckSaveBeforeClosing():
  1509             return
  1525             return
  1510         
  1526         
  1511         if not self.Config.HasEntry("lastopenedfolder"):
  1527         if not self.Config.HasEntry("lastopenedfolder"):
  1514             defaultpath = self.Config.Read("lastopenedfolder")
  1530             defaultpath = self.Config.Read("lastopenedfolder")
  1515         
  1531         
  1516         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
  1532         dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON)
  1517         if dialog.ShowModal() == wx.ID_OK:
  1533         if dialog.ShowModal() == wx.ID_OK:
  1518             projectpath = dialog.GetPath()
  1534             projectpath = dialog.GetPath()
  1519             dialog.Destroy()
       
  1520             self.Config.Write("lastopenedfolder", os.path.dirname(projectpath))
  1535             self.Config.Write("lastopenedfolder", os.path.dirname(projectpath))
  1521             self.Config.Flush()
  1536             self.Config.Flush()
  1522             self.ResetView()
  1537             self.ResetView()
  1523             self.PluginRoot = PluginsRoot(self, self.Log)
  1538             self.PluginRoot = PluginsRoot(self, self.Log)
  1524             self.Controler = self.PluginRoot
  1539             self.Controler = self.PluginRoot
  1525             result = self.PluginRoot.NewProject(projectpath)
  1540             result = self.PluginRoot.NewProject(projectpath)
  1526             if not result:
  1541             if not result:
       
  1542                 self.RefreshConfigRecentProjects(projectpath)
  1527                 if self.EnableDebug:
  1543                 if self.EnableDebug:
  1528                     self.DebugVariablePanel.SetDataProducer(self.PluginRoot)
  1544                     self.DebugVariablePanel.SetDataProducer(self.PluginRoot)
  1529                 self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
  1545                 self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
  1530                 self.RefreshAll()
  1546                 self.RefreshAll()
  1531             else:
  1547             else:
  1532                 self.ResetView()
  1548                 self.ResetView()
  1533                 self.ShowErrorMessage(result)
  1549                 self.ShowErrorMessage(result)
  1534             self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU)
  1550             self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU)
       
  1551         dialog.Destroy()
  1535     
  1552     
  1536     def OnOpenProjectMenu(self, event):
  1553     def OnOpenProjectMenu(self, event):
  1537         if self.PluginRoot is not None and not self.CheckSaveBeforeClosing():
  1554         if self.PluginRoot is not None and not self.CheckSaveBeforeClosing():
  1538             return
  1555             return
  1539         
  1556         
  1548         dialog.Destroy()
  1565         dialog.Destroy()
  1549     
  1566     
  1550     def OpenProject(self, projectpath):
  1567     def OpenProject(self, projectpath):
  1551         if os.path.isdir(projectpath):
  1568         if os.path.isdir(projectpath):
  1552             self.Config.Write("lastopenedfolder", os.path.dirname(projectpath))
  1569             self.Config.Write("lastopenedfolder", os.path.dirname(projectpath))
  1553             recent_projects = cPickle.loads(str(self.Config.Read("RecentProjects", cPickle.dumps([]))))
       
  1554             if projectpath in recent_projects:
       
  1555                 recent_projects.remove(projectpath)
       
  1556             recent_projects.insert(0, projectpath)
       
  1557             self.Config.Write("RecentProjects", cPickle.dumps(recent_projects[:MAX_RECENT_PROJECTS]))
       
  1558             self.Config.Flush()
  1570             self.Config.Flush()
  1559             self.ResetView()
  1571             self.ResetView()
  1560             self.PluginRoot = PluginsRoot(self, self.Log)
  1572             self.PluginRoot = PluginsRoot(self, self.Log)
  1561             self.Controler = self.PluginRoot
  1573             self.Controler = self.PluginRoot
  1562             result = self.PluginRoot.LoadProject(projectpath)
  1574             result = self.PluginRoot.LoadProject(projectpath)
  1563             if not result:
  1575             if not result:
       
  1576                 self.RefreshConfigRecentProjects(projectpath)
  1564                 if self.EnableDebug:
  1577                 if self.EnableDebug:
  1565                     self.DebugVariablePanel.SetDataProducer(self.PluginRoot)
  1578                     self.DebugVariablePanel.SetDataProducer(self.PluginRoot)
  1566                 self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
  1579                 self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
  1567                 self.RefreshAll()
  1580                 self.RefreshAll()
  1568             else:
  1581             else: