| 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 |
|
| 11 |
# Enthought library imports. |
| 12 |
from pyface.image_resource import ImageResource |
| 13 |
from pyface.tasks.api import TaskWindow as PyfaceTaskWindow |
| 14 |
from traits.api import Instance, Property |
| 15 |
|
| 16 |
|
| 17 |
class TaskWindow(PyfaceTaskWindow): |
| 18 |
"""A TaskWindow for use with the Envisage Tasks plugin.""" |
| 19 |
|
| 20 |
#: The application that created and is managing this window. |
| 21 |
application = Instance("envisage.ui.tasks.api.TasksApplication") |
| 22 |
|
| 23 |
#: The window's icon. We override it so it can delegate to the application |
| 24 |
#: icon if the window's icon is not set. |
| 25 |
icon = Property(Instance(ImageResource), observe="_icon") |
| 26 |
|
| 27 |
#### Protected interface ################################################## |
| 28 |
|
| 29 |
_icon = Instance(ImageResource, allow_none=True) |
| 30 |
|
| 31 |
########################################################################### |
| 32 |
# Protected 'TaskWindow' interface. |
| 33 |
########################################################################### |
| 34 |
|
| 35 |
def _get_title(self): |
| 36 |
"""If the application has a name, add it to the title. Otherwise, |
| 37 |
behave like the base class. |
| 38 |
""" |
| 39 |
if self._title or self.active_task is None: |
| 40 |
return self._title |
| 41 |
|
| 42 |
title = self.active_task.name |
| 43 |
if self.application.name: |
| 44 |
form = "%s - %s" |
| 45 |
title = form % (title, self.application.name) |
| 46 |
return title |
| 47 |
|
| 48 |
def _get_icon(self): |
| 49 |
"""If we have an icon return it, else delegate to the application.""" |
| 50 |
if self._icon is not None: |
| 51 |
return self._icon |
| 52 |
elif self.application is not None: |
| 53 |
return self.application.icon |
| 54 |
else: |
| 55 |
return None |
| 56 |
|
| 57 |
def _set_icon(self, icon): |
| 58 |
"""Explicitly set the icon to use. None is allowed.""" |
| 59 |
self._icon = icon |