<s> """<STR_LIT>""" <EOL> from herculeum . ui . gui . widgets import AnimatedLabel , TimerAdapter <EOL> from PyQt4 . QtCore import Qt , QTimer <EOL> from PyQt4 . QtGui import QDialog , QHBoxLayout , QLabel , QSizePolicy , QVBoxLayout <EOL> class StartGameWidget ( QDialog ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , generator , config , <EOL> parent , application , surface_manager , flags ) : <EOL> """<STR_LIT>""" <EOL> super ( ) . __init__ ( parent , flags ) <EOL> self . application = application <EOL> self . surface_manager = surface_manager <EOL> self . config = config <EOL> self . generator = generator <EOL> self . player_character = None <EOL> self . class_description = None <EOL> self . class_name = None <EOL> self . class_icon = None <EOL> self . selected_index = None <EOL> self . class_names = sorted ( application . config . player_classes ) <EOL> self . class_config = application . config . player_classes <EOL> self . animation_adapter = None <EOL> self . animation_timer = None <EOL> cnf = self . config <EOL> self . konami = [ cnf . move_up , cnf . move_up , <EOL> cnf . move_down , cnf . move_down , <EOL> cnf . move_left , cnf . move_right , <EOL> cnf . move_left , cnf . move_right , <EOL> cnf . action_b , cnf . action_a ] <EOL> self . konami_index = <NUM_LIT:0> <EOL> self . __set_layout ( ) <EOL> def __set_layout ( self ) : <EOL> """<STR_LIT>""" <EOL> self . setSizePolicy ( QSizePolicy ( <EOL> QSizePolicy . Fixed , <EOL> QSizePolicy . Fixed ) ) <EOL> main_layout = QVBoxLayout ( ) <EOL> top_layout = QHBoxLayout ( ) <EOL> middle_layout = QHBoxLayout ( ) <EOL> bottom_layout = QHBoxLayout ( ) <EOL> main_layout . addLayout ( top_layout ) <EOL> main_layout . addLayout ( middle_layout ) <EOL> main_layout . addLayout ( bottom_layout ) <EOL> self . class_name = QLabel ( '<STR_LIT>' ) <EOL> self . class_name . setMinimumSize ( <NUM_LIT:200> , <NUM_LIT:50> ) <EOL> self . class_name . setMaximumSize ( <NUM_LIT:200> , <NUM_LIT:50> ) <EOL> self . class_name . setAlignment ( Qt . AlignCenter ) <EOL> self . animation_adapter = TimerAdapter ( ) <EOL> self . animation_timer = QTimer ( self ) <EOL> self . animation_timer . timeout . connect ( self . animation_adapter . trigger_animations ) <EOL> self . animation_timer . start ( <NUM_LIT> ) <EOL> self . class_icon = AnimatedLabel ( self . animation_adapter ) <EOL> self . class_icon . setMinimumSize ( <NUM_LIT:64> , <NUM_LIT:64> ) <EOL> self . class_icon . setMaximumSize ( <NUM_LIT:64> , <NUM_LIT:64> ) <EOL> self . class_icon . setAlignment ( Qt . AlignCenter ) <EOL> self . class_description = QLabel ( '<STR_LIT>' ) <EOL> self . class_description . setWordWrap ( True ) <EOL> self . class_description . setMinimumSize ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . class_description . setMaximumSize ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . class_description . setAlignment ( Qt . AlignTop ) <EOL> top_layout . addStretch ( ) <EOL> top_layout . addWidget ( self . class_name ) <EOL> top_layout . addStretch ( ) <EOL> middle_layout . addStretch ( ) <EOL> middle_layout . addWidget ( self . class_icon ) <EOL> middle_layout . addStretch ( ) <EOL> bottom_layout . addStretch ( ) <EOL> bottom_layout . addWidget ( self . class_description ) <EOL> bottom_layout . addStretch ( ) <EOL> self . setLayout ( main_layout ) <EOL> self . selected_index = <NUM_LIT:0> <EOL> if len ( self . class_names ) > <NUM_LIT:0> : <EOL> self . _show_character ( <EOL> self . class_config [ self . class_names [ self . selected_index ] ] ) <EOL> def _show_character ( self , character ) : <EOL> """<STR_LIT>""" <EOL> icon = self . surface_manager . get_icon ( character [ '<STR_LIT>' ] ) <EOL> self . class_icon . setPixmap ( icon ) <EOL> self . class_name . setText ( character [ '<STR_LIT>' ] ) <EOL> self . class_description . setText ( character [ '<STR_LIT>' ] ) <EOL> def __generate_character ( self ) : <EOL> """<STR_LIT>""" <EOL> self . player_character = None <EOL> self . player_character = self . generator ( self . class_names [ self . selected_index ] ) <EOL> def keyPressEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if event . key ( ) in self . konami [ self . konami_index ] : <EOL> self . konami_index = self . konami_index + <NUM_LIT:1> <EOL> else : <EOL> self . konami_index = <NUM_LIT:0> <EOL> if self . konami_index == len ( self . konami ) : <EOL> self . application . enable_cheat ( ) <EOL> if event . key ( ) in self . config . action_a : <EOL> self . __generate_character ( ) <EOL> self . animation_adapter . glyphs . clear ( ) <EOL> self . accept ( ) <EOL> elif event . key ( ) in self . config . move_right : <EOL> self . selected_index = self . selected_index + <NUM_LIT:1> <EOL> if self . selected_index >= len ( self . class_names ) : <EOL> self . selected_index = <NUM_LIT:0> <EOL> self . _show_character ( <EOL> self . class_config [ self . class_names [ self . selected_index ] ] ) <EOL> elif event . key ( ) in self . config . move_left : <EOL> self . selected_index = self . selected_index - <NUM_LIT:1> <EOL> if self . selected_index < <NUM_LIT:0> : <EOL> self . selected_index = len ( self . class_names ) - <NUM_LIT:1> <EOL> self . _show_character ( <EOL> self . class_config [ self . class_names [ self . selected_index ] ] ) <EOL> else : <EOL> super ( ) . keyPressEvent ( event ) </s>
