<s> """<STR_LIT>""" <EOL> import warnings <EOL> from traits . api import HasPrivateTraits , Str , TraitError , Instance , Any , Bool <EOL> from mayavi . core . filter import Filter <EOL> from mayavi . core . engine import Engine <EOL> from mayavi . core . source import Source <EOL> from mayavi . core . scene import Scene <EOL> from mayavi . core . module_manager import ModuleManager <EOL> from tvtk . api import tvtk <EOL> from . auto_doc import make_doc <EOL> from . import tools <EOL> from . engine_manager import get_engine <EOL> def get_obj ( obj , components ) : <EOL> """<STR_LIT>""" <EOL> for component in components : <EOL> obj = getattr ( obj , component ) <EOL> return obj <EOL> def make_function ( factory_class ) : <EOL> def the_function ( * args , ** kwargs ) : <EOL> factory = factory_class ( * args , ** kwargs ) <EOL> return factory . _target <EOL> the_function . __doc__ = make_doc ( factory_class ) <EOL> the_function . __name__ = factory_class . __name__ . lower ( ) <EOL> return the_function <EOL> def get_module_manager ( obj ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( obj , '<STR_LIT>' ) : <EOL> return obj . module_manager <EOL> elif isinstance ( obj , ModuleManager ) : <EOL> return obj <EOL> for child in reversed ( obj . children ) : <EOL> if isinstance ( child , ModuleManager ) : <EOL> return child <EOL> else : <EOL> return None <EOL> class PipeFactory ( HasPrivateTraits ) : <EOL> """<STR_LIT>""" <EOL> name = Str ( adapts = '<STR_LIT:name>' , help = '<STR_LIT>' ) <EOL> figure = Instance ( Scene ) <EOL> _engine = Instance ( Engine , help = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> _target = Any <EOL> _do_redraw = Bool <EOL> def add_module ( self , parent , kwargs = dict ( ) ) : <EOL> """<STR_LIT>""" <EOL> if parent is not None : <EOL> module_manager = get_module_manager ( parent ) <EOL> if ( module_manager is not None and <EOL> len ( module_manager . children ) > <NUM_LIT:0> ) : <EOL> scalar_lut = module_manager . scalar_lut_manager <EOL> vector_lut = module_manager . vector_lut_manager <EOL> if '<STR_LIT>' in kwargs : <EOL> if not scalar_lut . use_default_range and kwargs [ '<STR_LIT>' ] != scalar_lut . data_range [ <NUM_LIT:0> ] : <EOL> parent = self . _engine . add_module ( ModuleManager ( ) , <EOL> module_manager . parent ) <EOL> elif not scalar_lut . use_default_range and kwargs [ '<STR_LIT>' ] != scalar_lut . data_range [ <NUM_LIT:0> ] : <EOL> parent = self . _engine . add_module ( ModuleManager ( ) , <EOL> module_manager . parent ) <EOL> elif '<STR_LIT>' in kwargs : <EOL> if not scalar_lut . use_default_range and kwargs [ '<STR_LIT>' ] != scalar_lut . data_range [ <NUM_LIT:1> ] : <EOL> parent = self . _engine . add_module ( ModuleManager ( ) , <EOL> module_manager . parent ) <EOL> elif not scalar_lut . use_default_range and kwargs [ '<STR_LIT>' ] != scalar_lut . data_range [ <NUM_LIT:1> ] : <EOL> parent = self . _engine . add_module ( ModuleManager ( ) , <EOL> module_manager . parent ) <EOL> elif '<STR_LIT>' in kwargs : <EOL> cmap = kwargs [ '<STR_LIT>' ] <EOL> if ( scalar_lut . lut_mode != cmap <EOL> or vector_lut . lut_mode != cmap ) : <EOL> parent = self . _engine . add_module ( ModuleManager ( ) , <EOL> module_manager . parent ) <EOL> self . _engine . add_module ( self . _target , obj = parent ) <EOL> def __init__ ( self , parent , ** kwargs ) : <EOL> super ( PipeFactory , self ) . __init__ ( ) <EOL> ancester = parent <EOL> while hasattr ( ancester , '<STR_LIT>' ) : <EOL> ancester = getattr ( ancester , '<STR_LIT>' ) <EOL> if isinstance ( ancester , Scene ) : <EOL> self . _scene = ancester <EOL> self . _engine = ancester . parent <EOL> break <EOL> else : <EOL> if self . figure is not None : <EOL> self . _scene = self . figure <EOL> else : <EOL> self . _scene = tools . gcf ( ) <EOL> self . _engine = get_engine ( ) <EOL> scene = self . _scene . scene <EOL> if self . figure is not None and self . figure is not self . _scene : <EOL> warnings . warn ( '<STR_LIT>' ) <EOL> if isinstance ( parent , ( Source , tvtk . DataSet ) ) and not isinstance ( parent , Filter ) and scene is not None : <EOL> if not parent in self . _scene . children : <EOL> parent = tools . add_dataset ( parent , figure = self . _scene ) <EOL> if scene is not None : <EOL> self . _do_redraw = not scene . disable_render <EOL> scene . disable_render = True <EOL> if issubclass ( self . _target . __class__ , Filter ) : <EOL> self . _engine . add_filter ( self . _target , obj = parent ) <EOL> else : <EOL> self . add_module ( parent , kwargs ) <EOL> if hasattr ( parent , '<STR_LIT>' ) : <EOL> ms = parent . mlab_source <EOL> self . _target . add_trait ( '<STR_LIT>' , Instance ( ms . __class__ ) ) <EOL> self . _target . mlab_source = ms <EOL> traits = self . get ( self . class_trait_names ( ) ) <EOL> [ traits . pop ( key ) for key in list ( traits . keys ( ) ) <EOL> if key [ <NUM_LIT:0> ] == '<STR_LIT:_>' or key is None ] <EOL> traits . update ( kwargs ) <EOL> self . set ( ** traits ) <EOL> if scene is not None : <EOL> scene . disable_render = not self . _do_redraw <EOL> def set ( self , trait_change_notify = True , ** traits ) : <EOL> """<STR_LIT>""" <EOL> HasPrivateTraits . set ( self , trait_change_notify = trait_change_notify , <EOL> ** traits ) <EOL> if trait_change_notify == False : <EOL> return <EOL> for trait in traits : <EOL> callback = getattr ( self , '<STR_LIT>' % trait ) <EOL> value = getattr ( self , trait ) <EOL> try : <EOL> if callback is not None : <EOL> callback ( ) <EOL> self . _anytrait_changed ( trait , value ) <EOL> except TraitError : <EOL> if value is None : <EOL> pass <EOL> else : <EOL> raise <EOL> def _anytrait_changed ( self , name , value ) : <EOL> """<STR_LIT>""" <EOL> trait = self . trait ( name ) <EOL> if name [ <NUM_LIT:0> ] == '<STR_LIT:_>' : <EOL> return <EOL> if not trait . adapts is None : <EOL> components = trait . adapts . split ( '<STR_LIT:.>' ) <EOL> obj = get_obj ( self . _target , components [ : - <NUM_LIT:1> ] ) <EOL> setattr ( obj , components [ - <NUM_LIT:1> ] , value ) </s>
