X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/932142005296b619b7eaf71de6c2e0fecae6d12d..61940a7061d0b5d5122b1e1e939cfa2d72596999:/wxPython/demo/wxFileHistory.py diff --git a/wxPython/demo/wxFileHistory.py b/wxPython/demo/wxFileHistory.py index 571cb8e9fa..7a0dc4962f 100644 --- a/wxPython/demo/wxFileHistory.py +++ b/wxPython/demo/wxFileHistory.py @@ -1,68 +1,83 @@ +# 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o Updated for wx namespace +# -from wxPython.wx import * -import os +import os +import wx #---------------------------------------------------------------------- text = """\ -Right-click on the panel to get a menu. This menu will be managed by -a wxFileHistory 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 selcted, either via the Open menu -item, or from the history, will be displayed in the log window below. +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. """ #---------------------------------------------------------------------- -class TestPanel(wxPanel): +class TestPanel(wx.Panel): def __init__(self, parent, log): self.log = log - wxPanel.__init__(self, parent, -1) - box = wxBoxSizer(wxVERTICAL) + wx.Panel.__init__(self, parent, -1) + box = wx.BoxSizer(wx.VERTICAL) # Make and layout the controls fs = self.GetFont().GetPointSize() - bf = wxFont(fs+4, wxSWISS, wxNORMAL, wxBOLD) - nf = wxFont(fs+2, wxSWISS, wxNORMAL, wxNORMAL) + bf = wx.Font(fs+4, wx.SWISS, wx.NORMAL, wx.BOLD) + nf = wx.Font(fs+2, wx.SWISS, wx.NORMAL, wx.NORMAL) - t = wxStaticText(self, -1, "wxFileHistory") + t = wx.StaticText(self, -1, "FileHistory") t.SetFont(bf) - box.Add(t, 0, wxCENTER|wxALL, 5) + box.Add(t, 0, wx.CENTER|wx.ALL, 5) - box.Add(wxStaticLine(self, -1), 0, wxEXPAND) - box.Add(10,20) + box.Add(wx.StaticLine(self, -1), 0, wx.EXPAND) + box.Add((10,20)) - t = wxStaticText(self, -1, text) + t = wx.StaticText(self, -1, text) t.SetFont(nf) - box.Add(t, 0, wxCENTER|wxALL, 5) + box.Add(t, 0, wx.CENTER|wx.ALL, 5) self.SetSizer(box) - self.SetAutoLayout(true) + self.SetAutoLayout(True) # Make a menu - self.menu = m = wxMenu() - m.Append(wxID_NEW, "&New") - m.Append(wxID_OPEN, "&Open...") - m.Append(wxID_CLOSE, "&Close") - m.Append(wxID_SAVE, "&Save") - m.Append(wxID_SAVEAS, "Save &as...") - m.Enable(wxID_NEW, false) - m.Enable(wxID_CLOSE, false) - m.Enable(wxID_SAVE, false) - m.Enable(wxID_SAVEAS, false) + 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) # and a file history - self.filehistory = wxFileHistory() + self.filehistory = wx.FileHistory() self.filehistory.UseMenu(self.menu) # and finally the event handler bindings - EVT_RIGHT_UP(self, self.OnRightClick) - EVT_MENU(self, wxID_OPEN, self.OnFileOpenDialog) - EVT_MENU_RANGE(self, wxID_FILE1, wxID_FILE9, self.OnFileHistory) - EVT_WINDOW_DESTROY(self, self.Cleanup) + 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) def Cleanup(self, *args): + # A little extra cleanup is required for the FileHistory control del self.filehistory self.menu.Destroy() @@ -72,11 +87,12 @@ class TestPanel(wxPanel): def OnFileOpenDialog(self, evt): - dlg = wxFileDialog(self, + dlg = wx.FileDialog(self, defaultDir = os.getcwd(), wildcard = "All Files|*", - style = wxOPEN | wxCHANGE_DIR) - if dlg.ShowModal() == wxID_OK: + style = wx.OPEN | wx.CHANGE_DIR) + + if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() self.log.write("You selected %s\n" % path) @@ -88,7 +104,7 @@ class TestPanel(wxPanel): def OnFileHistory(self, evt): # get the file based on the menu ID - fileNum = evt.GetId() - wxID_FILE1 + fileNum = evt.GetId() - wx.ID_FILE1 path = self.filehistory.GetHistoryFile(fileNum) self.log.write("You selected %s\n" % path) @@ -108,17 +124,24 @@ def runTest(frame, nb, log): overview = """
-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. + +
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. """ if __name__ == '__main__': - import os + import sys,os import run - run.main(['', os.path.basename(__file__)]) + run.main(['', os.path.basename(sys.argv[0])])