Debian Codegraph @

envisage/ui/tasks/action/task_window_launch_group.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
11 # Enthought library imports.
12 from pyface.action.api import ActionItem, Group
13 from pyface.tasks.action.api import TaskAction
14 from pyface.tasks.api import TaskWindowLayout
15 from traits.api import List, observe, Str
16
17
18 class TaskWindowLaunchAction(TaskAction):
19 """An Action that creates a task window with a single task."""
20
21 #### 'TaskWindowLaunchAction' interface ###################################
22
23 task_id = Str
24
25 ###########################################################################
26 # 'Action' interface.
27 ###########################################################################
28
29 def perform(self, event):
30 application = event.task.window.application
31 window = application.create_window(TaskWindowLayout(self.task_id))
32 window.open()
33
34 ###########################################################################
35 # Private interface.
36 ###########################################################################
37
38 #### Trait change handlers ################################################
39
40 @observe("task")
41 def _update_name(self, event):
42 """Name the action (unless a name has already been assigned)."""
43 task = event.new
44 if task and not self.name:
45 name = ""
46 for factory in task.window.application.task_factories:
47 if factory.id == self.task_id:
48 name = factory.name
49 break
50 self.name = name
51
52
53 class TaskWindowLaunchGroup(Group):
54 """A Group for creating task windows with a single task."""
55
56 #### 'Group' interface ####################################################
57
58 id = "TaskWindowLaunchGroup"
59 items = List
60
61 ###########################################################################
62 # Private interface.
63 ###########################################################################
64
65 def _items_default(self):
66 manager = self
67 while isinstance(manager, Group):
68 manager = manager.parent
69 application = manager.controller.task.window.application
70
71 items = []
72 for factory in application.task_factories:
73 action = TaskWindowLaunchAction(task_id=factory.id)
74 items.append(ActionItem(action=action))
75 return items