<s> """<STR_LIT>""" <EOL> from collections import deque <EOL> from copy import deepcopy <EOL> from mpf . media_controller . core . display import DisplayElement <EOL> from mpf . system . timing import Timing <EOL> import pygame <EOL> class CharacterPicker ( DisplayElement ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , slide , machine , x = None , y = None , h_pos = None , <EOL> v_pos = None , layer = <NUM_LIT:0> , ** kwargs ) : <EOL> super ( CharacterPicker , self ) . __init__ ( slide , x , y , h_pos , v_pos , layer ) <EOL> self . fonts = machine . display . fonts <EOL> self . slide = slide <EOL> self . machine = machine <EOL> self . layer = layer <EOL> self . config = deepcopy ( kwargs ) <EOL> self . char_list = deque ( ) <EOL> self . cursor_position = <NUM_LIT:0> <EOL> self . selected_char = '<STR_LIT>' <EOL> self . registered_event_handlers = list ( ) <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = <NUM_LIT:15> <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = <NUM_LIT:11> <EOL> if '<STR_LIT:width>' not in self . config : <EOL> self . config [ '<STR_LIT:width>' ] = None <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = <NUM_LIT:15> <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = '<STR_LIT:start>' <EOL> if '<STR_LIT:name>' in self . config : <EOL> self . name = self . config [ '<STR_LIT:name>' ] <EOL> else : <EOL> self . name = '<STR_LIT>' <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = <NUM_LIT:3> <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = None <EOL> else : <EOL> self . config [ '<STR_LIT>' ] = ( <EOL> Timing . string_to_secs ( self . config [ '<STR_LIT>' ] ) ) <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> if '<STR_LIT>' not in self . config : <EOL> self . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . config [ '<STR_LIT>' ] = ( <EOL> self . adjust_color ( self . config [ '<STR_LIT>' ] ) ) <EOL> self . config [ '<STR_LIT>' ] = ( <EOL> self . adjust_color ( self . config [ '<STR_LIT>' ] ) ) <EOL> self . adjust_colors ( ** self . config ) <EOL> self . config [ '<STR_LIT>' ] = self . adjusted_color <EOL> self . config [ '<STR_LIT>' ] = self . adjusted_bg_color <EOL> self . char_list . extend ( self . config [ '<STR_LIT>' ] ) <EOL> self . char_list . append ( '<STR_LIT>' ) <EOL> self . char_list . append ( '<STR_LIT:end>' ) <EOL> self . char_list . rotate ( len ( self . char_list ) / <NUM_LIT:2> ) <EOL> self . cursor_position = len ( self . char_list ) / <NUM_LIT:2> <EOL> self . selected_char = self . char_list [ self . cursor_position ] <EOL> self . machine . _set_machine_var ( name = self . name + '<STR_LIT>' , <EOL> value = '<STR_LIT>' ) <EOL> self . setup_switch_handlers ( ) <EOL> self . render ( ) <EOL> def setup_switch_handlers ( self ) : <EOL> self . registered_event_handlers . append ( self . machine . events . add_handler ( <EOL> '<STR_LIT>' + self . config [ '<STR_LIT>' ] + '<STR_LIT>' , <EOL> self . shift , places = <NUM_LIT:1> ) ) <EOL> self . registered_event_handlers . append ( self . machine . events . add_handler ( <EOL> '<STR_LIT>' + self . config [ '<STR_LIT>' ] + '<STR_LIT>' , <EOL> self . shift , places = - <NUM_LIT:1> ) ) <EOL> self . registered_event_handlers . append ( self . machine . events . add_handler ( <EOL> '<STR_LIT>' + self . config [ '<STR_LIT>' ] + '<STR_LIT>' , <EOL> self . select ) ) <EOL> def shift ( self , places = <NUM_LIT:1> ) : <EOL> if places > <NUM_LIT:0> : <EOL> self . machine . events . post ( self . name + '<STR_LIT>' ) <EOL> else : <EOL> self . machine . events . post ( self . name + '<STR_LIT>' ) <EOL> self . char_list . rotate ( places ) <EOL> self . selected_char = self . char_list [ self . cursor_position ] <EOL> self . render ( ) <EOL> def select ( self ) : <EOL> if self . selected_char == '<STR_LIT>' : <EOL> self . machine . _set_machine_var ( name = self . name + '<STR_LIT>' , <EOL> value = self . machine . machine_vars [ self . name + '<STR_LIT>' ] [ : - <NUM_LIT:1> ] ) <EOL> self . machine . events . post ( self . name + '<STR_LIT>' ) <EOL> elif self . selected_char == '<STR_LIT:end>' : <EOL> self . machine . events . post ( self . name + '<STR_LIT>' ) <EOL> self . complete ( ) <EOL> else : <EOL> self . machine . events . post ( self . name + '<STR_LIT>' ) <EOL> self . machine . _set_machine_var ( name = self . name + '<STR_LIT>' , <EOL> value = self . machine . machine_vars [ self . name + '<STR_LIT>' ] + <EOL> self . selected_char ) <EOL> if ( len ( self . machine . machine_vars [ self . name + '<STR_LIT>' ] ) == <EOL> self . config [ '<STR_LIT>' ] ) : <EOL> self . complete ( ) <EOL> def render ( self ) : <EOL> back_surface = ( <EOL> self . machine . images [ self . config [ '<STR_LIT>' ] ] . image_surface ) <EOL> end_surface = ( <EOL> self . machine . images [ self . config [ '<STR_LIT>' ] ] . image_surface ) <EOL> total_width = len ( self . char_list ) * self . config [ '<STR_LIT>' ] + ( <EOL> back_surface . get_width ( ) + end_surface . get_width ( ) + <EOL> ( self . config [ '<STR_LIT>' ] * <NUM_LIT:4> ) ) <EOL> self . create_element_surface ( total_width , self . config [ '<STR_LIT>' ] ) <EOL> current_x_position = <NUM_LIT:0> <EOL> for index , x in enumerate ( self . char_list ) : <EOL> if x == '<STR_LIT>' : <EOL> char_surface = back_surface <EOL> next_offset = char_surface . get_width ( ) + ( <EOL> <NUM_LIT:2> * self . config [ '<STR_LIT>' ] ) <EOL> x_offset = self . config [ '<STR_LIT>' ] <EOL> elif x == '<STR_LIT:end>' : <EOL> char_surface = end_surface <EOL> next_offset = char_surface . get_width ( ) + ( <EOL> <NUM_LIT:2> * self . config [ '<STR_LIT>' ] ) <EOL> x_offset = self . config [ '<STR_LIT>' ] <EOL> else : <EOL> char_surface = self . fonts . render ( text = x , ** self . config ) <EOL> next_offset = self . config [ '<STR_LIT>' ] <EOL> x_offset = ( ( ( self . config [ '<STR_LIT>' ] - <EOL> char_surface . get_width ( ) ) / <NUM_LIT:2> ) + <EOL> self . config [ '<STR_LIT>' ] ) <EOL> if index == self . cursor_position : <EOL> if x == '<STR_LIT>' : <EOL> char_surface = self . machine . images [ <EOL> self . config [ '<STR_LIT>' ] ] . image_surface <EOL> bg_width = char_surface . get_width ( ) + ( <EOL> <NUM_LIT:2> * self . config [ '<STR_LIT>' ] ) <EOL> elif x == '<STR_LIT:end>' : <EOL> char_surface = self . machine . images [ <EOL> self . config [ '<STR_LIT>' ] ] . image_surface <EOL> bg_width = char_surface . get_width ( ) + ( <EOL> <NUM_LIT:2> * self . config [ '<STR_LIT>' ] ) <EOL> else : <EOL> highlighted_config = deepcopy ( self . config ) <EOL> highlighted_config [ '<STR_LIT>' ] = ( <EOL> self . config [ '<STR_LIT>' ] ) <EOL> highlighted_config [ '<STR_LIT>' ] = ( <EOL> self . config [ '<STR_LIT>' ] ) <EOL> char_surface = self . fonts . render ( text = x , <EOL> ** highlighted_config ) <EOL> bg_width = self . config [ '<STR_LIT>' ] <EOL> pygame . draw . rect ( self . element_surface , <EOL> self . config [ '<STR_LIT>' ] , <EOL> ( current_x_position , <EOL> <NUM_LIT:0> , <EOL> bg_width , <EOL> self . config [ '<STR_LIT>' ] ) ) <EOL> self . element_surface . blit ( char_surface , ( <EOL> current_x_position + x_offset , self . config [ '<STR_LIT>' ] ) ) <EOL> current_x_position += next_offset <EOL> if self . config [ '<STR_LIT:width>' ] : <EOL> rendered_char_surface = self . element_surface <EOL> self . create_element_surface ( self . config [ '<STR_LIT:width>' ] , <EOL> self . config [ '<STR_LIT>' ] ) <EOL> h_offset = ( rendered_char_surface . get_width ( ) - <EOL> self . config [ '<STR_LIT:width>' ] ) / - <NUM_LIT:2> <EOL> self . element_surface . blit ( rendered_char_surface , ( h_offset , <NUM_LIT:0> ) ) <EOL> self . set_position ( self . x , self . y , self . h_pos , self . v_pos ) <EOL> self . dirty = True <EOL> self . slide . refresh ( force_dirty = True ) <EOL> def complete ( self ) : <EOL> self . scrub ( ) <EOL> name = self . machine . machine_vars [ self . name + '<STR_LIT>' ] <EOL> if not name : <EOL> name = '<STR_LIT:U+0020>' <EOL> self . machine . machine_vars [ self . name + '<STR_LIT>' ] = '<STR_LIT>' <EOL> return_param = { self . config [ '<STR_LIT>' ] : <EOL> self . config [ '<STR_LIT>' ] [ self . config [ '<STR_LIT>' ] ] } <EOL> self . machine . send ( bcp_command = '<STR_LIT>' , <EOL> name = self . name + '<STR_LIT>' , <EOL> player_name = name , <EOL> ** return_param ) <EOL> def scrub ( self ) : <EOL> self . machine . events . remove_handlers_by_keys ( <EOL> self . registered_event_handlers ) <EOL> self . registered_event_handlers = list ( ) <EOL> display_element_class = CharacterPicker <EOL> create_asset_manager = False </s>
