]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxFileHistory.py
Removed wxVTKRenderWindow since VTK now includes a much better python
[wxWidgets.git] / wxPython / demo / wxFileHistory.py
CommitLineData
7c41d11a
RD
1
2from wxPython.wx import *
3import os
4
5#----------------------------------------------------------------------
6
7text = """\
8Right-click on the panel to get a menu. This menu will be managed by
9a wxFileHistory object and so the files you select will automatically
10be added to the end of the menu and will be selectable the next time
11the menu is viewed. The filename selcted, either via the Open menu
12item, or from the history, will be displayed in the log window below.
13"""
14
15#----------------------------------------------------------------------
16
17class TestPanel(wxPanel):
18 def __init__(self, parent, log):
19 self.log = log
20 wxPanel.__init__(self, parent, -1)
21 box = wxBoxSizer(wxVERTICAL)
22
23 # Make and layout the controls
d3bfec74
RD
24 fs = self.GetFont().GetPointSize()
25 bf = wxFont(fs+4, wxSWISS, wxNORMAL, wxBOLD)
26 nf = wxFont(fs+2, wxSWISS, wxNORMAL, wxNORMAL)
7c41d11a
RD
27
28 t = wxStaticText(self, -1, "wxFileHistory")
29 t.SetFont(bf)
30 box.Add(t, 0, wxCENTER|wxALL, 5)
31
32 box.Add(wxStaticLine(self, -1), 0, wxEXPAND)
33 box.Add(10,20)
34
35 t = wxStaticText(self, -1, text)
36 t.SetFont(nf)
37 box.Add(t, 0, wxCENTER|wxALL, 5)
38
39 self.SetSizer(box)
40 self.SetAutoLayout(true)
41
42 # Make a menu
43 self.menu = m = wxMenu()
44 m.Append(wxID_NEW, "&New")
45 m.Append(wxID_OPEN, "&Open...")
46 m.Append(wxID_CLOSE, "&Close")
47 m.Append(wxID_SAVE, "&Save")
48 m.Append(wxID_SAVEAS, "Save &as...")
49 m.Enable(wxID_NEW, false)
50 m.Enable(wxID_CLOSE, false)
51 m.Enable(wxID_SAVE, false)
52 m.Enable(wxID_SAVEAS, false)
53
54 # and a file history
55 self.filehistory = wxFileHistory()
56 self.filehistory.UseMenu(self.menu)
57
58 # and finally the event handler bindings
59 EVT_RIGHT_UP(self, self.OnRightClick)
60 EVT_MENU(self, wxID_OPEN, self.OnFileOpenDialog)
61 EVT_MENU_RANGE(self, wxID_FILE1, wxID_FILE9, self.OnFileHistory)
f2a10cdc 62 EVT_WINDOW_DESTROY(self, self.Cleanup)
7c41d11a
RD
63
64
f2a10cdc 65 def Cleanup(self, *args):
7c41d11a
RD
66 del self.filehistory
67 self.menu.Destroy()
68
69
70 def OnRightClick(self, evt):
71 self.PopupMenu(self.menu, evt.GetPosition())
72
73
74 def OnFileOpenDialog(self, evt):
75 dlg = wxFileDialog(self,
76 defaultDir = os.getcwd(),
77 style = wxOPEN | wxCHANGE_DIR)
78 if dlg.ShowModal() == wxID_OK:
79 path = dlg.GetPath()
80 self.log.write("You selected %s\n" % path)
81
82 # add it to the history
83 self.filehistory.AddFileToHistory(path)
84
85 dlg.Destroy()
86
87
88 def OnFileHistory(self, evt):
89 # get the file based on the menu ID
90 fileNum = evt.GetId() - wxID_FILE1
91 path = self.filehistory.GetHistoryFile(fileNum)
92 self.log.write("You selected %s\n" % path)
93
94 # add it back to the history so it will be moved up the list
95 self.filehistory.AddFileToHistory(path)
96
97
98
99#----------------------------------------------------------------------
100
101def runTest(frame, nb, log):
102 win = TestPanel(nb, log)
103 return win
104
105#----------------------------------------------------------------------
106
107
108
109overview = """<html><body>
110<h3>wxFileHistory</h3>
111
112wxFileHistory encapsulates functionality to record the last few files
113visited, and to allow the user to quickly load these files using the
114list appended to a menu, such as the File menu.
115
116</body></html>
117"""