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