Debian Codegraph @

envisage/plugins/event_manager/plugin.py

raw
1 # (C) Copyright 2007-2025 Enthought, Inc., Austin, TX
2 # All rights reserved.
3 #
4 # This software is provided without warranty under the terms of the BSD
5 # license included in LICENSE.txt and may be redistributed only under
6 # the conditions described in the aforementioned license. The license
7 # is also available online at http://www.enthought.com/licenses/BSD.txt
8 #
9 # Thanks for using Enthought open source!
10 """ This module provides a plugin which adds an EventManager to application.
11
12 If the application does not already have an evt_mgr attribute which is an
13 instance of EventManager, the plugin creates a new EventManager instance,
14 creates a service to offer the event manager and sets the evt_mgr instance
15 of the application to the created event manager.
16 """
17
18 from traits.api import List
19
20 # Enthought library imports.
21 from envisage.api import Plugin, ServiceOffer
22
23
24 class EventManagerPlugin(Plugin):
25 """Plugin to add event manager to the application."""
26
27 #: The plugin's unique identifier.
28 id = "envisage.event_manager"
29
30 #: The plugin's name (suitable for displaying to the user).
31 name = "Event Manager"
32
33 SERVICE_OFFERS = "envisage.service_offers"
34 service_offers = List(contributes_to=SERVICE_OFFERS)
35
36 def _service_offers_default(self):
37 from encore.events.api import BaseEventManager, get_event_manager
38
39 evt_mgr_service_offer = ServiceOffer(
40 protocol=BaseEventManager,
41 factory=get_event_manager,
42 )
43 return [evt_mgr_service_offer]