<commit_before>"""Contains the parent class of the Text DisplayElement"""

# text.py
# Mission Pinball Framework
# Written by <NAME> & <NAME>
# Released under the MIT License. (See license info at the end of this file.)

# Documentation and more info at http://missionpinball.com/mpf

import re
from mpf.media_controller.core.display import DisplayElement


class Text(DisplayElement):
    """Represents an text display element.

    Args:
        slide: The Slide object this animation is being added to.
        machine: The main machine object.
        text: A string of the text you'd like to display. If you have the
            multi-language plug-in enabled, this text will be run through the
            language engine before it's displayed.
        x: The horizontal position offset for the placement of this element.
        y: The vertical position offset for the placement of this element.
        h_pos: The horizontal anchor.
        v_pos: The vertical anchor.

    Note: Full documentation on the use of the x, y, h_pos, and v_pos arguments
    can be found at: https://missionpinball.com/docs/displays/display-elements/positioning/

    """

    def __init__(self, slide, machine, text, x=None, y=None, h_pos=None,
                 v_pos=None, layer=0, text_variables=None, **kwargs):

        super(Text, self).__init__(slide, x, y, h_pos, v_pos, layer)

        self.text = str(text)
        self.original_text = self.text
        self.fonts = machine.display.fonts
        self.language = machine.language
        self.slide = slide
        self.machine = machine
        self.layer = layer

        self.config = kwargs

        self.var_finder = re.compile("(?<=%)[\S]+(?=%)")

        if not text_variables:
            text_variables = dict()

        self.adjust_colors(**self.config)

        self.config['color'] = self.adjusted_color
        self.config['bg_color'] = self.adjusted_bg_color

        # Set defaults
        if 'name' in self.config:
            self.name = self.config['name']
        else:
            self.name = text

        self._process_text(self.text, local_replacements=text_variables,
                           local_type='event')

    def _get_text_vars(self):
        return self.var_finder.findall(self.original_text)

    def _process_text(self, text, local_replacements=None, local_type=None):
        # text: source text with placeholder vars
        # local_replacements: dict of var names & their replacements
        # local_type: type specifier of local replacements. e.g. "event" means
        # it will look for %event|var_name% in the text string

        text = str(text)

        if not local_replacements:
            local_replacements = list()<commit_msg>Update text display element so percentage signs don't get caught in the regex<commit_after>"""Contains the parent class of the Text DisplayElement"""

# text.py
# Mission Pinball Framework
# Written by <NAME> & <NAME>
# Released under the MIT License. (See license info at the end of this file.)

# Documentation and more info at http://missionpinball.com/mpf

import re
from mpf.media_controller.core.display import DisplayElement


class Text(DisplayElement):
    """Represents an text display element.

    Args:
        slide: The Slide object this animation is being added to.
        machine: The main machine object.
        text: A string of the text you'd like to display. If you have the
            multi-language plug-in enabled, this text will be run through the
            language engine before it's displayed.
        x: The horizontal position offset for the placement of this element.
        y: The vertical position offset for the placement of this element.
        h_pos: The horizontal anchor.
        v_pos: The vertical anchor.

    Note: Full documentation on the use of the x, y, h_pos, and v_pos arguments
    can be found at: https://missionpinball.com/docs/displays/display-elements/positioning/

    """

    def __init__(self, slide, machine, text, x=None, y=None, h_pos=None,
                 v_pos=None, layer=0, text_variables=None, **kwargs):

        super(Text, self).__init__(slide, x, y, h_pos, v_pos, layer)

        self.text = str(text)
        self.original_text = self.text
        self.fonts = machine.display.fonts
        self.language = machine.language
        self.slide = slide
        self.machine = machine
        self.layer = layer

        self.config = kwargs

        self.var_finder = re.compile("(?<=%)[a-zA-Z_0-9|]+(?=%)")

        if not text_variables:
            text_variables = dict()

        self.adjust_colors(**self.config)

        self.config['color'] = self.adjusted_color
        self.config['bg_color'] = self.adjusted_bg_color

        # Set defaults
        if 'name' in self.config:
            self.name = self.config['name']
        else:
            self.name = text

        self._process_text(self.text, local_replacements=text_variables,
                           local_type='event')

    def _get_text_vars(self):
        return self.var_finder.findall(self.original_text)

    def _process_text(self, text, local_replacements=None, local_type=None):
        # text: source text with placeholder vars
        # local_replacements: dict of var names & their replacements
        # local_type: type specifier of local replacements. e.g. "event" means
        # it will look for %event|var_name% in the text string

        text = str(text)

        if not local_replacements:
            local_replacements = list()
{'fraction_non_alphanumeric': 0.08826189184300959, 'fraction_numerical': 0.0007234581298607343, 'mean_word_length': 2.56084996780425, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '7375371', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1510, 'n_words': 513}