]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/PyCrust/PyShellApp.py
2ef7aae07fefc4801a924b1fba96f84863965d8f
[wxWidgets.git] / wxPython / wxPython / lib / PyCrust / PyShellApp.py
1
2 """PyShellApp is a python shell 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 """PyShell standalone application."""
26
27 def OnInit(self):
28 from wxPython import wx
29 wx.wxInitAllImageHandlers()
30 locals = __main__.__dict__
31 from shell import ShellFrame
32 self.frame = ShellFrame(locals=locals)
33 self.frame.SetSize((750, 525))
34 self.frame.Show()
35 self.SetTopWindow(self.frame)
36 self.frame.shell.SetFocus()
37 # Add the application object to the sys module's namespace.
38 # This allows a shell user to do:
39 # >>> import sys
40 # >>> sys.app.whatever
41 import sys
42 sys.app = self
43 return 1
44
45 '''
46 The main() function needs to handle being imported, such as with the
47 pycrust script that wxPython installs:
48
49 #!/usr/bin/env python
50
51 from wxPython.lib.PyCrust.PyCrustApp import main
52 main()
53 '''
54
55 def main():
56 import __main__
57 md = __main__.__dict__
58 keepers = original
59 keepers.append('App')
60 for key in md.keys():
61 if key not in keepers:
62 del md[key]
63 app = App(0)
64 if md.has_key('App') and md['App'] is App:
65 del md['App']
66 if md.has_key('__main__') and md['__main__'] is __main__:
67 del md['__main__']
68 app.MainLoop()
69
70 if __name__ == '__main__':
71 main()