root/gaphor/tags/gaphor-0.11.1/gaphor/core.py

Revision 1806, 1.0 kB (checked in by arj..@yirdis.nl, 1 year ago)
  • fixed line endings
  • fix stock icon loading so it works in conjunction with plugins.
Line 
1 """
2 The Core module provides an entry point for Gaphor's core constructs.
3
4 An average module should only need to import this module.
5 """
6
7 from gaphor.application import Application as _Application
8 from gaphor.transaction import Transaction, transactional
9 from gaphor.action import action, toggle_action, radio_action, build_action_group
10 from gaphor.i18n import _
11
12
13 class inject(object):
14     """
15     Simple descriptor for dependency injection.
16     This is technically a wrapper around Application.get_service().
17
18     Usage::
19
20       class A(object):
21         gui_manager = inject('gui_manager')
22     """
23    
24     def __init__(self, name):
25         self._name = name
26         self._inj = None
27        
28     def __get__(self, obj, class_=None):
29         """
30         Resolve a dependency, but only if we're called from an object instance.
31         """
32         if not obj:
33             return self
34         if self._inj is None:
35             self._inj = _Application.get_service(self._name)
36         return self._inj
37
38
39 # vim:sw=4:et:ai
Note: See TracBrowser for help on using the browser.