<s> """<STR_LIT>""" <EOL> import logging <EOL> from PyQt5 . QtWidgets import QDialog <EOL> from PyQt5 . QtWidgets import QListWidgetItem <EOL> from PyQt5 . QtGui import QPixmap <EOL> from PyQt5 . QtGui import QBrush <EOL> from PyQt5 . QtGui import QColor <EOL> from PIL . ImageQt import ImageQt <EOL> import qt_techs <EOL> import saves <EOL> def new_tech_slot ( tech_asset ) : <EOL> module = { <EOL> "<STR_LIT>" : tech_asset , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> return module <EOL> def make_tech_list ( tech_names ) : <EOL> techs = [ ] <EOL> for i in tech_names : <EOL> techs . append ( saves . new_item_data ( i ) ) <EOL> return techs <EOL> class Techs ( object ) : <EOL> def __init__ ( self , main_window ) : <EOL> self . dialog = QDialog ( main_window . window ) <EOL> self . ui = qt_techs . Ui_Dialog ( ) <EOL> self . ui . setupUi ( self . dialog ) <EOL> self . main_window = main_window <EOL> self . assets = main_window . assets <EOL> self . player = main_window . player <EOL> self . selected_tech = None <EOL> self . ui . tech_list . currentItemChanged . connect ( lambda : self . set_select ( self . ui . tech_list ) ) <EOL> self . ui . tech_list . itemDoubleClicked . connect ( self . add_tech ) <EOL> self . ui . known_list . currentItemChanged . connect ( lambda : self . set_select ( self . ui . known_list ) ) <EOL> self . ui . known_list . itemDoubleClicked . connect ( self . remove_tech ) <EOL> self . techs = [ None , None , None , None ] <EOL> self . equip = [ None , None , None , None ] <EOL> self . populate_equipped ( ) <EOL> self . ui . toggle_button . clicked . connect ( self . toggle_tech ) <EOL> self . ui . add_button . clicked . connect ( self . add_tech ) <EOL> self . ui . remove_button . clicked . connect ( self . remove_tech ) <EOL> self . ui . unlock_button . clicked . connect ( self . learn_all_techs ) <EOL> self . ui . icon1_clear . clicked . connect ( lambda : self . clear_tech ( <NUM_LIT:0> ) ) <EOL> self . ui . icon2_clear . clicked . connect ( lambda : self . clear_tech ( <NUM_LIT:1> ) ) <EOL> self . ui . icon3_clear . clicked . connect ( lambda : self . clear_tech ( <NUM_LIT:2> ) ) <EOL> self . ui . icon4_clear . clicked . connect ( lambda : self . clear_tech ( <NUM_LIT:3> ) ) <EOL> self . ui . icon1_button . clicked . connect ( lambda : self . set_tech ( <NUM_LIT:0> ) ) <EOL> self . ui . icon2_button . clicked . connect ( lambda : self . set_tech ( <NUM_LIT:1> ) ) <EOL> self . ui . icon3_button . clicked . connect ( lambda : self . set_tech ( <NUM_LIT:2> ) ) <EOL> self . ui . icon4_button . clicked . connect ( lambda : self . set_tech ( <NUM_LIT:3> ) ) <EOL> self . update_lists ( ) <EOL> self . ui . tech_list . setFocus ( ) <EOL> if self . ui . tech_list . count ( ) > <NUM_LIT:0> : <EOL> self . ui . tech_list . setCurrentRow ( <NUM_LIT:0> ) <EOL> else : <EOL> self . ui . known_list . setCurrentRow ( <NUM_LIT:0> ) <EOL> def populate_equipped ( self ) : <EOL> current = <NUM_LIT:1> <EOL> for i in self . player . get_equipped_techs ( ) : <EOL> if i is None : <EOL> continue <EOL> try : <EOL> name = i [ "<STR_LIT:content>" ] [ "<STR_LIT:name>" ] <EOL> tech = self . assets . techs ( ) . get_tech ( name ) <EOL> icon = QPixmap . fromImage ( ImageQt ( tech [ <NUM_LIT:1> ] ) ) <EOL> getattr ( self . ui , "<STR_LIT>" + str ( current ) ) . setPixmap ( icon . scaled ( <NUM_LIT:32> , <NUM_LIT:32> ) ) <EOL> getattr ( self . ui , "<STR_LIT>" + str ( current ) ) . setToolTip ( tech [ <NUM_LIT:0> ] [ "<STR_LIT>" ] ) <EOL> self . techs [ current - <NUM_LIT:1> ] = new_tech_slot ( tech [ <NUM_LIT:0> ] [ "<STR_LIT>" ] ) <EOL> self . equip [ current - <NUM_LIT:1> ] = tech [ <NUM_LIT:0> ] [ "<STR_LIT>" ] <EOL> except TypeError : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> current += <NUM_LIT:1> <EOL> def update_lists ( self ) : <EOL> visible_techs = [ x [ "<STR_LIT:name>" ] for x in self . player . get_visible_techs ( ) ] <EOL> self . ui . tech_list . clear ( ) <EOL> for tech in sorted ( self . assets . techs ( ) . all ( ) ) : <EOL> if tech not in visible_techs : <EOL> item = QListWidgetItem ( tech ) <EOL> self . ui . tech_list . addItem ( item ) <EOL> enabled = [ x [ "<STR_LIT:name>" ] for x in self . player . get_enabled_techs ( ) ] <EOL> self . ui . known_list . clear ( ) <EOL> for tech in sorted ( visible_techs ) : <EOL> item = QListWidgetItem ( tech ) <EOL> if tech in enabled : <EOL> item . setBackground ( QBrush ( QColor ( "<STR_LIT>" ) ) ) <EOL> self . ui . known_list . addItem ( item ) <EOL> def update_selection ( self ) : <EOL> tech = self . assets . techs ( ) . get_tech ( self . selected_tech ) <EOL> if tech is None : <EOL> self . ui . tech_info . setText ( "<STR_LIT>" ) <EOL> self . ui . current_icon . setPixmap ( QPixmap ( ) ) <EOL> self . ui . add_button . setEnabled ( False ) <EOL> self . ui . remove_button . setEnabled ( True ) <EOL> return <EOL> visible = [ x [ "<STR_LIT:name>" ] for x in self . player . get_visible_techs ( ) ] <EOL> tech_info = "<STR_LIT>" % ( tech [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , <EOL> tech [ <NUM_LIT:0> ] [ "<STR_LIT>" ] ) <EOL> tech_info += "<STR_LIT>" % tech [ <NUM_LIT:3> ] [ "<STR_LIT:type>" ] <EOL> tech_info += "<STR_LIT>" % tech [ <NUM_LIT:0> ] [ "<STR_LIT>" ] <EOL> tech_info += "<STR_LIT>" % tech [ <NUM_LIT:0> ] [ "<STR_LIT>" ] <EOL> tech_info += tech [ <NUM_LIT:0> ] [ "<STR_LIT:description>" ] + "<STR_LIT>" <EOL> self . ui . tech_info . setText ( tech_info ) <EOL> self . ui . current_icon . setPixmap ( QPixmap . fromImage ( ImageQt ( tech [ <NUM_LIT:1> ] ) ) . scaled ( <NUM_LIT:32> , <NUM_LIT:32> ) ) <EOL> slots = [ "<STR_LIT>" , "<STR_LIT:body>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> index = <NUM_LIT:1> <EOL> for slot in slots : <EOL> set_button = getattr ( self . ui , "<STR_LIT>" + str ( index ) + "<STR_LIT>" ) <EOL> clear_button = getattr ( self . ui , "<STR_LIT>" + str ( index ) + "<STR_LIT>" ) <EOL> can_set = tech [ <NUM_LIT:3> ] [ "<STR_LIT:type>" ] == slot <EOL> is_set = self . equip [ index - <NUM_LIT:1> ] is not None <EOL> set_button . setEnabled ( can_set ) <EOL> clear_button . setEnabled ( is_set ) <EOL> index += <NUM_LIT:1> <EOL> can_add = self . selected_tech not in visible <EOL> self . ui . add_button . setEnabled ( can_add ) <EOL> self . ui . remove_button . setEnabled ( not can_add ) <EOL> self . ui . toggle_button . setEnabled ( not can_add ) <EOL> def set_select ( self , source ) : <EOL> selected = source . currentItem ( ) <EOL> if selected is not None : <EOL> self . selected_tech = selected . text ( ) <EOL> else : <EOL> return <EOL> self . update_selection ( ) <EOL> def toggle_tech ( self ) : <EOL> enabled = [ x [ "<STR_LIT:name>" ] for x in self . player . get_enabled_techs ( ) ] <EOL> item = self . selected_tech <EOL> if item in enabled : <EOL> new_techs = [ x for x in enabled if x != item ] <EOL> self . player . set_enabled_techs ( make_tech_list ( new_techs ) ) <EOL> else : <EOL> enabled . append ( item ) <EOL> self . player . set_enabled_techs ( make_tech_list ( enabled ) ) <EOL> self . update_lists ( ) <EOL> self . update_selection ( ) <EOL> def add_tech ( self ) : <EOL> item = self . selected_tech <EOL> visible = [ x [ "<STR_LIT:name>" ] for x in self . player . get_visible_techs ( ) ] <EOL> visible . append ( item ) <EOL> self . player . set_visible_techs ( make_tech_list ( visible ) ) <EOL> self . update_lists ( ) <EOL> self . update_selection ( ) <EOL> def remove_tech ( self ) : <EOL> if self . selected_tech is None : <EOL> return <EOL> item = self . selected_tech <EOL> visible = [ x [ "<STR_LIT:name>" ] for x in self . player . get_visible_techs ( ) ] <EOL> enabled = [ x [ "<STR_LIT:name>" ] for x in self . player . get_enabled_techs ( ) ] <EOL> self . player . set_visible_techs ( make_tech_list ( [ x for x in visible if x != item ] ) ) <EOL> self . player . set_enabled_techs ( make_tech_list ( [ x for x in enabled if x != item ] ) ) <EOL> self . update_lists ( ) <EOL> self . update_selection ( ) <EOL> def learn_all_techs ( self ) : <EOL> all_techs = self . assets . techs ( ) . all ( ) <EOL> self . player . set_visible_techs ( make_tech_list ( all_techs ) ) <EOL> self . player . set_enabled_techs ( make_tech_list ( all_techs ) ) <EOL> self . update_lists ( ) <EOL> self . update_selection ( ) <EOL> def set_tech ( self , index ) : <EOL> if self . selected_tech is None : <EOL> return <EOL> tech_name = self . selected_tech <EOL> tech = self . assets . techs ( ) . get_tech ( tech_name ) <EOL> if tech is None : <EOL> return <EOL> icon = QPixmap . fromImage ( ImageQt ( tech [ <NUM_LIT:1> ] ) ) <EOL> getattr ( self . ui , "<STR_LIT>" + str ( index + <NUM_LIT:1> ) ) . setPixmap ( icon . scaled ( <NUM_LIT:32> , <NUM_LIT:32> ) ) <EOL> getattr ( self . ui , "<STR_LIT>" + str ( index + <NUM_LIT:1> ) ) . setToolTip ( tech [ <NUM_LIT:0> ] [ "<STR_LIT>" ] ) <EOL> self . techs [ index ] = new_tech_slot ( tech [ <NUM_LIT:0> ] [ "<STR_LIT>" ] ) <EOL> self . equip [ index ] = tech [ <NUM_LIT:0> ] [ "<STR_LIT>" ] <EOL> self . update_selection ( ) <EOL> def clear_tech ( self , index ) : <EOL> self . techs [ index ] = None <EOL> self . equip [ index ] = None <EOL> getattr ( self . ui , "<STR_LIT>" + str ( index + <NUM_LIT:1> ) ) . setPixmap ( QPixmap ( ) ) <EOL> getattr ( self . ui , "<STR_LIT>" + str ( index + <NUM_LIT:1> ) ) . setToolTip ( None ) <EOL> self . update_selection ( ) <EOL> def write_techs ( self ) : <EOL> techs = [ ] <EOL> equip = [ None , None , None , None ] <EOL> for i in self . techs : <EOL> if i is not None : <EOL> techs . append ( i ) <EOL> index = <NUM_LIT:0> <EOL> for i in self . equip : <EOL> equip [ index ] = i <EOL> index += <NUM_LIT:1> <EOL> self . player . set_tech_modules ( techs , equip ) <EOL> self . main_window . window . setWindowModified ( True ) </s>
