File: task_factory.py

package info (click to toggle)
python-envisage 7.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,880 kB
  • sloc: python: 8,696; makefile: 76; sh: 5
file content (46 lines) | stat: -rw-r--r-- 1,535 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# (C) Copyright 2007-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
# Enthought library imports.
from traits.api import Callable, HasTraits, Str


class TaskFactory(HasTraits):
    """A factory for creating a Task with some additional metadata."""

    #: The task factory's unique identifier. This ID is assigned to all tasks
    #: created by the factory.
    id = Str

    #: The task factory's user-visible name.
    name = Str

    #: A callable with the following signature:
    #:
    #:     ``callable(**traits) -> Task``
    #:
    #: Often this attribute will simply be a Task subclass.
    factory = Callable

    def create(self, **traits):
        """Creates the Task.

        The default implementation simply calls the 'factory' attribute.
        """
        return self.factory(**traits)

    def create_with_extensions(self, extensions, **traits):
        """Creates the Task using the specified TaskExtensions."""
        task = self.create(**traits)
        for extension in extensions:
            task.extra_actions.extend(extension.actions)
            task.extra_dock_pane_factories.extend(
                extension.dock_pane_factories
            )
        return task