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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
"""
The definition of different kinds of metadata that is put into the
mayavi registry
"""
# Author: Prabhu Ramachandran <prabhu@aero.iitb.ac.in>
# Copyright (c) 2008, Enthought, Inc.
# License: BSD Style.
# Enthought library imports.
from traits.api import HasTraits, Str, Callable, Either, List, Instance
from mayavi.core.pipeline_info import PipelineInfo
################################################################################
# Utility functions.
################################################################################
def import_symbol(symbol_path):
""" Import the symbol defined by the specified symbol path.
Copied from envisage's import manager.
"""
if ':' in symbol_path:
module_name, symbol_name = symbol_path.split(':')
module = import_module(module_name)
symbol = eval(symbol_name, module.__dict__)
else:
components = symbol_path.split('.')
module_name = '.'.join(components[:-1])
symbol_name = components[-1]
module = __import__(
module_name, globals(), locals(), [symbol_name]
)
symbol = getattr(module, symbol_name)
return symbol
def import_module(module_name):
"""This imports the given module name. This code is copied from
envisage's import manager!
"""
module = __import__(module_name)
components = module_name.split('.')
for component in components[1:]:
module = getattr(module, component)
return module
################################################################################
# `Metadata` class.
################################################################################
class Metadata(HasTraits):
"""
This class allows us to define metadata related to mayavi's sources,
filters and modules.
"""
# Our ID.
id = Str
# The class that implements the module/filter/source.
class_name = Str
# The factory that implements the object overrides the class_name if
# not the empty string. The callable will be given the filename to
# open along with the engine (for sources).
factory = Either(Str, Callable, allow_none=False)
# Description of the object being described.
desc = Str
# Help string for the object.
help = Str
# The name of this object in a menu.
menu_name = Str
# The optional tooltip to display for this object.
tooltip = Str
# Information about what this object can consume.
input_info = Instance(PipelineInfo)
# Information about what this object can produce.
output_info = Instance(PipelineInfo)
######################################################################
# Metadata interface.
######################################################################
def get_callable(self):
"""Return the callable that will create a new instance of the
object implementing this metadata.
"""
factory = self.factory
if factory is not None:
if callable(factory):
symbol = factory
elif isinstance(factory, str) and len(factory) > 0:
symbol = import_symbol(factory)
else:
symbol = import_symbol(self.class_name)
else:
symbol = import_symbol(self.class_name)
return symbol
################################################################################
# `ModuleMetadata` class.
################################################################################
class ModuleMetadata(Metadata):
pass
################################################################################
# `FilterMetadata` class.
################################################################################
class FilterMetadata(Metadata):
pass
################################################################################
# `SourceMetadata` class.
################################################################################
class SourceMetadata(Metadata):
# The file name extension that this reader/source handles. Empty if
# it does not read a file.
extensions = List(Str)
# Wildcard for the file dialog.
wildcard = Str
# `Callable` to check if the reader can actually read the file
# `Callable` must accept the filename to be read and it should
# return `True` if its possible to read the file else 'False'
can_read_test = Str
|