File: task_window.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 (59 lines) | stat: -rw-r--r-- 2,173 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
47
48
49
50
51
52
53
54
55
56
57
58
59
# (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 pyface.image_resource import ImageResource
from pyface.tasks.api import TaskWindow as PyfaceTaskWindow
from traits.api import Instance, Property


class TaskWindow(PyfaceTaskWindow):
    """A TaskWindow for use with the Envisage Tasks plugin."""

    #: The application that created and is managing this window.
    application = Instance("envisage.ui.tasks.api.TasksApplication")

    #: The window's icon.  We override it so it can delegate to the application
    #: icon if the window's icon is not set.
    icon = Property(Instance(ImageResource), observe="_icon")

    #### Protected interface ##################################################

    _icon = Instance(ImageResource, allow_none=True)

    ###########################################################################
    # Protected 'TaskWindow' interface.
    ###########################################################################

    def _get_title(self):
        """If the application has a name, add it to the title. Otherwise,
        behave like the base class.
        """
        if self._title or self.active_task is None:
            return self._title

        title = self.active_task.name
        if self.application.name:
            form = "%s - %s"
            title = form % (title, self.application.name)
        return title

    def _get_icon(self):
        """If we have an icon return it, else delegate to the application."""
        if self._icon is not None:
            return self._icon
        elif self.application is not None:
            return self.application.icon
        else:
            return None

    def _set_icon(self, icon):
        """Explicitly set the icon to use.  None is allowed."""
        self._icon = icon