<commit_before>""" A viewer for mlab scene. Adds a button to open up the engine.
"""

# Author: <NAME> <gael dot varoquaux at normalesup dot org> 
# Copyright (c) 2008, Enthought, Inc.
# License: BSD Style.

# Standard library imports
from os.path import join

# Enthought library imports
from enthought.tvtk.tools.ivtk import IVTK
from enthought.tvtk.pyface.api import DecoratedScene
from enthought.traits.api import Callable
from enthought.pyface.api import ImageResource
from enthought.pyface.action.api import Action, Group
from enthought.resource.api import resource_path

# Local imports
from enthought.mayavi.core.common import error
from enthought.mayavi.preferences.api import set_scene_preferences, \
        get_scene_preferences

###############################################################################
# A decorated scene with an additional button.
###############################################################################
class MayaviScene(DecoratedScene):
    """ Like a decorated scene, but with more buttons.
    """

    image_search_path = [join(resource_path(), 'images'), ]

    ##########################################################################
    # Non-public interface.
    ##########################################################################
    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)

    ######################################################################
    # Trait handlers.
    ######################################################################
    def _actions_default(self):
        actions = [ Group(
                    Action(tooltip="View the Mayavi pipeline",
                        image=ImageResource('m2', 
                                search_path=self.image_search_path),
                        on_perform=self.show_engine,
                        ),
                        ),
                        ]
        actions.extend(DecoratedScene._actions_default(self))
        return actions


def mayavi_scene_factory(parent):
    """A mayavi scene factory that creates a scene with preferences
    appropriately set."""
    p = get_scene_preferences()
    s = MayaviScene(parent, stereo=p['stereo'])
    set_scene_preferences(s, p)
    return s

###############################################################################
# A viewer making use of the MayaviScene 
###############################################################################
class MayaviViewer(IVTK):
    """ A viewer window for mlab.
    """
    size=(400, 350)

    _scene_factory = Callable(mayavi_scene_factory)


def viewer_factory(size=(400, 350)):
    viewer = MayaviViewer()
    viewer.menu_bar_manager = None
    viewer.size=size
    viewer.open()
    return viewer<commit_msg>BUG: The size trait was being overridden and was different from the parent causing a bug with resizing the viewer.  This has been fixed by making use of a trait default initializer.<commit_after>""" A viewer for mlab scene. Adds a button to open up the engine.
"""

# Author: <NAME> <gael dot varoquaux at normalesup dot org> 
# Copyright (c) 2008, Enthought, Inc.
# License: BSD Style.

# Standard library imports
from os.path import join

# Enthought library imports
from enthought.tvtk.tools.ivtk import IVTK
from enthought.tvtk.pyface.api import DecoratedScene
from enthought.traits.api import Callable
from enthought.pyface.api import ImageResource
from enthought.pyface.action.api import Action, Group
from enthought.resource.api import resource_path

# Local imports
from enthought.mayavi.core.common import error
from enthought.mayavi.preferences.api import set_scene_preferences, \
        get_scene_preferences

###############################################################################
# A decorated scene with an additional button.
###############################################################################
class MayaviScene(DecoratedScene):
    """ Like a decorated scene, but with more buttons.
    """

    image_search_path = [join(resource_path(), 'images'), ]

    ##########################################################################
    # Non-public interface.
    ##########################################################################
    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)

    ######################################################################
    # Trait handlers.
    ######################################################################
    def _actions_default(self):
        actions = [ Group(
                    Action(tooltip="View the Mayavi pipeline",
                        image=ImageResource('m2', 
                                search_path=self.image_search_path),
                        on_perform=self.show_engine,
                        ),
                        ),
                        ]
        actions.extend(DecoratedScene._actions_default(self))
        return actions


def mayavi_scene_factory(parent):
    """A mayavi scene factory that creates a scene with preferences
    appropriately set."""
    p = get_scene_preferences()
    s = MayaviScene(parent, stereo=p['stereo'])
    set_scene_preferences(s, p)
    return s

###############################################################################
# A viewer making use of the MayaviScene 
###############################################################################
class MayaviViewer(IVTK):
    """ A viewer window for mlab.
    """

    _scene_factory = Callable(mayavi_scene_factory)

    def _size_default(self):
        return (400, 300)


def viewer_factory(size=(400, 350)):
    viewer = MayaviViewer()
    viewer.menu_bar_manager = None
    viewer.size=size
    viewer.open()
    return viewer
{'fraction_non_alphanumeric': 0.24863138686131386, 'fraction_numerical': 0.005170316301703163, 'mean_word_length': 3.495557074504443, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '659690', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1567, 'n_words': 437}