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