<s> from __future__ import division <EOL> from PyQt4 import QtCore , QtGui <EOL> from PyQt4 . QtCore import pyqtSlot <EOL> from vistrails . core . data_structures . bijectivedict import Bidict <EOL> from vistrails . core import debug <EOL> from vistrails . gui . base_view import BaseView <EOL> from vistrails . gui . mashups . mashups_manager import MashupsManager <EOL> from vistrails . gui . mashups . alias_list import QAliasListPanel <EOL> from vistrails . gui . utils import show_question , YES_BUTTON , NO_BUTTON , CANCEL_BUTTON <EOL> class QMashupView ( QtGui . QMainWindow , BaseView ) : <EOL> def __init__ ( self , parent = None , f = QtCore . Qt . WindowFlags ( ) ) : <EOL> QtGui . QMainWindow . __init__ ( self , parent , f ) <EOL> BaseView . __init__ ( self ) <EOL> self . set_title ( "<STR_LIT>" ) <EOL> self . controller = None <EOL> self . mshpController = None <EOL> self . createActions ( ) <EOL> self . createToolBar ( ) <EOL> self . tab_to_stack_idx = { } <EOL> self . button_to_tab_idx = Bidict ( ) <EOL> widget = QtGui . QWidget ( self ) <EOL> layout = QtGui . QVBoxLayout ( ) <EOL> layout . setMargin ( <NUM_LIT:0> ) <EOL> layout . setSpacing ( <NUM_LIT:0> ) <EOL> self . tabBar = QtGui . QTabBar ( self ) <EOL> self . tabBar . setDocumentMode ( True ) <EOL> self . tabBar . setTabsClosable ( False ) <EOL> self . tabBar . setExpanding ( False ) <EOL> self . tabBar . currentChanged . connect ( self . switchTab ) <EOL> self . stack = QtGui . QStackedWidget ( self ) <EOL> layout . addWidget ( self . tabBar ) <EOL> layout . addWidget ( self . stack ) <EOL> widget . setLayout ( layout ) <EOL> self . setCentralWidget ( widget ) <EOL> self . createAliasPanelTab ( ) <EOL> widget . setVisible ( True ) <EOL> self . setWindowTitle ( "<STR_LIT>" ) <EOL> self . vtversion = - <NUM_LIT:1> <EOL> self . manager = MashupsManager . getInstance ( ) <EOL> def set_default_layout ( self ) : <EOL> from vistrails . gui . mashups . mashups_inspector import QMashupsInspector <EOL> from vistrails . gui . mashups . alias_parameter_view import QAliasParameterView <EOL> self . set_palette_layout ( <EOL> { QtCore . Qt . LeftDockWidgetArea : QMashupsInspector , <EOL> QtCore . Qt . RightDockWidgetArea : QAliasParameterView , <EOL> } ) <EOL> def set_action_links ( self ) : <EOL> self . action_links = { <EOL> } <EOL> def set_action_defaults ( self ) : <EOL> self . action_defaults [ '<STR_LIT>' ] = [ ( '<STR_LIT>' , False , False ) ] <EOL> def set_controller ( self , controller ) : <EOL> """<STR_LIT>""" <EOL> if controller == self . controller : <EOL> return <EOL> self . controller = controller <EOL> def versionChanged ( self , version ) : <EOL> window = self . window ( ) <EOL> self . vtversion = version <EOL> if self . vtversion > - <NUM_LIT:1> : <EOL> window . qactions [ '<STR_LIT>' ] . setEnabled ( True ) <EOL> else : <EOL> window . qactions [ '<STR_LIT>' ] . setEnabled ( False ) <EOL> def controllerChanged ( self , controller ) : <EOL> if controller is self . controller : <EOL> return <EOL> from vistrails . gui . vistrails_window import _app <EOL> self . set_controller ( controller ) <EOL> self . versionChanged ( self . controller . current_version ) <EOL> if _app . get_current_tab ( ) == self : <EOL> self . updateView ( ) <EOL> def updateView ( self ) : <EOL> from vistrails . gui . vistrails_window import _app <EOL> if self . vtversion > <NUM_LIT:0> : <EOL> if self . mshpController is not None : <EOL> try : <EOL> self . mshpController . versionChanged . disconnect ( self . mshpVersionChanged ) <EOL> self . mshpController . stateChanged . disconnect ( self . mshpStateChanged ) <EOL> if self . mshpController . vtController is not None : <EOL> self . disconnect ( self . mshpController . vtController , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . mshpControllerVistrailChanged ) <EOL> except Exception , e : <EOL> debug . unexpected_exception ( e ) <EOL> debug . print_exc ( ) <EOL> self . controller . flush_delayed_actions ( ) <EOL> self . vtversion = self . controller . current_version <EOL> self . mshpController = self . manager . createMashupController ( self . controller , <EOL> self . vtversion ) <EOL> self . mshpController . vtController . change_selected_version ( self . vtversion ) <EOL> self . connect ( self . mshpController . vtController , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . mshpControllerVistrailChanged ) <EOL> self . mshpController . versionChanged . connect ( self . mshpVersionChanged ) <EOL> self . mshpController . stateChanged . connect ( self . mshpStateChanged ) <EOL> self . aliasPanel . updateController ( self . mshpController ) <EOL> self . clearPreviewTabs ( ) <EOL> _app . notify ( '<STR_LIT>' , self . mshpController ) <EOL> def createActions ( self ) : <EOL> self . saveAction = QtGui . QAction ( "<STR_LIT>" , self , <EOL> triggered = self . saveTriggered ) <EOL> self . saveAction . setToolTip ( "<STR_LIT>" ) <EOL> self . saveAction . setEnabled ( False ) <EOL> self . previewAction = QtGui . QAction ( "<STR_LIT>" , self , <EOL> triggered = self . previewTriggered , <EOL> checkable = False ) <EOL> self . previewAction . setToolTip ( "<STR_LIT>" ) <EOL> def createToolBar ( self ) : <EOL> self . toolbar = QtGui . QToolBar ( self ) <EOL> self . toolbar . addAction ( self . previewAction ) <EOL> self . toolbar . addSeparator ( ) <EOL> self . toolbar . addAction ( self . saveAction ) <EOL> self . addToolBar ( self . toolbar ) <EOL> def createAliasPanelTab ( self ) : <EOL> self . aliasPanel = QAliasListPanel ( parent = self ) <EOL> idx = self . stack . addWidget ( self . aliasPanel ) <EOL> self . aliasPanel . set_index ( idx ) <EOL> tab_idx = self . tabBar . addTab ( "<STR_LIT>" ) <EOL> self . aliasPanel . set_tab_idx ( tab_idx ) <EOL> self . tab_to_stack_idx [ tab_idx ] = idx <EOL> def createPreviewTab ( self , version ) : <EOL> previewTab = QMashupViewTab ( self . mshpController , version ) <EOL> previewApp = self . manager . createMashupApp ( self . controller , <EOL> self . mshpController . mshptrail , <EOL> version ) <EOL> previewApp . appWasClosed . connect ( self . previewTabWasClosed ) <EOL> layout = QtGui . QVBoxLayout ( ) <EOL> layout . setMargin ( <NUM_LIT:0> ) <EOL> layout . setSpacing ( <NUM_LIT:5> ) <EOL> layout . addWidget ( previewApp ) <EOL> previewTab . setLayout ( layout ) <EOL> idx = self . stack . addWidget ( previewTab ) <EOL> previewTab . set_index ( idx ) <EOL> tab_idx = self . tabBar . addTab ( "<STR_LIT>" % self . mshpController . getMashupName ( version ) ) <EOL> previewTab . set_tab_idx ( tab_idx ) <EOL> self . tab_to_stack_idx [ tab_idx ] = idx <EOL> closeButton = QMashupViewCloseButton ( self . tabBar ) <EOL> closeSide = self . tabBar . style ( ) . styleHint ( <EOL> QtGui . QStyle . SH_TabBar_CloseButtonPosition , <EOL> None , self . tabBar ) <EOL> closeButton . clicked . connect ( self . closePreviewTab ) <EOL> self . tabBar . setTabButton ( tab_idx , closeSide , closeButton ) <EOL> self . button_to_tab_idx [ closeButton ] = tab_idx <EOL> self . tabBar . setCurrentIndex ( tab_idx ) <EOL> @ pyqtSlot ( ) <EOL> def closePreviewTab ( self ) : <EOL> closeButton = self . sender ( ) <EOL> tab_idx = self . button_to_tab_idx [ closeButton ] <EOL> self . tabBar . removeTab ( tab_idx ) <EOL> stack_idx = self . tab_to_stack_idx [ tab_idx ] <EOL> if stack_idx >= <NUM_LIT:0> : <EOL> self . stack . removeWidget ( self . stack . widget ( stack_idx ) ) <EOL> del self . button_to_tab_idx [ closeButton ] <EOL> self . updateIndexes ( tab_idx , stack_idx ) <EOL> def previewTabWasClosed ( self , previewApp ) : <EOL> previewTab = previewApp . parent ( ) <EOL> tab_idx = previewTab . get_tab_idx ( ) <EOL> stack_idx = self . tab_to_stack_idx [ tab_idx ] <EOL> if previewTab == self . stack . widget ( stack_idx ) : <EOL> closeButton = self . button_to_tab_idx . inverse [ tab_idx ] <EOL> self . tabBar . removeTab ( tab_idx ) <EOL> self . stack . removeWidget ( self . stack . widget ( stack_idx ) ) <EOL> del self . button_to_tab_idx [ closeButton ] <EOL> self . updateIndexes ( tab_idx , stack_idx ) <EOL> def updateIndexes ( self , rm_tab_idx , rm_stack_idx ) : <EOL> for ( b , tab_idx ) in self . button_to_tab_idx . iteritems ( ) : <EOL> if tab_idx > rm_tab_idx : <EOL> self . button_to_tab_idx [ b ] -= <NUM_LIT:1> <EOL> for idx in range ( self . stack . count ( ) ) : <EOL> if idx >= rm_stack_idx : <EOL> view = self . stack . widget ( idx ) <EOL> view . set_index ( idx ) <EOL> view . set_tab_idx ( view . tab_idx - <NUM_LIT:1> ) <EOL> def clearPreviewTabs ( self ) : <EOL> tab_idx = self . tabBar . count ( ) - <NUM_LIT:1> <EOL> while self . tabBar . count ( ) > <NUM_LIT:1> : <EOL> idx = self . tab_to_stack_idx [ tab_idx ] <EOL> if isinstance ( self . stack . widget ( idx ) , QMashupViewTab ) : <EOL> self . tabBar . removeTab ( tab_idx ) <EOL> if idx >= <NUM_LIT:0> : <EOL> self . stack . removeWidget ( self . stack . widget ( idx ) ) <EOL> tab_idx -= <NUM_LIT:1> <EOL> @ pyqtSlot ( int ) <EOL> def switchTab ( self , index ) : <EOL> try : <EOL> self . stack . setCurrentIndex ( self . tab_to_stack_idx [ index ] ) <EOL> except KeyError : <EOL> pass <EOL> def previewTriggered ( self ) : <EOL> self . createPreviewTab ( self . mshpController . currentVersion ) <EOL> def saveTriggered ( self ) : <EOL> ( pid , pname ) = self . mshpController . findFirstTaggedParent ( self . mshpController . currentVersion ) <EOL> if pid >= <NUM_LIT:1> : <EOL> res = show_question ( "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % pname , <EOL> [ CANCEL_BUTTON , YES_BUTTON , NO_BUTTON ] , <NUM_LIT:0> ) <EOL> if res == YES_BUTTON : <EOL> self . mshpController . moveTag ( pid , <EOL> self . mshpController . currentVersion , <EOL> pname ) <EOL> elif res == NO_BUTTON : <EOL> tag_exists = True <EOL> ok = True <EOL> while ok and tag_exists : <EOL> ( text , ok ) = QtGui . QInputDialog . getText ( self , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> text = "<STR_LIT>" ) <EOL> if ok and text : <EOL> tag = str ( text ) <EOL> if self . mshpController . updateCurrentTag ( tag ) : <EOL> tag_exists = False <EOL> def mshpControllerVistrailChanged ( self ) : <EOL> pipeline = self . mshpController . vtController . current_pipeline <EOL> self . mshpController . updateAliasesFromPipeline ( pipeline ) <EOL> def mshpVersionChanged ( self , versionId ) : <EOL> from vistrails . gui . vistrails_window import _app <EOL> self . aliasPanel . updateVersion ( versionId ) <EOL> if not self . mshpController . versionHasTag ( versionId ) : <EOL> self . saveAction . setEnabled ( True ) <EOL> else : <EOL> self . saveAction . setEnabled ( False ) <EOL> _app . notify ( '<STR_LIT>' , versionId ) <EOL> def mshpStateChanged ( self ) : <EOL> for idx in range ( self . stack . count ( ) ) : <EOL> view = self . stack . widget ( idx ) <EOL> if isinstance ( view , QMashupViewTab ) : <EOL> tab_idx = view . tab_idx <EOL> self . tabBar . setTabText ( tab_idx , <EOL> "<STR_LIT>" % self . mshpController . getMashupName ( view . version ) ) <EOL> def aliasChanged ( self , param ) : <EOL> self . mshpController . updateAliasFromParam ( param ) <EOL> class QMashupViewTab ( QtGui . QWidget , BaseView ) : <EOL> def __init__ ( self , mshpController , version , parent = None ) : <EOL> QtGui . QWidget . __init__ ( self , parent ) <EOL> BaseView . __init__ ( self ) <EOL> self . mshpController = mshpController <EOL> self . version = version <EOL> def set_default_layout ( self ) : <EOL> from vistrails . gui . mashups . mashups_inspector import QMashupsInspector <EOL> from vistrails . gui . mashups . alias_parameter_view import QAliasParameterView <EOL> self . set_palette_layout ( <EOL> { QtCore . Qt . LeftDockWidgetArea : QMashupsInspector , <EOL> QtCore . Qt . RightDockWidgetArea : QAliasParameterView , <EOL> } ) <EOL> def set_action_links ( self ) : <EOL> self . action_links = { <EOL> } <EOL> def set_action_defaults ( self ) : <EOL> self . action_defaults = { <EOL> } <EOL> class QMashupViewCloseButton ( QtGui . QAbstractButton ) : <EOL> def __init__ ( self , parent ) : <EOL> QtGui . QAbstractButton . __init__ ( self ) <EOL> self . setFocusPolicy ( QtCore . Qt . NoFocus ) <EOL> self . setCursor ( QtCore . Qt . ArrowCursor ) <EOL> self . setToolTip ( "<STR_LIT>" ) <EOL> self . resize ( self . sizeHint ( ) ) <EOL> def sizeHint ( self ) : <EOL> self . ensurePolished ( ) <EOL> width = self . style ( ) . pixelMetric ( QtGui . QStyle . PM_TabCloseIndicatorWidth , <EOL> None , self ) <EOL> height = self . style ( ) . pixelMetric ( QtGui . QStyle . PM_TabCloseIndicatorHeight , <EOL> None , self ) <EOL> return QtCore . QSize ( width , height ) <EOL> def enterEvent ( self , event ) : <EOL> if self . isEnabled ( ) : <EOL> self . update ( ) <EOL> QtGui . QAbstractButton . enterEvent ( self , event ) <EOL> def leaveEvent ( self , event ) : <EOL> if self . isEnabled ( ) : <EOL> self . update ( ) <EOL> QtGui . QAbstractButton . leaveEvent ( self , event ) <EOL> def paintEvent ( self , event ) : <EOL> p = QtGui . QPainter ( self ) <EOL> opt = QtGui . QStyleOption ( ) <EOL> opt . init ( self ) <EOL> opt . state |= QtGui . QStyle . State_AutoRaise <EOL> if ( self . isEnabled ( ) and self . underMouse ( ) and <EOL> not self . isChecked ( ) and not self . isDown ( ) ) : <EOL> opt . state |= QtGui . QStyle . State_Raised <EOL> if self . isChecked ( ) : <EOL> opt . state |= QtGui . QStyle . State_On <EOL> if self . isDown ( ) : <EOL> opt . state |= QtGui . QStyle . State_Sunken <EOL> tb = self . parent ( ) <EOL> if isinstance ( tb , QtGui . QTabBar ) : <EOL> index = tb . currentIndex ( ) <EOL> position = self . style ( ) . styleHint ( QtGui . QStyle . SH_TabBar_CloseButtonPosition , <EOL> None , tb ) <EOL> if tb . tabButton ( index , position ) == self : <EOL> opt . state |= QtGui . QStyle . State_Selected <EOL> self . style ( ) . drawPrimitive ( QtGui . QStyle . PE_IndicatorTabClose , opt , p , <EOL> self ) </s>
