Exemple #1
0
    def __init__(self,
                 mpfdisplay,
                 machine,
                 slide_a,
                 slide_b,
                 duration='1s',
                 **kwargs):

        super(Transition, self).__init__(mpfdisplay, machine, name=self.name)

        self.slide_a = slide_a
        self.slide_b = slide_b
        self.priority = slide_b.priority
        self.duration = Timing.string_to_secs(duration)

        # Need to make sure both the slides have rendered in case they're new
        self.slide_b.update()
        self.slide_a.update()

        self.start_time = time.time()
        self.end_time = self.start_time + self.duration

        # mark both slides as active
        self.slide_a.active = True
        self.slide_b.active = True
    def __init__(self,
                 mpfdisplay,
                 machine,
                 priority,
                 mode,
                 slide_a,
                 slide_b,
                 duration='1s',
                 **kwargs):

        super(Transition, self).__init__(mpfdisplay=mpfdisplay,
                                         machine=machine,
                                         priority=priority,
                                         mode=mode)

        self.slide_a = slide_a
        self.slide_b = slide_b
        self.priority = slide_b.priority
        self.duration = Timing.string_to_secs(duration)
        self.active_transition = True
        self.slide_a.active_transition = True
        self.slide_b.active_transition = True
        self.name = str(slide_a.name) + "_transition_" + str(slide_b.name)

        self.start_time = time.time()
        self.end_time = self.start_time + self.duration

        # mark both slides as active
        self.slide_a.active = True
        self.slide_b.active = True

        # Need to set the initial surface of the transition slide to the
        # existing slide's surface since the transition slide will be active
        self.surface.blit(self.slide_a.surface, (0, 0))
Exemple #3
0
    def __init__(self, mpfdisplay, machine, priority,
                 mode, slide_a, slide_b, duration='1s', **kwargs):

        super(Transition, self).__init__(mpfdisplay=mpfdisplay,
                                         machine=machine,
                                         priority=priority,
                                         mode=mode)

        self.slide_a = slide_a
        self.slide_b = slide_b
        self.priority = slide_b.priority
        self.duration = Timing.string_to_secs(duration)
        self.active_transition = True
        self.slide_a.active_transition = True
        self.slide_b.active_transition = True
        self.name = str(slide_a.name) + "_transition_" + str(slide_b.name)

        self.start_time = time.time()
        self.end_time = self.start_time + self.duration

        # mark both slides as active
        self.slide_a.active = True
        self.slide_b.active = True

        # Need to set the initial surface of the transition slide to the
        # existing slide's surface since the transition slide will be active
        self.surface.blit(self.slide_a.surface, (0, 0))
Exemple #4
0
    def __init__(self, machine, mode, name, config):
        self.machine = machine
        self.mode = mode
        self.name = name
        self.config = config

        self.tick_var = self.mode.name + '_' + self.name + '_tick'
        self.mode.player[self.tick_var] = 0

        self.running = False
        self.start_value = 0
        self.restart_on_complete = False
        self._ticks = 0
        self.end_value = 0
        self.max_value = None
        self.direction = 'up'
        self.tick_secs = 1
        self.timer = None
        self.bcp = False
        self.event_keys = set()
        self.delay = DelayManager()

        if 'start_value' in self.config:
            self.start_value = self.config['start_value']
        else:
            self.start_value = 0

        if 'start_running' in self.config and self.config['start_running']:
            self.running = True

        if 'end_value' in self.config:
            self.end_value = self.config['end_value']

        if 'control_events' in self.config and self.config['control_events']:
            if type(self.config['control_events']) is dict:
                self.config['control_events'] = [self.config['control_events']]
        else:
            self.config['control_events'] = list()

        if 'direction' in self.config and self.config['direction'] == 'down':
            self.direction = 'down'

        if 'tick_interval' in self.config:
            self.tick_secs = Timing.string_to_secs(self.config['tick_interval'])

        if 'max_value' in self.config:
            self.max_value = self.config['max_value']

        if ('restart_on_complete' in self.config and
                self.config['restart_on_complete']):
            self.restart_on_complete = True

        if 'bcp' in self.config and self.config['bcp']:
            self.bcp = True

        self.mode.player[self.tick_var] = self.start_value

        self._setup_control_events(self.config['control_events'])
Exemple #5
0
    def __init__(self, mpfdisplay, machine, slide_a, slide_b, duration="1s", **kwargs):

        super(Transition, self).__init__(mpfdisplay, machine, name=self.name)

        self.slide_a = slide_a
        self.slide_b = slide_b
        self.priority = slide_b.priority
        self.duration = Timing.string_to_secs(duration)

        # Need to make sure both the slides have rendered in case they're new
        self.slide_b.update()
        self.slide_a.update()

        self.start_time = time.time()
        self.end_time = self.start_time + self.duration

        # mark both slides as active
        self.slide_a.active = True
        self.slide_b.active = True
Exemple #6
0
    def validate_config_item(spec, item='item not in config!@#'):

        default = 'default required!@#'

        if '|' in spec:
            item_type, default = spec.split('|')
            if type(default) is str and default.lower() == 'none':
                default = None
        else:
            item_type = spec

        if item == 'item not in config!@#':
            if default == 'default required!@#':
                log.error(
                    'Required setting missing from config file. Run with '
                    'verbose logging and look for the last '
                    'ConfigProcessor entry above this line to see where '
                    'the problem is.')
                sys.exit()
            else:
                item = default

        if item_type == 'list':
            return Config.string_to_list(item)
        elif item_type == 'int':
            return int(item)
        elif item_type == 'float':
            return float(item)
        elif item_type == 'string':
            return str(item)
        elif item_type == 'boolean':
            if type(item) is bool:
                return item
            else:
                return item.lower() in ('yes', 'true')
        elif item_type == 'ms':
            return Timing.string_to_ms(item)
        elif item_type == 'secs':
            return Timing.string_to_secs(item)
        elif item_type == 'list_of_lists':
            return Config.list_of_lists(item)
Exemple #7
0
    def validate_config_item(spec, item='item not in config!@#'):

        default = 'default required!@#'

        if '|' in spec:
            item_type, default = spec.split('|')
            if type(default) is str and default.lower() == 'none':
                default = None
        else:
            item_type = spec

        if item == 'item not in config!@#':
            if default == 'default required!@#':
                log.error('Required setting missing from config file. Run with '
                          'verbose logging and look for the last '
                          'ConfigProcessor entry above this line to see where '
                          'the problem is.')
                sys.exit()
            else:
                item = default

        if item_type == 'list':
            return Config.string_to_list(item)
        elif item_type == 'int':
            return int(item)
        elif item_type == 'float':
            return float(item)
        elif item_type == 'string':
            return str(item)
        elif item_type == 'boolean':
            if type(item) is bool:
                return item
            else:
                return item.lower() in ('yes', 'true')
        elif item_type == 'ms':
            return Timing.string_to_ms(item)
        elif item_type == 'secs':
            return Timing.string_to_secs(item)
        elif item_type == 'list_of_lists':
            return Config.list_of_lists(item)
Exemple #8
0
    def __init__(self, machine, mode, name, config):
        self.machine = machine
        self.mode = mode
        self.name = name
        self.config = config

        self.tick_var = self.mode.name + "_" + self.name + "_tick"
        self.mode.player[self.tick_var] = 0

        self.running = False
        self.start_value = 0
        self.restart_on_complete = False
        self._ticks = 0
        self.end_value = None
        self.ticks_remaining = 0
        self.max_value = None
        self.direction = "up"
        self.tick_secs = 1
        self.timer = None
        self.bcp = False
        self.event_keys = set()
        self.delay = DelayManager()
        self.log = None
        self.debug = False

        if "start_value" in self.config:
            self.start_value = self.config["start_value"]
        else:
            self.start_value = 0

        if "start_running" in self.config and self.config["start_running"]:
            self.running = True

        if "end_value" in self.config:
            self.end_value = self.config["end_value"]

        if "control_events" in self.config and self.config["control_events"]:
            if type(self.config["control_events"]) is dict:
                self.config["control_events"] = [self.config["control_events"]]
        else:
            self.config["control_events"] = list()

        if "direction" in self.config and self.config["direction"].lower() == "down":
            self.direction = "down"

            if not self.end_value:
                self.end_value = 0  # need it to be 0 not None

        if "tick_interval" in self.config:
            self.tick_secs = Timing.string_to_secs(self.config["tick_interval"])

        if "max_value" in self.config:
            self.max_value = self.config["max_value"]

        if "restart_on_complete" in self.config and self.config["restart_on_complete"]:
            self.restart_on_complete = True

        if "bcp" in self.config and self.config["bcp"]:
            self.bcp = True

        if "debug" in self.config and self.config["debug"]:
            self.debug = True
            self.log.debug("Enabling Debug Logging")

        self.mode.player[self.tick_var] = self.start_value

        if self.log:
            self.log.debug("----------- Initial Values -----------")
            self.log.debug("running: %s", self.running)
            self.log.debug("start_value: %s", self.start_value)
            self.log.debug("restart_on_complete: %s", self.restart_on_complete)
            self.log.debug("_ticks: %s", self._ticks)
            self.log.debug("end_value: %s", self.end_value)
            self.log.debug("ticks_remaining: %s", self.ticks_remaining)
            self.log.debug("max_value: %s", self.max_value)
            self.log.debug("direction: %s", self.direction)
            self.log.debug("tick_secs: %s", self.tick_secs)
            self.log.debug("--------------------------------------")

        self._setup_control_events(self.config["control_events"])
Exemple #9
0
    def validate_item(self, item, validator, validation_failure_info):

        try:
            if item.lower() == 'none':
                item = None
        except AttributeError:
            pass

        if ':' in validator:
            validator = validator.split(':')
            # item could be str, list, or list of dicts
            item = Util.event_config_to_dict(item)

            return_dict = dict()

            for k, v in item.iteritems():
                return_dict[self.validate_item(k, validator[0],
                                               validation_failure_info)] = (
                    self.validate_item(v, validator[1], validation_failure_info)
                    )

            item = return_dict

        elif '%' in validator:

            if type(item) is str:

                try:
                    item = eval(validator.replace('%', "'" + item + "'"))
                except KeyError:
                    self.validation_error(item, validation_failure_info)
            else:
                item = None

        elif validator == 'str':
            if item is not None:
                item = str(item)
            else:
                item = None

        elif validator == 'float':
            try:
                item = float(item)
            except (TypeError, ValueError):
                # TODO error
                pass

        elif validator == 'int':
            try:
                item = int(item)
            except (TypeError, ValueError):
                # TODO error
                pass

        elif validator in ('bool', 'boolean'):
            if type(item) is str:
                if item.lower() in ['false', 'f', 'no', 'disable', 'off']:
                    item = False

            elif not item:
                item = False

            else:
                item = True

        elif validator == 'ms':
            item = Timing.string_to_ms(item)

        elif validator == 'secs':
            item = Timing.string_to_secs(item)

        elif validator == 'ticks':
            item = Timing.string_to_ticks(item)

        elif validator == 'ticks_int':
            item = int(Timing.string_to_ticks(item))

        else:
            self.log.error("Invalid Validator '%s' in config spec %s:%s",
                           validator,
                           validation_failure_info[0][0],
                           validation_failure_info[1])
            sys.exit()

        return item
Exemple #10
0
    def validate_config_item(spec, item='item not in config!@#'):

        try:
            if item.lower() == 'none':
                item = None
        except AttributeError:
            pass

        default = 'default required!@#'

        if '|' in spec:
            item_type, default = spec.split('|')
            if type(default) is str and default.lower() == 'none':
                default = None
        else:
            item_type = spec

        if item == 'item not in config!@#':
            if default == 'default required!@#':
                log.error('Required setting missing from config file. Run with '
                          'verbose logging and look for the last '
                          'ConfigProcessor entry above this line to see where '
                          'the problem is.')
                sys.exit()
            else:
                item = default

        if item_type == 'list':
            return Util.string_to_list(item)

        if item_type == 'list_of_dicts':
            if type(item) is list:
                return item
            elif type(item) is dict:
                return [item]

        elif item_type == 'set':
            return set(Util.string_to_list(item))

        elif item_type == 'dict':
            if type(item) is dict or type(item) is CaseInsensitiveDict:
                return item
            elif not default:
                return dict()
            else:
                log.error('Config error. "%s" is not a dictionary', item)
                sys.exit()

        elif item_type == 'int':
            try:
                return int(item)
            except TypeError:
                return None

        elif item_type == 'float':
            try:
                return float(item)
            except TypeError:
                return None

        elif item_type in ('string', 'str'):

            if item:
                return str(item)
            else:
                return None

        elif item_type in ('boolean', 'bool'):
            if type(item) is bool:
                return item
            else:
                return str(item).lower() in ('yes', 'true')

        elif item_type == 'ms':
            return Timing.string_to_ms(item)

        elif item_type == 'secs':
            return Timing.string_to_secs(item)

        elif item_type == 'list_of_lists':
            return Util.list_of_lists(item)
Exemple #11
0
    def validate_item(self, item, validator, validation_failure_info):

        try:
            if item.lower() == 'none':
                item = None
        except AttributeError:
            pass

        if ':' in validator:
            validator = validator.split(':')
            # item could be str, list, or list of dicts
            item = Util.event_config_to_dict(item)

            return_dict = dict()

            for k, v in item.iteritems():
                return_dict[self.validate_item(
                    k, validator[0],
                    validation_failure_info)] = (self.validate_item(
                        v, validator[1], validation_failure_info))

            item = return_dict

        elif '%' in validator:

            if type(item) is str:

                try:
                    item = eval(validator.replace('%', "'" + item + "'"))
                except KeyError:
                    self.validation_error(item, validation_failure_info)
            else:
                item = None

        elif validator == 'str':
            if item is not None:
                item = str(item)
            else:
                item = None

        elif validator == 'float':
            try:
                item = float(item)
            except (TypeError, ValueError):
                # TODO error
                pass

        elif validator == 'int':
            try:
                item = int(item)
            except (TypeError, ValueError):
                # TODO error
                pass

        elif validator in ('bool', 'boolean'):
            if type(item) is str:
                if item.lower() in ['false', 'f', 'no', 'disable', 'off']:
                    item = False

            elif not item:
                item = False

            else:
                item = True

        elif validator == 'ms':
            item = Timing.string_to_ms(item)

        elif validator == 'secs':
            item = Timing.string_to_secs(item)

        elif validator == 'ticks':
            item = Timing.string_to_ticks(item)

        elif validator == 'ticks_int':
            item = int(Timing.string_to_ticks(item))

        elif validator == 'list':
            item = Util.string_to_list(item)

        else:
            self.log.error("Invalid Validator '%s' in config spec %s:%s",
                           validator, validation_failure_info[0][0],
                           validation_failure_info[1])
            sys.exit()

        return item
Exemple #12
0
    def validate_config_item(spec, item='item not in config!@#'):

        try:
            if item.lower() == 'none':
                item = None
        except AttributeError:
            pass

        default = 'default required!@#'

        if '|' in spec:
            item_type, default = spec.split('|')
            if type(default) is str and default.lower() == 'none':
                default = None
        else:
            item_type = spec

        if item == 'item not in config!@#':
            if default == 'default required!@#':
                log.error(
                    'Required setting missing from config file. Run with '
                    'verbose logging and look for the last '
                    'ConfigProcessor entry above this line to see where '
                    'the problem is.')
                sys.exit()
            else:
                item = default

        if item_type == 'list':
            return Util.string_to_list(item)

        if item_type == 'list_of_dicts':
            if type(item) is list:
                return item
            elif type(item) is dict:
                return [item]

        elif item_type == 'set':
            return set(Util.string_to_list(item))

        elif item_type == 'dict':
            if type(item) is dict or type(item) is CaseInsensitiveDict:
                return item
            elif not default:
                return dict()
            else:
                log.error('Config error. "%s" is not a dictionary', item)
                sys.exit()

        elif item_type == 'int':
            try:
                return int(item)
            except TypeError:
                return None

        elif item_type == 'float':
            try:
                return float(item)
            except TypeError:
                return None

        elif item_type in ('string', 'str'):

            if item:
                return str(item)
            else:
                return None

        elif item_type in ('boolean', 'bool'):
            if type(item) is bool:
                return item
            else:
                return str(item).lower() in ('yes', 'true')

        elif item_type == 'ms':
            return Timing.string_to_ms(item)

        elif item_type == 'secs':
            return Timing.string_to_secs(item)

        elif item_type == 'list_of_lists':
            return Util.list_of_lists(item)
Exemple #13
0
    def __init__(self, machine, mode, name, config):
        self.machine = machine
        self.mode = mode
        self.name = name
        self.config = config

        self.tick_var = self.mode.name + '_' + self.name + '_tick'
        self.mode.player[self.tick_var] = 0

        self.running = False
        self.start_value = 0
        self.restart_on_complete = False
        self._ticks = 0
        self.end_value = None
        self.ticks_remaining = 0
        self.max_value = None
        self.direction = 'up'
        self.tick_secs = 1
        self.timer = None
        self.bcp = False
        self.event_keys = set()
        self.delay = DelayManager()
        self.log = None
        self.debug = False

        if 'start_value' in self.config:
            self.start_value = self.config['start_value']
        else:
            self.start_value = 0

        if 'start_running' in self.config and self.config['start_running']:
            self.running = True

        if 'end_value' in self.config:
            self.end_value = self.config['end_value']

        if 'control_events' in self.config and self.config['control_events']:
            if type(self.config['control_events']) is dict:
                self.config['control_events'] = [self.config['control_events']]
        else:
            self.config['control_events'] = list()

        if ('direction' in self.config and
                self.config['direction'].lower() == 'down'):
            self.direction = 'down'

            if not self.end_value:
                self.end_value = 0  # need it to be 0 not None

        if 'tick_interval' in self.config:
            self.tick_secs = Timing.string_to_secs(self.config['tick_interval'])

        if 'max_value' in self.config:
            self.max_value = self.config['max_value']

        if ('restart_on_complete' in self.config and
                self.config['restart_on_complete']):
            self.restart_on_complete = True

        if 'bcp' in self.config and self.config['bcp']:
            self.bcp = True

        if 'debug' in self.config and self.config['debug']:
            self.debug = True
            self.log.debug("Enabling Debug Logging")

        self.mode.player[self.tick_var] = self.start_value

        if self.log:
            self.log.debug("----------- Initial Values -----------")
            self.log.debug("running: %s", self.running)
            self.log.debug("start_value: %s", self.start_value)
            self.log.debug("restart_on_complete: %s", self.restart_on_complete)
            self.log.debug("_ticks: %s", self._ticks)
            self.log.debug("end_value: %s", self.end_value)
            self.log.debug("ticks_remaining: %s", self.ticks_remaining)
            self.log.debug("max_value: %s", self.max_value)
            self.log.debug("direction: %s", self.direction)
            self.log.debug("tick_secs: %s", self.tick_secs)
            self.log.debug("--------------------------------------")

        self._setup_control_events(self.config['control_events'])
Exemple #14
0
    def __init__(self, machine, mode, name, config):
        self.machine = machine
        self.mode = mode
        self.name = name
        self.config = config

        self.tick_var = self.mode.name + '_' + self.name + '_tick'
        self.mode.player[self.tick_var] = 0

        self.running = False
        self.start_value = 0
        self.restart_on_complete = False
        self._ticks = 0
        self.end_value = None
        self.ticks_remaining = 0
        self.max_value = None
        self.direction = 'up'
        self.tick_secs = 1
        self.timer = None
        self.bcp = False
        self.event_keys = set()
        self.delay = DelayManager()
        self.log = None
        self.debug = False

        if 'start_value' in self.config:
            self.start_value = self.config['start_value']
        else:
            self.start_value = 0

        if 'start_running' in self.config and self.config['start_running']:
            self.running = True

        if 'end_value' in self.config:
            self.end_value = self.config['end_value']

        if 'control_events' in self.config and self.config['control_events']:
            if type(self.config['control_events']) is dict:
                self.config['control_events'] = [self.config['control_events']]
        else:
            self.config['control_events'] = list()

        if ('direction' in self.config and
                self.config['direction'].lower() == 'down'):
            self.direction = 'down'

            if not self.end_value:
                self.end_value = 0  # need it to be 0 not None

        if 'tick_interval' in self.config:
            self.tick_secs = Timing.string_to_secs(self.config[
                                                       'tick_interval'])

        if 'max_value' in self.config:
            self.max_value = self.config['max_value']

        if ('restart_on_complete' in self.config and
                self.config['restart_on_complete']):
            self.restart_on_complete = True

        if 'bcp' in self.config and self.config['bcp']:
            self.bcp = True

        if 'debug' in self.config and self.config['debug']:
            self.debug = True
            self.log.debug("Enabling Debug Logging")

        self.mode.player[self.tick_var] = self.start_value

        if self.log:
            self.log.debug("----------- Initial Values -----------")
            self.log.debug("running: %s", self.running)
            self.log.debug("start_value: %s", self.start_value)
            self.log.debug("restart_on_complete: %s", self.restart_on_complete)
            self.log.debug("_ticks: %s", self._ticks)
            self.log.debug("end_value: %s", self.end_value)
            self.log.debug("ticks_remaining: %s", self.ticks_remaining)
            self.log.debug("max_value: %s", self.max_value)
            self.log.debug("direction: %s", self.direction)
            self.log.debug("tick_secs: %s", self.tick_secs)
            self.log.debug("--------------------------------------")

        self._setup_control_events(self.config['control_events'])
Exemple #15
0
    def __init__(self, slide, machine, x=None, y=None, h_pos=None,
                     v_pos=None, layer=0, **kwargs):

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

        self.fonts = machine.display.fonts
        self.slide = slide
        self.machine = machine
        self.layer = layer
        self.config = deepcopy(kwargs)
        self.char_list = deque()
        self.cursor_position = 0
        self.selected_char = ''
        self.registered_event_handlers = list()

        if 'selected_char_color' not in self.config:
            self.config['selected_char_color'] = 0

        if 'selected_char_bg' not in self.config:
            self.config['selected_char_bg'] = 15

        if 'char_width' not in self.config:
            self.config['char_width'] = 11

        if 'width' not in self.config:
            self.config['width'] = None

        if 'height' not in self.config:
            self.config['height'] = 15

        if 'char_x_offset' not in self.config:
            self.config['char_x_offset'] = 0

        if 'char_y_offset' not in self.config:
            self.config['char_y_offset'] = 0

        if 'shift_left_tag' not in self.config:
            self.config['shift_left_tag'] = 'left_flipper'

        if 'shift_right_tag' not in self.config:
            self.config['shift_right_tag'] = 'right_flipper'

        if 'select_tag' not in self.config:
            self.config['select_tag'] = 'start'

        if 'name' in self.config:
            self.name = self.config['name']
        else:
            self.name = 'character_picker'

        if 'char_list' not in self.config:
            self.config['char_list'] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

        if 'max_chars' not in self.config:
            self.config['max_chars'] = 3

        if 'timeout' not in self.config:
            self.config['timeout'] = None
        else:
            self.config['timeout'] = (
                Timing.string_to_secs(self.config['timeout']))

        if 'back_char' not in self.config:
            self.config['back_char'] = 'back_arrow_7x7'

        if 'end_char' not in self.config:
            self.config['end_char'] = 'end_11x7'

        if 'back_char_selected' not in self.config:
            self.config['back_char_selected'] = 'back_arrow_7x7_selected'

        if 'end_char_selected' not in self.config:
            self.config['end_char_selected'] = 'end_11x7_selected'

        if 'image_padding' not in self.config:
            self.config['image_padding'] = 1

        if 'return_param' not in self.config:
            self.config['return_param'] = 'award'

        self.config['selected_char_color'] = (
            self.adjust_color(self.config['selected_char_color']))
        self.config['selected_char_bg'] = (
            self.adjust_color(self.config['selected_char_bg']))

        self.adjust_colors(**self.config)

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

        self.char_list.extend(self.config['char_list'])
        self.char_list.append('back')
        self.char_list.append('end')
        self.char_list.rotate(len(self.char_list)/2)

        self.cursor_position = len(self.char_list)/2
        self.selected_char = self.char_list[self.cursor_position]

        self.machine._set_machine_var(name=self.name + '_chars_entered',
                                      value='')

        self.setup_switch_handlers()

        self.render()