X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1fded56b375bf7a4687af1cdb182899614c1b2a8..609b563c8b9ade4fcde9160f11c7deaf16a9f7b6:/wxPython/wx/py/PyCrust.py diff --git a/wxPython/wx/py/PyCrust.py b/wxPython/wx/py/PyCrust.py index 26b64d239d..b9a222763e 100644 --- a/wxPython/wx/py/PyCrust.py +++ b/wxPython/wx/py/PyCrust.py @@ -1,11 +1,70 @@ +"""PyCrust is a python shell and namespace browser application.""" -"""Renamer stub: provides a way to drop the wx prefix from wxPython objects.""" +# 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() +__author__ = "Patrick K. O'Brien " __cvsid__ = "$Id$" __revision__ = "$Revision$"[11:-2] -from wx import _rename -from wxPython.py import PyCrust -_rename(globals(), PyCrust.__dict__, modulename='py.PyCrust') -del PyCrust -del _rename +import wx + +class App(wx.App): + """PyCrust standalone application.""" + + def OnInit(self): + import wx + from wx import py + wx.InitAllImageHandlers() + self.frame = py.crust.CrustFrame() + self.frame.SetSize((800, 600)) + self.frame.Show() + self.SetTopWindow(self.frame) + return True + +''' +The main() function needs to handle being imported, such as with the +pycrust script that wxPython installs: + + #!/usr/bin/env python + + from wx.py.PyCrust import main + main() +''' + +def main(): + """The main function for the PyCrust 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) + # 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 + # 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__'] + # Start the wxPython event loop. + app.MainLoop() + +if __name__ == '__main__': + main()