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

Revision 262, 2.9 kB (checked in by arjanmol, 5 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 import version
16 import types
17
18 import gaphor.version
19
20 _resources = {
21     'Name': 'gaphor',
22     'Version': gaphor.version.VERSION,
23     'DataDir': gaphor.version.DATA_DIR
24 }
25
26 _main_window = None
27
28 class GaphorError(Exception):
29     """
30     Gaphor specific exception class
31     """
32     def __init__(self, args=None):
33             self.args = args
34
35
36 def main():
37     """Start the interactive application.
38     """
39     global _resources
40     # Import stuff here, since the user might not need all the GUI stuff
41     import gtk
42     #import bonobo
43     #import gnome
44     # Initialize gnome.ui, since we need some definitions from it
45     #import gnome.ui
46     from ui import MainWindow
47     #gnome.init('gaphor', gaphor.version.VERSION)
48     # should we set a default icon here or something?
49     main_window = MainWindow()
50     main_window.construct()
51     # When the state changes to CLOSED, quit the application
52     #main_window.connect(lambda win: win.get_state() == MainWindow.STATE_CLOSED and bonobo.main_quit())
53     main_window.connect(lambda win: win.get_state() == MainWindow.STATE_CLOSED and gtk.main_quit())
54     #mainwin = GaphorResource(WindowFactory).create(type=MainWindow)
55     _resources['MainWindow'] = main_window
56     #gtk.threads_init()
57     #gtk.threads_enter()
58     gtk.main()
59     #gtk.threads_leave()
60     log.info('Bye!')
61
62
63 def get_conf(self, key):
64     if not self.__conf:
65         from gaphor.misc.conf import Conf
66         self.__conf = Conf(self.NAME)
67     return self.__conf[key]
68
69
70 _no_default = []
71
72 def resource(r, default=_no_default):
73     """Locate a resource.
74
75     Resource should be the class of the resource to look for or a string. In
76     case of a string the resource will be looked up in the GConf configuration.
77
78     example: Get the element factory:
79             factory = gaphor.resource(gaphor.UML.ElementFactory)
80
81     Also builtin resources are 'Name', 'Version' and 'DataDir'. In case main()
82     is run, 'MainWindow' points to the main window of the application.
83
84     If a class name is given as a resource, the resource is created if not
85     yet available. If the resource is a string, KeyError is issued if the
86     resource could not be localed, unless a default value was set.
87     """
88     global _resources
89     try:
90         return _resources[r]
91     except KeyError:
92         pass
93     # Handle string-like resources
94     if isinstance (r, types.StringType):
95         # TODO: It might be a GConf resource string
96
97         if default is not _no_default:
98             return default
99         raise KeyError, 'No resource with name "%s"' % r
100     # Instantiate the resource and return it
101     i = r()
102     _resources[r] = i
103     _resources[r.__name__] = i
104     return i
105
106
107 import __builtin__
108 __builtin__.__dict__['log'] = misc.logger.Logger()
109
110 if __debug__:
111     refs = []
112
Note: See TracBrowser for help on using the browser.