1
"""A view of the pipeline with a panel to edit objects.
4
# Author: Gael Varoquaux <gael dot varoquaux at normalesup dot org>
5
# Copyright (c) 2009, Enthought, Inc.
8
# Enthought library imports.
9
from enthought.traits.ui.api import Item, View, HSplit, InstanceEditor
10
from enthought.traits.ui.menu import Action, Separator
11
from enthought.pyface.image_resource import ImageResource
12
from enthought.pyface.api import GUI
13
from enthought.mayavi.core.adder_node import SceneAdderNode
16
from enthought.mayavi.core.scene import Scene
17
from enthought.mayavi.preferences.preference_manager_view import \
18
preference_manager_view
19
from enthought.mayavi.core.ui.engine_view import EngineView, \
23
class EngineRichViewHandler(EngineViewHandler):
24
""" A handler for the EngineRichView object.
27
def init_info(self, info):
28
""" Informs the handler what the UIInfo object for a View will be.
29
Overridden here to add a callback on the creation of the view.
32
super(EngineRichViewHandler, self).init_info(info)
33
info.on_trait_change(self.select_selected, 'initialized')
37
def select_selected(self, initialized):
38
""" Force the tree editor to select the current engine selection,
39
and eventually collapse other scenes.
41
# We need to explore the editors to find the one we are
42
# interested in, and to switch its selection to None, and then
43
# back to what we are interested in.
44
editors = self.info.ui._editors
45
if editors is not None:
46
for editor in editors:
47
if editor.factory is self.info.object.tree_editor:
55
# We switch the selection to None, but we avoid
56
# trait callback, to avoid changing the engine's
58
tree_editor.set(selected=None, trait_change_notify=False)
59
current_selection = self.info.object.engine.current_selection
60
GUI.set_trait_later(tree_editor, 'selected', current_selection)
62
# If we are selecting a scene, collapse the others
63
if isinstance(current_selection, Scene) and \
64
hasattr(tree_editor._tree, 'Collapse'):
65
# The wx editor can collapse, dunno for the Qt
66
for scene in self.info.object.engine.scenes:
67
if scene is not current_selection:
68
tree_editor._tree.Collapse(
69
tree_editor._get_object_nid(scene))
72
def _on_dclick(self, object):
73
""" Called when a node in the tree editor is double-clicked.
75
if isinstance(object, SceneAdderNode):
76
self.info.object._perform_new_scene()
78
# In this view, we want the dialogs not to be modals, so that
79
# the EngineRichView window can be closed while leaving
80
# objects dialogs open.
81
object.edit_traits(view=object.dialog_view())
84
##############################################################################
85
# EngineRichView class.
86
##############################################################################
87
class EngineRichView(EngineView):
88
""" A view displaying the engine's object tree, alongside with a
89
panel to edit the objects.
92
###########################################################################
93
# `HasTraits` interface.
94
###########################################################################
95
def default_traits_view(self):
96
"""The default traits view of the Engine View.
100
id='mayavi.engine_rich_view.pipeline_view',
103
editor=self.tree_editor,
107
id='mayavi.engine_rich_view.current_selection',
108
editor=InstanceEditor(
109
view='current_selection_view'),
115
id='enthought.mayavi.engine_rich_view',
122
title='Mayavi pipeline',
124
toolbar=self.toolbar,
125
handler=EngineRichViewHandler)
129
def _actions_default(self):
130
""" Append a preferences action to the toolbar: this view of the
131
engine is meant to be a powerful view giving access to
132
all of Mayavi's functionality.
134
preferences_action = \
136
image=ImageResource('preferences.png',
137
search_path=self._image_path),
138
tooltip="Modify Mayavi's preferences",
141
perform=preference_manager_view.dialog_view,
144
actions = super(EngineRichView, self)._actions_default()
145
actions.extend((Separator(), preferences_action))
148
###########################################################################
149
# EngineRichView interface.
150
###########################################################################
152
def scene_editing_view(self, scene):
153
# Selecting an object if good, because it forces the HSplit to
154
# choose a sensible split ratio
155
for mayavi_scene in self.engine.scenes:
156
sc = mayavi_scene.scene
157
# Support for the `MlabSceneModel` where the `scene_editor`
158
# trait contains the scene.
159
s = getattr(sc, 'scene_editor', sc)
161
self.engine.current_selection = mayavi_scene
163
return self.edit_traits()
166
### EOF ######################################################################