| 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, HasTraits, Str |
| 12 |
|
| 13 |
|
| 14 |
class TaskFactory(HasTraits): |
| 15 |
"""A factory for creating a Task with some additional metadata.""" |
| 16 |
|
| 17 |
#: The task factory's unique identifier. This ID is assigned to all tasks |
| 18 |
#: created by the factory. |
| 19 |
id = Str |
| 20 |
|
| 21 |
#: The task factory's user-visible name. |
| 22 |
name = Str |
| 23 |
|
| 24 |
#: A callable with the following signature: |
| 25 |
#: |
| 26 |
#: ``callable(**traits) -> Task`` |
| 27 |
#: |
| 28 |
#: Often this attribute will simply be a Task subclass. |
| 29 |
factory = Callable |
| 30 |
|
| 31 |
def create(self, **traits): |
| 32 |
"""Creates the Task. |
| 33 |
|
| 34 |
The default implementation simply calls the 'factory' attribute. |
| 35 |
""" |
| 36 |
return self.factory(**traits) |
| 37 |
|
| 38 |
def create_with_extensions(self, extensions, **traits): |
| 39 |
"""Creates the Task using the specified TaskExtensions.""" |
| 40 |
task = self.create(**traits) |
| 41 |
for extension in extensions: |
| 42 |
task.extra_actions.extend(extension.actions) |
| 43 |
task.extra_dock_pane_factories.extend( |
| 44 |
extension.dock_pane_factories |
| 45 |
) |
| 46 |
return task |