<commit_before>"""A scene object manages a TVTK scene and objects in it.
"""
# Author: <NAME> <<EMAIL>>
# Copyright (c) 2005,  Enthought, Inc.
# License: BSD Style.

# Enthought library imports.
from traits.api import Event, List, Str, Instance
from traitsui.api import View, Group, Item
from apptools.persistence.state_pickler import set_state

# Local imports.
from tvtk.pyface.tvtk_scene import TVTKScene
from mayavi.core.base import Base
from mayavi.core.source import Source
from mayavi.core.common import handle_children_state, exception
from mayavi.core.adder_node import SourceAdderNode

######################################################################
# `Scene` class.
######################################################################
class Scene(Base):
    """ The Mayavi scene class.
    """

    # The version of this class.  Used for persistence.
    __version__ = 0

    # The scene (RenderWindow) associated with this component -- we
    # redeclare it here just to be able to record this scene, we don't
    # want it recorded on all objects since the scene is shared
    # (although it isn't an error to register an object twice with the
    # recorder).
    scene = Instance(TVTKScene, record=True)

    # The source objects associated with this object.
    children = List(Source, record=True)

    # The name of this scene.
    name = Str('TVTK Scene')

    # The icon
    icon = Str('scene.ico')

    # The human-readable type for this object
    type = Str(' scene')

    # The objects view.
    view = View(Group(Item(name='scene', style='custom'),
                           show_labels=False)
               )

    # The adder node dialog class
    _adder_node_class = SourceAdderNode

    # The dispatch, to register callbacks on mouse pick
    _mouse_pick_dispatcher = Instance(
        'mayavi.core.mouse_pick_dispatcher.MousePickDispatcher',
        record=False)

    # The scene has been closed.
    closed = Event()

    ######################################################################
    # `object` interface
    ######################################################################
    def __get_pure_state__(self):
        # Base removes the scene, but we need to save it!
        d = super(Scene, self).__get_pure_state__()
        d['scene'] = self.scene
        d.pop('_mouse_pick_dispatcher', None)
        return d

    def __set_pure_state__(self, state):
        handle_children_state(self.children, state.children)
        # Now set our complete state.  Doing the scene last ensures
        # that the camera view is set right.
        set_state(self, state, last=['scene'])

    ######################################################################
    # `Scene` interface
    ######################################################################

    def on_mouse_pick(self, callback, type='point', button='Left',
                            remove=False):
        """ Add a picking callback on mouse click.

            When the mouse button is press, object picking is called, and
            the given callback is invoked with the resulting pick
            as an argument.<commit_msg>Remove unused closed event var<commit_after>"""A scene object manages a TVTK scene and objects in it.
"""
# Author: <NAME> <<EMAIL>>
# Copyright (c) 2005,  Enthought, Inc.
# License: BSD Style.

# Enthought library imports.
from traits.api import Event, List, Str, Instance
from traitsui.api import View, Group, Item
from apptools.persistence.state_pickler import set_state

# Local imports.
from tvtk.pyface.tvtk_scene import TVTKScene
from mayavi.core.base import Base
from mayavi.core.source import Source
from mayavi.core.common import handle_children_state, exception
from mayavi.core.adder_node import SourceAdderNode

######################################################################
# `Scene` class.
######################################################################
class Scene(Base):
    """ The Mayavi scene class.
    """

    # The version of this class.  Used for persistence.
    __version__ = 0

    # The scene (RenderWindow) associated with this component -- we
    # redeclare it here just to be able to record this scene, we don't
    # want it recorded on all objects since the scene is shared
    # (although it isn't an error to register an object twice with the
    # recorder).
    scene = Instance(TVTKScene, record=True)

    # The source objects associated with this object.
    children = List(Source, record=True)

    # The name of this scene.
    name = Str('TVTK Scene')

    # The icon
    icon = Str('scene.ico')

    # The human-readable type for this object
    type = Str(' scene')

    # The objects view.
    view = View(Group(Item(name='scene', style='custom'),
                           show_labels=False)
               )

    # The adder node dialog class
    _adder_node_class = SourceAdderNode

    # The dispatch, to register callbacks on mouse pick
    _mouse_pick_dispatcher = Instance(
        'mayavi.core.mouse_pick_dispatcher.MousePickDispatcher',
        record=False)

    ######################################################################
    # `object` interface
    ######################################################################
    def __get_pure_state__(self):
        # Base removes the scene, but we need to save it!
        d = super(Scene, self).__get_pure_state__()
        d['scene'] = self.scene
        d.pop('_mouse_pick_dispatcher', None)
        return d

    def __set_pure_state__(self, state):
        handle_children_state(self.children, state.children)
        # Now set our complete state.  Doing the scene last ensures
        # that the camera view is set right.
        set_state(self, state, last=['scene'])

    ######################################################################
    # `Scene` interface
    ######################################################################

    def on_mouse_pick(self, callback, type='point', button='Left',
                            remove=False):
        """ Add a picking callback on mouse click.

            When the mouse button is press, object picking is called, and
            the given callback is invoked with the resulting pick
            as an argument.
{'fraction_non_alphanumeric': 0.20590111642743222, 'fraction_numerical': 0.001594896331738437, 'mean_word_length': 3.3010973936899863, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1264273', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1532, 'n_words': 558}