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

Revision 465, 2.1 kB (checked in by arjanmol, 4 years ago)

*** empty log message ***

  • 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.singleton
14 import misc.logger
15
16 import version
17
18 from misc.resource import Resource
19
20 # Application wide resources can be stored in the 'resource' like this
21 #
22 # >>> resource('myResource', some_value)
23 #
24 # If the resource doesn't already exist, it is created, otherwise the existing
25 # resource is returned.
26 resource = Resource(initial_resources = {
27                         'Name': 'gaphor',
28                         'Version': version.VERSION,
29                         'DataDir': version.DATA_DIR,
30                         'UserDataDir': version.USER_DATA_DIR
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 stuff here, since the user might not need all the GUI stuff
47     import gtk
48     import diagram
49     # Load plugin definitions:
50     import pluginmanager
51     from ui.mainwindow import MainWindow
52
53     resource('PluginManager').bootstrap()
54
55     # should we set a default icon here or something?
56     main_window = resource(MainWindow)
57     main_window.construct()
58     # When the state changes to CLOSED, quit the application
59     main_window.connect(lambda win: win.get_state() == MainWindow.STATE_CLOSED and gtk.main_quit())
60     # Make the mainwindow accessable as a resource
61     #gtk.threads_init()
62     #gtk.threads_enter()
63     log.debug('Loading model %s' % gaphor_file)
64     if gaphor_file:
65         main_window.set_filename(gaphor_file)
66         main_window.execute_action('FileRevert')
67     else:
68         main_window.execute_action('FileNew')
69     gtk.main()
70     #gtk.threads_leave()
71     log.info('Bye!')
72
73 # TODO: Remove this
74 import __builtin__
75 __builtin__.__dict__['log'] = misc.logger.Logger()
76
77 if __debug__:
78     refs = []
79
Note: See TracBrowser for help on using the browser.