<commit_before># ===============================================================================
# Copyright 2013 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================

# ============= enthought library imports =======================
from traits.api import on_trait_change, Bool, Instance, Event, Color
# from traitsui.api import View, Item
from pyface.tasks.task_layout import PaneItem, TaskLayout, Splitter, Tabbed
from pyface.constant import CANCEL, NO
#============= standard library imports ========================
import shutil
import weakref
import os
#============= local library imports  ==========================
import xlrd
from pychron.core.ui.preference_binding import bind_preference, color_bind_preference
from pychron.envisage.tasks.pane_helpers import ConsolePane
from pychron.experiment.queue.base_queue import extract_meta
from pychron.experiment.tasks.experiment_panes import ExperimentFactoryPane, StatsPane, \
    ControlsPane, WaitPane, IsotopeEvolutionPane, ConnectionStatusPane

from pychron.envisage.tasks.editor_task import EditorTask
from pychron.experiment.tasks.experiment_editor import ExperimentEditor, UVExperimentEditor
from pychron.experiment.utilities.identifier import convert_extract_device
from pychron.image.tasks.video_pane import VideoDockPane
from pychron.lasers.laser_managers.ilaser_manager import ILaserManager
from pychron.paths import paths
from pychron.core.helpers.filetools import add_extension, unique_date_path
from pychron.messaging.notify.notifier import Notifier
from pychron.lasers.pattern.pattern_maker_view import PatternMakerView


class ExperimentEditorTask(EditorTask):
    wildcard = '*.txt'
    group_count = 0
    name = 'Experiment'

    use_notifications = Bool
    use_syslogger = Bool
    #notifications_port = Int

    loading_manager = Instance('pychron.loading.loading_manager.LoadingManager')
    notifier = Instance(Notifier, ())
    syslogger = Instance('pychron.experiment.sys_log.SysLogger')

    # analysis_health = Instance(AnalysisHealth)
    last_experiment_changed = Event

    bgcolor = Color

    automated_runs_editable = Bool

    def new_pattern(self):
        pm = PatternMakerView()
        self.window.application.open_view(pm)

    def open_pattern(self):
        pm = PatternMakerView()
        if pm.load_pattern():
            self.window.application.open_view(pm)

    def send_test_notification(self):
        self.debug('sending test notification')
        db = self.manager.db
        #         an=db.get_last_analysis('bu-FD-o')
        an = db.get_last_analysis('ba-01-o')
        an = self.manager.make_analysis(an)
        if an:
            self.debug('test push {}'.format(an.record_id))
            self._publish_notification(an)
        else:
            self.debug('problem recalling last analysis')

    def deselect(self):
        if self.active_editor:
            self.active_editor.queue.selected = []
            self.active_editor.queue.executed_selected = []

    def undo(self):
        if self.has_active_editor():
            self.manager.experiment_factory.undo()

    def edit_queue_conditionals(self):
        if self.has_active_editor():
            from pychron.experiment.conditional.conditionals_edit_view import edit_conditionals

            dnames = None
            spec = self.application.get_service(
                'pychron.spectrometer.base_spectrometer_manager.BaseSpectrometerManager')
            if spec:
                dnames = spec.spectrometer.detector_names

            edit_conditionals(self.manager.experiment_factory.queue_factory.queue_conditionals_name,
                            detectors=dnames,
                            app=self.application)

    def prepare_destroy(self):
        super(ExperimentEditorTask, self).prepare_destroy()

        self.manager.experiment_factory.destroy()

        if self.use_notifications:
            self.notifier.close()

    def bind_preferences(self):
        #notifications

        self._preference_binder('pychron.experiment',
                                ('use_notifications',
                                 'notifications_port',
                                 'automated_runs_editable'))

        #force notifier setup
        if self.use_notifications:
            self.notifier.setup(self.notifier.port)

        #sys logger
        bind_preference(self, 'use_syslogger', 'pychron.use_syslogger')
        if self.use_syslogger:
            self._use_syslogger_changed()

        color_bind_preference(self, 'bgcolor', 'pychron.experiment.bg_color')

    def activated(self):

        self.bind_preferences()
        super(ExperimentEditorTask, self).activated()

    def _use_syslogger_changed(self):
        if self.use_syslogger:
            from pychron.experiment.sys_log import SysLogger

            self.syslogger = SysLogger()<commit_msg>fixed experiment task preference binding<commit_after># ===============================================================================
# Copyright 2013 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================

# ============= enthought library imports =======================
from traits.api import on_trait_change, Bool, Instance, Event, Color, Int
# from traitsui.api import View, Item
from pyface.tasks.task_layout import PaneItem, TaskLayout, Splitter, Tabbed
from pyface.constant import CANCEL, NO
#============= standard library imports ========================
import shutil
import weakref
import os
#============= local library imports  ==========================
import xlrd
from pychron.core.ui.preference_binding import bind_preference, color_bind_preference
from pychron.envisage.tasks.pane_helpers import ConsolePane
from pychron.experiment.queue.base_queue import extract_meta
from pychron.experiment.tasks.experiment_panes import ExperimentFactoryPane, StatsPane, \
    ControlsPane, WaitPane, IsotopeEvolutionPane, ConnectionStatusPane

from pychron.envisage.tasks.editor_task import EditorTask
from pychron.experiment.tasks.experiment_editor import ExperimentEditor, UVExperimentEditor
from pychron.experiment.utilities.identifier import convert_extract_device
from pychron.image.tasks.video_pane import VideoDockPane
from pychron.lasers.laser_managers.ilaser_manager import ILaserManager
from pychron.paths import paths
from pychron.core.helpers.filetools import add_extension, unique_date_path
from pychron.messaging.notify.notifier import Notifier
from pychron.lasers.pattern.pattern_maker_view import PatternMakerView


class ExperimentEditorTask(EditorTask):
    wildcard = '*.txt'
    group_count = 0
    name = 'Experiment'

    use_notifications = Bool
    use_syslogger = Bool
    notifications_port = Int

    loading_manager = Instance('pychron.loading.loading_manager.LoadingManager')
    notifier = Instance(Notifier, ())
    syslogger = Instance('pychron.experiment.sys_log.SysLogger')

    # analysis_health = Instance(AnalysisHealth)
    last_experiment_changed = Event

    bgcolor = Color

    automated_runs_editable = Bool

    def new_pattern(self):
        pm = PatternMakerView()
        self.window.application.open_view(pm)

    def open_pattern(self):
        pm = PatternMakerView()
        if pm.load_pattern():
            self.window.application.open_view(pm)

    def send_test_notification(self):
        self.debug('sending test notification')
        db = self.manager.db
        #         an=db.get_last_analysis('bu-FD-o')
        an = db.get_last_analysis('ba-01-o')
        an = self.manager.make_analysis(an)
        if an:
            self.debug('test push {}'.format(an.record_id))
            self._publish_notification(an)
        else:
            self.debug('problem recalling last analysis')

    def deselect(self):
        if self.active_editor:
            self.active_editor.queue.selected = []
            self.active_editor.queue.executed_selected = []

    def undo(self):
        if self.has_active_editor():
            self.manager.experiment_factory.undo()

    def edit_queue_conditionals(self):
        if self.has_active_editor():
            from pychron.experiment.conditional.conditionals_edit_view import edit_conditionals

            dnames = None
            spec = self.application.get_service(
                'pychron.spectrometer.base_spectrometer_manager.BaseSpectrometerManager')
            if spec:
                dnames = spec.spectrometer.detector_names

            edit_conditionals(self.manager.experiment_factory.queue_factory.queue_conditionals_name,
                            detectors=dnames,
                            app=self.application)

    def prepare_destroy(self):
        super(ExperimentEditorTask, self).prepare_destroy()

        self.manager.experiment_factory.destroy()

        if self.use_notifications:
            self.notifier.close()

    def bind_preferences(self):
        #notifications

        self._preference_binder('pychron.experiment',
                                ('use_notifications',
                                 # 'notifications_port',
                                 'automated_runs_editable'))

        #force notifier setup
        if self.use_notifications:
            self.notifier.setup(self.notifications_port)

        #sys logger
        bind_preference(self, 'use_syslogger', 'pychron.use_syslogger')
        if self.use_syslogger:
            self._use_syslogger_changed()

        color_bind_preference(self, 'bgcolor', 'pychron.experiment.bg_color')

    def activated(self):

        self.bind_preferences()
        super(ExperimentEditorTask, self).activated()

    def _use_syslogger_changed(self):
        if self.use_syslogger:
            from pychron.experiment.sys_log import SysLogger

            self.syslogger = SysLogger()
{'fraction_non_alphanumeric': 0.12215700660308144, 'fraction_numerical': 0.0020176082171680116, 'mean_word_length': 3.306872037914692, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3620540', 'n_tokens_mistral': 3009, 'n_tokens_neox': 2890, 'n_words': 654}