/usr/share/pyshared/mayavi/plugins/script.py is in mayavi2 4.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | """This represents the scripting API for MayaVi.
The Script class provides a scriptable view of the MayaVi Engine. It is
safe to instantiate as many Script instances as desired.
"""
# Author: Prabhu Ramachandran <prabhu_r@users.sf.net>
# Copyright (c) 2005-2008, Enthought, Inc.
# License: BSD Style.
# Enthought imports
from traits.api import HasTraits, Instance
# Local imports
from mayavi.core.engine import Engine
from mayavi.core.common import exception
##############################################################################
# Utility functions.
##############################################################################
def get_imayavi_engine(window):
"""Returns the MayaVi Engine given the Envisage worbench window.
"""
return window.get_service(Engine)
def get_imayavi(window):
"""Given the Envisage workbench window, returns the
mayavi.script.Script instance (registered as
`mayavi.services.IMAYAVI`).
"""
return window.get_service(Script)
##############################################################################
# `Script` class.
##############################################################################
class Script(HasTraits):
"""This class basically presents a scriptable 'view' of the MayaVi
Engine. It is registered as the IMayaVi service (via an
ApplicationObject) because this is the interface users should be
using when they script.
"""
# The workbench window we are associated with.
window = Instance('pyface.workbench.api.WorkbenchWindow')
# The MayaVi engine that we are managing.
engine = Instance(Engine)
######################################################################
# `Script` interface
######################################################################
def add_source(self, src, scene=None):
"""Adds a given source to the MayaVi pipeline.
"""
try:
self.engine.add_source(src, scene=scene)
except:
exception()
def add_module(self, mod, obj=None):
"""Adds a given module to the MayaVi pipeline. Adds it to the selected
object, or to an object passed thought the kwarg `obj`.
"""
try:
self.engine.add_module(mod, obj=obj)
except:
exception()
def add_filter(self, fil, obj=None):
"""Adds a given filter to the MayaVi pipeline. Adds it to the selected
object, or to an object passed thought the kwarg `obj`.
"""
try:
self.engine.add_filter(fil, obj=obj)
except:
exception()
def new_scene(self):
"""Creates a new VTK scene window.
"""
return self.engine.new_scene()
def load_visualization(self, fname):
"""Given a file/file name this loads the visualization.
"""
try:
self.engine.load_visualization(fname)
except:
exception()
def save_visualization(self, fname):
"""Given a file or a file name, this saves the current
visualization to the file.
"""
try:
self.engine.save_visualization(fname)
except:
exception()
def get_active_window(self):
"""Get the currently active window."""
return self.window
def open(self, filename):
"""Open a data file if possible.
"""
try:
return self.engine.open(filename)
except:
exception()
######################################################################
# Non-public interface
######################################################################
def _window_changed(self, window):
"""Traits handler for changes to application.
"""
self.engine = get_imayavi_engine(window)
|