<s> from __future__ import absolute_import , division , print_function <EOL> from glue . external . qt . QtCore import Qt <EOL> from glue . external . qt import QtGui <EOL> class SettingsEditor ( object ) : <EOL> def __init__ ( self , app ) : <EOL> w = QtGui . QTableWidget ( parent = None ) <EOL> w . setColumnCount ( <NUM_LIT:2> ) <EOL> w . setRowCount ( len ( list ( app . settings ) ) ) <EOL> w . setHorizontalHeaderLabels ( [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> for row , ( key , value ) in enumerate ( app . settings ) : <EOL> k = QtGui . QTableWidgetItem ( key ) <EOL> v = QtGui . QTableWidgetItem ( str ( value ) ) <EOL> k . setFlags ( k . flags ( ) ^ ( Qt . ItemIsEditable | Qt . ItemIsSelectable ) ) <EOL> w . setItem ( row , <NUM_LIT:0> , k ) <EOL> w . setItem ( row , <NUM_LIT:1> , v ) <EOL> w . sortItems ( <NUM_LIT:0> ) <EOL> w . cellChanged . connect ( self . update_setting ) <EOL> w . setWindowModality ( Qt . ApplicationModal ) <EOL> w . resize ( <NUM_LIT> , <NUM_LIT> ) <EOL> w . setColumnWidth ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> w . setColumnWidth ( <NUM_LIT:1> , <NUM_LIT> ) <EOL> w . setWindowTitle ( "<STR_LIT>" ) <EOL> self . _widget = w <EOL> self . app = app <EOL> def update_setting ( self , row , column ) : <EOL> key = self . _widget . item ( row , <NUM_LIT:0> ) . text ( ) <EOL> value = self . _widget . item ( row , <NUM_LIT:1> ) . text ( ) <EOL> try : <EOL> self . app . set_setting ( key , value ) <EOL> except ValueError : <EOL> pass <EOL> new_txt = str ( self . app . get_setting ( key ) ) <EOL> self . _widget . item ( row , <NUM_LIT:1> ) . setText ( new_txt ) <EOL> @ property <EOL> def widget ( self ) : <EOL> return self . _widget </s>
