Ejemplo n.º 1
0
    def __init__(self, parent, **kwargs):
        # We are not passing the traits to the parent class
        super(PipeFactory, self).__init__()
        # Try to find the right engine and scene to work with
        ancester = parent
        while hasattr(ancester, 'parent'):
            ancester = getattr(ancester, 'parent')
            if isinstance(ancester, Scene):
                self._scene = ancester
                self._engine = ancester.parent
                break
        else:
            if self.figure is not None:
                self._scene = self.figure
            else:
                self._scene = tools.gcf()
                self._engine = get_engine()
        scene = self._scene.scene
        if self.figure is not None and self.figure is not self._scene:
            warnings.warn('Trying to add a module on the wrong scene')
        if isinstance(parent, (Source, tvtk.DataSet)) \
                and not isinstance(parent, Filter) and scene is not None:
            # Search the current scene to see if the  source is already
            # in it, if not add it.
            if not parent in self._scene.children:
                parent = tools.add_dataset(parent, figure=self._scene)

        if scene is not None:
            self._do_redraw = not scene.disable_render
            scene.disable_render = True
        if issubclass(self._target.__class__, Filter):
            self._engine.add_filter(self._target, obj=parent)
        else:
            self.add_module(parent, kwargs)

        # Inject the magical mlab source trait.
        if hasattr(parent, 'mlab_source'):
            ms = parent.mlab_source
            self._target.add_trait('mlab_source', Instance(ms.__class__))
            self._target.mlab_source = ms

        traits = self.get(self.class_trait_names())
        [
            traits.pop(key) for key in traits.keys()
            if key[0] == '_' or key is None
        ]
        traits.update(kwargs)
        # Now calling the traits setter, so that traits handlers are
        # called
        self.set(**traits)
        if scene is not None:
            scene.disable_render = not self._do_redraw
Ejemplo n.º 2
0
    def __init__(self, parent, **kwargs):
        # We are not passing the traits to the parent class
        super(PipeFactory, self).__init__()
        # Try to find the right engine and scene to work with
        ancester = parent
        while hasattr(ancester, 'parent'):
            ancester = getattr(ancester, 'parent')
            if isinstance(ancester, Scene):
                self._scene = ancester
                self._engine = ancester.parent
                break
        else:
            if self.figure is not None:
                self._scene = self.figure
            else:
                self._scene = tools.gcf()
                self._engine = get_engine()
        scene = self._scene.scene
        if self.figure is not None and self.figure is not self._scene:
            warnings.warn('Trying to add a module on the wrong scene')
        if isinstance(parent, (Source, tvtk.DataSet)) \
                and not isinstance(parent, Filter) and scene is not None:
            # Search the current scene to see if the  source is already
            # in it, if not add it.
            if not parent in self._scene.children:
                parent = tools.add_dataset(parent, figure=self._scene)


        if scene is not None:
            self._do_redraw = not scene.disable_render
            scene.disable_render = True
        if issubclass(self._target.__class__, Filter):
            self._engine.add_filter(self._target, obj=parent)
        else:
            self.add_module(parent, kwargs)

        # Inject the magical mlab source trait.
        if hasattr(parent, 'mlab_source'):
            ms = parent.mlab_source
            self._target.add_trait('mlab_source', Instance(ms.__class__))
            self._target.mlab_source = ms

        traits = self.get(self.class_trait_names())
        [traits.pop(key) for key in traits.keys()
                                    if key[0]=='_' or key is None]
        traits.update(kwargs)
        # Now calling the traits setter, so that traits handlers are
        # called
        self.set(**traits)
        if scene is not None:
            scene.disable_render = not self._do_redraw
Ejemplo n.º 3
0
 def __call__(self, *args, **kwargs):
     """ Calls the logics of the factory, but only after disabling
         rendering, if needed.
     """
     # First retrieve the scene, if any.
     if 'figure' in kwargs:
         figure = kwargs['figure']
         assert isinstance(figure, (Scene, None))
         scene = figure.scene
     else:
         scene = tools.gcf().scene
     if scene is not None:
         self._do_redraw = not scene.disable_render
         scene.disable_render = True
     # Then call the real logic
     output = self.__call_internal__(*args, **kwargs)
     # And re-enable the rendering, if needed.
     if scene is not None:
         scene.disable_render = not self._do_redraw
     return output
Ejemplo n.º 4
0
 def __call__(self, *args, **kwargs):
     """ Calls the logics of the factory, but only after disabling
         rendering, if needed.
     """
     # First retrieve the scene, if any.
     if 'figure' in kwargs:
         figure = kwargs['figure']
         assert isinstance(figure, (Scene, None))
         scene = figure.scene
     else:
         scene = tools.gcf().scene
     if scene is not None:
         self._do_redraw = not scene.disable_render
         scene.disable_render = True
     # Then call the real logic
     output = self.__call_internal__(*args, **kwargs)
     # And re-enable the rendering, if needed.
     if scene is not None:
         scene.disable_render = not self._do_redraw
     return output