<commit_before>from pyface.api import MessageDialog
from traits.api import Float, Int, Button, Bool, HasTraits, Instance
from traitsui.api import View, VGroup, HGroup, Item

from simphony.core.cuba import CUBA
from simphony.cuds.abc_modeling_engine import ABCModelingEngine

from .run_and_animate import RunAndAnimate


class RunAndAnimatePanel(HasTraits):
    ''' GUI for running a Simphony Modeling Engine and animating
    the result in an existing scene

    Attributes
    ----------
    engine : Instance of ABCModelingEngine
        Simphony Engine
    mayavi_engine : mayavi.core.engine.Engine instance
        for retrieving current scenes
    time_step : float
        CUBA.TIME_STEP of the Simphony Engine
    number_of_time_steps : float
        CUBA.NUMBER_OF_TIME_STEPS of the Simphony Engine
    '''

    engine = Instance(ABCModelingEngine)

    mayavi_engine = Instance("mayavi.core.engine.Engine")

    handler = Instance(RunAndAnimate)

    # Label to be displayed in tab
    label = "Run/Animate"

    # -------------------------------------------------------
    # Basic time step parameters to interact with the engine
    # -------------------------------------------------------
    time_step = Float(allow_none=False)
    number_of_time_steps = Float(allow_none=False)

    # ----------------------------------------------
    # For running the engine and animating scenes
    # (Only relevant to UI)
    # ----------------------------------------------
    _number_of_runs = Int(1)
    _animate = Button("Animate")
    _update_all_scenes = Bool(False)

    panel_view = View(
        VGroup(
            Item("time_step"),
            Item("number_of_time_steps"),
            HGroup(Item(name="_number_of_runs", label="Runs for"),
                   Item(label="time(s)")),
            HGroup(Item("_animate", show_label=False),
                   Item(name="_update_all_scenes", label="Update all scenes")),
            ),
        title="Run and Animate")

    # ------------------------------------------------------------
    # UI operation
    # ------------------------------------------------------------

    def __animate_fired(self):
        try:
            self.handler.animate(self._number_of_runs, ui=True,
                                 update_all_scenes=self._update_all_scenes)
        except RuntimeError as exception:
            message_dialog = MessageDialog()
            message_dialog.error(exception.message)

    # ----------------------------------------------------------
    # Trait handlers
    # ----------------------------------------------------------

    def _handler_default(self):
        return RunAndAnimate(self.engine, self.mayavi_engine)
<commit_msg>use Event instead of Button for _animate in run_and_animate_panel<commit_after>from pyface.api import MessageDialog
from traits.api import Float, Int, Bool, HasTraits, Instance, Event
from traitsui.api import View, VGroup, HGroup, Item, ButtonEditor

from simphony.core.cuba import CUBA
from simphony.cuds.abc_modeling_engine import ABCModelingEngine

from .run_and_animate import RunAndAnimate


class RunAndAnimatePanel(HasTraits):
    ''' GUI for running a Simphony Modeling Engine and animating
    the result in an existing scene

    Attributes
    ----------
    engine : Instance of ABCModelingEngine
        Simphony Engine
    mayavi_engine : mayavi.core.engine.Engine instance
        for retrieving current scenes
    time_step : float
        CUBA.TIME_STEP of the Simphony Engine
    number_of_time_steps : float
        CUBA.NUMBER_OF_TIME_STEPS of the Simphony Engine
    '''

    engine = Instance(ABCModelingEngine)

    mayavi_engine = Instance("mayavi.core.engine.Engine")

    handler = Instance(RunAndAnimate)

    # Label to be displayed in tab
    label = "Run/Animate"

    # -------------------------------------------------------
    # Basic time step parameters to interact with the engine
    # -------------------------------------------------------
    time_step = Float(allow_none=False)
    number_of_time_steps = Float(allow_none=False)

    # ----------------------------------------------
    # For running the engine and animating scenes
    # (Only relevant to UI)
    # ----------------------------------------------
    _number_of_runs = Int(1)
    _animate = Event
    _update_all_scenes = Bool(False)

    panel_view = View(
        VGroup(
            Item("time_step"),
            Item("number_of_time_steps"),
            HGroup(Item(name="_number_of_runs", label="Runs for"),
                   Item(label="time(s)")),
            HGroup(Item("_animate", show_label=False,
                        enabled_when="engine",
                        editor=ButtonEditor(label="Animate")),
                   Item(name="_update_all_scenes", label="Update all scenes")),
            ),
        title="Run and Animate")

    # ------------------------------------------------------------
    # UI operation
    # ------------------------------------------------------------

    def __animate_fired(self):
        try:
            self.handler.animate(self._number_of_runs, ui=True,
                                 update_all_scenes=self._update_all_scenes)
        except RuntimeError as exception:
            message_dialog = MessageDialog()
            message_dialog.error(exception.message)

    # ----------------------------------------------------------
    # Trait handlers
    # ----------------------------------------------------------

    def _handler_default(self):
        return RunAndAnimate(self.engine, self.mayavi_engine)

{'fraction_non_alphanumeric': 0.22483940042826553, 'fraction_numerical': 0.00035688793718772306, 'mean_word_length': 1.5477272727272726, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3427339', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1367, 'n_words': 333}