/Python25Einstein/Lib/site-packages/wx-2.8-msw-unicode/wx/py/PyShell.py

https://github.com/Einstein-NTE/einstein
Python | 79 lines | 44 code | 10 blank | 25 comment | 9 complexity | 8573adb0edd9471bc0254fbcf975c7c6 MD5 | raw file
  1. """PyShell is a python shell application."""
  2. # The next two lines, and the other code below that makes use of
  3. # ``__main__`` and ``original``, serve the purpose of cleaning up the
  4. # main namespace to look as much as possible like the regular Python
  5. # shell environment.
  6. import __main__
  7. original = __main__.__dict__.keys()
  8. __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
  9. __cvsid__ = "$Id: PyShell.py 41078 2006-09-09 00:38:53Z RD $"
  10. __revision__ = "$Revision: 41078 $"[11:-2]
  11. import wx
  12. import os
  13. class App(wx.App):
  14. """PyShell standalone application."""
  15. def OnInit(self):
  16. import os
  17. import wx
  18. from wx import py
  19. self.SetAppName("pyshell")
  20. confDir = wx.StandardPaths.Get().GetUserDataDir()
  21. if not os.path.exists(confDir):
  22. os.mkdir(confDir)
  23. fileName = os.path.join(confDir, 'config')
  24. self.config = wx.FileConfig(localFilename=fileName)
  25. self.config.SetRecordDefaults(True)
  26. self.frame = py.shell.ShellFrame(config=self.config, dataDir=confDir)
  27. self.frame.Show()
  28. self.SetTopWindow(self.frame)
  29. return True
  30. '''
  31. The main() function needs to handle being imported, such as with the
  32. pyshell script that wxPython installs:
  33. #!/usr/bin/env python
  34. from wx.py.PyShell import main
  35. main()
  36. '''
  37. def main():
  38. """The main function for the PyShell program."""
  39. # Cleanup the main namespace, leaving the App class.
  40. import __main__
  41. md = __main__.__dict__
  42. keepers = original
  43. keepers.append('App')
  44. for key in md.keys():
  45. if key not in keepers:
  46. del md[key]
  47. # Create an application instance.
  48. app = App(0)
  49. # Cleanup the main namespace some more.
  50. if md.has_key('App') and md['App'] is App:
  51. del md['App']
  52. if md.has_key('__main__') and md['__main__'] is __main__:
  53. del md['__main__']
  54. # Mimic the contents of the standard Python shell's sys.path.
  55. import sys
  56. if sys.path[0]:
  57. sys.path[0] = ''
  58. # Add the application object to the sys module's namespace.
  59. # This allows a shell user to do:
  60. # >>> import sys
  61. # >>> sys.app.whatever
  62. sys.app = app
  63. del sys
  64. # Start the wxPython event loop.
  65. app.MainLoop()
  66. if __name__ == '__main__':
  67. main()