#NEWLINE# def color_editor_for( editor , parent ) : #NEWLINE# #INDENT# ' Creates a custom color editor panel for a specified editor.\n    ' #NEWLINE# if ( len ( color_samples ) == 0 ) : #NEWLINE# #INDENT# color_choices = ( 0 , 128 , 192 , 255 ) #NEWLINE# for r in color_choices : #NEWLINE# #INDENT# for g in color_choices : #NEWLINE# #INDENT# for b in ( 0 , 128 , 255 ) : #NEWLINE# #INDENT# color_samples . append ( QtGui . QColor ( r , g , b ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# root = QtGui . QWidget ( ) #NEWLINE# panel = QtGui . QHBoxLayout ( root ) #NEWLINE# panel . setContentsMargins ( 0 , 0 , 0 , 0 ) #NEWLINE# swatch_editor = editor . factory . simple_editor ( editor . ui , editor . object , editor . name , editor . description , None ) #NEWLINE# swatch_editor . prepare ( parent ) #NEWLINE# panel . addWidget ( swatch_editor . control ) #NEWLINE# grid = QtGui . QGridLayout ( ) #NEWLINE# grid . setSpacing ( 0 ) #NEWLINE# mapper = QtCore . QSignalMapper ( panel ) #NEWLINE# rows = 4 #NEWLINE# cols = ( len ( color_samples ) // rows ) #NEWLINE# i = 0 #NEWLINE# sheet_template = '\n    QPushButton {\n        min-height: 18px;\n        max-height: 18px;\n        min-width: 18px;\n        max-width: 18px;\n        background-color: rgb(%s);\n    }\n    ' #NEWLINE# for r in range ( rows ) : #NEWLINE# #INDENT# for c in range ( cols ) : #NEWLINE# #INDENT# control = FixedButton ( ) #NEWLINE# color = color_samples [ ( ( r * cols ) + c ) ] #NEWLINE# color_text = ( '%d,%d,%d,%d' % color . getRgb ( ) ) #NEWLINE# control . setStyleSheet ( ( sheet_template % color_text ) ) #NEWLINE# control . setAttribute ( QtCore . Qt . WA_LayoutUsesWidgetRect , True ) #NEWLINE# control . clicked . connect ( mapper . map ) #NEWLINE# mapper . setMapping ( control , color_text ) #NEWLINE# grid . addWidget ( control , r , c ) #NEWLINE# editor . set_tooltip ( control ) #NEWLINE# i += 1 #NEWLINE# #UNINDENT# #UNINDENT# mapper . mapped [ unicode ] . connect ( editor . update_object_from_swatch ) #NEWLINE# panel . addLayout ( grid ) #NEWLINE# return ( root , swatch_editor )