<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> from PyQt4 import QtCore , QtGui <EOL> from vistrails . core . inspector import PipelineInspector <EOL> from vistrails . core . modules . module_registry import get_module_registry <EOL> from vistrails . gui . common_widgets import QSearchTreeWindow , QSearchTreeWidget <EOL> from vistrails . gui . paramexplore . pe_pipeline import QAnnotatedPipelineView <EOL> from vistrails . gui . vistrails_palette import QVistrailsPaletteInterface <EOL> from vistrails . core . utils import InstanceObject <EOL> from vistrails . core . debug import debug <EOL> class ParameterInfo ( InstanceObject ) : <EOL> pass <EOL> class QParameterView ( QtGui . QWidget , QVistrailsPaletteInterface ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , controller = None , parent = None ) : <EOL> QtGui . QWidget . __init__ ( self , parent ) <EOL> self . set_title ( '<STR_LIT>' ) <EOL> self . controller = None <EOL> vLayout = QtGui . QVBoxLayout ( ) <EOL> vLayout . setMargin ( <NUM_LIT:0> ) <EOL> vLayout . setSpacing ( <NUM_LIT:5> ) <EOL> self . setLayout ( vLayout ) <EOL> self . toggleUnsetParameters = QtGui . QCheckBox ( '<STR_LIT>' ) <EOL> vLayout . addWidget ( self . toggleUnsetParameters , <NUM_LIT:0> , QtCore . Qt . AlignRight ) <EOL> self . parameterWidget = QParameterWidget ( ) <EOL> vLayout . addWidget ( self . parameterWidget ) <EOL> self . treeWidget = self . parameterWidget . treeWidget <EOL> self . pipeline_view = QAnnotatedPipelineView ( ) <EOL> self . pipeline_view . setReadOnlyMode ( True ) <EOL> vLayout . addWidget ( self . pipeline_view ) <EOL> vLayout . setStretch ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> vLayout . setStretch ( <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> vLayout . setStretch ( <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> self . connect ( self . toggleUnsetParameters , QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> self . parameterWidget . treeWidget . toggleUnsetParameters ) <EOL> self . set_controller ( controller ) <EOL> def set_controller ( self , controller ) : <EOL> if self . controller == controller : <EOL> return <EOL> self . controller = controller <EOL> self . pipeline_view . set_controller ( controller ) <EOL> if self . controller is not None : <EOL> self . set_pipeline ( controller . current_pipeline ) <EOL> else : <EOL> self . set_pipeline ( None ) <EOL> def set_pipeline ( self , pipeline ) : <EOL> if self . controller is None : <EOL> return <EOL> self . pipeline = pipeline <EOL> self . parameterWidget . set_pipeline ( pipeline , self . controller ) <EOL> if pipeline : <EOL> self . pipeline_view . scene ( ) . setupScene ( pipeline ) <EOL> else : <EOL> self . pipeline_view . scene ( ) . clear ( ) <EOL> self . pipeline_view . updateAnnotatedIds ( pipeline ) <EOL> self . get_palette ( ) . set_pipeline ( pipeline ) <EOL> def get_palette ( self ) : <EOL> from vistrails . gui . paramexplore . pe_inspector import QParamExploreInspector <EOL> return QParamExploreInspector . instance ( ) <EOL> class QParameterWidget ( QSearchTreeWindow ) : <EOL> """<STR_LIT>""" <EOL> def createTreeWidget ( self ) : <EOL> """<STR_LIT>""" <EOL> treeWidget = QParameterTreeWidget ( self ) <EOL> return treeWidget <EOL> def set_pipeline ( self , pipeline , controller ) : <EOL> self . pipeline = pipeline <EOL> self . treeWidget . updateFromPipeline ( pipeline , controller ) <EOL> class QParameterTreeWidget ( QSearchTreeWidget ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent = None ) : <EOL> """<STR_LIT>""" <EOL> QSearchTreeWidget . __init__ ( self , parent ) <EOL> self . header ( ) . hide ( ) <EOL> self . setRootIsDecorated ( False ) <EOL> self . delegate = QParameterTreeWidgetItemDelegate ( self , self ) <EOL> self . setItemDelegate ( self . delegate ) <EOL> self . showUnsetParameters = False <EOL> def updateFromPipeline ( self , pipeline , controller ) : <EOL> """<STR_LIT>""" <EOL> self . clear ( ) <EOL> if not pipeline : <EOL> return <EOL> if len ( pipeline . aliases ) > <NUM_LIT:0> : <EOL> aliasRoot = QParameterTreeWidgetItem ( None , self , [ '<STR_LIT>' ] ) <EOL> aliasRoot . setFlags ( QtCore . Qt . ItemIsEnabled ) <EOL> for ( alias , info ) in pipeline . aliases . iteritems ( ) : <EOL> ptype , pId , parentType , parentId , mId = info <EOL> parameter = pipeline . db_get_object ( ptype , pId ) <EOL> function = pipeline . db_get_object ( parentType , parentId ) <EOL> v = parameter . strValue <EOL> port_spec = function . get_spec ( '<STR_LIT:input>' ) <EOL> port_spec_item = port_spec . port_spec_items [ parameter . pos ] <EOL> label = [ '<STR_LIT>' % ( alias , v ) ] <EOL> pInfo = ParameterInfo ( module_id = mId , <EOL> name = function . name , <EOL> pos = parameter . pos , <EOL> value = v , <EOL> spec = port_spec_item , <EOL> is_alias = True ) <EOL> QParameterTreeWidgetItem ( ( alias , [ pInfo ] ) , <EOL> aliasRoot , label ) <EOL> aliasRoot . setExpanded ( True ) <EOL> vistrailVarsRoot = QParameterTreeWidgetItem ( None , self , <EOL> [ '<STR_LIT>' ] ) <EOL> vistrailVarsRoot . setHidden ( True ) <EOL> inspector = PipelineInspector ( ) <EOL> inspector . inspect_ambiguous_modules ( pipeline ) <EOL> sortedModules = sorted ( pipeline . modules . iteritems ( ) , <EOL> key = lambda item : item [ <NUM_LIT:1> ] . name ) <EOL> reg = get_module_registry ( ) <EOL> for mId , module in sortedModules : <EOL> if module . is_vistrail_var ( ) : <EOL> vistrailVarsRoot . setHidden ( False ) <EOL> vistrailVarsRoot . setExpanded ( True ) <EOL> port_spec = module . get_port_spec ( '<STR_LIT:value>' , '<STR_LIT:input>' ) <EOL> if not port_spec : <EOL> debug . critical ( "<STR_LIT>" % module ) <EOL> continue <EOL> if not controller . has_vistrail_variable_with_uuid ( <EOL> module . get_vistrail_var ( ) ) : <EOL> continue <EOL> vv = controller . get_vistrail_variable_by_uuid ( <EOL> module . get_vistrail_var ( ) ) <EOL> label = [ '<STR_LIT>' % ( vv . name , vv . value ) ] <EOL> pList = [ ParameterInfo ( module_id = mId , <EOL> name = port_spec . name , <EOL> pos = port_spec . port_spec_items [ pId ] . pos , <EOL> value = "<STR_LIT>" , <EOL> spec = port_spec . port_spec_items [ pId ] , <EOL> is_alias = False ) <EOL> for pId in xrange ( len ( port_spec . port_spec_items ) ) ] <EOL> QParameterTreeWidgetItem ( ( vv . name , pList ) , <EOL> vistrailVarsRoot , <EOL> label ) <EOL> continue <EOL> function_names = { } <EOL> mLabel = [ module . name ] <EOL> moduleItem = None <EOL> if len ( module . functions ) > <NUM_LIT:0> : <EOL> for fId in xrange ( len ( module . functions ) ) : <EOL> function = module . functions [ fId ] <EOL> function_names [ function . name ] = function <EOL> if len ( function . params ) == <NUM_LIT:0> : continue <EOL> if moduleItem == None : <EOL> if inspector . annotated_modules . has_key ( mId ) : <EOL> annotatedId = inspector . annotated_modules [ mId ] <EOL> moduleItem = QParameterTreeWidgetItem ( annotatedId , <EOL> self , mLabel ) <EOL> else : <EOL> moduleItem = QParameterTreeWidgetItem ( None , <EOL> self , mLabel ) <EOL> v = '<STR_LIT:U+002CU+0020>' . join ( [ p . strValue for p in function . params ] ) <EOL> label = [ '<STR_LIT>' % ( function . name , v ) ] <EOL> try : <EOL> port_spec = function . get_spec ( '<STR_LIT:input>' ) <EOL> except Exception : <EOL> debug . critical ( "<STR_LIT>" % ( module , function , function . sigstring ) ) <EOL> continue <EOL> port_spec_items = port_spec . port_spec_items <EOL> pList = [ ParameterInfo ( module_id = mId , <EOL> name = function . name , <EOL> pos = function . params [ pId ] . pos , <EOL> value = function . params [ pId ] . strValue , <EOL> spec = port_spec_items [ pId ] , <EOL> is_alias = False ) <EOL> for pId in xrange ( len ( function . params ) ) ] <EOL> mName = module . name <EOL> if moduleItem . parameter is not None : <EOL> mName += '<STR_LIT>' % moduleItem . parameter <EOL> fName = '<STR_LIT>' % ( mName , function . name ) <EOL> QParameterTreeWidgetItem ( ( fName , pList ) , <EOL> moduleItem , <EOL> label ) <EOL> if module . is_valid : <EOL> for port_spec in module . destinationPorts ( ) : <EOL> if ( port_spec . name in function_names or <EOL> not port_spec . is_valid or <EOL> not len ( port_spec . port_spec_items ) or <EOL> not reg . is_constant ( port_spec ) ) : <EOL> continue <EOL> if moduleItem == None : <EOL> if inspector . annotated_modules . has_key ( mId ) : <EOL> annotatedId = inspector . annotated_modules [ mId ] <EOL> moduleItem = QParameterTreeWidgetItem ( annotatedId , <EOL> self , <EOL> mLabel , <EOL> False ) <EOL> else : <EOL> moduleItem = QParameterTreeWidgetItem ( None , self , <EOL> mLabel , False ) <EOL> v = '<STR_LIT:U+002CU+0020>' . join ( [ p . module for p in port_spec . port_spec_items ] ) <EOL> label = [ '<STR_LIT>' % ( port_spec . name , v ) ] <EOL> pList = [ ParameterInfo ( module_id = mId , <EOL> name = port_spec . name , <EOL> pos = port_spec . port_spec_items [ pId ] . pos , <EOL> value = "<STR_LIT>" , <EOL> spec = port_spec . port_spec_items [ pId ] , <EOL> is_alias = False ) <EOL> for pId in xrange ( len ( port_spec . port_spec_items ) ) ] <EOL> mName = module . name <EOL> if moduleItem . parameter is not None : <EOL> mName += '<STR_LIT>' % moduleItem . parameter <EOL> fName = '<STR_LIT>' % ( mName , port_spec . name ) <EOL> QParameterTreeWidgetItem ( ( fName , pList ) , <EOL> moduleItem , <EOL> label , False ) <EOL> if moduleItem : <EOL> moduleItem . setExpanded ( True ) <EOL> self . toggleUnsetParameters ( self . showUnsetParameters ) <EOL> def toggleUnsetParameters ( self , state ) : <EOL> self . showUnsetParameters = state <EOL> for item in self . findItems ( "<STR_LIT:*>" , QtCore . Qt . MatchWildcard | QtCore . Qt . MatchRecursive ) : <EOL> if not item . isSet : <EOL> item . setHidden ( not state ) <EOL> class QParameterTreeWidgetItemDelegate ( QtGui . QItemDelegate ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , view , parent ) : <EOL> """<STR_LIT>""" <EOL> QtGui . QItemDelegate . __init__ ( self , parent ) <EOL> self . treeView = view <EOL> def paint ( self , painter , option , index ) : <EOL> """<STR_LIT>""" <EOL> model = index . model ( ) <EOL> if not model . parent ( index ) . isValid ( ) : <EOL> style = self . treeView . style ( ) <EOL> r = option . rect <EOL> textrect = QtCore . QRect ( r . left ( ) + <NUM_LIT:10> , <EOL> r . top ( ) , <EOL> r . width ( ) - <NUM_LIT:10> , <EOL> r . height ( ) ) <EOL> font = painter . font ( ) <EOL> font . setBold ( True ) <EOL> painter . setFont ( font ) <EOL> text = option . fontMetrics . elidedText ( <EOL> model . data ( index , QtCore . Qt . DisplayRole ) , <EOL> QtCore . Qt . ElideMiddle , <EOL> textrect . width ( ) - <NUM_LIT:10> ) <EOL> style . drawItemText ( painter , <EOL> textrect , <EOL> QtCore . Qt . AlignLeft , <EOL> option . palette , <EOL> self . treeView . isEnabled ( ) , <EOL> text ) <EOL> painter . setPen ( QtGui . QPen ( QtCore . Qt . black ) ) <EOL> fm = QtGui . QFontMetrics ( font ) <EOL> size = fm . size ( QtCore . Qt . TextSingleLine , text ) <EOL> painter . drawLine ( textrect . left ( ) - <NUM_LIT:5> , <EOL> textrect . bottom ( ) - <NUM_LIT:1> , <EOL> textrect . left ( ) + size . width ( ) + <NUM_LIT:5> , <EOL> textrect . bottom ( ) - <NUM_LIT:1> ) <EOL> annotatedId = model . data ( index , QtCore . Qt . UserRole + <NUM_LIT:1> ) <EOL> if annotatedId : <EOL> idRect = QtCore . QRect ( <EOL> QtCore . QPoint ( textrect . left ( ) + size . width ( ) + <NUM_LIT:5> , <EOL> textrect . top ( ) ) , <EOL> textrect . bottomRight ( ) ) <EOL> QAnnotatedPipelineView . drawId ( painter , idRect , <EOL> annotatedId , <EOL> QtCore . Qt . AlignLeft | <EOL> QtCore . Qt . AlignVCenter ) <EOL> else : <EOL> QtGui . QItemDelegate . paint ( self , painter , option , index ) <EOL> def sizeHint ( self , option , index ) : <EOL> """<STR_LIT>""" <EOL> return ( QtGui . QItemDelegate . sizeHint ( self , option , index ) + <EOL> QtCore . QSize ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> class QParameterTreeWidgetItem ( QtGui . QTreeWidgetItem ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , info , parent , labelList , isSet = True ) : <EOL> """<STR_LIT>""" <EOL> self . parameter = info <EOL> QtGui . QTreeWidgetItem . __init__ ( self , parent , labelList ) <EOL> if isinstance ( self . parameter , int ) : <EOL> self . setData ( <NUM_LIT:0> , QtCore . Qt . UserRole + <NUM_LIT:1> , <EOL> self . parameter ) <EOL> self . isSet = isSet </s>
