]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/PyCrust/PyCrustApp.py
036e368002eacbc27cfbb7a05b188f84e2a0e271
[wxWidgets.git] / wxPython / wxPython / lib / PyCrust / PyCrustApp.py
1
2 """PyCrustApp is a python shell and namespace browser application."""
3
4 # The next two lines, and the other code below that makes use of
5 # ``__main__`` and ``original``, serve the purpose of cleaning up the
6 # main namespace to look as much as possible like the regular Python
7 # shell environment.
8 import __main__
9 original = __main__.__dict__.keys()
10
11 __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
12 __cvsid__ = "$Id$"
13 __revision__ = "$Revision$"[11:-2]
14
15 from wxPython import wx
16
17 try:
18 True
19 except NameError:
20 True = 1==1
21 False = 1==0
22
23
24 class App(wx.wxApp):
25 """PyCrust standalone application."""
26
27 def OnInit(self):
28 from wxPython import wx
29 wx.wxInitAllImageHandlers()
30 locals = __main__.__dict__
31 from crust import CrustFrame
32 self.frame = CrustFrame(locals=locals)
33 self.frame.SetSize((800, 600))
34 self.frame.Show()
35 self.SetTopWindow(self.frame)
36 # Add the application object to the sys module's namespace.
37 # This allows a shell user to do:
38 # >>> import sys
39 # >>> sys.app.whatever
40 import sys
41 sys.app = self
42 return 1
43
44 '''
45 The main() function needs to handle being imported, such as with the
46 pycrust script that wxPython installs:
47
48 #!/usr/bin/env python
49
50 from wxPython.lib.PyCrust.PyCrustApp import main
51 main()
52 '''
53
54 def main():
55 import __main__
56 md = __main__.__dict__
57 keepers = original
58 keepers.append('App')
59 for key in md.keys():
60 if key not in keepers:
61 del md[key]
62 app = App(0)
63 if md.has_key('App') and md['App'] is App:
64 del md['App']
65 if md.has_key('__main__') and md['__main__'] is __main__:
66 del md['__main__']
67 app.MainLoop()
68
69 if __name__ == '__main__':
70 main()