Cope with python2.2.
[dom-editor.git] / Dome / AppRun
blob419d2e950ff0abcb4f80317c4de874cf59e4e0a2
1 #! /usr/bin/env python
2 # vi: set syntax=python : */
4 import gc
6 import findrox; findrox.version(1, 9, 8)
7 import rox
9 try:
10 bool
11 except:
12 # Python 2.2
13 __builtins__.bool = lambda x: not not x
15 show_leaks = False
17 #rox.setup_app_options('Dome')
19 from rox.Menu import Menu, set_save_name
21 set_save_name('Dome')
23 no_gui_mode = 0
25 # Ugly hack to stop wierd chars appearing...
26 #import xml.dom.html
27 #xml.dom.html.HTML_CHARACTER_ENTITIES = {}
29 import sys
30 from os.path import dirname
32 app_dir = dirname(sys.argv[0])
34 from rox import g, mime
35 from rox.options import Option
36 from Window import Window
37 rox.setup_app_options('Dome')
39 default_font = Option('default_font', 'sans 12')
41 # All options must be registered by the time we get here
42 rox.app_options.notify()
44 #sys.argv.append('--disable-crash-dialog')
45 #import gnome.ui
46 #sys.argv.pop()
48 mime.install_mime_info('Dome')
50 mono = 0
51 while len(sys.argv) > 1 and sys.argv[1].startswith('--'):
52 option = sys.argv[1][2:]
53 del sys.argv[1]
54 if option == 'mono':
55 mono = 1 # Black & White
56 elif option == '':
57 break
58 else:
59 raise Exception("Unknown option", option)
61 files = sys.argv[1:]
62 del sys.argv[1:] # GnomeCanvas can't cope with -
64 def go():
65 apply(Window, files)
67 if show_leaks:
68 # Run twice, once to make sure everything is initialised, and
69 # again to make sure the memory use doesn't grow further.
70 go()
71 rox.mainloop()
73 log = file('leak-log', 'w')
75 gc.collect()
76 old = {}
77 for x in gc.get_objects():
78 old[id(x)] = None
79 import profile
80 #profile.run('go()')
81 go()
83 #profile.run('rox.mainloop()')
84 rox.mainloop()
86 if show_leaks:
87 gc.collect()
88 for x in gc.get_objects():
89 if id(x) not in old:
90 print `x`[:80]
91 print>>log, "New %s: %s" % (type(x), `x`)
92 for y in gc.get_referrers(x):
93 if y is not globals() and id(y) in old:
94 if type(y) == dict:
95 print>>log, "\t(dict, key is %s)" % [k for k in y if y[k] is x]
96 print>>log, "\t%s" % `y`