root/gaphor/tags/gaphor-0.9.2/gaphor/__init__.py

Revision 1135, 2.1 kB (checked in by arjanmol, 2 years ago)

cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/env python
2 # vim:sw=4
3 """This is Gaphor, a Python based UML editor.
4 """
5
6 __all__ = [ 'main', 'resource', 'GaphorError' ]
7
8 # Check for GTK-2.0, since we need it anyway...
9 #import pygtk
10 #pygtk.require('2.0')
11 #del pygtk
12
13 import misc.logger
14
15 import version
16
17 from misc.resource import Resource
18
19 # Application wide resources can be stored in the 'resource' like this
20 #
21 # >>> resource('myResource', some_value)
22 #
23 # If the resource doesn't already exist, it is created, otherwise the existing
24 # resource is returned.
25 resource = Resource(initial_resources={
26                         'Name': 'gaphor',
27                         'Version': version.VERSION,
28                         'DataDir': version.DATA_DIR,
29                         'UserDataDir': version.USER_DATA_DIR,
30                         'ui.toolbox.classes': True,
31                     })
32
33 class GaphorError(Exception):
34     """
35     Gaphor specific exception class
36     """
37     def __init__(self, args=None):
38             Exception.__init__(self)
39             self.args = args
40
41 def main(gaphor_file=None):
42     """Start the interactive application.
43
44     This involves importing plugins and creating the main window.
45     """
46     # Import GUI stuff here, since the user might not need all the GUI stuff
47     import gtk
48     import ui
49     import adapters
50     import actions
51     # Load plugin definitions:
52     import pluginmanager
53     from ui.mainwindow import MainWindow
54
55     resource('PluginManager').bootstrap()
56
57     ui.load_accel_map()
58
59     # should we set a default icon here or something?
60     main_window = resource(MainWindow)
61     main_window.construct()
62
63     # When the state changes to CLOSED, quit the application
64     main_window.connect(lambda win: win.get_state() == MainWindow.STATE_CLOSED and gtk.main_quit())
65
66     if gaphor_file:
67         main_window.set_filename(gaphor_file)
68         main_window.execute_action('FileRevert')
69     else:
70         main_window.execute_action('FileNew')
71
72     gtk.main()
73     #gtk.threads_leave()
74
75     resource.save()
76
77     ui.save_accel_map()
78
79     log.info('Bye!')
80
81
82 # TODO: Remove this
83 import __builtin__
84 __builtin__.__dict__['log'] = misc.logger.Logger()
85
86 if __debug__:
87     refs = []
88
Note: See TracBrowser for help on using the browser.