2003-11-12 16:34:20 -05:00
|
|
|
"""PyShell is a python shell application."""
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
# The next two lines, and the other code below that makes use of
|
|
|
|
# ``__main__`` and ``original``, serve the purpose of cleaning up the
|
|
|
|
# main namespace to look as much as possible like the regular Python
|
|
|
|
# shell environment.
|
|
|
|
import __main__
|
|
|
|
original = __main__.__dict__.keys()
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
|
|
|
|
__cvsid__ = "$Id$"
|
|
|
|
__revision__ = "$Revision$"[11:-2]
|
|
|
|
|
|
|
|
import wx
|
2006-09-08 16:09:27 -04:00
|
|
|
import os
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
class App(wx.App):
|
|
|
|
"""PyShell standalone application."""
|
|
|
|
|
|
|
|
def OnInit(self):
|
2005-12-30 18:02:03 -05:00
|
|
|
import os
|
2003-11-12 16:34:20 -05:00
|
|
|
import wx
|
2004-03-15 08:42:37 -05:00
|
|
|
from wx import py
|
2005-12-30 18:02:03 -05:00
|
|
|
|
|
|
|
self.SetAppName("pyshell")
|
|
|
|
confDir = wx.StandardPaths.Get().GetUserDataDir()
|
|
|
|
if not os.path.exists(confDir):
|
|
|
|
os.mkdir(confDir)
|
|
|
|
fileName = os.path.join(confDir, 'config')
|
|
|
|
self.config = wx.FileConfig(localFilename=fileName)
|
|
|
|
self.config.SetRecordDefaults(True)
|
|
|
|
|
|
|
|
self.frame = py.shell.ShellFrame(config=self.config, dataDir=confDir)
|
2003-11-12 16:34:20 -05:00
|
|
|
self.frame.Show()
|
|
|
|
self.SetTopWindow(self.frame)
|
|
|
|
return True
|
|
|
|
|
|
|
|
'''
|
|
|
|
The main() function needs to handle being imported, such as with the
|
|
|
|
pyshell script that wxPython installs:
|
|
|
|
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from wx.py.PyShell import main
|
|
|
|
main()
|
|
|
|
'''
|
|
|
|
|
|
|
|
def main():
|
|
|
|
"""The main function for the PyShell program."""
|
|
|
|
# Cleanup the main namespace, leaving the App class.
|
|
|
|
import __main__
|
|
|
|
md = __main__.__dict__
|
|
|
|
keepers = original
|
|
|
|
keepers.append('App')
|
|
|
|
for key in md.keys():
|
|
|
|
if key not in keepers:
|
|
|
|
del md[key]
|
|
|
|
# Create an application instance.
|
|
|
|
app = App(0)
|
|
|
|
# Cleanup the main namespace some more.
|
|
|
|
if md.has_key('App') and md['App'] is App:
|
|
|
|
del md['App']
|
|
|
|
if md.has_key('__main__') and md['__main__'] is __main__:
|
|
|
|
del md['__main__']
|
|
|
|
# Mimic the contents of the standard Python shell's sys.path.
|
|
|
|
import sys
|
|
|
|
if sys.path[0]:
|
|
|
|
sys.path[0] = ''
|
|
|
|
# Add the application object to the sys module's namespace.
|
|
|
|
# This allows a shell user to do:
|
|
|
|
# >>> import sys
|
|
|
|
# >>> sys.app.whatever
|
|
|
|
sys.app = app
|
|
|
|
del sys
|
|
|
|
# Start the wxPython event loop.
|
|
|
|
app.MainLoop()
|
2003-10-01 20:58:06 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|