<s> """<STR_LIT>""" <EOL> from pyface . qt import QtCore , QtGui <EOL> from traits . api import Bool <EOL> from traitsui . qt4 . table_editor import TableDelegate <EOL> class TableImageRenderer ( TableDelegate ) : <EOL> """<STR_LIT>""" <EOL> scale_to_cell = Bool ( True ) <EOL> def get_image_for_obj ( self , value , row , col ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> def paint ( self , painter , option , index ) : <EOL> """<STR_LIT>""" <EOL> QtGui . QStyledItemDelegate . paint ( self , painter , option , index ) <EOL> value = index . data ( QtCore . Qt . UserRole ) <EOL> image = self . get_image_for_obj ( value , index . row ( ) , index . column ( ) ) <EOL> if image : <EOL> image = image . create_bitmap ( ) <EOL> if self . scale_to_cell : <EOL> w = min ( image . width ( ) , option . rect . width ( ) ) <EOL> h = min ( image . height ( ) , option . rect . height ( ) ) <EOL> else : <EOL> w = image . width ( ) <EOL> h = image . height ( ) <EOL> x = option . rect . x ( ) <EOL> y = option . rect . y ( ) + ( option . rect . height ( ) - h ) / <NUM_LIT:2> <EOL> target = QtCore . QRect ( x , y , w , h ) <EOL> painter . drawPixmap ( target , image ) <EOL> def sizeHint ( self , option , index ) : <EOL> """<STR_LIT>""" <EOL> size = QtGui . QStyledItemDelegate . sizeHint ( self , option , index ) <EOL> value = index . data ( QtCore . Qt . UserRole ) <EOL> image = self . get_image_for_obj ( value , index . row ( ) , index . column ( ) ) <EOL> if image : <EOL> image = image . create_bitmap ( ) <EOL> size . setWidth ( max ( image . width ( ) , size . width ( ) ) ) <EOL> size . setHeight ( max ( image . height ( ) , size . height ( ) ) ) <EOL> return size </s>
