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