<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> from ast import literal_eval <EOL> import copy <EOL> import gc <EOL> import os . path <EOL> from PyQt4 import QtCore , QtGui <EOL> from vistrails . core . db . locator import FileLocator , _DBLocator as DBLocator <EOL> from vistrails . core . interpreter . default import get_default_interpreter <EOL> from vistrails . core . utils import DummyView <EOL> from vistrails . core . utils . uxml import XMLWrapper , named_elements <EOL> from vistrails . db . services . io import SaveBundle <EOL> from vistrails . gui . theme import CurrentTheme <EOL> from vistrails . gui . utils import show_warning <EOL> from . spreadsheet_registry import spreadsheetRegistry <EOL> from . spreadsheet_tab import StandardWidgetTabBar , StandardWidgetSheetTab , StandardTabDockWidget <EOL> class StandardWidgetTabController ( QtGui . QTabWidget ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent = None ) : <EOL> """<STR_LIT>""" <EOL> QtGui . QTabWidget . __init__ ( self , parent ) <EOL> self . operatingWidget = self <EOL> self . setTabBar ( StandardWidgetTabBar ( self ) ) <EOL> self . setTabShape ( QtGui . QTabWidget . Triangular ) <EOL> self . setTabPosition ( QtGui . QTabWidget . South ) <EOL> self . tabWidgets = [ ] <EOL> self . floatingTabWidgets = [ ] <EOL> self . addTabWidget ( StandardWidgetSheetTab ( self ) , '<STR_LIT>' ) <EOL> self . connect ( self . tabBar ( ) , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . moveTab ) <EOL> self . connect ( self . tabBar ( ) , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . splitTab ) <EOL> self . connect ( self . tabBar ( ) , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . changeTabText ) <EOL> self . addAction ( self . showNextTabAction ( ) ) <EOL> self . addAction ( self . showPrevTabAction ( ) ) <EOL> self . executedPipelines = [ [ ] , { } , { } ] <EOL> self . monitoredPipelines = { } <EOL> self . spreadsheetFileName = None <EOL> self . loadingMode = False <EOL> self . editingMode = False <EOL> self . closeButton = QtGui . QToolButton ( self ) <EOL> self . closeButton . setIcon ( CurrentTheme . VIEW_MANAGER_CLOSE_ICON ) <EOL> self . closeButton . setAutoRaise ( True ) <EOL> self . setCornerWidget ( self . closeButton ) <EOL> self . connect ( self . closeButton , QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . deleteSheetAction ( ) . trigger ) <EOL> def isLoadingMode ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . loadingMode <EOL> def getMonitoredLocations ( self , spec ) : <EOL> """<STR_LIT>""" <EOL> key = ( ( spec [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , spec [ <NUM_LIT:0> ] [ '<STR_LIT:version>' ] ) , spec [ <NUM_LIT:1> ] , spec [ <NUM_LIT:2> ] ) <EOL> return self . monitoredPipelines . get ( key , [ ] ) <EOL> def appendMonitoredLocations ( self , spec , value ) : <EOL> """<STR_LIT>""" <EOL> key = ( ( spec [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , spec [ <NUM_LIT:0> ] [ '<STR_LIT:version>' ] ) , spec [ <NUM_LIT:1> ] , spec [ <NUM_LIT:2> ] ) <EOL> if key in self . monitoredPipelines : <EOL> self . monitoredPipelines [ key ] . append ( value ) <EOL> else : <EOL> self . monitoredPipelines [ key ] = [ value ] <EOL> def newSheetAction ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> icon = QtGui . QIcon ( '<STR_LIT>' ) <EOL> self . newSheetActionVar = QtGui . QAction ( icon , '<STR_LIT>' , self ) <EOL> self . newSheetActionVar . setToolTip ( '<STR_LIT>' ) <EOL> self . newSheetActionVar . setStatusTip ( '<STR_LIT>' ) <EOL> self . newSheetActionVar . setShortcut ( QtGui . QKeySequence ( '<STR_LIT>' ) ) <EOL> self . connect ( self . newSheetActionVar , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . newSheetActionTriggered ) <EOL> return self . newSheetActionVar <EOL> def deleteSheetAction ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> icon = QtGui . QIcon ( '<STR_LIT>' ) <EOL> self . deleteSheetActionVar = QtGui . QAction ( icon , '<STR_LIT>' , <EOL> self ) <EOL> self . deleteSheetActionVar . setToolTip ( '<STR_LIT>' ) <EOL> self . deleteSheetActionVar . setStatusTip ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> key = QtGui . QKeySequence ( '<STR_LIT>' ) <EOL> self . deleteSheetActionVar . setShortcut ( key ) <EOL> self . connect ( self . deleteSheetActionVar , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . deleteSheetActionTriggered ) <EOL> return self . deleteSheetActionVar <EOL> def showNextTabAction ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> icon = QtGui . QIcon ( '<STR_LIT>' ) <EOL> self . showNextTabActionVar = QtGui . QAction ( icon , '<STR_LIT>' , self ) <EOL> self . showNextTabActionVar . setToolTip ( '<STR_LIT>' ) <EOL> self . showNextTabActionVar . setStatusTip ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . showNextTabActionShortcut = QtGui . QShortcut ( self ) <EOL> self . showNextTabActionVar . setShortcut ( '<STR_LIT>' ) <EOL> self . connect ( self . showNextTabActionVar , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . showNextTab ) <EOL> return self . showNextTabActionVar <EOL> def showPrevTabAction ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> icon = QtGui . QIcon ( '<STR_LIT>' ) <EOL> self . showPrevTabActionVar = QtGui . QAction ( icon , '<STR_LIT>' , self ) <EOL> self . showPrevTabActionVar . setToolTip ( '<STR_LIT>' ) <EOL> self . showPrevTabActionVar . setStatusTip ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . showPrevTabActionVar . setShortcut ( '<STR_LIT>' ) <EOL> self . connect ( self . showPrevTabActionVar , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . showPrevTab ) <EOL> return self . showPrevTabActionVar <EOL> def saveAction ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . saveActionVar = QtGui . QAction ( QtGui . QIcon ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' , self ) <EOL> self . saveActionVar . setStatusTip ( '<STR_LIT>' ) <EOL> self . saveActionVar . setShortcut ( '<STR_LIT>' ) <EOL> self . connect ( self . saveActionVar , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . saveSpreadsheet ) <EOL> return self . saveActionVar <EOL> def saveAsAction ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> icon = QtGui . QIcon ( '<STR_LIT>' ) <EOL> self . saveAsActionVar = QtGui . QAction ( icon , '<STR_LIT>' , self ) <EOL> self . saveAsActionVar . setStatusTip ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . connect ( self . saveAsActionVar , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . saveSpreadsheetAs ) <EOL> return self . saveAsActionVar <EOL> def openAction ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . openActionVar = QtGui . QAction ( QtGui . QIcon ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' , self ) <EOL> self . openActionVar . setStatusTip ( '<STR_LIT>' ) <EOL> self . openActionVar . setShortcut ( '<STR_LIT>' ) <EOL> self . connect ( self . openActionVar , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . openSpreadsheetAs ) <EOL> return self . openActionVar <EOL> def exportSheetToImageAction ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . exportSheetToImageVar = QtGui . QAction ( '<STR_LIT>' , self ) <EOL> self . exportSheetToImageVar . setStatusTip ( <EOL> '<STR_LIT>' ) <EOL> exportMenu = QtGui . QMenu ( self ) <EOL> singleAction = exportMenu . addAction ( '<STR_LIT>' ) <EOL> multiAction = exportMenu . addAction ( '<STR_LIT>' ) <EOL> self . exportSheetToImageVar . setMenu ( exportMenu ) <EOL> self . connect ( self . exportSheetToImageVar , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . exportSheetToSingleImageActionTriggered ) <EOL> self . connect ( singleAction , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . exportSheetToSingleImageActionTriggered ) <EOL> self . connect ( multiAction , <EOL> QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . exportSheetToSeparateImagesActionTriggered ) <EOL> return self . exportSheetToImageVar <EOL> def exportSheetToSingleImageActionTriggered ( self , action = None ) : <EOL> """<STR_LIT>""" <EOL> filename = QtGui . QFileDialog . getSaveFileName ( <EOL> self , "<STR_LIT>" , <EOL> "<STR_LIT:.>" , "<STR_LIT>" ) <EOL> if filename : <EOL> self . currentWidget ( ) . exportSheetToImage ( filename ) <EOL> def exportSheetToSeparateImagesActionTriggered ( self , action = None ) : <EOL> """<STR_LIT>""" <EOL> dirname = QtGui . QFileDialog . getExistingDirectory ( <EOL> self , '<STR_LIT>' , "<STR_LIT:.>" , <EOL> QtGui . QFileDialog . ShowDirsOnly ) <EOL> if dirname : <EOL> self . currentWidget ( ) . exportSheetToImages ( dirname ) <EOL> def newSheetActionTriggered ( self , checked = False ) : <EOL> """<STR_LIT>""" <EOL> self . setCurrentIndex ( self . addTabWidget ( StandardWidgetSheetTab ( self ) , <EOL> '<STR_LIT>' % ( self . count ( ) + <NUM_LIT:1> ) ) ) <EOL> self . currentWidget ( ) . sheet . stretchCells ( ) <EOL> def tabInserted ( self , index ) : <EOL> """<STR_LIT>""" <EOL> self . deleteSheetAction ( ) . setEnabled ( True ) <EOL> self . saveAction ( ) . setEnabled ( True ) <EOL> self . saveAsAction ( ) . setEnabled ( True ) <EOL> def tabRemoved ( self , index ) : <EOL> """<STR_LIT>""" <EOL> if self . count ( ) == <NUM_LIT:0> : <EOL> self . deleteSheetAction ( ) . setEnabled ( False ) <EOL> self . saveAction ( ) . setEnabled ( False ) <EOL> self . saveAsAction ( ) . setEnabled ( False ) <EOL> def removeSheetReference ( self , sheet ) : <EOL> """<STR_LIT>""" <EOL> for ( code , locations ) in self . monitoredPipelines . iteritems ( ) : <EOL> for lid in reversed ( xrange ( len ( locations ) ) ) : <EOL> if sheet == locations [ lid ] [ <NUM_LIT:0> ] : <EOL> del locations [ lid ] <EOL> def deleteSheetActionTriggered ( self , checked = False ) : <EOL> """<STR_LIT>""" <EOL> if self . count ( ) > <NUM_LIT:0> : <EOL> widget = self . currentWidget ( ) <EOL> self . tabWidgets . remove ( widget ) <EOL> self . removeTab ( self . currentIndex ( ) ) <EOL> self . removeSheetReference ( widget ) <EOL> widget . deleteAllCells ( ) <EOL> widget . deleteLater ( ) <EOL> QtCore . QCoreApplication . processEvents ( ) <EOL> gc . collect ( ) <EOL> def clearTabs ( self ) : <EOL> """<STR_LIT>""" <EOL> self . executedPipelines = [ [ ] , { } , { } ] <EOL> while self . count ( ) > <NUM_LIT:0> : <EOL> self . deleteSheetActionTriggered ( ) <EOL> for i in reversed ( range ( len ( self . tabWidgets ) ) ) : <EOL> t = self . tabWidgets [ i ] <EOL> del self . tabWidgets [ i ] <EOL> self . removeSheetReference ( t ) <EOL> t . deleteAllCells ( ) <EOL> t . deleteLater ( ) <EOL> def insertTab ( self , idx , tabWidget , tabText ) : <EOL> """<STR_LIT>""" <EOL> if self . operatingWidget != self : <EOL> ret = self . operatingWidget . insertWidget ( idx , tabWidget ) <EOL> self . operatingWidget . setCurrentIndex ( ret ) <EOL> return ret <EOL> else : <EOL> return QtGui . QTabWidget . insertTab ( self , idx , tabWidget , tabText ) <EOL> def findSheet ( self , sheetReference ) : <EOL> """<STR_LIT>""" <EOL> if not sheetReference : <EOL> return None <EOL> sheetReference . clearCandidate ( ) <EOL> for idx in xrange ( len ( self . tabWidgets ) ) : <EOL> tabWidget = self . tabWidgets [ idx ] <EOL> tabLabel = tabWidget . windowTitle ( ) <EOL> sheetReference . checkCandidate ( tabWidget , tabLabel , idx , <EOL> self . operatingWidget . currentIndex ( ) ) <EOL> return sheetReference . setupCandidate ( self ) <EOL> def changeTabText ( self , tabIdx , newTabText ) : <EOL> """<STR_LIT>""" <EOL> self . operatingWidget . widget ( tabIdx ) . setWindowTitle ( newTabText ) <EOL> def moveTab ( self , tabIdx , destination ) : <EOL> """<STR_LIT>""" <EOL> if ( tabIdx < <NUM_LIT:0> or tabIdx > self . count ( ) or <EOL> destination < <NUM_LIT:0> or destination > self . count ( ) ) : <EOL> return <EOL> tabText = self . tabText ( tabIdx ) <EOL> tabWidget = self . widget ( tabIdx ) <EOL> self . removeTab ( tabIdx ) <EOL> self . insertTab ( destination , tabWidget , tabText ) <EOL> if tabIdx == self . currentIndex ( ) : <EOL> self . setCurrentIndex ( destination ) <EOL> def splitTab ( self , tabIdx , pos = None ) : <EOL> """<STR_LIT>""" <EOL> if tabIdx < <NUM_LIT:0> or tabIdx > self . count ( ) or self . count ( ) == <NUM_LIT:0> : <EOL> return <EOL> tabWidget = self . widget ( tabIdx ) <EOL> self . removeTab ( tabIdx ) <EOL> frame = StandardTabDockWidget ( tabWidget . windowTitle ( ) , tabWidget , <EOL> self . tabBar ( ) , self ) <EOL> if pos : <EOL> frame . move ( pos ) <EOL> frame . show ( ) <EOL> self . floatingTabWidgets . append ( frame ) <EOL> def mergeTab ( self , frame , tabIdx ) : <EOL> """<STR_LIT>""" <EOL> if tabIdx < <NUM_LIT:0> or tabIdx > self . count ( ) : <EOL> return <EOL> if tabIdx == self . count ( ) : tabIdx = - <NUM_LIT:1> <EOL> tabWidget = frame . widget ( ) <EOL> frame . setWidget ( None ) <EOL> while frame in self . floatingTabWidgets : <EOL> self . floatingTabWidgets . remove ( frame ) <EOL> frame . deleteLater ( ) <EOL> tabWidget . setParent ( None ) <EOL> newIdx = self . insertTab ( tabIdx , tabWidget , tabWidget . windowTitle ( ) ) <EOL> self . setCurrentIndex ( newIdx ) <EOL> def addTabWidget ( self , tabWidget , sheetLabel ) : <EOL> """<STR_LIT>""" <EOL> return self . insertTabWidget ( - <NUM_LIT:1> , tabWidget , sheetLabel ) <EOL> def insertTabWidget ( self , index , tabWidget , sheetLabel ) : <EOL> """<STR_LIT>""" <EOL> if sheetLabel == None : <EOL> sheetLabel = '<STR_LIT>' % ( len ( self . tabWidgets ) + <NUM_LIT:1> ) <EOL> if not tabWidget in self . tabWidgets : <EOL> self . tabWidgets . append ( tabWidget ) <EOL> tabWidget . setWindowTitle ( sheetLabel ) <EOL> return self . insertTab ( index , tabWidget , sheetLabel ) <EOL> def tabWidgetUnderMouse ( self ) : <EOL> """<STR_LIT>""" <EOL> result = None <EOL> for t in self . tabWidgets : <EOL> if t . underMouse ( ) : <EOL> result = t <EOL> else : <EOL> t . showHelpers ( False , QtCore . QPoint ( - <NUM_LIT:1> , - <NUM_LIT:1> ) ) <EOL> return result <EOL> def setupFullScreenWidget ( self , fs , stackedWidget ) : <EOL> """<STR_LIT>""" <EOL> if fs : <EOL> idx = self . currentIndex ( ) <EOL> for i in xrange ( self . count ( ) ) : <EOL> widget = self . widget ( <NUM_LIT:0> ) <EOL> self . removeTab ( <NUM_LIT:0> ) <EOL> self . tabTrueParent = widget . parent ( ) <EOL> widget . setParent ( stackedWidget ) <EOL> stackedWidget . addWidget ( widget ) <EOL> stackedWidget . setCurrentIndex ( idx ) <EOL> self . operatingWidget = stackedWidget <EOL> else : <EOL> idx = stackedWidget . currentIndex ( ) <EOL> for i in xrange ( stackedWidget . count ( ) ) : <EOL> widget = stackedWidget . widget ( <NUM_LIT:0> ) <EOL> stackedWidget . removeWidget ( widget ) <EOL> widget . setParent ( self . tabTrueParent ) <EOL> self . addTab ( widget , widget . windowTitle ( ) ) <EOL> self . setCurrentIndex ( idx ) <EOL> self . operatingWidget = self <EOL> def showNextTab ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . operatingWidget . currentIndex ( ) < self . operatingWidget . count ( ) - <NUM_LIT:1> : <EOL> index = self . operatingWidget . currentIndex ( ) + <NUM_LIT:1> <EOL> self . operatingWidget . setCurrentIndex ( index ) <EOL> def showPrevTab ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . operatingWidget . currentIndex ( ) > <NUM_LIT:0> : <EOL> index = self . operatingWidget . currentIndex ( ) - <NUM_LIT:1> <EOL> self . operatingWidget . setCurrentIndex ( index ) <EOL> def tabPopupMenu ( self ) : <EOL> """<STR_LIT>""" <EOL> menu = QtGui . QMenu ( self ) <EOL> en = self . operatingWidget . currentIndex ( ) < self . operatingWidget . count ( ) - <NUM_LIT:1> <EOL> self . showNextTabAction ( ) . setEnabled ( en ) <EOL> menu . addAction ( self . showNextTabAction ( ) ) <EOL> en = self . operatingWidget . currentIndex ( ) > <NUM_LIT:0> <EOL> self . showPrevTabAction ( ) . setEnabled ( en ) <EOL> menu . addAction ( self . showPrevTabAction ( ) ) <EOL> menu . addSeparator ( ) <EOL> for idx in xrange ( self . operatingWidget . count ( ) ) : <EOL> t = self . operatingWidget . widget ( idx ) <EOL> action = menu . addAction ( t . windowTitle ( ) ) <EOL> action . setData ( idx ) <EOL> if t == self . operatingWidget . currentWidget ( ) : <EOL> action . setIcon ( QtGui . QIcon ( '<STR_LIT>' ) ) <EOL> menu . addAction ( self . parent ( ) . parent ( ) . fullScreenAction ( ) ) <EOL> return menu <EOL> def showPopupMenu ( self ) : <EOL> """<STR_LIT>""" <EOL> menu = self . tabPopupMenu ( ) <EOL> action = menu . exec_ ( QtGui . QCursor . pos ( ) ) <EOL> self . showNextTabAction ( ) . setEnabled ( True ) <EOL> self . showPrevTabAction ( ) . setEnabled ( True ) <EOL> if not action : return <EOL> if not action in self . actions ( ) : <EOL> self . operatingWidget . setCurrentIndex ( action . data ( ) [ <NUM_LIT:0> ] ) <EOL> menu . deleteLater ( ) <EOL> def changeSpreadsheetFileName ( self , fileName ) : <EOL> """<STR_LIT>""" <EOL> self . spreadsheetFileName = fileName <EOL> if self . spreadsheetFileName : <EOL> displayName = self . spreadsheetFileName <EOL> else : <EOL> displayName = '<STR_LIT>' <EOL> self . emit ( QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' % displayName ) <EOL> def pipelineId ( self , pipelineInfo ) : <EOL> return ( pipelineInfo [ '<STR_LIT>' ] , pipelineInfo [ '<STR_LIT:version>' ] ) <EOL> def addPipeline ( self , pipelineInfo ) : <EOL> """<STR_LIT>""" <EOL> vistrail = self . pipelineId ( pipelineInfo ) <EOL> self . executedPipelines [ <NUM_LIT:0> ] . append ( vistrail ) <EOL> if not vistrail in self . executedPipelines [ <NUM_LIT:1> ] : <EOL> self . executedPipelines [ <NUM_LIT:1> ] [ vistrail ] = <NUM_LIT:0> <EOL> else : <EOL> self . executedPipelines [ <NUM_LIT:1> ] [ vistrail ] += <NUM_LIT:1> <EOL> self . executedPipelines [ <NUM_LIT:2> ] [ vistrail ] = <NUM_LIT:0> <EOL> def getCurrentPipelineId ( self , pipelineInfo ) : <EOL> """<STR_LIT>""" <EOL> vistrail = self . pipelineId ( pipelineInfo ) <EOL> return self . executedPipelines [ <NUM_LIT:1> ] [ vistrail ] <EOL> def increasePipelineCellId ( self , pipelineInfo ) : <EOL> """<STR_LIT>""" <EOL> vistrail = self . pipelineId ( pipelineInfo ) <EOL> cid = self . executedPipelines [ <NUM_LIT:2> ] [ vistrail ] <EOL> self . executedPipelines [ <NUM_LIT:2> ] [ vistrail ] += <NUM_LIT:1> <EOL> return cid <EOL> def getCurrentPipelineCellId ( self , pipelineInfo ) : <EOL> """<STR_LIT>""" <EOL> vistrail = self . pipelineId ( pipelineInfo ) <EOL> return self . executedPipelines [ <NUM_LIT:2> ] [ vistrail ] <EOL> def addPipelineCell ( self , pipelineInfo ) : <EOL> """<STR_LIT>""" <EOL> vistrail = self . pipelineId ( pipelineInfo ) <EOL> self . executedPipelines [ <NUM_LIT:0> ] . append ( vistrail ) <EOL> if not vistrail in self . executedPipelines [ <NUM_LIT:1> ] : <EOL> self . executedPipelines [ <NUM_LIT:1> ] [ vistrail ] = <NUM_LIT:0> <EOL> else : <EOL> self . executedPipelines [ <NUM_LIT:1> ] [ vistrail ] += <NUM_LIT:1> <EOL> def saveSpreadsheet ( self , fileName = None ) : <EOL> """<STR_LIT>""" <EOL> def serialize_locator ( locator ) : <EOL> wrapper = XMLWrapper ( ) <EOL> dom = wrapper . create_document ( '<STR_LIT>' ) <EOL> root = dom . documentElement <EOL> root . setAttribute ( "<STR_LIT:version>" , "<STR_LIT:1.0>" ) <EOL> locator . serialize ( dom , root ) <EOL> return dom . toxml ( ) <EOL> def need_save ( ) : <EOL> from vistrails . gui . vistrails_window import _app <EOL> need_save_vt = False <EOL> for t in self . tabWidgets : <EOL> dim = t . getDimension ( ) <EOL> for r in xrange ( dim [ <NUM_LIT:0> ] ) : <EOL> for c in xrange ( dim [ <NUM_LIT:1> ] ) : <EOL> info = t . getCellPipelineInfo ( r , c ) <EOL> if info : <EOL> controller = info [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> view = _app . ensureController ( controller ) <EOL> if view : <EOL> controller = view . get_controller ( ) <EOL> if controller . changed : <EOL> need_save_vt = True <EOL> return need_save_vt <EOL> if need_save ( ) : <EOL> show_warning ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return <EOL> if fileName == None : <EOL> fileName = self . spreadsheetFileName <EOL> if fileName : <EOL> indexFile = open ( fileName , '<STR_LIT:w>' ) <EOL> indexFile . write ( str ( len ( self . tabWidgets ) ) + '<STR_LIT:\n>' ) <EOL> for t in self . tabWidgets : <EOL> dim = t . getDimension ( ) <EOL> sheet = spreadsheetRegistry . getSheetByType ( type ( t ) ) <EOL> indexFile . write ( '<STR_LIT>' % str ( ( str ( t . windowTitle ( ) ) , <EOL> sheet , <EOL> dim [ <NUM_LIT:0> ] , dim [ <NUM_LIT:1> ] ) ) ) <EOL> for r in xrange ( dim [ <NUM_LIT:0> ] ) : <EOL> for c in xrange ( dim [ <NUM_LIT:1> ] ) : <EOL> info = t . getCellPipelineInfo ( r , c ) <EOL> if info : <EOL> newinfo0 = copy . copy ( info [ <NUM_LIT:0> ] ) <EOL> newinfo0 [ '<STR_LIT>' ] = None <EOL> newinfo0 [ '<STR_LIT>' ] = [ ] <EOL> newinfo0 [ '<STR_LIT>' ] = serialize_locator ( newinfo0 [ '<STR_LIT>' ] . locator ) <EOL> newinfo0 [ '<STR_LIT>' ] = None <EOL> indexFile . write ( '<STR_LIT>' <EOL> % str ( ( r , c , <EOL> newinfo0 , <EOL> info [ <NUM_LIT:1> ] , info [ <NUM_LIT:2> ] ) ) ) <EOL> indexFile . write ( '<STR_LIT>' ) <EOL> indexFile . write ( str ( len ( self . executedPipelines [ <NUM_LIT:0> ] ) ) + '<STR_LIT:\n>' ) <EOL> for vistrail in self . executedPipelines [ <NUM_LIT:0> ] : <EOL> indexFile . write ( '<STR_LIT>' % str ( ( serialize_locator ( vistrail [ <NUM_LIT:0> ] . locator ) , <EOL> vistrail [ <NUM_LIT:1> ] ) ) ) <EOL> self . changeSpreadsheetFileName ( fileName ) <EOL> indexFile . close ( ) <EOL> else : <EOL> self . saveSpreadsheetAs ( ) <EOL> def saveSpreadsheetAs ( self ) : <EOL> """<STR_LIT>""" <EOL> fileName = QtGui . QFileDialog . getSaveFileName ( self , <EOL> '<STR_LIT>' <EOL> '<STR_LIT:name>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if fileName : <EOL> ( root , ext ) = os . path . splitext ( fileName ) <EOL> if ext == '<STR_LIT>' : <EOL> fileName += '<STR_LIT>' <EOL> self . saveSpreadsheet ( fileName ) <EOL> def openSpreadsheet ( self , fileName ) : <EOL> """<STR_LIT>""" <EOL> def parse_locator ( text ) : <EOL> locator = None <EOL> wrapper = XMLWrapper ( ) <EOL> dom = wrapper . create_document_from_string ( text ) <EOL> root = dom . documentElement <EOL> version = None <EOL> version = root . getAttribute ( '<STR_LIT:version>' ) <EOL> if version == '<STR_LIT:1.0>' : <EOL> for element in named_elements ( root , '<STR_LIT>' ) : <EOL> if str ( element . getAttribute ( '<STR_LIT:type>' ) ) == '<STR_LIT:file>' : <EOL> locator = FileLocator . parse ( element ) <EOL> elif str ( element . getAttribute ( '<STR_LIT:type>' ) ) == '<STR_LIT>' : <EOL> locator = DBLocator . parse ( element ) <EOL> return locator <EOL> locators = { } <EOL> indexFile = open ( fileName , '<STR_LIT:r>' ) <EOL> contents = indexFile . read ( ) <EOL> self . clearTabs ( ) <EOL> lidx = <NUM_LIT:0> <EOL> lines = contents . split ( '<STR_LIT:\n>' ) <EOL> tabCount = int ( lines [ lidx ] ) <EOL> lidx += <NUM_LIT:1> <EOL> for tabIdx in xrange ( tabCount ) : <EOL> tabInfo = literal_eval ( lines [ lidx ] ) <EOL> lidx += <NUM_LIT:1> <EOL> sheet = spreadsheetRegistry . getSheet ( tabInfo [ <NUM_LIT:1> ] ) ( self ) <EOL> sheet . setDimension ( tabInfo [ <NUM_LIT:2> ] , tabInfo [ <NUM_LIT:3> ] ) <EOL> self . addTabWidget ( sheet , tabInfo [ <NUM_LIT:0> ] ) <EOL> while lines [ lidx ] != '<STR_LIT>' : <EOL> ( r , c , vistrail , pid , cid ) = literal_eval ( lines [ lidx ] ) <EOL> locator = vistrail [ '<STR_LIT>' ] <EOL> if locators . has_key ( locator ) : <EOL> vistrail [ '<STR_LIT>' ] = locators [ locator ] <EOL> else : <EOL> locators [ locator ] = parse_locator ( vistrail [ '<STR_LIT>' ] ) <EOL> vistrail [ '<STR_LIT>' ] = locators [ locator ] <EOL> self . appendMonitoredLocations ( ( vistrail , pid , cid ) , <EOL> ( sheet , r , c ) ) <EOL> lidx += <NUM_LIT:1> <EOL> lidx += <NUM_LIT:1> <EOL> pipelineCount = int ( lines [ lidx ] ) <EOL> lidx += <NUM_LIT:1> <EOL> self . loadingMode = True <EOL> progress = QtGui . QProgressDialog ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <NUM_LIT:0> , pipelineCount , <EOL> self , <EOL> QtCore . Qt . WindowStaysOnTopHint <EOL> ) <EOL> progress . show ( ) <EOL> for pipelineIdx in xrange ( pipelineCount ) : <EOL> ( serializedLocator , version ) = literal_eval ( lines [ lidx ] ) <EOL> try : <EOL> locator = locators [ serializedLocator ] <EOL> except KeyError : <EOL> locator = parse_locator ( serializedLocator ) <EOL> if locator : <EOL> bundle = locator . load ( ) <EOL> if isinstance ( bundle , SaveBundle ) : <EOL> pipeline = bundle . vistrail . getPipeline ( version ) <EOL> else : <EOL> pipeline = bundle . getPipeline ( version ) <EOL> execution = get_default_interpreter ( ) <EOL> progress . setValue ( pipelineIdx ) <EOL> QtCore . QCoreApplication . processEvents ( ) <EOL> if progress . wasCanceled ( ) : <EOL> break <EOL> kwargs = { '<STR_LIT>' : locator , <EOL> '<STR_LIT>' : version , <EOL> '<STR_LIT>' : DummyView ( ) , <EOL> } <EOL> execution . execute ( pipeline , ** kwargs ) <EOL> else : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> lidx += <NUM_LIT:1> <EOL> progress . setValue ( pipelineCount ) <EOL> QtCore . QCoreApplication . processEvents ( ) <EOL> self . changeSpreadsheetFileName ( fileName ) <EOL> self . loadingMode = False <EOL> indexFile . close ( ) <EOL> def openSpreadsheetAs ( self ) : <EOL> """<STR_LIT>""" <EOL> fileName = QtGui . QFileDialog . getOpenFileName ( self , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ) <EOL> if fileName : <EOL> self . openSpreadsheet ( fileName ) <EOL> def cleanup ( self ) : <EOL> """<STR_LIT>""" <EOL> self . clearTabs ( ) <EOL> def setEditingMode ( self , editing = True ) : <EOL> """<STR_LIT>""" <EOL> self . editingMode = editing <EOL> for w in self . tabWidgets : <EOL> w . setEditingMode ( editing ) </s>
