<commit_before>from bisect import bisect

from kivy.graphics.context_instructions import Color
from kivy.graphics.vertex_instructions import Rectangle
from kivy.uix.screenmanager import Screen
from kivy.uix.stencilview import StencilView

from mpfmc.core.mode import Mode
from mpfmc.core.utils import set_position


class Slide(Screen):
    next_id = 0

    @classmethod
    def get_id(cls):
        Slide.next_id += 1
        return Slide.next_id

    def __init__(self, mc, name, config=None, target='default', mode=None,
                 priority=None, play_kwargs=None):

        # config is a dict. widgets will be in a key

        self.creation_order = Slide.get_id()

        if not name:
            name = 'Anon_{}'.format(self.creation_order)

        self.mc = mc
        self.name = name
        self.priority = None
        self.pending_widgets = set()

        if not config:
            config = dict()

        if priority is None:
            try:
                self.priority = mode.priority
            except AttributeError:
                self.priority = 0
        else:
            self.priority = int(priority)

        if mode:
            if isinstance(mode, Mode):
                self.mode = mode
            else:
                self.mode = self.mc.modes[mode]
        else:
            self.mode = None

        self.transition_out = config.get('transition_out', None)
        self.expire = config.get('expire', None)

        target = mc.targets[target]

        self.size_hint = (None, None)
        super().__init__()
        self.size = target.native_size
        self.orig_w, self.orig_h = self.size

        self.stencil = StencilView(size_hint=(None, None),
                                   size=self.size)
        self.stencil.config = dict()
        self.stencil.config['z'] = 0
        super().add_widget(self.stencil)

        if 'widgets' in config:  # don't want try, swallows too much
            self.add_widgets_from_config(config=config['widgets'],
                                         mode=self.mode,
                                         play_kwargs=play_kwargs)

        self.mc.active_slides[name] = self
        target.add_widget(self)
        mc.slides[name] = config

        # Make the slide not transparent. (Widgets are drawn in reverse order,
        # so the before method draws it on the bottom.)
        with self.canvas.before:
            Color(0, 0, 0, 1)
            Rectangle(size=self.size, pos=(0, 0))

    def __repr__(self):
        return '<Slide name={}, priority={}, id={}>'.format(self.name,
            self.priority, self.creation_order)

    def add_widgets_from_library(self, name, mode=None, key=None, **kwargs):
        if name not in self.mc.widgets:
            raise ValueError("Widget %s not found", name)

        if not key:
            key = name

        return self.add_widgets_from_config(config=self.mc.widgets[name],
                                            mode=mode, key=key)

    def add_widgets_from_config(self, config, mode=None, key=None,
                                play_kwargs=None):

        if type(config) is not list:
            config = [config]
        widgets_added = list()

        if not play_kwargs:
            play_kwargs = dict()

        for widget in config:

            if 'key' in widget and widget['key']:
                this_key = widget['key']
            else:
                this_key = key

            if '_widget_cls' in widget:  # don't want try, swallows too much
                widget_obj = widget['_widget_cls'](mc=self.mc, config=widget,
                                                   slide=self, mode=mode,
                                                   key=this_key, **play_kwargs)
            else:
                widget_obj = self.mc.widgets.type_map[widget['type']](
                    mc=self.mc, config=widget, slide=self, mode=mode,<commit_msg>Undid fix that was based on MPF being the wrong version, updated MPF version required<commit_after>from bisect import bisect

from kivy.graphics.context_instructions import Color
from kivy.graphics.vertex_instructions import Rectangle
from kivy.uix.screenmanager import Screen
from kivy.uix.stencilview import StencilView

from mpfmc.core.mode import Mode
from mpfmc.core.utils import set_position


class Slide(Screen):
    next_id = 0

    @classmethod
    def get_id(cls):
        Slide.next_id += 1
        return Slide.next_id

    def __init__(self, mc, name, config=None, target='default', mode=None,
                 priority=None, play_kwargs=None):

        # config is a dict. widgets will be in a key

        self.creation_order = Slide.get_id()

        if not name:
            name = 'Anon_{}'.format(self.creation_order)

        self.mc = mc
        self.name = name
        self.priority = None
        self.pending_widgets = set()

        if not config:
            config = dict()

        if priority is None:
            try:
                self.priority = mode.priority
            except AttributeError:
                self.priority = 0
        else:
            self.priority = int(priority)

        if mode:
            if isinstance(mode, Mode):
                self.mode = mode
            else:
                self.mode = self.mc.modes[mode]
        else:
            self.mode = None

        self.transition_out = config.get('transition_out', None)
        self.expire = config.get('expire', None)

        target = mc.targets[target]

        self.size_hint = (None, None)
        super().__init__()
        self.size = target.native_size
        self.orig_w, self.orig_h = self.size

        self.stencil = StencilView(size_hint=(None, None),
                                   size=self.size)
        self.stencil.config = dict()
        self.stencil.config['z'] = 0
        super().add_widget(self.stencil)

        if 'widgets' in config:  # don't want try, swallows too much
            self.add_widgets_from_config(config=config['widgets'],
                                         mode=self.mode,
                                         play_kwargs=play_kwargs)

        self.mc.active_slides[name] = self
        target.add_widget(self)
        mc.slides[name] = config

        # Make the slide not transparent. (Widgets are drawn in reverse order,
        # so the before method draws it on the bottom.)
        with self.canvas.before:
            Color(0, 0, 0, 1)
            Rectangle(size=self.size, pos=(0, 0))

    def __repr__(self):
        return '<Slide name={}, priority={}, id={}>'.format(self.name,
            self.priority, self.creation_order)

    def add_widgets_from_library(self, name, mode=None, key=None, **kwargs):
        if name not in self.mc.widgets:
            raise ValueError("Widget %s not found", name)

        if not key:
            key = name

        return self.add_widgets_from_config(config=self.mc.widgets[name],
                                            mode=mode, key=key)

    def add_widgets_from_config(self, config, mode=None, key=None,
                                play_kwargs=None):

        if type(config) is not list:
            config = [config]
        widgets_added = list()

        if not play_kwargs:
            play_kwargs = dict()

        for widget in config:

            if widget['key']:
                this_key = widget['key']
            else:
                this_key = key

            if '_widget_cls' in widget:  # don't want try, swallows too much
                widget_obj = widget['_widget_cls'](mc=self.mc, config=widget,
                                                   slide=self, mode=mode,
                                                   key=this_key, **play_kwargs)
            else:
                widget_obj = self.mc.widgets.type_map[widget['type']](
                    mc=self.mc, config=widget, slide=self, mode=mode,
{'fraction_non_alphanumeric': 0.0942176008115648, 'fraction_numerical': 0.00253613999492772, 'mean_word_length': 1.6780984719864176, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2084785', 'n_tokens_mistral': 2271, 'n_tokens_neox': 2136, 'n_words': 553}