]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wx/py/PyCrust.py
Fixed a typo
[wxWidgets.git] / wxPython / wx / py / PyCrust.py
CommitLineData
d14a1e28 1"""PyCrust is a python shell and namespace browser application."""
1fded56b 2
d14a1e28
RD
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.
7import __main__
8original = __main__.__dict__.keys()
1fded56b 9
d14a1e28
RD
10__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
11__cvsid__ = "$Id$"
12__revision__ = "$Revision$"[11:-2]
13
14import wx
15
16try:
17 True
18except NameError:
19 True = 1==1
20 False = 1==0
21
22
23class App(wx.App):
24 """PyCrust standalone application."""
25
26 def OnInit(self):
27 import wx
28 wx.InitAllImageHandlers()
29 locals = __main__.__dict__
30 from crust import CrustFrame
31 self.frame = CrustFrame(locals=locals)
32 self.frame.SetSize((800, 600))
33 self.frame.Show()
34 self.SetTopWindow(self.frame)
35 return True
36
37'''
38The main() function needs to handle being imported, such as with the
39pycrust script that wxPython installs:
40
41 #!/usr/bin/env python
42
43 from wx.py.PyCrust import main
44 main()
45'''
46
47def main():
48 """The main function for the PyCrust program."""
49 # Cleanup the main namespace, leaving the App class.
50 import __main__
51 md = __main__.__dict__
52 keepers = original
53 keepers.append('App')
54 for key in md.keys():
55 if key not in keepers:
56 del md[key]
57 # Create an application instance.
58 app = App(0)
59 # Mimic the contents of the standard Python shell's sys.path.
60 import sys
61 if sys.path[0]:
62 sys.path[0] = ''
63 # Add the application object to the sys module's namespace.
64 # This allows a shell user to do:
65 # >>> import sys
66 # >>> sys.app.whatever
67 sys.app = app
68 del sys
69 # Cleanup the main namespace some more.
70 if md.has_key('App') and md['App'] is App:
71 del md['App']
72 if md.has_key('__main__') and md['__main__'] is __main__:
73 del md['__main__']
74 # Start the wxPython event loop.
75 app.MainLoop()
8b9a4190
RD
76
77if __name__ == '__main__':
78 main()