Debian Codegraph @

envisage/ui/tasks/tasks_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 # Enthought library imports.
11 from traits.api import Callable, Instance, List
12
13 from envisage.api import ExtensionPoint, Plugin, ServiceOffer
14
15 # Local imports.
16 from .preferences_category import PreferencesCategory
17
18 # Constants.
19 PKG = ".".join(__name__.split(".")[:-1])
20
21
22 class TasksPlugin(Plugin):
23 """The Envisage Tasks plugin.
24
25 The Tasks plugin uses Pyface Tasks to provide an extensible framework for
26 building user interfaces. For more information, see the Tasks User Manual.
27 """
28
29 # The IDs of the extension point that this plugin offers.
30 PREFERENCES_CATEGORIES = PKG + ".preferences_categories"
31 PREFERENCES_PANES = PKG + ".preferences_panes"
32 TASKS = PKG + ".tasks"
33 TASK_EXTENSIONS = PKG + ".task_extensions"
34
35 # The IDs of the extension points that this plugin contributes to.
36 SERVICE_OFFERS = "envisage.service_offers"
37
38 #### 'IPlugin' interface ##################################################
39
40 #: The plugin's unique identifier.
41 id = "envisage.ui.tasks"
42
43 #: The plugin's name (suitable for displaying to the user).
44 name = "Tasks"
45
46 #### Extension points offered by this plugin ##############################
47
48 #: Contributed preference categories. Contributions to this extension
49 #: point must have type ``PreferencesCategory``. Preference categories
50 #: will be created automatically if necessary; this extension point is
51 #: useful when ensuring that a category is inserted at a specific location.
52 preferences_categories = ExtensionPoint(
53 List(PreferencesCategory),
54 id=PREFERENCES_CATEGORIES,
55 desc="""
56
57 This extension point makes preference categories available to the
58 application. Note that preference categories will be created
59 automatically if necessary; this extension point is useful when one
60 wants to ensure that a category is inserted at a specific location.
61 """,
62 )
63
64 #: Contributed preference pane factories. Each contribution to this
65 #: extension point must be a callable with the signature
66 #: ``callable(**traits) -> PreferencePane``.
67 preferences_panes = ExtensionPoint(
68 List(Callable),
69 id=PREFERENCES_PANES,
70 desc="""
71
72 A preferences pane appears in the preferences dialog to allow the user
73 manipulate certain preference values.
74
75 Each contribution to this extension point must be a factory that
76 creates a preferences pane, where 'factory' means any callable with the
77 following signature::
78
79 callable(**traits) -> PreferencesPane
80
81 The easiest way to contribute such a factory is to create a class
82 that derives from 'envisage.ui.tasks.api.PreferencesPane'.
83 """,
84 )
85
86 #: Contributed task factories. Contributions to this extension point
87 #: must have type ``TaskFactory``.
88 tasks = ExtensionPoint(
89 List(Instance("envisage.ui.tasks.task_factory.TaskFactory")),
90 id=TASKS,
91 desc="""
92
93 This extension point makes tasks avaiable to the application.
94
95 Each contribution to the extension point must be an instance of
96 'envisage.tasks.api.TaskFactory.
97 """,
98 )
99
100 #: Contributed task extensions. Contributions to this extension point
101 #: must have type ``TaskExtension``.
102 task_extensions = ExtensionPoint(
103 List(Instance("envisage.ui.tasks.task_extension.TaskExtension")),
104 id=TASK_EXTENSIONS,
105 desc="""
106
107 This extension point permits the contribution of new actions and panes
108 to existing tasks (without creating a new task).
109
110 Each contribution to the extension point must be an instance of
111 'envisage.tasks.api.TaskExtension'.
112 """,
113 )
114
115 #### Contributions to extension points made by this plugin ################
116
117 my_service_offers = List(contributes_to=SERVICE_OFFERS)
118
119 def _my_service_offers_default(self):
120 preferences_dialog_service_offer = ServiceOffer(
121 protocol="envisage.ui.tasks.preferences_dialog.PreferencesDialog",
122 factory=self._create_preferences_dialog_service,
123 )
124
125 return [preferences_dialog_service_offer]
126
127 my_task_extensions = List(contributes_to=TASK_EXTENSIONS)
128
129 def _my_task_extensions_default(self):
130 from pyface.tasks.action.api import DockPaneToggleGroup, SchemaAddition
131
132 from .action.exit_action import ExitAction
133 from .action.preferences_action import PreferencesGroup
134 from .task_extension import TaskExtension
135
136 actions = [
137 SchemaAddition(id="Exit", factory=ExitAction, path="MenuBar/File"),
138 SchemaAddition(
139 id="Preferences", factory=PreferencesGroup, path="MenuBar/Edit"
140 ),
141 SchemaAddition(
142 id="DockPaneToggleGroup",
143 factory=DockPaneToggleGroup,
144 path="MenuBar/View",
145 ),
146 ]
147
148 return [TaskExtension(actions=actions)]
149
150 ###########################################################################
151 # Private interface.
152 ###########################################################################
153
154 def _create_preferences_dialog_service(self):
155 """Factory method for preferences dialog service."""
156 from .preferences_dialog import PreferencesDialog
157
158 dialog = PreferencesDialog(application=self.application)
159 dialog.trait_set(
160 categories=self.preferences_categories,
161 panes=[
162 factory(dialog=dialog) for factory in self.preferences_panes
163 ],
164 )
165 return dialog