chiark / gitweb /
Added MRU file list for models & profiles
authorsmorloc <smorloc@gmail.com>
Tue, 15 Jan 2013 13:33:01 +0000 (08:33 -0500)
committersmorloc <smorloc@gmail.com>
Tue, 15 Jan 2013 13:33:01 +0000 (08:33 -0500)
Added "Most Recently Used" (MRU) file list for models & profiles

Cura/gui/mainWindow.py
Cura/util/profile.py

index eee7d20aa8f663afa66909ad6e5bc4ff6061595c..54f05e55f23b7f1d74a3be6125945e0bcb092f2d 100644 (file)
@@ -38,6 +38,21 @@ class mainWindow(wx.Frame):
 
                self.normalModeOnlyItems = []
 
+               mruFile = os.path.join(profile.getBasePath(), 'mru_filelist.ini')
+               self.config = wx.FileConfig(appName="Cura", 
+                                               localFilename=mruFile,
+                                               style=wx.CONFIG_USE_LOCAL_FILE)
+                                               
+               self.ID_MRU_MODEL1, self.ID_MRU_MODEL2, self.ID_MRU_MODEL3, self.ID_MRU_MODEL4, self.ID_MRU_MODEL5, self.ID_MRU_MODEL6, self.ID_MRU_MODEL7, self.ID_MRU_MODEL8, self.ID_MRU_MODEL9, self.ID_MRU_MODEL10 = [wx.NewId() for line in xrange(10)]
+               self.modelFileHistory = wx.FileHistory(10, self.ID_MRU_MODEL1)
+               self.config.SetPath("/ModelMRU")
+               self.modelFileHistory.Load(self.config)
+
+               self.ID_MRU_PROFILE1, self.ID_MRU_PROFILE2, self.ID_MRU_PROFILE3, self.ID_MRU_PROFILE4, self.ID_MRU_PROFILE5, self.ID_MRU_PROFILE6, self.ID_MRU_PROFILE7, self.ID_MRU_PROFILE8, self.ID_MRU_PROFILE9, self.ID_MRU_PROFILE10 = [wx.NewId() for line in xrange(10)]
+               self.profileFileHistory = wx.FileHistory(10, self.ID_MRU_PROFILE1)
+               self.config.SetPath("/ProfileMRU")
+               self.profileFileHistory.Load(self.config)
+
                self.menubar = wx.MenuBar()
                self.fileMenu = wx.Menu()
                i = self.fileMenu.Append(-1, 'Load model file...\tCTRL+L')
@@ -65,6 +80,22 @@ class mainWindow(wx.Frame):
                self.fileMenu.AppendSeparator()
                i = self.fileMenu.Append(-1, 'Preferences...\tCTRL+,')
                self.Bind(wx.EVT_MENU, self.OnPreferences, i)
+               self.fileMenu.AppendSeparator()
+
+               # Model MRU list
+               modelHistoryMenu = wx.Menu()
+               self.fileMenu.AppendMenu(wx.NewId(), "&Recent Model Files", modelHistoryMenu)
+               self.modelFileHistory.UseMenu(modelHistoryMenu)
+               self.modelFileHistory.AddFilesToMenu()
+               self.Bind(wx.EVT_MENU_RANGE, self.OnModelMRU, id=self.ID_MRU_MODEL1, id2=self.ID_MRU_MODEL10)
+
+               # Profle MRU list
+               profileHistoryMenu = wx.Menu()
+               self.fileMenu.AppendMenu(wx.NewId(), "&Recent Profile Files", profileHistoryMenu)
+               self.profileFileHistory.UseMenu(profileHistoryMenu)
+               self.profileFileHistory.AddFilesToMenu()
+               self.Bind(wx.EVT_MENU_RANGE, self.OnProfileMRU, id=self.ID_MRU_PROFILE1, id2=self.ID_MRU_PROFILE10)
+               
                self.fileMenu.AppendSeparator()
                i = self.fileMenu.Append(wx.ID_EXIT, 'Quit')
                self.Bind(wx.EVT_MENU, self.OnQuit, i)
@@ -245,6 +276,12 @@ class mainWindow(wx.Frame):
                profile.putPreference('lastFile', ';'.join(self.filelist))
                self.preview3d.loadModelFiles(self.filelist, True)
                self.preview3d.setViewMode("Normal")
+               # Update the Model MRU
+               for idx in xrange(0, len(self.filelist)):
+                       self.modelFileHistory.AddFileToHistory(self.filelist[idx])
+               self.config.SetPath("/ModelMRU")
+               self.modelFileHistory.Save(self.config)
+               self.config.Flush()
 
        def OnDropFiles(self, files):
                self._loadModels(files)
@@ -291,6 +328,30 @@ class mainWindow(wx.Frame):
                        return
                printWindow.printFile(sliceRun.getExportFilename(self.filelist[0]))
 
+       def OnModelMRU(self, e):
+               fileNum = e.GetId() - self.ID_MRU_MODEL1
+               path = self.modelFileHistory.GetHistoryFile(fileNum)
+               # Update Model MRU
+               self.modelFileHistory.AddFileToHistory(path)  # move up the list
+               self.config.SetPath("/ModelMRU")
+               self.modelFileHistory.Save(self.config)
+               self.config.Flush()
+               # Load Model
+               filelist = [ path ]
+               self._loadModels(filelist)
+
+       def OnProfileMRU(self, e):
+               fileNum = e.GetId() - self.ID_MRU_PROFILE1
+               path = self.profileFileHistory.GetHistoryFile(fileNum)
+               # Update Profile MRU
+               self.profileFileHistory.AddFileToHistory(path)  # move up the list
+               self.config.SetPath("/ProfileMRU")
+               self.profileFileHistory.Save(self.config)
+               self.config.Flush()
+               # Load Profile  
+               profile.loadGlobalProfile(path)
+               self.updateProfileToControls()
+
        def removeSliceProgress(self, spp):
                self.progressPanelList.remove(spp)
                newSize = self.GetSize()
@@ -319,6 +380,12 @@ class mainWindow(wx.Frame):
                        profileFile = dlg.GetPath()
                        profile.loadGlobalProfile(profileFile)
                        self.updateProfileToControls()
+
+                       # Update the Profile MRU
+                       self.profileFileHistory.AddFileToHistory(profileFile)
+                       self.config.SetPath("/ProfileMRU")
+                       self.profileFileHistory.Save(self.config)
+                       self.config.Flush()                     
                dlg.Destroy()
 
        def OnLoadProfileFromGcode(self, e):
index 064b77489a1b674ea18fcbc04128d2d5c8ef0c56..747ed995427666ee2520c58b7246d4cfa3d762e3 100644 (file)
@@ -196,7 +196,7 @@ preferencesDefaultSettings = {
 #########################################################
 
 ## Profile functions
-def getDefaultProfilePath():
+def getBasePath():
        if platform.system() == "Windows":
                basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
                #If we have a frozen python install, we need to step out of the library.zip
@@ -206,7 +206,10 @@ def getDefaultProfilePath():
                basePath = os.path.expanduser('~/.cura/%s' % version.getVersion(False))
        if not os.path.isdir(basePath):
                os.makedirs(basePath)
-       return os.path.join(basePath, 'current_profile.ini')
+       return basePath
+
+def getDefaultProfilePath():
+       return os.path.join(getBasePath(), 'current_profile.ini')
 
 def loadGlobalProfile(filename):
        #Read a configuration file as global config
@@ -321,16 +324,7 @@ global globalPreferenceParser
 globalPreferenceParser = None
 
 def getPreferencePath():
-       if platform.system() == "Windows":
-               basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
-               #If we have a frozen python install, we need to step out of the library.zip
-               if hasattr(sys, 'frozen'):
-                       basePath = os.path.normpath(os.path.join(basePath, ".."))
-       else:
-               basePath = os.path.expanduser('~/.cura/%s' % version.getVersion(False))
-       if not os.path.isdir(basePath):
-               os.makedirs(basePath)
-       return os.path.join(basePath, 'preferences.ini')
+       return os.path.join(getBasePath(), 'preferences.ini')
 
 def getPreferenceFloat(name):
        try: