<s> from PySide . QtCore import * <EOL> from PySide . QtGui import * <EOL> class QParamEdit ( QTableWidget ) : <EOL> def __init__ ( self , parent = None ) : <EOL> super ( QParamEdit , self ) . __init__ ( parent ) <EOL> self . setStyleSheet ( "<STR_LIT>" ) <EOL> self . setShowGrid ( False ) <EOL> self . nameoptions = [ ] <EOL> self . valueoptions = [ ] <EOL> self . setColumnCount ( <NUM_LIT:2> ) <EOL> self . setHorizontalHeaderLabels ( [ '<STR_LIT:Name>' , '<STR_LIT>' ] ) <EOL> self . horizontalHeader ( ) . setVisible ( False ) <EOL> self . setColumnWidth ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> self . setColumnWidth ( <NUM_LIT:1> , <NUM_LIT> ) <EOL> self . horizontalHeader ( ) . setStretchLastSection ( True ) <EOL> self . setRowCount ( <NUM_LIT:0> ) <EOL> self . verticalHeader ( ) . setVisible ( False ) <EOL> self . isCalculating = False <EOL> self . cellChanged . connect ( self . calcRows ) <EOL> self . calcRows ( ) <EOL> self . resizeRowsToContents ( ) <EOL> def setNameOptions ( self , options ) : <EOL> '''<STR_LIT>''' <EOL> self . isCalculating = True <EOL> self . nameoptions = options <EOL> for row in range ( <NUM_LIT:0> , self . rowCount ( ) ) : <EOL> self . setComboBox ( row , <NUM_LIT:0> , options ) <EOL> self . isCalculating = False <EOL> def setValueOptions ( self , options ) : <EOL> self . isCalculating = True <EOL> self . valueoptions = options <EOL> for row in range ( <NUM_LIT:0> , self . rowCount ( ) ) : <EOL> self . setComboBox ( row , <NUM_LIT:1> , options ) <EOL> self . isCalculating = False <EOL> def getComboBox ( self , row , col ) : <EOL> combo = self . cellWidget ( row , col ) <EOL> if combo is None : <EOL> combo = QComboBox ( self ) <EOL> combo . setEditable ( True ) <EOL> combo . row = row <EOL> combo . col = col <EOL> combo . editTextChanged . connect ( self . calcRows ) <EOL> combo . activated . connect ( self . onItemSelected ) <EOL> self . setCellWidget ( row , col , combo ) <EOL> return ( combo ) <EOL> def setComboBox ( self , row , col , options ) : <EOL> combo = self . getComboBox ( row , col ) <EOL> combo . clear ( ) <EOL> for o in reversed ( options ) : <EOL> combo . insertItem ( <NUM_LIT:0> , o . get ( "<STR_LIT:name>" , "<STR_LIT>" ) ) <EOL> combo . setItemData ( <NUM_LIT:0> , o . get ( "<STR_LIT>" , None ) , Qt . ToolTipRole ) <EOL> if ( o . get ( "<STR_LIT>" , False ) ) : <EOL> combo . setItemData ( <NUM_LIT:0> , QColor ( "<STR_LIT>" ) , Qt . BackgroundColorRole ) <EOL> if ( '<STR_LIT>' in o ) : <EOL> combo . setItemData ( <NUM_LIT:0> , o . get ( "<STR_LIT>" , [ ] ) , Qt . UserRole ) <EOL> return ( combo ) <EOL> def setValue ( self , row , col , val ) : <EOL> combo = self . getComboBox ( row , col ) <EOL> combo . setEditText ( val ) <EOL> def getValue ( self , row , col ) : <EOL> combo = self . getComboBox ( row , col ) <EOL> return ( combo . currentText ( ) ) <EOL> def setParams ( self , vals = { } ) : <EOL> self . setRowCount ( len ( vals ) ) <EOL> self . setValueOptions ( self . valueoptions ) <EOL> self . setNameOptions ( self . nameoptions ) <EOL> row = <NUM_LIT:0> <EOL> for name in vals : <EOL> self . setValue ( row , <NUM_LIT:0> , name ) <EOL> self . setValue ( row , <NUM_LIT:1> , vals [ name ] ) <EOL> row = row + <NUM_LIT:1> <EOL> self . calcRows ( ) <EOL> self . resizeRowsToContents ( ) <EOL> def getParams ( self ) : <EOL> params = { } <EOL> for row in range ( <NUM_LIT:0> , self . rowCount ( ) ) : <EOL> if not self . rowEmpty ( row ) : <EOL> params [ self . getValue ( row , <NUM_LIT:0> ) ] = self . getValue ( row , <NUM_LIT:1> ) <EOL> return params <EOL> def rowEmpty ( self , row ) : <EOL> col0 = self . getValue ( row , <NUM_LIT:0> ) <EOL> col1 = self . getValue ( row , <NUM_LIT:1> ) <EOL> return ( ( ( col0 == '<STR_LIT>' ) | ( col0 == '<STR_LIT>' ) ) & ( ( col1 == '<STR_LIT>' ) | ( col1 == '<STR_LIT>' ) ) ) <EOL> @ Slot ( ) <EOL> def onItemSelected ( self , index = <NUM_LIT:0> ) : <EOL> '''<STR_LIT>''' <EOL> sender = self . sender ( ) <EOL> options = sender . itemData ( index , Qt . UserRole ) <EOL> if not options : <EOL> options = self . valueoptions <EOL> if hasattr ( sender , '<STR_LIT>' ) and hasattr ( sender , '<STR_LIT>' ) and ( sender . col == <NUM_LIT:0> ) : <EOL> self . setComboBox ( sender . row , <NUM_LIT:1> , options ) <EOL> def calcRows ( self ) : <EOL> if ( self . isCalculating ) : return ( False ) <EOL> self . isCalculating = True <EOL> for row in range ( self . rowCount ( ) - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> if self . rowEmpty ( row ) : <EOL> self . removeRow ( row ) <EOL> row = self . rowCount ( ) <EOL> self . setRowCount ( row + <NUM_LIT:1> ) <EOL> self . setComboBox ( row , <NUM_LIT:0> , self . nameoptions ) <EOL> self . setComboBox ( row , <NUM_LIT:1> , self . valueoptions ) <EOL> self . setValue ( row , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> self . setValue ( row , <NUM_LIT:1> , '<STR_LIT>' ) <EOL> self . resizeRowsToContents ( ) <EOL> self . isCalculating = False </s>
