<s> from PySide import QtGui <EOL> from . . fe import FE <EOL> from . . widget_factory import EditorFactory <EOL> from . . base_editor import BaseValueEditor <EOL> from . . core . undo_redo_manager import UndoRedoManager <EOL> class ColorEditor ( BaseValueEditor ) : <EOL> def __init__ ( self , valueController , parent = None ) : <EOL> super ( ColorEditor , self ) . __init__ ( valueController , parent = parent ) <EOL> hbox = QtGui . QHBoxLayout ( ) <EOL> self . _editors = [ ] <EOL> self . _qgraphcsScene = QtGui . QGraphicsScene ( self ) <EOL> self . _qgraphcsView = QtGui . QGraphicsView ( self ) <EOL> self . _qgraphcsView . setScene ( self . _qgraphcsScene ) <EOL> self . _qgraphcsView . setFixedSize ( <NUM_LIT:100> , <NUM_LIT:20> ) <EOL> self . _qgraphcsView . setSizePolicy ( QtGui . QSizePolicy . Fixed , QtGui . QSizePolicy . Fixed ) <EOL> hbox . addWidget ( self . _qgraphcsView , <NUM_LIT:1> ) <EOL> hbox . addStretch ( <NUM_LIT:0> ) <EOL> hbox . setContentsMargins ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . setLayout ( hbox ) <EOL> self . setSizePolicy ( QtGui . QSizePolicy . Preferred , QtGui . QSizePolicy . Fixed ) <EOL> self . updateEditorValue ( ) <EOL> self . setEditable ( valueController . isEditable ( ) ) <EOL> def setEditable ( self , editable ) : <EOL> self . setEnabled ( editable ) <EOL> def getEditorValue ( self ) : <EOL> scalarKLType = FE . getInstance ( ) . types ( ) . Scalar <EOL> colorKLType = FE . getInstance ( ) . types ( ) . Color <EOL> return colorKLType ( <EOL> scalarKLType ( self . __color . redF ( ) ) , <EOL> scalarKLType ( self . __color . greenF ( ) ) , <EOL> scalarKLType ( self . __color . blueF ( ) ) <EOL> ) <EOL> def setEditorValue ( self , value ) : <EOL> self . __color = QtGui . QColor ( value . r * <NUM_LIT:255> , value . g * <NUM_LIT:255> , value . b * <NUM_LIT:255> ) <EOL> self . _qgraphcsView . setBackgroundBrush ( self . __color ) <EOL> self . _qgraphcsView . update ( ) <EOL> def mousePressEvent ( self , event ) : <EOL> if self . _valueController . isEditable ( ) : <EOL> self . __backupColor = self . __color <EOL> self . beginInteraction ( ) <EOL> dialog = QtGui . QColorDialog ( self . __color , self ) <EOL> dialog . currentColorChanged . connect ( self . __onColorChanged ) <EOL> dialog . accepted . connect ( self . __onAccepted ) <EOL> dialog . rejected . connect ( self . __onCanceled ) <EOL> dialog . setModal ( True ) <EOL> dialog . show ( ) <EOL> def __onColorChanged ( self , qcolor ) : <EOL> self . __color = QtGui . QColor ( qcolor . redF ( ) * <NUM_LIT:255> , qcolor . greenF ( ) * <NUM_LIT:255> , qcolor . blueF ( ) * <NUM_LIT:255> ) <EOL> self . _qgraphcsView . setBackgroundBrush ( self . __color ) <EOL> self . _setValueToController ( ) <EOL> def __onAccepted ( self ) : <EOL> self . endInteraction ( ) <EOL> def __onCanceled ( self ) : <EOL> self . endInteraction ( ) <EOL> undoManager = UndoRedoManager . getInstance ( ) <EOL> if undoManager and undoManager . canUndo ( ) : <EOL> undoManager . undo ( ) <EOL> else : <EOL> self . __onColorChanged ( self . __backupColor ) <EOL> @ classmethod <EOL> def canDisplay ( cls , valueController ) : <EOL> if valueController . getDataType ( ) == '<STR_LIT>' : <EOL> return True <EOL> return False <EOL> EditorFactory . registerEditorClass ( ColorEditor ) </s>
