]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/py/PyShell.py
Use GetKeyCode() instead of KeyCode()
[wxWidgets.git] / wxPython / wx / py / PyShell.py
1 """PyShell is a python shell application."""
2
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.
7 import __main__
8 original = __main__.__dict__.keys()
9
10 __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
11 __cvsid__ = "$Id$"
12 __revision__ = "$Revision$"[11:-2]
13
14 import wx
15 import os
16 print "PID:", os.getpid()
17 raw_input("...")
18
19 class App(wx.App):
20 """PyShell standalone application."""
21
22 def OnInit(self):
23 import os
24 import wx
25 from wx import py
26
27 self.SetAppName("pyshell")
28 confDir = wx.StandardPaths.Get().GetUserDataDir()
29 if not os.path.exists(confDir):
30 os.mkdir(confDir)
31 fileName = os.path.join(confDir, 'config')
32 self.config = wx.FileConfig(localFilename=fileName)
33 self.config.SetRecordDefaults(True)
34
35 self.frame = py.shell.ShellFrame(config=self.config, dataDir=confDir)
36 self.frame.Show()
37 self.SetTopWindow(self.frame)
38 return True
39
40 '''
41 The main() function needs to handle being imported, such as with the
42 pyshell script that wxPython installs:
43
44 #!/usr/bin/env python
45
46 from wx.py.PyShell import main
47 main()
48 '''
49
50 def main():
51 """The main function for the PyShell program."""
52 # Cleanup the main namespace, leaving the App class.
53 import __main__
54 md = __main__.__dict__
55 keepers = original
56 keepers.append('App')
57 for key in md.keys():
58 if key not in keepers:
59 del md[key]
60 # Create an application instance.
61 app = App(0)
62 # Cleanup the main namespace some more.
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 # Mimic the contents of the standard Python shell's sys.path.
68 import sys
69 if sys.path[0]:
70 sys.path[0] = ''
71 # Add the application object to the sys module's namespace.
72 # This allows a shell user to do:
73 # >>> import sys
74 # >>> sys.app.whatever
75 sys.app = app
76 del sys
77 # Start the wxPython event loop.
78 app.MainLoop()
79
80 if __name__ == '__main__':
81 main()