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