]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/py/PyCrust.py
Added __nonzero__ for wxTraskBarIcon
[wxWidgets.git] / wxPython / wx / py / PyCrust.py
1 """PyCrust is a python shell and namespace browser 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
16
17 class App(wx.App):
18 """PyCrust standalone application."""
19
20 def OnInit(self):
21 import wx
22 wx.InitAllImageHandlers()
23 from crust import CrustFrame
24 self.frame = CrustFrame()
25 self.frame.SetSize((800, 600))
26 self.frame.Show()
27 self.SetTopWindow(self.frame)
28 return True
29
30 '''
31 The main() function needs to handle being imported, such as with the
32 pycrust script that wxPython installs:
33
34 #!/usr/bin/env python
35
36 from wx.py.PyCrust import main
37 main()
38 '''
39
40 def main():
41 """The main function for the PyCrust 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 # Mimic the contents of the standard Python shell's sys.path.
53 import sys
54 if sys.path[0]:
55 sys.path[0] = ''
56 # Add the application object to the sys module's namespace.
57 # This allows a shell user to do:
58 # >>> import sys
59 # >>> sys.app.whatever
60 sys.app = app
61 del sys
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 # Start the wxPython event loop.
68 app.MainLoop()
69
70 if __name__ == '__main__':
71 main()