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