Debian Codegraph @

envisage/examples/demo/plugins/tasks/attractors/visualize_2d_task.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 # Local imports.
12 from attractors.model.i_plottable_2d import IPlottable2d
13 from attractors.model_config_pane import ModelConfigPane
14 from attractors.model_help_pane import ModelHelpPane
15 from attractors.plot_2d_pane import Plot2dPane
16
17 # Enthought library imports.
18 from pyface.tasks.action.api import SMenu, SMenuBar, TaskToggleGroup
19 from pyface.tasks.api import PaneItem, Tabbed, Task, TaskLayout
20 from traits.api import adapt, Any, Instance, List
21
22
23 class Visualize2dTask(Task):
24 """A task for visualizing attractors in 2D."""
25
26 #### 'Task' interface #####################################################
27
28 id = "example.attractors.task_2d"
29 name = "2D Visualization"
30
31 menu_bar = SMenuBar(
32 SMenu(id="File", name="&File"),
33 SMenu(id="Edit", name="&Edit"),
34 SMenu(TaskToggleGroup(), id="View", name="&View"),
35 )
36
37 #### 'Visualize2dTask' interface ##########################################
38
39 # The attractor model that is currently active (visible in the center
40 # pane).
41 active_model = Any
42
43 # The list of available attractor models.
44 models = List(Instance(IPlottable2d))
45
46 ###########################################################################
47 # 'Task' interface.
48 ###########################################################################
49
50 def create_central_pane(self):
51 """Create a plot pane with a list of models. Keep track of which model
52 is active so that dock panes can introspect it.
53 """
54 pane = Plot2dPane(models=self.models)
55
56 self.active_model = pane.active_model
57 pane.on_trait_change(self._update_active_model, "active_model")
58
59 return pane
60
61 def create_dock_panes(self):
62 return [
63 ModelConfigPane(model=self.active_model),
64 ModelHelpPane(model=self.active_model),
65 ]
66
67 ###########################################################################
68 # Protected interface.
69 ###########################################################################
70
71 #### Trait initializers ###################################################
72
73 def _default_layout_default(self):
74 return TaskLayout(
75 left=Tabbed(
76 PaneItem("example.attractors.model_config_pane"),
77 PaneItem("example.attractors.model_help_pane"),
78 )
79 )
80
81 def _models_default(self):
82 from attractors.model.henon import Henon
83 from attractors.model.lorenz import Lorenz
84 from attractors.model.rossler import Rossler
85
86 models = [Henon(), Lorenz(), Rossler()]
87
88 return [adapt(model, IPlottable2d) for model in models]
89
90 #### Trait change handlers ################################################
91
92 def _update_active_model(self):
93 self.active_model = self.window.central_pane.active_model
94 for dock_pane in self.window.dock_panes:
95 dock_pane.model = self.active_model