<s> from PySide import QtCore <EOL> from undo_redo_manager import UndoRedoManager , Command <EOL> class ValueChangeCommand ( Command ) : <EOL> def __init__ ( self , valueController , newValue ) : <EOL> super ( ValueChangeCommand , self ) . __init__ ( ) <EOL> self . _valueController = valueController <EOL> self . oldValue = self . _valueController . getValue ( ) <EOL> self . newValue = newValue <EOL> def shortDesc ( self ) : <EOL> return "<STR_LIT>" + self . _valueController . getName ( ) + "<STR_LIT:'>" <EOL> def redo ( self ) : <EOL> self . _valueController . _setValue_NoUndo ( self . newValue ) <EOL> def undo ( self ) : <EOL> self . _valueController . _setValue_NoUndo ( self . oldValue ) <EOL> def mergeWith ( self , prevCommand ) : <EOL> if isinstance ( prevCommand , ValueChangeCommand ) : <EOL> if prevCommand . _valueController == self . _valueController : <EOL> self . newValue = prevCommand . newValue <EOL> self . _valueController . _setValue_NoUndo ( self . newValue ) <EOL> return True <EOL> return False <EOL> class ValueController ( QtCore . QObject ) : <EOL> valueChanged = QtCore . Signal ( object ) <EOL> editableChanged = QtCore . Signal ( bool ) <EOL> optionChanged = QtCore . Signal ( str ) <EOL> def __init__ ( self , name , dataType , editable = True , ** kwargs ) : <EOL> super ( ValueController , self ) . __init__ ( ) <EOL> self . name = name <EOL> self . dataType = dataType <EOL> self . editable = editable <EOL> self . options = kwargs <EOL> def getName ( self ) : <EOL> return str ( self . name ) <EOL> def getDataType ( self ) : <EOL> return self . dataType <EOL> def setValue ( self , value ) : <EOL> command = ValueChangeCommand ( self , value ) <EOL> UndoRedoManager . getInstance ( ) . addCommand ( command , invokeRedoOnAdd = True ) <EOL> def _setValue_NoUndo ( self , value ) : <EOL> raise NotImplementedError ( ) <EOL> def getValue ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def getOption ( self , key , defaultValue = None ) : <EOL> return self . options . get ( key , defaultValue ) <EOL> def hasOption ( self , key ) : <EOL> return key in self . options <EOL> def setOption ( self , key , value ) : <EOL> self . options [ key ] = value <EOL> self . optionChanged . emit ( key ) <EOL> def isEditable ( self ) : <EOL> return self . editable <EOL> def setEditable ( self , editable ) : <EOL> self . editable = editable <EOL> self . editableChanged . emit ( editable ) <EOL> def _extractSimpleTypes ( self , value ) : <EOL> if str ( type ( value ) ) == "<STR_LIT>" and ( <EOL> self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' or self . dataType == '<STR_LIT>' ) : <EOL> return value <EOL> else : <EOL> return value <EOL> def emitValueChanged ( self ) : <EOL> self . valueChanged . emit ( self . getValue ( ) ) <EOL> class MemberController ( ValueController ) : <EOL> def __init__ ( self , name , dataType , owner , editable = True , ** kwargs ) : <EOL> super ( MemberController , self ) . __init__ ( name , dataType , editable , ** kwargs ) <EOL> self . owner = owner <EOL> def _setValue_NoUndo ( self , value ) : <EOL> setattr ( self . owner , self . name , value ) <EOL> self . valueChanged . emit ( self . getValue ( ) ) <EOL> def getValue ( self ) : <EOL> return self . _extractSimpleTypes ( getattr ( self . owner , self . name ) ) <EOL> class ElementController ( ValueController ) : <EOL> def __init__ ( self , name , dataType , owner , editable = True , ** kwargs ) : <EOL> super ( ElementController , self ) . __init__ ( name , dataType , editable , ** kwargs ) <EOL> self . owner = owner <EOL> def _setValue_NoUndo ( self , value ) : <EOL> self . owner [ self . name ] = value <EOL> self . valueChanged . emit ( self . getValue ( ) ) <EOL> def getValue ( self ) : <EOL> return self . _extractSimpleTypes ( self . owner [ self . name ] ) <EOL> class GetterSetterController ( ValueController ) : <EOL> def __init__ ( self , name , dataType , getter = None , setter = None , defaultValue = None , ** kwargs ) : <EOL> super ( GetterSetterController , self ) . __init__ ( name , dataType = dataType , editable = ( getter is not None and setter is not None ) , ** kwargs ) <EOL> self . getter = getter <EOL> self . setter = setter <EOL> self . value = defaultValue <EOL> def _setValue_NoUndo ( self , value ) : <EOL> if self . setter is None : <EOL> self . value = value <EOL> else : <EOL> self . setter ( value ) <EOL> self . valueChanged . emit ( self . getValue ( ) ) <EOL> def getValue ( self ) : <EOL> if self . getter is None : <EOL> return self . _extractSimpleTypes ( self . value ) <EOL> else : <EOL> return self . _extractSimpleTypes ( self . getter ( ) ) <EOL> def setGetter ( self , getter ) : <EOL> self . getter = getter <EOL> self . value = self . getter ( ) <EOL> self . valueChanged . emit ( self . getValue ( ) ) <EOL> def setGetterSetter ( self , getter , setter ) : <EOL> self . getter = getter <EOL> self . setter = setter <EOL> self . value = getter ( ) <EOL> self . setEditable ( self . setter is not None ) <EOL> self . valueChanged . emit ( self . getValue ( ) ) </s>
