]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/StandardPaths.py
mention wxLogInterposer(Temp)
[wxWidgets.git] / wxPython / demo / StandardPaths.py
1
2 import wx
3
4 #----------------------------------------------------------------------
5
6 class TestPanel(wx.Panel):
7 def __init__(self, parent, log):
8 self.log = log
9 wx.Panel.__init__(self, parent, -1)
10
11 sizer = wx.FlexGridSizer(0, 3, 5, 5)
12 sizer.AddGrowableCol(1)
13 box = wx.BoxSizer(wx.VERTICAL)
14 fs = self.GetFont().GetPointSize()
15 bf = wx.Font(fs+4, wx.SWISS, wx.NORMAL, wx.BOLD)
16
17 t = wx.StaticText(self, -1, "StandardPaths")
18 t.SetFont(bf)
19 box.Add(t, 0, wx.CENTER|wx.ALL, 4)
20 box.Add(wx.StaticLine(self, -1), 0, wx.EXPAND)
21
22 # get the global (singleton) instance of wx.StandardPaths
23 sp = wx.StandardPaths.Get()
24
25 # StandardPaths will use the value of wx.App().GetAppName()
26 # for some of the stnadard path components. Let's set it to
27 # something that makes that obvious for the demo. In your own
28 # apps you'll set it in to something more meaningfull for your
29 # app in your OnInit, (or just let it default.)
30 wx.GetApp().SetAppName("AppName")
31
32 self.help = {}
33
34 # Loop through all of the getters in wx.StandardPaths and make
35 # a set of items in the sizer for each.
36 def makeitem(name, *args):
37 func = getattr(sp, name)
38 sizer.Add(wx.StaticText(self, -1, "%s%s:" %(name, repr(args))),
39 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
40 sizer.Add(wx.TextCtrl(self, -1, func(*args),
41 size=(275,-1), style=wx.TE_READONLY),
42 0, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL)
43
44 btn = wx.Button(self, wx.ID_HELP)
45 sizer.Add(btn)
46 self.help[btn] = func.__doc__
47
48 for x in ['GetConfigDir',
49 'GetUserConfigDir',
50 'GetDataDir',
51 'GetLocalDataDir',
52 'GetUserDataDir',
53 'GetUserLocalDataDir',
54 'GetDocumentsDir',
55 'GetPluginsDir',
56 'GetInstallPrefix',
57 'GetResourcesDir',
58 'GetTempDir',
59 'GetExecutablePath',
60 ]:
61 makeitem(x)
62
63 # this one needs parameters
64 makeitem('GetLocalizedResourcesDir', 'en',
65 wx.StandardPaths.ResourceCat_Messages )
66
67 self.Bind(wx.EVT_BUTTON, self.OnShowDoc, id=wx.ID_HELP)
68
69 box.Add(sizer, 0, wx.CENTER|wx.EXPAND|wx.ALL, 20)
70 self.SetSizer(box)
71
72
73 def OnShowDoc(self, evt):
74 doc = self.help[evt.GetEventObject()]
75
76 # trim the whitespace from each line
77 lines = []
78 for line in doc.split('\n'):
79 lines.append(line.strip())
80 doc = '\n'.join(lines)
81 wx.TipWindow(self, doc, 500)
82
83
84 #----------------------------------------------------------------------
85
86 def runTest(frame, nb, log):
87 win = TestPanel(nb, log)
88 return win
89
90 #----------------------------------------------------------------------
91
92
93
94 overview = """<html><body>
95 <h2><center>StandardPaths</center></h2>
96
97 wxWidgets provides this class to simply determine where to locate
98 certain types of files in a platform specific manner. This includes
99 things like configuration files, general data files writeable by the
100 user, and application files that are shared by all user.
101
102 </body></html>
103 """
104
105
106
107 if __name__ == '__main__':
108 import sys,os
109 import run
110 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
111