<commit_before>"""
   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.
"""

import os
import logging
import functools
import threading
import collections

from .server import runtimeInstances, update_event

log = logging.getLogger('remi.gui')


def debounce_button(btn_attr_name, t=2, final_value=True):
    def wrapper(f):
        @functools.wraps(f)
        def wrapped(self, *f_args, **f_kwargs):
            btn = getattr(self, btn_attr_name)
            btn.set_enabled(False)
            try:
                f(self, *f_args, **f_kwargs)
            except Exception as e:
                print e
            finally:
                threading.Timer(t, btn.set_enabled, (final_value,)).start()
        return wrapped
    return wrapper


def decorate_set_on_listener(event_name, params):
    """ private decorator for use in the editor

    Args:
        event_name (str): Name of the event to which it refers (es. For set_on_click_listener the event_name is "onclick"
        params (str): The list of parameters for the listener function (es. "(self, new_value)")
    """

    def add_annotation(function):
        function._event_listener = {}
        function._event_listener['eventName'] = event_name
        function._event_listener['prototype'] = params
        return function

    return add_annotation


def decorate_constructor_parameter_types(type_list):
    def add_annotation(function):
        function._constructor_types = type_list
        return function

    return add_annotation


def to_pix(x):
    return str(x) + 'px'


def from_pix(x):
    v = 0
    try:
        v = int(float(x.replace('px', '')))
    except ValueError:
        log.error('error parsing px', exc_info=True)
    return v


def jsonize(d):
    return ';'.join(map(lambda k, v: k + ':' + v + '', d.keys(), d.values()))


class _VersionedDictionary(dict):
    """This dictionary allows to check if its content is changed.
       It has an attribute __version__ of type int that increments every change
    """
    def __init__(self, *args, **kwargs):
        self.__version__ = 0
        super(_VersionedDictionary, self).__init__(*args, **kwargs)

    def __setitem__(self, key, value, version_increment=1):
        if key in self:
            if self[key] == value:
                return
        self.__version__ += version_increment
        return super(_VersionedDictionary, self).__setitem__(key, value)

    def __delitem__(self, key, version_increment=1):
        if not key in self:
            return
        self.__version__ += version_increment
        return super(_VersionedDictionary, self).__delitem__(key)
    
    def pop(self, key, d=None, version_increment=1):
        if not key in self:
            return
        self.__version__ += version_increment
        return super(_VersionedDictionary, self).pop(key, d)
        
    def clear(self, version_increment=1):
        self.__version__ += version_increment
        return super(_VersionedDictionary, self).clear()


class _EventManager(object):<commit_msg>gui: small style tidy<commit_after>"""
   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.
"""

import os
import logging
import functools
import threading
import collections

from .server import runtimeInstances, update_event

log = logging.getLogger('remi.gui')


def debounce_button(btn_attr_name, t=2, final_value=True):
    def wrapper(f):
        @functools.wraps(f)
        def wrapped(self, *f_args, **f_kwargs):
            btn = getattr(self, btn_attr_name)
            btn.set_enabled(False)
            try:
                f(self, *f_args, **f_kwargs)
            except Exception as e:
                print e
            finally:
                threading.Timer(t, btn.set_enabled, (final_value,)).start()
        return wrapped
    return wrapper


def decorate_set_on_listener(event_name, params):
    """ private decorator for use in the editor

    Args:
        event_name (str): Name of the event to which it refers (es. For set_on_click_listener the event_name is "onclick"
        params (str): The list of parameters for the listener function (es. "(self, new_value)")
    """

    def add_annotation(function):
        function._event_listener = {}
        function._event_listener['eventName'] = event_name
        function._event_listener['prototype'] = params
        return function

    return add_annotation


def decorate_constructor_parameter_types(type_list):
    def add_annotation(function):
        function._constructor_types = type_list
        return function

    return add_annotation


def to_pix(x):
    return str(x) + 'px'


def from_pix(x):
    v = 0
    try:
        v = int(float(x.replace('px', '')))
    except ValueError:
        log.error('error parsing px', exc_info=True)
    return v


def jsonize(d):
    return ';'.join(map(lambda k, v: k + ':' + v + '', d.keys(), d.values()))


class _VersionedDictionary(dict):
    """This dictionary allows to check if its content is changed.
       It has an attribute __version__ of type int that increments every change
    """
    def __init__(self, *args, **kwargs):
        self.__version__ = 0
        super(_VersionedDictionary, self).__init__(*args, **kwargs)

    def __setitem__(self, key, value, version_increment=1):
        if key in self:
            if self[key] == value:
                return
        self.__version__ += version_increment
        return super(_VersionedDictionary, self).__setitem__(key, value)

    def __delitem__(self, key, version_increment=1):
        if key not in self:
            return
        self.__version__ += version_increment
        return super(_VersionedDictionary, self).__delitem__(key)
    
    def pop(self, key, d=None, version_increment=1):
        if key not in self:
            return
        self.__version__ += version_increment
        return super(_VersionedDictionary, self).pop(key, d)
        
    def clear(self, version_increment=1):
        self.__version__ += version_increment
        return super(_VersionedDictionary, self).clear()


class _EventManager(object):
{'fraction_non_alphanumeric': 0.08996882969679795, 'fraction_numerical': 0.0031170303202040237, 'mean_word_length': 2.8405875952121873, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1395945', 'n_tokens_mistral': 1994, 'n_tokens_neox': 1956, 'n_words': 632}