]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wx/py/PyCrust.py
Use the system settings for the selection colours
[wxWidgets.git] / wxPython / wx / py / PyCrust.py
CommitLineData
d14a1e28 1"""PyCrust is a python shell and namespace browser application."""
1fded56b 2
d14a1e28
RD
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.
7import __main__
8original = __main__.__dict__.keys()
1fded56b 9
d14a1e28
RD
10__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
11__cvsid__ = "$Id$"
12__revision__ = "$Revision$"[11:-2]
13
14import wx
15
d14a1e28
RD
16class App(wx.App):
17 """PyCrust standalone application."""
18
19 def OnInit(self):
02b800ce 20 import os
d14a1e28 21 import wx
d40bbd4d 22 from wx import py
02b800ce
RD
23
24 self.SetAppName("pycrust")
25 confDir = wx.StandardPaths.Get().GetUserDataDir()
26 if not os.path.exists(confDir):
27 os.mkdir(confDir)
28 fileName = os.path.join(confDir, 'config')
29 self.config = wx.FileConfig(localFilename=fileName)
30 self.config.SetRecordDefaults(True)
31
32 self.frame = py.crust.CrustFrame(config=self.config, dataDir=confDir)
33## self.frame.startupFileName = os.path.join(confDir,'pycrust_startup')
34## self.frame.historyFileName = os.path.join(confDir,'pycrust_history')
d14a1e28
RD
35 self.frame.Show()
36 self.SetTopWindow(self.frame)
37 return True
02b800ce
RD
38
39
d14a1e28
RD
40'''
41The main() function needs to handle being imported, such as with the
42pycrust script that wxPython installs:
43
44 #!/usr/bin/env python
45
46 from wx.py.PyCrust import main
47 main()
48'''
49
50def main():
51 """The main function for the PyCrust 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 # Mimic the contents of the standard Python shell's sys.path.
63 import sys
64 if sys.path[0]:
65 sys.path[0] = ''
66 # Add the application object to the sys module's namespace.
67 # This allows a shell user to do:
68 # >>> import sys
69 # >>> sys.app.whatever
70 sys.app = app
71 del sys
72 # Cleanup the main namespace some more.
73 if md.has_key('App') and md['App'] is App:
74 del md['App']
75 if md.has_key('__main__') and md['__main__'] is __main__:
76 del md['__main__']
77 # Start the wxPython event loop.
78 app.MainLoop()
8b9a4190
RD
79
80if __name__ == '__main__':
81 main()