[hdf-compass] 87/295: Added Open Recent file menu
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun May 8 10:35:29 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/master
in repository hdf-compass.
commit fbcf8508120879dbfe18dfc565f02dccd7cab72d
Author: Christian Oyarzun <co at oyarzun.net>
Date: Mon Aug 31 15:31:03 2015 -0400
Added Open Recent file menu
use wx.FileHistory to open recently opened files from the file menu
---
compass_viewer/frame.py | 38 +++++++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/compass_viewer/frame.py b/compass_viewer/frame.py
index 9a6ac57..c3d2c92 100644
--- a/compass_viewer/frame.py
+++ b/compass_viewer/frame.py
@@ -50,13 +50,22 @@ class BaseFrame(wx.Frame):
"""
wx.Frame.__init__(self, None, **kwds)
+ self.filehistory = wx.FileHistory(8)
+ self.config = wx.Config("HDFCompass", style=wx.CONFIG_USE_LOCAL_FILE)
+ self.filehistory.Load(self.config)
menubar = wx.MenuBar()
# File menu
fm = wx.Menu()
+
+ # Open Recent Menu
+ recent = wx.Menu()
+ self.filehistory.UseMenu(recent)
+ self.filehistory.AddFilesToMenu()
fm.Append(wx.ID_OPEN, "&Open...\tCtrl-O")
fm.Append(ID_OPEN_RESOURCE, "Open &Resource...\tCtrl-R")
+ fm.AppendMenu(wx.ID_ANY, "O&pen Recent", recent)
fm.AppendSeparator()
@@ -80,6 +89,7 @@ class BaseFrame(wx.Frame):
self.Bind(wx.EVT_MENU, self.on_resource_open, id=ID_OPEN_RESOURCE)
self.Bind(wx.EVT_MENU, self.on_about, id=wx.ID_ABOUT)
self.Bind(wx.EVT_MENU, self.on_exit, id=wx.ID_EXIT)
+ self.Bind(wx.EVT_MENU_RANGE, self.on_file_history, id=wx.ID_FILE1, id2=wx.ID_FILE9)
def on_exit(self, evt):
@@ -135,13 +145,39 @@ class BaseFrame(wx.Frame):
if dlg.ShowModal() != wx.ID_OK:
return
path = dlg.GetPath()
+ self.filehistory.AddFileToHistory(path)
+ self.filehistory.Save(self.config)
+ self.config.Flush()
+
url = 'file://'+path
if not open_store(url):
+ self.filehistory.RemoveFileToHistory(path)
+ self.filehistory.Save(self.config)
+ self.config.Flush()
+ dlg = wx.MessageDialog(self, 'The following file could not be opened:\n\n%s' % path,
+ 'No handler for file', wx.OK | wx.ICON_INFORMATION)
+ dlg.ShowModal()
+ dlg.Destroy()
+
+ def on_file_history(self, event):
+ """ Opens file from history """
+ fileNum = event.GetId() - wx.ID_FILE1
+ path = self.filehistory.GetHistoryFile(fileNum)
+ self.filehistory.AddFileToHistory(path) # move up the list
+ self.filehistory.Save(self.config)
+ self.config.Flush()
+
+ # open the file
+ from . import open_store
+ url = 'file://'+path
+ if not open_store(url):
+ self.filehistory.RemoveFileToHistory(path)
+ self.filehistory.Save(self.config)
+ self.config.Flush()
dlg = wx.MessageDialog(self, 'The following file could not be opened:\n\n%s' % path,
'No handler for file', wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
-
def on_window_close(self, evt):
""" Close Window file event, or cmd-W """
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/hdf-compass.git
More information about the debian-science-commits
mailing list