| 1 |
""" |
|---|
| 2 |
""" |
|---|
| 3 |
|
|---|
| 4 |
import pkg_resources |
|---|
| 5 |
from zope import interface |
|---|
| 6 |
from gaphor.interfaces import IService, IActionProvider |
|---|
| 7 |
from gaphor.ui.interfaces import IUIComponent |
|---|
| 8 |
from gaphor.core import inject |
|---|
| 9 |
|
|---|
| 10 |
class GUIManager(object): |
|---|
| 11 |
|
|---|
| 12 |
interface.implements(IService) |
|---|
| 13 |
|
|---|
| 14 |
action_manager = inject('action_manager') |
|---|
| 15 |
|
|---|
| 16 |
def __init__(self): |
|---|
| 17 |
self._ui_components = dict() |
|---|
| 18 |
|
|---|
| 19 |
main_window = property(lambda s: s._main_window) |
|---|
| 20 |
|
|---|
| 21 |
def init(self, app): |
|---|
| 22 |
self._app = app |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
self.init_stock_icons() |
|---|
| 26 |
self.init_ui_components() |
|---|
| 27 |
self.init_main_window() |
|---|
| 28 |
|
|---|
| 29 |
def init_pygtk(self): |
|---|
| 30 |
""" |
|---|
| 31 |
Make sure we have GTK+ >= 2.0 |
|---|
| 32 |
""" |
|---|
| 33 |
import pygtk |
|---|
| 34 |
pygtk.require('2.0') |
|---|
| 35 |
del pygtk |
|---|
| 36 |
|
|---|
| 37 |
def init_stock_icons(self): |
|---|
| 38 |
|
|---|
| 39 |
import gaphor.ui.stock |
|---|
| 40 |
gaphor.ui.stock.load_stock_icons() |
|---|
| 41 |
|
|---|
| 42 |
def init_ui_components(self): |
|---|
| 43 |
ui_manager = self.action_manager.ui_manager |
|---|
| 44 |
for ep in pkg_resources.iter_entry_points('gaphor.uicomponents'): |
|---|
| 45 |
log.debug('found entry point uicomponent.%s' % ep.name) |
|---|
| 46 |
cls = ep.load() |
|---|
| 47 |
if not IUIComponent.implementedBy(cls): |
|---|
| 48 |
raise 'MisConfigurationException', 'Entry point %s doesn''t provide IUIComponent' % ep.name |
|---|
| 49 |
uicomp = cls() |
|---|
| 50 |
uicomp.ui_manager = ui_manager |
|---|
| 51 |
self._ui_components[ep.name] = uicomp |
|---|
| 52 |
if IActionProvider.providedBy(uicomp): |
|---|
| 53 |
self.action_manager.register_action_provider(uicomp) |
|---|
| 54 |
|
|---|
| 55 |
def init_main_window(self): |
|---|
| 56 |
from gaphor.ui.accelmap import load_accel_map |
|---|
| 57 |
|
|---|
| 58 |
load_accel_map() |
|---|
| 59 |
self._main_window = self._ui_components['mainwindow'] |
|---|
| 60 |
self._main_window.construct() |
|---|
| 61 |
|
|---|
| 62 |
def shutdown(self): |
|---|
| 63 |
if self._main_window.window: |
|---|
| 64 |
self._main_window.window.destroy() |
|---|
| 65 |
from gaphor.ui.accelmap import save_accel_map |
|---|
| 66 |
save_accel_map() |
|---|
| 67 |
|
|---|
| 68 |
|
|---|