]>
Commit | Line | Data |
---|---|---|
1 | """PyCrust is a python shell and namespace browser application.""" | |
2 | ||
3 | # The next two lines, and the other code below that makes use of | |
4 | # ``__main__`` and ``original``, serve the purpose of cleaning up the | |
5 | # main namespace to look as much as possible like the regular Python | |
6 | # shell environment. | |
7 | import __main__ | |
8 | original = __main__.__dict__.keys() | |
9 | ||
10 | __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>" | |
11 | __cvsid__ = "$Id$" | |
12 | __revision__ = "$Revision$"[11:-2] | |
13 | ||
14 | import wx | |
15 | ||
16 | class App(wx.App): | |
17 | """PyCrust standalone application.""" | |
18 | ||
19 | def OnInit(self): | |
20 | import os | |
21 | import wx | |
22 | from wx import py | |
23 | ||
24 | self.SetAppName("pycrust") | |
25 | confDir = wx.StandardPaths.Get().GetUserDataDir() | |
26 | if not os.path.exists(confDir): | |
27 | os.mkdir(confDir) | |
28 | fileName = os.path.join(confDir, 'config') | |
29 | self.config = wx.FileConfig(localFilename=fileName) | |
30 | self.config.SetRecordDefaults(True) | |
31 | ||
32 | self.frame = py.crust.CrustFrame(config=self.config, dataDir=confDir) | |
33 | ## self.frame.startupFileName = os.path.join(confDir,'pycrust_startup') | |
34 | ## self.frame.historyFileName = os.path.join(confDir,'pycrust_history') | |
35 | self.frame.Show() | |
36 | self.SetTopWindow(self.frame) | |
37 | return True | |
38 | ||
39 | ||
40 | ''' | |
41 | The main() function needs to handle being imported, such as with the | |
42 | pycrust script that wxPython installs: | |
43 | ||
44 | #!/usr/bin/env python | |
45 | ||
46 | from wx.py.PyCrust import main | |
47 | main() | |
48 | ''' | |
49 | ||
50 | def main(): | |
51 | """The main function for the PyCrust program.""" | |
52 | # Cleanup the main namespace, leaving the App class. | |
53 | import __main__ | |
54 | md = __main__.__dict__ | |
55 | keepers = original | |
56 | keepers.append('App') | |
57 | for key in md.keys(): | |
58 | if key not in keepers: | |
59 | del md[key] | |
60 | # Create an application instance. | |
61 | app = App(0) | |
62 | # Mimic the contents of the standard Python shell's sys.path. | |
63 | import sys | |
64 | if sys.path[0]: | |
65 | sys.path[0] = '' | |
66 | # Add the application object to the sys module's namespace. | |
67 | # This allows a shell user to do: | |
68 | # >>> import sys | |
69 | # >>> sys.app.whatever | |
70 | sys.app = app | |
71 | del sys | |
72 | # Cleanup the main namespace some more. | |
73 | if md.has_key('App') and md['App'] is App: | |
74 | del md['App'] | |
75 | if md.has_key('__main__') and md['__main__'] is __main__: | |
76 | del md['__main__'] | |
77 | # Start the wxPython event loop. | |
78 | app.MainLoop() | |
79 | ||
80 | if __name__ == '__main__': | |
81 | main() |