2002-04-05 00:28:37 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
import os
|
|
|
|
import wx
|
2002-04-05 00:28:37 +00:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
text = """\
|
2003-12-09 01:23:28 +00:00
|
|
|
Right-click on the panel above the line to get a menu. This menu will
|
|
|
|
be managed by a FileHistory object and so the files you select will
|
|
|
|
automatically be added to the end of the menu and will be selectable
|
|
|
|
the next time the menu is viewed. The filename selected, either via the
|
|
|
|
Open menu item, or from the history, will be displayed in the log
|
|
|
|
window below.
|
2002-04-05 00:28:37 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
class TestPanel(wx.Panel):
|
2002-04-05 00:28:37 +00:00
|
|
|
def __init__(self, parent, log):
|
|
|
|
self.log = log
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
|
|
|
box = wx.BoxSizer(wx.VERTICAL)
|
2002-04-05 00:28:37 +00:00
|
|
|
|
|
|
|
# Make and layout the controls
|
2002-04-09 01:25:47 +00:00
|
|
|
fs = self.GetFont().GetPointSize()
|
2003-12-09 01:23:28 +00:00
|
|
|
bf = wx.Font(fs+4, wx.SWISS, wx.NORMAL, wx.BOLD)
|
|
|
|
nf = wx.Font(fs+2, wx.SWISS, wx.NORMAL, wx.NORMAL)
|
2002-04-05 00:28:37 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
t = wx.StaticText(self, -1, "FileHistory")
|
2002-04-05 00:28:37 +00:00
|
|
|
t.SetFont(bf)
|
2003-12-09 01:23:28 +00:00
|
|
|
box.Add(t, 0, wx.CENTER|wx.ALL, 5)
|
2002-04-05 00:28:37 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
box.Add(wx.StaticLine(self, -1), 0, wx.EXPAND)
|
2003-11-12 21:34:20 +00:00
|
|
|
box.Add((10,20))
|
2002-04-05 00:28:37 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
t = wx.StaticText(self, -1, text)
|
2002-04-05 00:28:37 +00:00
|
|
|
t.SetFont(nf)
|
2003-12-09 01:23:28 +00:00
|
|
|
box.Add(t, 0, wx.CENTER|wx.ALL, 5)
|
2002-04-05 00:28:37 +00:00
|
|
|
|
|
|
|
self.SetSizer(box)
|
2003-03-25 06:35:27 +00:00
|
|
|
self.SetAutoLayout(True)
|
2002-04-05 00:28:37 +00:00
|
|
|
|
|
|
|
# Make a menu
|
2003-12-09 01:23:28 +00:00
|
|
|
self.menu = m = wx.Menu()
|
|
|
|
|
|
|
|
# Little know wx Fact #42: there are a number of pre-set IDs
|
|
|
|
# in the wx package, to be used for common controls such as those
|
|
|
|
# illustrated below. Neat, huh?
|
|
|
|
m.Append(wx.ID_NEW, "&New")
|
|
|
|
m.Append(wx.ID_OPEN, "&Open...")
|
|
|
|
m.Append(wx.ID_CLOSE, "&Close")
|
|
|
|
m.Append(wx.ID_SAVE, "&Save")
|
|
|
|
m.Append(wx.ID_SAVEAS, "Save &as...")
|
|
|
|
m.Enable(wx.ID_NEW, False)
|
|
|
|
m.Enable(wx.ID_CLOSE, False)
|
|
|
|
m.Enable(wx.ID_SAVE, False)
|
|
|
|
m.Enable(wx.ID_SAVEAS, False)
|
2002-04-05 00:28:37 +00:00
|
|
|
|
|
|
|
# and a file history
|
2003-12-09 01:23:28 +00:00
|
|
|
self.filehistory = wx.FileHistory()
|
2002-04-05 00:28:37 +00:00
|
|
|
self.filehistory.UseMenu(self.menu)
|
|
|
|
|
|
|
|
# and finally the event handler bindings
|
2003-12-09 01:23:28 +00:00
|
|
|
self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
|
|
|
|
|
|
|
|
self.Bind(wx.EVT_MENU, self.OnFileOpenDialog, id=wx.ID_OPEN)
|
|
|
|
|
|
|
|
self.Bind(
|
|
|
|
wx.EVT_MENU_RANGE, self.OnFileHistory, id=wx.ID_FILE1, id2=wx.ID_FILE9
|
|
|
|
)
|
|
|
|
|
|
|
|
self.Bind(wx.EVT_WINDOW_DESTROY, self.Cleanup)
|
2002-04-05 00:28:37 +00:00
|
|
|
|
|
|
|
|
2002-04-23 15:58:41 +00:00
|
|
|
def Cleanup(self, *args):
|
2003-12-09 01:23:28 +00:00
|
|
|
# A little extra cleanup is required for the FileHistory control
|
2002-04-05 00:28:37 +00:00
|
|
|
del self.filehistory
|
|
|
|
self.menu.Destroy()
|
|
|
|
|
|
|
|
|
|
|
|
def OnRightClick(self, evt):
|
|
|
|
self.PopupMenu(self.menu, evt.GetPosition())
|
|
|
|
|
|
|
|
|
|
|
|
def OnFileOpenDialog(self, evt):
|
2003-12-09 01:23:28 +00:00
|
|
|
dlg = wx.FileDialog(self,
|
2002-04-05 00:28:37 +00:00
|
|
|
defaultDir = os.getcwd(),
|
2002-05-27 21:22:37 +00:00
|
|
|
wildcard = "All Files|*",
|
2003-12-09 01:23:28 +00:00
|
|
|
style = wx.OPEN | wx.CHANGE_DIR)
|
|
|
|
|
|
|
|
if dlg.ShowModal() == wx.ID_OK:
|
2002-04-05 00:28:37 +00:00
|
|
|
path = dlg.GetPath()
|
|
|
|
self.log.write("You selected %s\n" % path)
|
|
|
|
|
|
|
|
# add it to the history
|
|
|
|
self.filehistory.AddFileToHistory(path)
|
|
|
|
|
|
|
|
dlg.Destroy()
|
|
|
|
|
|
|
|
|
|
|
|
def OnFileHistory(self, evt):
|
|
|
|
# get the file based on the menu ID
|
2003-12-09 01:23:28 +00:00
|
|
|
fileNum = evt.GetId() - wx.ID_FILE1
|
2002-04-05 00:28:37 +00:00
|
|
|
path = self.filehistory.GetHistoryFile(fileNum)
|
|
|
|
self.log.write("You selected %s\n" % path)
|
|
|
|
|
|
|
|
# add it back to the history so it will be moved up the list
|
|
|
|
self.filehistory.AddFileToHistory(path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overview = """<html><body>
|
2003-12-09 01:23:28 +00:00
|
|
|
<h3>FileHistory</h3>
|
2002-04-05 00:28:37 +00:00
|
|
|
|
|
|
|
wxFileHistory encapsulates functionality to record the last few files
|
|
|
|
visited, and to allow the user to quickly load these files using the
|
|
|
|
list appended to a menu, such as the File menu.
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
<p>Note that this inclusion is not automatic; as illustrated in this example,
|
|
|
|
you must add files (and remove them) as deemed necessary within the framework
|
|
|
|
of your program.
|
|
|
|
|
|
|
|
<p>Note also the additional cleanup required for this class, namely trapping the
|
|
|
|
enclosing window's Destroy event and deleting the file history control and its
|
|
|
|
associated menu.
|
2002-04-05 00:28:37 +00:00
|
|
|
</body></html>
|
|
|
|
"""
|
2002-05-27 21:22:37 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2002-05-27 22:14:41 +00:00
|
|
|
import sys,os
|
2002-05-27 21:22:37 +00:00
|
|
|
import run
|
2004-03-05 00:06:33 +00:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
2002-05-27 21:22:37 +00:00
|
|
|
|