]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxFileHistory.py
2 from wxPython
.wx
import *
5 #----------------------------------------------------------------------
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 selected, either via the Open menu
12 item, or from the history, will be displayed in the log window below.
15 #----------------------------------------------------------------------
17 class TestPanel(wxPanel
):
18 def __init__(self
, parent
, log
):
20 wxPanel
.__init
__(self
, parent
, -1)
21 box
= wxBoxSizer(wxVERTICAL
)
23 # Make and layout the controls
24 fs
= self
.GetFont().GetPointSize()
25 bf
= wxFont(fs
+4, wxSWISS
, wxNORMAL
, wxBOLD
)
26 nf
= wxFont(fs
+2, wxSWISS
, wxNORMAL
, wxNORMAL
)
28 t
= wxStaticText(self
, -1, "wxFileHistory")
30 box
.Add(t
, 0, wxCENTER|wxALL
, 5)
32 box
.Add(wxStaticLine(self
, -1), 0, wxEXPAND
)
35 t
= wxStaticText(self
, -1, text
)
37 box
.Add(t
, 0, wxCENTER|wxALL
, 5)
40 self
.SetAutoLayout(True)
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)
55 self
.filehistory
= wxFileHistory()
56 self
.filehistory
.UseMenu(self
.menu
)
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
)
62 EVT_WINDOW_DESTROY(self
, self
.Cleanup
)
65 def Cleanup(self
, *args
):
70 def OnRightClick(self
, evt
):
71 self
.PopupMenu(self
.menu
, evt
.GetPosition())
74 def OnFileOpenDialog(self
, evt
):
75 dlg
= wxFileDialog(self
,
76 defaultDir
= os
.getcwd(),
77 wildcard
= "All Files|*",
78 style
= wxOPEN | wxCHANGE_DIR
)
79 if dlg
.ShowModal() == wxID_OK
:
81 self
.log
.write("You selected %s\n" % path
)
83 # add it to the history
84 self
.filehistory
.AddFileToHistory(path
)
89 def OnFileHistory(self
, evt
):
90 # get the file based on the menu ID
91 fileNum
= evt
.GetId() - wxID_FILE1
92 path
= self
.filehistory
.GetHistoryFile(fileNum
)
93 self
.log
.write("You selected %s\n" % path
)
95 # add it back to the history so it will be moved up the list
96 self
.filehistory
.AddFileToHistory(path
)
100 #----------------------------------------------------------------------
102 def runTest(frame
, nb
, log
):
103 win
= TestPanel(nb
, log
)
106 #----------------------------------------------------------------------
110 overview
= """<html><body>
111 <h3>wxFileHistory</h3>
113 wxFileHistory encapsulates functionality to record the last few files
114 visited, and to allow the user to quickly load these files using the
115 list appended to a menu, such as the File menu.
120 if __name__
== '__main__':
123 run
.main(['', os
.path
.basename(sys
.argv
[0])])