<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> from PyQt4 import QtCore , QtGui <EOL> from vistrails . core . configuration import get_vistrails_configuration <EOL> from vistrails . core import debug <EOL> from vistrails . core . system import systemType <EOL> from vistrails . core . thumbnails import ThumbnailCache <EOL> from vistrails . core . vistrail . controller import custom_color_key , parse_custom_color <EOL> from vistrails . core . vistrail . vistrail import Vistrail <EOL> from vistrails . gui . base_view import BaseView <EOL> from vistrails . gui . graphics_view import ( QInteractiveGraphicsScene , <EOL> QInteractiveGraphicsView , <EOL> QGraphicsItemInterface ) <EOL> from vistrails . gui . qt import qt_super <EOL> from vistrails . gui . theme import CurrentTheme <EOL> from vistrails . gui . version_prop import QVersionPropOverlay <EOL> from vistrails . gui . collection . workspace import QParamExplorationEntityItem <EOL> import vistrails . gui . utils <EOL> class QGraphicsLinkItem ( QGraphicsItemInterface , QtGui . QGraphicsPolygonItem ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent = None , scene = None ) : <EOL> """<STR_LIT>""" <EOL> QtGui . QGraphicsPolygonItem . __init__ ( self , parent , scene ) <EOL> self . setFlags ( QtGui . QGraphicsItem . ItemIsSelectable ) <EOL> self . setZValue ( <NUM_LIT:0> ) <EOL> self . linkPen = CurrentTheme . LINK_PEN <EOL> self . ghosted = False <EOL> self . c1 = None <EOL> self . c2 = None <EOL> self . expand = None <EOL> self . collapse = None <EOL> def mousePressEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> qt_super ( QGraphicsLinkItem , self ) . mousePressEvent ( event ) <EOL> self . setSelected ( True ) <EOL> def mouseReleaseEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> qt_super ( QGraphicsLinkItem , self ) . mouseReleaseEvent ( event ) <EOL> if self . expand : <EOL> self . scene ( ) . controller . expand_versions ( self . startVersion , self . endVersion ) <EOL> elif self . collapse : <EOL> self . scene ( ) . controller . collapse_versions ( self . endVersion ) <EOL> self . setSelected ( False ) <EOL> def setGhosted ( self , ghosted ) : <EOL> """<STR_LIT>""" <EOL> if self . ghosted < > ghosted : <EOL> self . ghosted = ghosted <EOL> if ghosted : <EOL> self . linkPen = CurrentTheme . GHOSTED_LINK_PEN <EOL> else : <EOL> self . linkPen = CurrentTheme . LINK_PEN <EOL> def setupLink ( self , v1 , v2 , expand = False , collapse = False ) : <EOL> """<STR_LIT>""" <EOL> self . startVersion = min ( v1 . id , v2 . id ) <EOL> self . endVersion = max ( v1 . id , v2 . id ) <EOL> c1 = v1 . sceneBoundingRect ( ) . center ( ) <EOL> c2 = v2 . sceneBoundingRect ( ) . center ( ) <EOL> if self . c1 is not None and self . c2 is not None and self . expand is not None and self . collapse != None : <EOL> isTheSame = self . c1 == c1 and self . c2 == c2 and self . expand == expand and self . collapse == collapse <EOL> if isTheSame : <EOL> return <EOL> self . c1 = c1 <EOL> self . c2 = c2 <EOL> self . collapse = collapse <EOL> self . expand = expand <EOL> mainLine = QtCore . QLineF ( c1 , c2 ) <EOL> normalLine = mainLine . normalVector ( ) <EOL> normalLine . setLength ( CurrentTheme . LINK_SEGMENT_LENGTH ) <EOL> dis = ( mainLine . pointAt ( <NUM_LIT:0.5> ) - mainLine . p1 ( ) + <EOL> normalLine . p1 ( ) - normalLine . pointAt ( <NUM_LIT:0.5> ) ) <EOL> normalLine . translate ( dis . x ( ) , dis . y ( ) ) <EOL> if not self . collapse and not self . expand : <EOL> self . lines = [ mainLine ] <EOL> poly = QtGui . QPolygonF ( ) <EOL> poly . append ( self . lines [ <NUM_LIT:0> ] . p1 ( ) ) <EOL> poly . append ( self . lines [ <NUM_LIT:0> ] . p2 ( ) ) <EOL> poly . append ( self . lines [ <NUM_LIT:0> ] . p1 ( ) ) <EOL> self . setPolygon ( poly ) <EOL> else : <EOL> self . lines = [ ] <EOL> normalLine = mainLine . normalVector ( ) <EOL> normalLine . setLength ( CurrentTheme . LINK_SEGMENT_SQUARE_LENGTH ) <EOL> dis = ( mainLine . pointAt ( <NUM_LIT:0.5> ) - mainLine . p1 ( ) + <EOL> normalLine . p1 ( ) - normalLine . pointAt ( <NUM_LIT:0.5> ) ) <EOL> normalLine . translate ( dis . x ( ) , dis . y ( ) ) <EOL> gapLine = QtCore . QLineF ( mainLine ) <EOL> gapLine . setLength ( CurrentTheme . LINK_SEGMENT_SQUARE_LENGTH / <NUM_LIT:2> ) <EOL> gapVector = gapLine . p2 ( ) - gapLine . p1 ( ) <EOL> line = QtCore . QLineF ( mainLine ) <EOL> line . setLength ( line . length ( ) / <NUM_LIT:2> - CurrentTheme . LINK_SEGMENT_SQUARE_LENGTH / <NUM_LIT:2> ) <EOL> self . lines . append ( QtCore . QLineF ( line ) ) <EOL> line . translate ( line . p2 ( ) - line . p1 ( ) + gapVector * <NUM_LIT:2> ) <EOL> self . lines . append ( QtCore . QLineF ( line ) ) <EOL> line_t = QtCore . QLineF ( normalLine ) <EOL> line_t . translate ( gapVector * ( - <NUM_LIT:1.0> ) ) <EOL> self . lines . append ( QtCore . QLineF ( line_t ) ) <EOL> line_b = QtCore . QLineF ( normalLine ) <EOL> line_b . translate ( gapVector ) <EOL> self . lines . append ( QtCore . QLineF ( line_b ) ) <EOL> line = QtCore . QLineF ( line_t . p1 ( ) , line_b . p1 ( ) ) <EOL> self . lines . append ( QtCore . QLineF ( line ) ) <EOL> line = QtCore . QLineF ( line_t . p2 ( ) , line_b . p2 ( ) ) <EOL> self . lines . append ( QtCore . QLineF ( line ) ) <EOL> line_h = QtCore . QLineF ( normalLine . pointAt ( <NUM_LIT> ) , normalLine . pointAt ( <NUM_LIT> ) ) <EOL> self . lines . append ( QtCore . QLineF ( line_h ) ) <EOL> if self . expand : <EOL> line = QtCore . QLineF ( mainLine ) <EOL> line . translate ( ( line . p2 ( ) - line . p1 ( ) ) / <NUM_LIT:2> - gapVector ) <EOL> line . setLength ( CurrentTheme . LINK_SEGMENT_SQUARE_LENGTH ) <EOL> line_v = QtCore . QLineF ( line . pointAt ( <NUM_LIT> ) , line . pointAt ( <NUM_LIT> ) ) <EOL> self . lines . append ( QtCore . QLineF ( line_v ) ) <EOL> poly = QtGui . QPolygonF ( ) <EOL> poly . append ( self . lines [ <NUM_LIT:0> ] . p1 ( ) ) <EOL> poly . append ( self . lines [ <NUM_LIT:2> ] . p1 ( ) ) <EOL> poly . append ( self . lines [ <NUM_LIT:3> ] . p1 ( ) ) <EOL> poly . append ( self . lines [ <NUM_LIT:1> ] . p2 ( ) ) <EOL> poly . append ( self . lines [ <NUM_LIT:3> ] . p2 ( ) ) <EOL> poly . append ( self . lines [ <NUM_LIT:2> ] . p2 ( ) ) <EOL> poly . append ( self . lines [ <NUM_LIT:0> ] . p1 ( ) ) <EOL> self . setPolygon ( poly ) <EOL> self . setGhosted ( v1 . ghosted and v2 . ghosted ) <EOL> def paint ( self , painter , option , widget = None ) : <EOL> """<STR_LIT>""" <EOL> if self . isSelected ( ) : <EOL> painter . setPen ( CurrentTheme . LINK_SELECTED_PEN ) <EOL> else : <EOL> painter . setPen ( self . linkPen ) <EOL> for line in self . lines : <EOL> painter . drawLine ( line ) <EOL> def itemChange ( self , change , value ) : <EOL> """<STR_LIT>""" <EOL> if change == QtGui . QGraphicsItem . ItemSelectedChange and value : <EOL> return False <EOL> return QtGui . QGraphicsPolygonItem . itemChange ( self , change , value ) <EOL> class QGraphicsVersionTextItem ( QGraphicsItemInterface , QtGui . QGraphicsTextItem ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent = None , scene = None ) : <EOL> """<STR_LIT>""" <EOL> QtGui . QGraphicsTextItem . __init__ ( self , parent , scene ) <EOL> self . timer = None <EOL> self . isEditable = None <EOL> self . setEditable ( False ) <EOL> self . setFont ( CurrentTheme . VERSION_FONT ) <EOL> self . setTextWidth ( CurrentTheme . VERSION_LABEL_MARGIN [ <NUM_LIT:0> ] ) <EOL> self . setDefaultTextColor ( CurrentTheme . VERSION_LABEL_COLOR ) <EOL> self . centerX = <NUM_LIT:0.0> <EOL> self . centerY = <NUM_LIT:0.0> <EOL> self . label = '<STR_LIT>' <EOL> self . isTag = True <EOL> self . updatingTag = False <EOL> def setEditable ( self , editable = True ) : <EOL> if self . timer : <EOL> self . timer . stop ( ) <EOL> self . timer = None <EOL> if editable == self . isEditable : <EOL> return <EOL> self . isEditable = editable <EOL> if editable : <EOL> self . setTextInteractionFlags ( QtCore . Qt . TextEditorInteraction ) <EOL> else : <EOL> if self . textCursor ( ) : <EOL> c = self . textCursor ( ) <EOL> c . clearSelection ( ) <EOL> self . setTextCursor ( c ) <EOL> self . setTextInteractionFlags ( QtCore . Qt . NoTextInteraction ) <EOL> def setEditableLater ( self ) : <EOL> self . timer = QtCore . QTimer ( self ) <EOL> self . timer . setSingleShot ( True ) <EOL> self . connect ( self . timer , QtCore . SIGNAL ( "<STR_LIT>" ) , self . setEditable ) <EOL> self . timer . start ( QtGui . QApplication . doubleClickInterval ( ) + <NUM_LIT:5> ) <EOL> def setGhosted ( self , ghosted ) : <EOL> if ghosted : <EOL> self . setDefaultTextColor ( CurrentTheme . GHOSTED_VERSION_LABEL_COLOR ) <EOL> else : <EOL> self . setDefaultTextColor ( CurrentTheme . VERSION_LABEL_COLOR ) <EOL> def changed ( self , x , y , label , tag = True ) : <EOL> """<STR_LIT>""" <EOL> if self . centerX < > x or self . centerY < > y or self . label < > label : <EOL> self . centerX = x <EOL> self . centerY = y <EOL> self . label = label <EOL> self . isTag = tag <EOL> if self . isTag : <EOL> self . setFont ( CurrentTheme . VERSION_FONT ) <EOL> else : <EOL> self . setFont ( CurrentTheme . VERSION_DESCRIPTION_FONT ) <EOL> self . reset ( ) <EOL> def reset ( self ) : <EOL> """<STR_LIT>""" <EOL> self . setPlainText ( self . label ) <EOL> self . setEditable ( False ) <EOL> if ( len ( str ( self . label ) ) > <NUM_LIT:0> ) : <EOL> self . setTextWidth ( - <NUM_LIT:1> ) <EOL> else : <EOL> self . setTextWidth ( CurrentTheme . VERSION_LABEL_MARGIN [ <NUM_LIT:0> ] ) <EOL> if self . isTag : <EOL> self . setFont ( CurrentTheme . VERSION_FONT ) <EOL> else : <EOL> self . setFont ( CurrentTheme . VERSION_DESCRIPTION_FONT ) <EOL> self . updatePos ( ) <EOL> self . parentItem ( ) . updateWidthFromLabel ( ) <EOL> def updatePos ( self ) : <EOL> """<STR_LIT>""" <EOL> self . setPos ( self . centerX - self . boundingRect ( ) . width ( ) / <NUM_LIT> , <EOL> self . centerY - self . boundingRect ( ) . height ( ) / <NUM_LIT> ) <EOL> def keyPressEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if event . key ( ) in [ QtCore . Qt . Key_Enter , QtCore . Qt . Key_Return ] : <EOL> self . updatingTag = True <EOL> if ( self . label == str ( self . toPlainText ( ) ) or <EOL> not self . scene ( ) . controller . update_current_tag ( str ( self . toPlainText ( ) ) ) ) : <EOL> self . reset ( ) <EOL> self . updatingTag = False <EOL> event . ignore ( ) <EOL> self . clearFocus ( ) <EOL> return <EOL> qt_super ( QGraphicsVersionTextItem , self ) . keyPressEvent ( event ) <EOL> if ( len ( str ( self . toPlainText ( ) ) ) > <NUM_LIT:0> ) : <EOL> self . setTextWidth ( - <NUM_LIT:1> ) <EOL> self . updatePos ( ) <EOL> self . parentItem ( ) . updateWidthFromLabel ( ) <EOL> def focusOutEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> qt_super ( QGraphicsVersionTextItem , self ) . focusOutEvent ( event ) <EOL> if not self . updatingTag and self . label != self . toPlainText ( ) : <EOL> self . updatingTag = True <EOL> if ( self . label == str ( self . toPlainText ( ) ) or <EOL> not self . scene ( ) . controller . update_current_tag ( str ( self . toPlainText ( ) ) ) ) : <EOL> self . reset ( ) <EOL> self . updatingTag = False <EOL> class QGraphicsVersionItem ( QGraphicsItemInterface , QtGui . QGraphicsEllipseItem ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent = None , scene = None ) : <EOL> """<STR_LIT>""" <EOL> QtGui . QGraphicsEllipseItem . __init__ ( self , parent , scene ) <EOL> self . setZValue ( <NUM_LIT:1> ) <EOL> self . setAcceptDrops ( True ) <EOL> self . setFlags ( QtGui . QGraphicsItem . ItemIsSelectable ) <EOL> self . _versionPenNormal = CurrentTheme . VERSION_PEN <EOL> self . _versionPen = CurrentTheme . VERSION_PEN <EOL> self . _versionBrush = CurrentTheme . VERSION_USER_BRUSH <EOL> self . id = - <NUM_LIT:1> <EOL> self . label = '<STR_LIT>' <EOL> self . descriptionLabel = '<STR_LIT>' <EOL> self . dragging = False <EOL> self . ghosted = False <EOL> self . updatePainterState ( ) <EOL> self . rank = - <NUM_LIT:1> <EOL> self . max_rank = - <NUM_LIT:1> <EOL> self . text = QGraphicsVersionTextItem ( self ) <EOL> self . dragTimer = QtCore . QTimer ( ) <EOL> self . dragTimer . setSingleShot ( True ) <EOL> self . dragTimer . connect ( self . dragTimer , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . startDrag ) <EOL> self . dragPos = QtCore . QPoint ( ) <EOL> def _get_versionPen ( self ) : <EOL> return self . _versionPen <EOL> def _set_versionPen ( self , pen ) : <EOL> self . _versionPen = pen <EOL> self . updatePainterState ( ) <EOL> versionPen = property ( _get_versionPen , _set_versionPen ) <EOL> def _get_versionBrush ( self ) : <EOL> return self . _versionBrush <EOL> def _set_versionBrush ( self , brush ) : <EOL> self . _versionBrush = brush <EOL> self . updatePainterState ( ) <EOL> versionBrush = property ( _get_versionBrush , _set_versionBrush ) <EOL> def itemChange ( self , change , value ) : <EOL> if change == QtGui . QGraphicsItem . ItemSelectedHasChanged : <EOL> if self . isSelected ( ) : <EOL> self . versionPen = CurrentTheme . VERSION_SELECTED_PEN <EOL> self . text . setEditableLater ( ) <EOL> else : <EOL> self . versionPen = self . _versionPenNormal <EOL> self . text . setEditable ( False ) <EOL> self . updatePainterState ( ) <EOL> return QtGui . QGraphicsItem . itemChange ( self , change , value ) <EOL> def setGhosted ( self , ghosted = True ) : <EOL> """<STR_LIT>""" <EOL> if self . ghosted < > ghosted : <EOL> self . ghosted = ghosted <EOL> self . text . setGhosted ( ghosted ) <EOL> if ghosted : <EOL> self . _versionPenNormal = CurrentTheme . GHOSTED_VERSION_PEN <EOL> self . _versionBrush = CurrentTheme . GHOSTED_VERSION_USER_BRUSH <EOL> else : <EOL> self . _versionPenNormal = CurrentTheme . VERSION_PEN <EOL> self . _versionBrush = CurrentTheme . VERSION_USER_BRUSH <EOL> if not self . isSelected ( ) : <EOL> self . _versionPen = self . _versionPenNormal <EOL> self . updatePainterState ( ) <EOL> def update_color ( self , isThisUs , new_rank , new_max_rank , new_ghosted , <EOL> new_customcolor ) : <EOL> """<STR_LIT>""" <EOL> if ( new_rank == self . rank and new_max_rank == self . max_rank and <EOL> new_ghosted == self . ghosted and <EOL> new_customcolor == self . custom_color ) : <EOL> return <EOL> self . setGhosted ( new_ghosted ) <EOL> self . custom_color = new_customcolor <EOL> self . rank = new_rank <EOL> self . max_rank = new_max_rank <EOL> if not self . ghosted : <EOL> if self . custom_color is not None : <EOL> configuration = get_vistrails_configuration ( ) <EOL> sat_from_rank = not configuration . check ( <EOL> '<STR_LIT>' ) <EOL> brush = QtGui . QBrush ( QtGui . QColor . fromRgb ( * self . custom_color ) ) <EOL> else : <EOL> if isThisUs : <EOL> brush = CurrentTheme . VERSION_USER_BRUSH <EOL> else : <EOL> brush = CurrentTheme . VERSION_OTHER_BRUSH <EOL> sat_from_rank = True <EOL> if sat_from_rank : <EOL> sat = float ( new_rank + <NUM_LIT:1> ) / new_max_rank <EOL> ( h , s , v , a ) = brush . color ( ) . getHsvF ( ) <EOL> newHsv = ( h , s * sat , v + ( <NUM_LIT:1.0> - v ) * ( <NUM_LIT:1> - sat ) , a ) <EOL> brush = QtGui . QBrush ( brush ) <EOL> brush . setColor ( QtGui . QColor . fromHsvF ( * newHsv ) ) <EOL> self . versionBrush = brush <EOL> self . update ( ) <EOL> def setSaturation ( self , isThisUser , sat ) : <EOL> """<STR_LIT>""" <EOL> if not self . ghosted : <EOL> if isThisUser : <EOL> brush = CurrentTheme . VERSION_USER_BRUSH <EOL> else : <EOL> brush = CurrentTheme . VERSION_OTHER_BRUSH <EOL> ( h , s , v , a ) = brush . color ( ) . getHsvF ( ) <EOL> newHsv = ( h , s * sat , v + ( <NUM_LIT:1.0> - v ) * ( <NUM_LIT:1> - sat ) , a ) <EOL> self . versionBrush = QtGui . QBrush ( QtGui . QColor . fromHsvF ( * newHsv ) ) <EOL> def updateWidthFromLabel ( self ) : <EOL> """<STR_LIT>""" <EOL> prevWidth = self . rect ( ) . width ( ) <EOL> width = self . text . boundingRect ( ) . width ( ) + CurrentTheme . VERSION_LABEL_MARGIN [ <NUM_LIT:0> ] - <NUM_LIT:4> <EOL> r = self . rect ( ) <EOL> r . setX ( r . x ( ) + ( prevWidth - width ) / <NUM_LIT> ) <EOL> r . setWidth ( width ) <EOL> self . setRect ( r ) <EOL> self . update ( ) <EOL> def setupVersion ( self , node , action , tag , description ) : <EOL> """<STR_LIT>""" <EOL> rect = QtCore . QRectF ( node . p . x - node . width / <NUM_LIT> , <EOL> node . p . y - node . height / <NUM_LIT> , <EOL> node . width , <EOL> node . height ) <EOL> validLabel = True <EOL> if tag is None : <EOL> label = '<STR_LIT>' <EOL> validLabel = False <EOL> else : <EOL> label = tag <EOL> self . id = node . id <EOL> self . label = label <EOL> if description is None : <EOL> self . descriptionLabel = '<STR_LIT>' <EOL> else : <EOL> self . descriptionLabel = description <EOL> if validLabel : <EOL> textToDraw = self . label <EOL> else : <EOL> textToDraw = self . descriptionLabel <EOL> if ( ThumbnailCache . getInstance ( ) . conf . mouseHover and <EOL> action and action . thumbnail is not None ) : <EOL> fname = ThumbnailCache . getInstance ( ) . get_abs_name_entry ( action . thumbnail ) <EOL> self . setToolTip ( '<STR_LIT>' % fname ) <EOL> else : <EOL> self . setToolTip ( '<STR_LIT>' ) <EOL> self . text . changed ( node . p . x , node . p . y , textToDraw , validLabel ) <EOL> self . setRect ( rect ) <EOL> def boundingRect ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . rect ( ) . adjusted ( - <NUM_LIT:2> , - <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> def paint ( self , painter , option , widget = None ) : <EOL> option . state &= ~ QtGui . QStyle . State_Selected <EOL> QtGui . QGraphicsEllipseItem . paint ( self , painter , option , widget ) <EOL> def updatePainterState ( self ) : <EOL> self . setPen ( self . _versionPen ) <EOL> self . setBrush ( self . _versionBrush ) <EOL> def mousePressEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if event . button ( ) == QtCore . Qt . LeftButton : <EOL> self . dragging = True <EOL> self . dragPos = QtCore . QPoint ( event . screenPos ( ) ) <EOL> return QtGui . QGraphicsEllipseItem . mousePressEvent ( self , event ) <EOL> def mouseMoveEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if ( self . dragging and <EOL> ( event . screenPos ( ) - self . dragPos ) . manhattanLength ( ) > <NUM_LIT:2> ) : <EOL> self . dragging = False <EOL> if systemType not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> self . dragTimer . start ( <NUM_LIT:1> ) <EOL> else : <EOL> self . startDrag ( ) <EOL> QtGui . QGraphicsEllipseItem . mouseMoveEvent ( self , event ) <EOL> def startDrag ( self ) : <EOL> """<STR_LIT>""" <EOL> data = QtCore . QMimeData ( ) <EOL> data . versionId = self . id <EOL> data . controller = self . scene ( ) . controller <EOL> drag = QtGui . QDrag ( self . scene ( ) . views ( ) [ <NUM_LIT:0> ] ) <EOL> drag . setMimeData ( data ) <EOL> drag . setPixmap ( CurrentTheme . VERSION_DRAG_PIXMAP ) <EOL> drag . start ( ) <EOL> def mouseReleaseEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . dragging = False <EOL> QtGui . QGraphicsEllipseItem . mouseReleaseEvent ( self , event ) <EOL> def dragEnterEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> data = event . mimeData ( ) <EOL> if ( hasattr ( data , '<STR_LIT>' ) and <EOL> hasattr ( data , '<STR_LIT>' ) and <EOL> data . versionId != self . id ) or ( hasattr ( data , '<STR_LIT>' ) and <EOL> len ( data . items ) == <NUM_LIT:1> and <EOL> isinstance ( data . items [ <NUM_LIT:0> ] , QParamExplorationEntityItem ) ) : <EOL> event . accept ( ) <EOL> else : <EOL> event . ignore ( ) <EOL> def dropEvent ( self , event ) : <EOL> data = event . mimeData ( ) <EOL> if ( hasattr ( data , '<STR_LIT>' ) and hasattr ( data , '<STR_LIT>' ) and <EOL> data . controller == self . scene ( ) . controller ) : <EOL> event . accept ( ) <EOL> self . scene ( ) . emit ( QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> data . versionId , self . id ) <EOL> elif ( hasattr ( data , '<STR_LIT>' ) and <EOL> len ( data . items ) == <NUM_LIT:1> and <EOL> isinstance ( data . items [ <NUM_LIT:0> ] , QParamExplorationEntityItem ) ) : <EOL> from vistrails . gui . vistrails_window import _app <EOL> view = _app . get_current_view ( ) <EOL> view . apply_parameter_exploration ( self . id , data . items [ <NUM_LIT:0> ] . entity . pe ) <EOL> event . accept ( ) <EOL> else : <EOL> event . ignore ( ) <EOL> def perform_analogy ( self ) : <EOL> sender = self . scene ( ) . sender ( ) <EOL> analogy_name = str ( sender . text ( ) ) <EOL> controller = self . scene ( ) . controller <EOL> print "<STR_LIT>" , analogy_name , self . id <EOL> controller . perform_analogy ( analogy_name , self . id ) <EOL> def show_raw_pipeline ( self ) : <EOL> self . scene ( ) . emit_selection = False <EOL> for item in self . scene ( ) . selectedItems ( ) : <EOL> item . setSelected ( False ) <EOL> self . setSelected ( True ) <EOL> self . scene ( ) . emit_selection = True <EOL> self . scene ( ) . emit ( <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . id , True , False , True , True ) <EOL> def construct_from_root ( self ) : <EOL> self . scene ( ) . emit_selection = False <EOL> for item in self . scene ( ) . selectedItems ( ) : <EOL> item . setSelected ( False ) <EOL> self . setSelected ( True ) <EOL> self . scene ( ) . emit_selection = True <EOL> self . scene ( ) . emit ( <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . id , True , True , True , True ) <EOL> def contextMenuEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> controller = self . scene ( ) . controller <EOL> menu = QtGui . QMenu ( ) <EOL> raw_action = QtGui . QAction ( "<STR_LIT>" , self . scene ( ) ) <EOL> from_root_action = QtGui . QAction ( "<STR_LIT>" , self . scene ( ) ) <EOL> QtCore . QObject . connect ( raw_action , <EOL> QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> self . show_raw_pipeline ) <EOL> QtCore . QObject . connect ( from_root_action , <EOL> QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> self . construct_from_root ) <EOL> menu . addAction ( raw_action ) <EOL> menu . addAction ( from_root_action ) <EOL> if len ( controller . analogy ) > <NUM_LIT:0> : <EOL> analogies = QtGui . QMenu ( "<STR_LIT>" ) <EOL> for title in sorted ( controller . analogy . keys ( ) ) : <EOL> act = QtGui . QAction ( title , self . scene ( ) ) <EOL> analogies . addAction ( act ) <EOL> QtCore . QObject . connect ( act , <EOL> QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> self . perform_analogy ) <EOL> menu . addMenu ( analogies ) <EOL> menu . exec_ ( event . screenPos ( ) ) <EOL> def mouseDoubleClickEvent ( self , event ) : <EOL> event . accept ( ) <EOL> self . scene ( ) . double_click ( self . id ) <EOL> class QVersionTreeScene ( QInteractiveGraphicsScene ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent = None ) : <EOL> """<STR_LIT>""" <EOL> QInteractiveGraphicsScene . __init__ ( self , parent ) <EOL> self . setBackgroundBrush ( CurrentTheme . VERSION_TREE_BACKGROUND_BRUSH ) <EOL> self . setSceneRect ( QtCore . QRectF ( - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> self . versions = { } <EOL> self . edges = { } <EOL> self . controller = None <EOL> self . fullGraph = None <EOL> self . emit_selection = True <EOL> self . select_by_click = True <EOL> self . connect ( self , QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> self . selectionChanged ) <EOL> def addVersion ( self , node , action , tag , description ) : <EOL> """<STR_LIT>""" <EOL> versionShape = QGraphicsVersionItem ( None ) <EOL> versionShape . setupVersion ( node , action , tag , description ) <EOL> self . addItem ( versionShape ) <EOL> self . versions [ node . id ] = versionShape <EOL> def removeVersion ( self , v ) : <EOL> """<STR_LIT>""" <EOL> versionShape = self . versions [ v ] <EOL> self . removeItem ( versionShape ) <EOL> self . versions . pop ( v ) <EOL> def addLink ( self , guiSource , guiTarget , expand , collapse ) : <EOL> """<STR_LIT>""" <EOL> linkShape = QGraphicsLinkItem ( ) <EOL> linkShape . setupLink ( guiSource , guiTarget , expand , collapse ) <EOL> self . addItem ( linkShape ) <EOL> self . edges [ ( guiSource . id , guiTarget . id ) ] = linkShape <EOL> def removeLink ( self , source , target ) : <EOL> """<STR_LIT>""" <EOL> linkShape = self . edges [ ( source , target ) ] <EOL> self . removeItem ( linkShape ) <EOL> self . edges . pop ( ( source , target ) ) <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> self . versions = { } <EOL> self . clearItems ( ) <EOL> def adjust_version_colors ( self , controller ) : <EOL> """<STR_LIT>""" <EOL> currentUser = controller . vistrail . getUser ( ) <EOL> ranks = { } <EOL> ourMaxRank = <NUM_LIT:0> <EOL> otherMaxRank = <NUM_LIT:0> <EOL> am = controller . vistrail . actionMap <EOL> for nodeId in sorted ( self . versions . keys ( ) ) : <EOL> if nodeId != <NUM_LIT:0> : <EOL> nodeUser = am [ nodeId ] . user <EOL> if nodeUser == currentUser : <EOL> ranks [ nodeId ] = ourMaxRank <EOL> ourMaxRank += <NUM_LIT:1> <EOL> else : <EOL> ranks [ nodeId ] = otherMaxRank <EOL> otherMaxRank += <NUM_LIT:1> <EOL> for ( nodeId , item ) in self . versions . iteritems ( ) : <EOL> if nodeId == <NUM_LIT:0> : <EOL> item . setGhosted ( True ) <EOL> continue <EOL> nodeUser = am [ nodeId ] . user <EOL> if controller . search and nodeId != <NUM_LIT:0> : <EOL> action = am [ nodeId ] <EOL> if getattr ( get_vistrails_configuration ( ) , '<STR_LIT>' , <EOL> True ) : <EOL> action = am [ controller . vistrail . get_upgrade ( nodeId , False ) ] <EOL> ghosted = not controller . search . match ( controller , action ) <EOL> else : <EOL> ghosted = False <EOL> if nodeUser == currentUser : <EOL> max_rank = ourMaxRank <EOL> else : <EOL> max_rank = otherMaxRank <EOL> configuration = get_vistrails_configuration ( ) <EOL> if configuration . check ( '<STR_LIT>' ) : <EOL> custom_color = controller . vistrail . get_action_annotation ( <EOL> nodeId , <EOL> custom_color_key ) <EOL> if custom_color is not None : <EOL> try : <EOL> custom_color = parse_custom_color ( custom_color . value ) <EOL> except ValueError , e : <EOL> debug . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( nodeId , e ) ) <EOL> custom_color = None <EOL> else : <EOL> custom_color = None <EOL> item . update_color ( nodeUser == currentUser , <EOL> ranks [ nodeId ] , <EOL> max_rank , ghosted , custom_color ) <EOL> for ( version_from , version_to ) , link in self . edges . iteritems ( ) : <EOL> if self . versions [ version_from ] . ghosted and self . versions [ version_to ] . ghosted : <EOL> link . setGhosted ( True ) <EOL> else : <EOL> link . setGhosted ( False ) <EOL> def update_scene_single_node_change ( self , controller , old_version , new_version ) : <EOL> """<STR_LIT>""" <EOL> self . adjust_version_colors ( controller ) <EOL> v = self . versions [ old_version ] <EOL> old_desc = controller . vistrail . get_description ( old_version ) <EOL> new_desc = controller . vistrail . get_description ( new_version ) <EOL> if old_desc != new_desc : <EOL> v . descriptionLabel = new_desc <EOL> v . text . changed ( v . text . centerX , v . text . centerY , new_desc , False ) <EOL> v . updateWidthFromLabel ( ) <EOL> self . versions [ new_version ] = v <EOL> del self . versions [ old_version ] <EOL> v . id = new_version <EOL> dst = controller . _current_terse_graph . edges_from ( new_version ) <EOL> for eto , ( expand , collapse ) in dst : <EOL> edge = self . edges [ ( old_version , eto ) ] <EOL> edge . setupLink ( self . versions [ new_version ] , <EOL> self . versions [ eto ] , <EOL> expand , <EOL> False ) <EOL> self . edges [ ( new_version , eto ) ] = edge <EOL> del self . edges [ ( old_version , eto ) ] <EOL> src = controller . _current_terse_graph . edges_to ( new_version ) <EOL> for efrom , ( expand , collapse ) in src : <EOL> edge = self . edges [ ( efrom , old_version ) ] <EOL> edge . setupLink ( self . versions [ efrom ] , <EOL> self . versions [ new_version ] , <EOL> expand , <EOL> False ) <EOL> self . edges [ ( efrom , new_version ) ] = edge <EOL> del self . edges [ ( efrom , old_version ) ] <EOL> def setupScene ( self , controller , select_node = True ) : <EOL> """<STR_LIT>""" <EOL> self . select_by_click = False <EOL> self . controller = controller <EOL> ( tree , self . fullGraph , layout ) = controller . refine_graph ( ) <EOL> removeNodeSet = set ( i for i in self . versions <EOL> if not i in tree . vertices ) <EOL> removeEdgeSet = set ( ( s , t ) for ( s , t ) in self . edges <EOL> if ( s in removeNodeSet or <EOL> t in removeNodeSet or <EOL> not tree . has_edge ( s , t ) ) ) <EOL> vistrail = controller . vistrail <EOL> am = vistrail . actionMap <EOL> last_n = vistrail . getLastActions ( controller . num_versions_always_shown ) <EOL> self . emit_selection = False <EOL> for node in layout . nodes . itervalues ( ) : <EOL> v = node . id <EOL> tag = tree . vertices . get ( v , None ) <EOL> action = am . get ( v , None ) <EOL> description = vistrail . get_description ( v ) <EOL> if v in self . versions : <EOL> versionShape = self . versions [ v ] <EOL> versionShape . setupVersion ( node , action , tag , description ) <EOL> else : <EOL> self . addVersion ( node , action , tag , description ) <EOL> if select_node : <EOL> self . versions [ v ] . setSelected ( v == controller . current_base_version ) <EOL> self . emit_selection = True <EOL> self . selectionChanged ( ) <EOL> for ( v1 , v2 ) in removeEdgeSet : <EOL> self . removeLink ( v1 , v2 ) <EOL> for v in removeNodeSet : <EOL> self . removeVersion ( v ) <EOL> self . adjust_version_colors ( controller ) <EOL> for source , source_tag in tree . vertices . iteritems ( ) : <EOL> eFrom = tree . edges_from ( source ) <EOL> for target , ( expand , collapse ) in eFrom : <EOL> guiSource = self . versions [ source ] <EOL> guiTarget = self . versions [ target ] <EOL> if self . edges . has_key ( ( source , target ) ) : <EOL> linkShape = self . edges [ ( source , target ) ] <EOL> linkShape . setupLink ( guiSource , guiTarget , <EOL> expand , collapse ) <EOL> else : <EOL> self . addLink ( guiSource , guiTarget , <EOL> expand , collapse ) <EOL> self . updateSceneBoundingRect ( ) <EOL> self . select_by_click = True <EOL> def keyPressEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> selectedItems = self . selectedItems ( ) <EOL> versions = [ item . id for item in selectedItems <EOL> if isinstance ( item , QGraphicsVersionItem ) <EOL> and not item . text . hasFocus ( ) ] <EOL> if ( self . controller and len ( versions ) > <NUM_LIT:0> and <EOL> event . key ( ) in [ QtCore . Qt . Key_Backspace , QtCore . Qt . Key_Delete ] ) : <EOL> event . accept ( ) <EOL> versions = [ item . id for item in selectedItems ] <EOL> res = vistrails . gui . utils . show_question ( "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> [ vistrails . gui . utils . YES_BUTTON , <EOL> vistrails . gui . utils . NO_BUTTON ] , <EOL> vistrails . gui . utils . NO_BUTTON ) <EOL> if res == vistrails . gui . utils . YES_BUTTON : <EOL> self . controller . prune_versions ( versions ) <EOL> else : <EOL> qt_super ( QVersionTreeScene , self ) . keyPressEvent ( event ) <EOL> def selectionChanged ( self ) : <EOL> if not self . emit_selection : <EOL> return <EOL> selected_items = self . selectedItems ( ) <EOL> if len ( selected_items ) == <NUM_LIT:1> : <EOL> self . emit ( QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> selected_items [ <NUM_LIT:0> ] . id , self . select_by_click , <EOL> True , False , False ) <EOL> else : <EOL> for item in selected_items : <EOL> if item . text . isEditable : <EOL> item . text . setEditable ( False ) <EOL> self . emit ( QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> - <NUM_LIT:1> , self . select_by_click , True , False , False ) <EOL> if len ( selected_items ) == <NUM_LIT:2> : <EOL> self . emit ( <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> selected_items [ <NUM_LIT:0> ] . id , selected_items [ <NUM_LIT:1> ] . id ) <EOL> def double_click ( self , version_id ) : <EOL> self . mouseGrabberItem ( ) . ungrabMouse ( ) <EOL> self . emit ( QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> version_id , self . select_by_click , True , False , True ) <EOL> class QVersionTreeView ( QInteractiveGraphicsView , BaseView ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent = None ) : <EOL> """<STR_LIT>""" <EOL> QInteractiveGraphicsView . __init__ ( self , parent ) <EOL> BaseView . __init__ ( self ) <EOL> self . controller = None <EOL> self . set_title ( '<STR_LIT>' ) <EOL> self . setScene ( QVersionTreeScene ( self ) ) <EOL> self . versionProp = QVersionPropOverlay ( self , self . viewport ( ) ) <EOL> self . versionProp . hide ( ) <EOL> self . _view_fitted = False <EOL> def set_default_layout ( self ) : <EOL> from vistrails . gui . collection . workspace import QWorkspaceWindow <EOL> from vistrails . gui . version_prop import QVersionProp <EOL> self . set_palette_layout ( <EOL> { QtCore . Qt . LeftDockWidgetArea : QWorkspaceWindow , <EOL> QtCore . Qt . RightDockWidgetArea : QVersionProp , <EOL> } ) <EOL> def set_action_links ( self ) : <EOL> self . action_links = { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , self . check_publish_db ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , self . check_publish ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , self . can_redo ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , self . can_undo ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , self . can_execute ) <EOL> } <EOL> def set_action_defaults ( self ) : <EOL> self . action_defaults [ '<STR_LIT>' ] = [ ( '<STR_LIT>' , True , self . set_action_execute_default ) ] <EOL> def set_action_execute_default ( self ) : <EOL> if self . controller : <EOL> if self . controller . current_pipeline : <EOL> return len ( self . controller . current_pipeline . modules ) > <NUM_LIT:0> <EOL> return False <EOL> def check_publish_db ( self , versionId ) : <EOL> loc = self . controller . locator <EOL> result = False <EOL> if hasattr ( loc , '<STR_LIT:host>' ) : <EOL> result = True <EOL> return result and self . check_publish ( versionId ) <EOL> def check_publish ( self , versionId ) : <EOL> return versionId > <NUM_LIT:0> <EOL> def can_redo ( self , versionId ) : <EOL> return self . controller and self . controller . can_redo ( ) <EOL> def can_undo ( self , versionId ) : <EOL> return self . controller and self . controller . can_undo ( ) <EOL> def can_execute ( self , pipeline ) : <EOL> return pipeline is not None and len ( pipeline . modules ) > <NUM_LIT:0> <EOL> def execute ( self ) : <EOL> res = self . controller . execute_user_workflow ( ) <EOL> from vistrails . gui . vistrails_window import _app <EOL> if len ( res [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] . errors ) > <NUM_LIT:0> : <EOL> _app . qactions [ '<STR_LIT>' ] . trigger ( ) <EOL> _app . notify ( '<STR_LIT>' ) <EOL> def publish_to_web ( self ) : <EOL> from vistrails . gui . publishing import QVersionEmbed <EOL> panel = QVersionEmbed . instance ( ) <EOL> panel . switchType ( '<STR_LIT>' ) <EOL> panel . set_visible ( True ) <EOL> def publish_to_paper ( self ) : <EOL> from vistrails . gui . publishing import QVersionEmbed <EOL> panel = QVersionEmbed . instance ( ) <EOL> panel . switchType ( '<STR_LIT>' ) <EOL> panel . set_visible ( True ) <EOL> def selectModules ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . canSelectRectangle : <EOL> br = self . selectionBox . sceneBoundingRect ( ) <EOL> else : <EOL> br = QtCore . QRectF ( self . startSelectingPos , <EOL> self . startSelectingPos ) <EOL> items = self . scene ( ) . items ( br ) <EOL> if len ( items ) == <NUM_LIT:0> or items == [ self . selectionBox ] : <EOL> for item in self . scene ( ) . selectedItems ( ) : <EOL> if isinstance ( item , QGraphicsVersionItem ) : <EOL> item . text . clearFocus ( ) <EOL> qt_super ( QVersionTreeView , self ) . selectModules ( ) <EOL> def set_title ( self , title ) : <EOL> BaseView . set_title ( self , title ) <EOL> self . setWindowTitle ( title ) <EOL> def set_controller ( self , controller ) : <EOL> self . _view_fitted = False <EOL> oldController = self . controller <EOL> if oldController != controller : <EOL> if oldController is not None : <EOL> self . disconnect ( oldController , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . vistrailChanged ) <EOL> self . disconnect ( oldController , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . single_node_changed ) <EOL> self . disconnect ( oldController , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . notesChanged ) <EOL> self . controller = controller <EOL> self . scene ( ) . controller = controller <EOL> self . connect ( controller , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . vistrailChanged ) <EOL> self . connect ( controller , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . single_node_changed ) <EOL> self . connect ( controller , <EOL> QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> self . notesChanged ) <EOL> if controller : <EOL> self . versionProp . updateController ( controller ) <EOL> self . scene ( ) . setupScene ( controller ) <EOL> def vistrailChanged ( self ) : <EOL> """<STR_LIT>""" <EOL> from vistrails . gui . vistrails_window import _app <EOL> select_node = True <EOL> if _app . _previous_view and _app . _previous_view . window ( ) != self . window ( ) : <EOL> select_node = False <EOL> self . scene ( ) . setupScene ( self . controller , select_node ) <EOL> if self . controller and self . controller . reset_version_view : <EOL> self . scene ( ) . fitToAllViews ( ) <EOL> if self . controller : <EOL> self . versionProp . updateVersion ( self . controller . current_version ) <EOL> self . emit ( QtCore . SIGNAL ( "<STR_LIT>" ) ) <EOL> def single_node_changed ( self , old_version , new_version ) : <EOL> """<STR_LIT>""" <EOL> self . scene ( ) . update_scene_single_node_change ( self . controller , <EOL> old_version , <EOL> new_version ) <EOL> if self . controller and self . controller . reset_version_view : <EOL> self . scene ( ) . fitToAllViews ( ) <EOL> if self . controller : <EOL> self . versionProp . updateVersion ( self . controller . current_version ) <EOL> self . emit ( QtCore . SIGNAL ( "<STR_LIT>" ) ) <EOL> def notesChanged ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . controller : <EOL> self . versionProp . updateVersion ( self . controller . current_version ) <EOL> def select_current_version ( self ) : <EOL> self . scene ( ) . setupScene ( self . controller ) <EOL> def viewSelected ( self ) : <EOL> if not self . _view_fitted and self . isVisible ( ) : <EOL> self . zoomToFit ( ) <EOL> self . _view_fitted = True </s>
