Example #1
0
 def close_scene(scene=None, all=None):
     import copy, warnings
     from enthought.mayavi.tools.engine_manager import get_engine
     from enthought.mayavi.core.scene import Scene
     from enthought.mayavi.core.registry import registry
     if all is True:
         engine = get_engine()
         for scene in copy.copy(engine.scenes):
             engine.close_scene(scene)
         return
     if not isinstance(scene, Scene):
         engine = get_engine()
         if scene is None:
             scene = engine.current_scene
         else:
             try:
                 scene = int(scene)
                 name = 'Mayavi Scene %d' % scene
             except TypeError:
                 name = str(scene)
             for scene in engine.scenes:
                 if scene.name == name:
                     break
             else:
                 warnings.warn('Scene %s not managed by mlab' % name)
                 return
     else:
         if scene.scene is None:
             engine = registry.find_scene_engine(scene)
         else:
             engine = registry.find_scene_engine(scene.scene)
     engine.close_scene(scene)
Example #2
0
def close(scene=None, all=False):
    """ Close a figure window

        close() by itself closes the current figure. 
        
        close(num) closes figure number num.

        close(name) closes figure named name.

        close(figure), where figure is a scene instance, closes that
        figure.

        close(all=True) closes all figures controlled by mlab
    """
    if all is True:
        engine = get_engine()
        # We need the copy, as the list gets pruned as we close scenes
        for scene in copy.copy(engine.scenes):
            engine.close_scene(scene)
        return
    if not isinstance(scene, Scene):
        engine = get_engine()
        if scene is None:
            scene = engine.current_scene
        else:
            if type(scene) in (IntType, np.int, np.int0, np.int8, np.int16,
                               np.int32, np.int64):
                scene = int(scene)
                name = 'Mayavi Scene %d' % scene
            else:
                name = str(scene)
            # Go looking in the engine see if the scene is not already
            # running
            for scene in engine.scenes:
                if scene.name == name:
                    break
            else:
                warnings.warn('Scene %s not managed by mlab' % name)
                return
    else:
        if scene.scene is None:
            engine = registry.find_scene_engine(scene)
        else:
            engine = registry.find_scene_engine(scene.scene)
    engine.close_scene(scene)
Example #3
0
def close(scene=None, all=False):
    """ Close a figure window

        close() by itself closes the current figure. 
        
        close(num) closes figure number num.

        close(name) closes figure named name.

        close(figure), where figure is a scene instance, closes that
        figure.

        close(all=True) closes all figures controlled by mlab
    """
    if all is True:
        engine = get_engine()
        # We need the copy, as the list gets pruned as we close scenes
        for scene in copy.copy(engine.scenes):
            engine.close_scene(scene)
        return
    if not isinstance(scene, Scene):
        engine = get_engine()
        if scene is None:
            scene = engine.current_scene
        else:
            if type(scene) in (IntType, np.int, np.int0, np.int8,
                            np.int16, np.int32, np.int64):
                scene = int(scene)
                name = 'Mayavi Scene %d' % scene
            else:
                name = str(scene)
            # Go looking in the engine see if the scene is not already
            # running
            for scene in engine.scenes:
                if scene.name == name:
                    break
            else:
                warnings.warn('Scene %s not managed by mlab' % name)
                return
    else:
        if scene.scene is None:
            engine = registry.find_scene_engine(scene)
        else:
            engine = registry.find_scene_engine(scene.scene)
    engine.close_scene(scene)
Example #4
0
 def show_engine(self):
     """ Open the engine view corresponding to the engine of the
         scene.
     """
     from enthought.mayavi.core.registry import registry
     from enthought.mayavi.core.ui.engine_rich_view import EngineRichView
     try:
         engine = registry.find_scene_engine(self)
     except TypeError:
         error('This scene is not managed by Mayavi')
     return EngineRichView(engine=engine).scene_editing_view(scene=self)
Example #5
0
    def show_engine(self):
        """ Open the engine view corresponding to the engine of the
            scene.
        """
        from enthought.mayavi.core.registry import registry
        from enthought.mayavi.core.ui.engine_rich_view import EngineRichView

        try:
            engine = registry.find_scene_engine(self)
        except TypeError:
            error("This scene is not managed by Mayavi")
        return EngineRichView(engine=engine).scene_editing_view(scene=self)
Example #6
0
def figure(figure=None,
           bgcolor=None,
           fgcolor=None,
           engine=None,
           size=(400, 350)):
    """ Creates a new scene or retrieves an existing scene. If the mayavi
    engine is not running this also starts it.

    **Keyword arguments**

        :figure: The name of the figure, or handle to it.

        :bgcolor: The color of the background (None is default).

        :fgcolor: The color of the foreground, that is the color of all text
                  annotation labels (axes, orientation axes, scalar bar 
                  labels). It should be sufficiently far from `bgcolor` 
                  to see the annotation texts. (None is default).

        :engine: The mayavi engine that controls the figure.

        :size: The size of the scene created, in pixels. May not apply
               for certain scene viewer.
    """
    if isinstance(figure, Scene):
        if figure.scene is None:
            engine = registry.find_scene_engine(figure)
        else:
            engine = registry.find_scene_engine(figure.scene)
        set_engine(engine)
        engine.current_scene = figure
    else:
        if engine is None:
            engine = get_engine()
        if figure is None:
            name = max(__scene_number_list) + 1
            __scene_number_list.update((name, ))
            name = 'Mayavi Scene %d' % name
            engine.new_scene(name=name, size=size)
            engine.current_scene.name = name
        else:
            if type(figure) in (IntType, np.int, np.int0, np.int8, np.int16,
                                np.int32, np.int64):
                name = int(figure)
                __scene_number_list.update((name, ))
                name = 'Mayavi Scene %d' % name
            else:
                name = str(figure)
            # Go looking in the engine see if the scene is not already
            # running
            for scene in engine.scenes:
                if scene.name == name:
                    engine.current_scene = scene
                    return scene
            else:
                engine.new_scene(name=name, size=size)
                engine.current_scene.name = name
        figure = engine.current_scene
        scene = figure.scene
        if scene is not None:
            if hasattr(scene, 'isometric_view'):
                scene.isometric_view()
            else:
                # Not every viewer might implement this method
                view(40, 50)
    scene = figure.scene
    if scene is not None:
        if bgcolor is None:
            bgcolor = options.background_color
        scene.background = bgcolor
        if fgcolor is None:
            fgcolor = options.foreground_color
        scene.foreground = fgcolor
    return figure
Example #7
0
def figure(figure=None, bgcolor=None, fgcolor=None, engine=None,
                size=(400, 350)):
    """ Creates a new scene or retrieves an existing scene. If the mayavi
    engine is not running this also starts it.

    **Keyword arguments**

        :figure: The name of the figure, or handle to it.

        :bgcolor: The color of the background (None is default).

        :fgcolor: The color of the foreground, that is the color of all text
                  annotation labels (axes, orientation axes, scalar bar 
                  labels). It should be sufficiently far from `bgcolor` 
                  to see the annotation texts. (None is default).

        :engine: The mayavi engine that controls the figure.

        :size: The size of the scene created, in pixels. May not apply
               for certain scene viewer.
    """
    if isinstance(figure, Scene):
        if figure.scene is None:
            engine = registry.find_scene_engine(figure)
        else:
            engine = registry.find_scene_engine(figure.scene)
        set_engine(engine)
        engine.current_scene = figure
    else:
        if engine is None:
            engine = get_engine()
        if figure is None:
            name = max(__scene_number_list) + 1
            __scene_number_list.update((name,))
            name = 'Mayavi Scene %d' % name
            engine.new_scene(name=name, size=size)
            engine.current_scene.name = name
        else:
            if type(figure) in (IntType, np.int, np.int0, np.int8,
                            np.int16, np.int32, np.int64):
                name = int(figure)
                __scene_number_list.update((name,))
                name = 'Mayavi Scene %d' % name
            else:
                name = str(figure)
            # Go looking in the engine see if the scene is not already
            # running
            for scene in engine.scenes:
                if scene.name == name:
                    engine.current_scene = scene
                    return scene
            else:
                engine.new_scene(name=name, size=size)
                engine.current_scene.name = name
        figure = engine.current_scene
        scene = figure.scene
        if scene is not None:
            if hasattr(scene, 'isometric_view'):
                scene.isometric_view()
            else:
                # Not every viewer might implement this method
                view(40, 50)
    scene = figure.scene
    if scene is not None:
        if bgcolor is None:
            bgcolor = options.background_color
        scene.background = bgcolor
        if fgcolor is None:
            fgcolor = options.foreground_color
        scene.foreground = fgcolor
    return figure