<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> import copy <EOL> from PyQt4 import QtCore , QtGui <EOL> from vistrails . core . inspector import PipelineInspector <EOL> from vistrails . core . interpreter . default import get_default_interpreter <EOL> from vistrails . core . modules . module_registry import get_module_registry <EOL> from vistrails . core . vistrail . controller import VistrailController <EOL> from vistrails . core . utils import DummyView <EOL> from . identifiers import identifier as spreadsheet_pkg <EOL> def assignPipelineCellLocations ( pipeline , sheetName , <EOL> row , col , cellIds = None , <EOL> minRowCount = None , minColCount = None ) : <EOL> reg = get_module_registry ( ) <EOL> spreadsheet_cell_desc = reg . get_descriptor_by_name ( spreadsheet_pkg , <EOL> '<STR_LIT>' ) <EOL> output_module_desc = reg . get_descriptor_by_name ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> create_module = VistrailController . create_module_static <EOL> create_function = VistrailController . create_function_static <EOL> create_connection = VistrailController . create_connection_static <EOL> pipeline = copy . copy ( pipeline ) <EOL> root_pipeline = pipeline <EOL> if cellIds is None : <EOL> inspector = PipelineInspector ( ) <EOL> inspector . inspect_spreadsheet_cells ( pipeline ) <EOL> inspector . inspect_ambiguous_modules ( pipeline ) <EOL> cellIds = inspector . spreadsheet_cells <EOL> def fix_cell_module ( pipeline , mId ) : <EOL> conns_to_delete = [ ] <EOL> for c in pipeline . connection_list : <EOL> if c . destinationId == mId and c . destination . name == '<STR_LIT>' : <EOL> conns_to_delete . append ( c . id ) <EOL> for c_id in conns_to_delete : <EOL> pipeline . delete_connection ( c_id ) <EOL> id_scope = pipeline . tmp_id <EOL> orig_getNewId = pipeline . tmp_id . __class__ . getNewId <EOL> def getNewId ( self , objType ) : <EOL> return - orig_getNewId ( self , objType ) <EOL> pipeline . tmp_id . __class__ . getNewId = getNewId <EOL> sheetReference = create_module ( id_scope , spreadsheet_pkg , <EOL> "<STR_LIT>" ) <EOL> sheetNameFunction = create_function ( id_scope , sheetReference , <EOL> "<STR_LIT>" , [ str ( sheetName ) ] ) <EOL> sheetReference . add_function ( sheetNameFunction ) <EOL> if minRowCount is not None : <EOL> minRowFunction = create_function ( id_scope , sheetReference , <EOL> "<STR_LIT>" , [ str ( minRowCount ) ] ) <EOL> sheetReference . add_function ( minRowFunction ) <EOL> if minColCount is not None : <EOL> minColFunction = create_function ( id_scope , sheetReference , <EOL> "<STR_LIT>" , <EOL> [ str ( minColCount ) ] ) <EOL> sheetReference . add_function ( minColFunction ) <EOL> cellLocation = create_module ( id_scope , spreadsheet_pkg , <EOL> "<STR_LIT>" ) <EOL> rowFunction = create_function ( id_scope , cellLocation , "<STR_LIT>" , [ str ( row ) ] ) <EOL> colFunction = create_function ( id_scope , cellLocation , "<STR_LIT>" , <EOL> [ str ( col ) ] ) <EOL> cellLocation . add_function ( rowFunction ) <EOL> cellLocation . add_function ( colFunction ) <EOL> sheet_conn = create_connection ( id_scope , sheetReference , "<STR_LIT:value>" , <EOL> cellLocation , "<STR_LIT>" ) <EOL> cell_module = pipeline . get_module_by_id ( mId ) <EOL> cell_conn = create_connection ( id_scope , cellLocation , "<STR_LIT:value>" , <EOL> cell_module , "<STR_LIT>" ) <EOL> pipeline . add_module ( sheetReference ) <EOL> pipeline . add_module ( cellLocation ) <EOL> pipeline . add_connection ( sheet_conn ) <EOL> pipeline . add_connection ( cell_conn ) <EOL> pipeline . tmp_id . __class__ . getNewId = orig_getNewId <EOL> def fix_output_module ( pipeline , mId ) : <EOL> conns_to_delete = [ ] <EOL> for c in pipeline . connection_list : <EOL> if ( c . destinationId == mId and <EOL> c . destination . name == '<STR_LIT>' ) : <EOL> conns_to_delete . append ( c . id ) <EOL> for c_id in conns_to_delete : <EOL> pipeline . delete_connection ( c_id ) <EOL> m = pipeline . modules [ mId ] <EOL> funcs_to_delete = [ ] <EOL> for f in m . functions : <EOL> if f . name == '<STR_LIT>' : <EOL> funcs_to_delete . append ( f . real_id ) <EOL> for f_id in funcs_to_delete : <EOL> m . delete_function_by_real_id ( f_id ) <EOL> id_scope = pipeline . tmp_id <EOL> orig_getNewId = pipeline . tmp_id . __class__ . getNewId <EOL> def getNewId ( self , objType ) : <EOL> return - orig_getNewId ( self , objType ) <EOL> pipeline . tmp_id . __class__ . getNewId = getNewId <EOL> config = { '<STR_LIT>' : row - <NUM_LIT:1> , '<STR_LIT>' : col - <NUM_LIT:1> } <EOL> if minRowCount is not None : <EOL> config [ '<STR_LIT>' ] = minRowCount <EOL> if minColCount is not None : <EOL> config [ '<STR_LIT>' ] = minColCount <EOL> if sheetName is not None : <EOL> config [ '<STR_LIT>' ] = sheetName <EOL> config = { '<STR_LIT>' : config } <EOL> config_function = create_function ( id_scope , m , <EOL> '<STR_LIT>' , [ repr ( config ) ] ) <EOL> m . add_function ( config_function ) <EOL> pipeline . tmp_id . __class__ . getNewId = orig_getNewId <EOL> for id_list in cellIds : <EOL> cell_pipeline = pipeline <EOL> if isinstance ( id_list , ( int , long ) ) : <EOL> mId = id_list <EOL> m = cell_pipeline . modules [ mId ] <EOL> else : <EOL> id_iter = iter ( id_list ) <EOL> mId = next ( id_iter ) <EOL> m = cell_pipeline . modules [ mId ] <EOL> for mId in id_iter : <EOL> cell_pipeline = m . pipeline <EOL> m = cell_pipeline . modules [ mId ] <EOL> if reg . is_descriptor_subclass ( m . module_descriptor , <EOL> spreadsheet_cell_desc ) : <EOL> fix_cell_module ( cell_pipeline , mId ) <EOL> elif reg . is_descriptor_subclass ( m . module_descriptor , <EOL> output_module_desc ) : <EOL> fix_output_module ( cell_pipeline , mId ) <EOL> return root_pipeline <EOL> def executePipelineWithProgress ( pipeline , <EOL> pTitle = '<STR_LIT>' , <EOL> pCaption = '<STR_LIT>' , <EOL> pCancel = '<STR_LIT>' , <EOL> ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> withoutCancel = True <EOL> totalProgress = len ( pipeline . modules ) <EOL> progress = QtGui . QProgressDialog ( pCaption , <EOL> pCancel , <EOL> <NUM_LIT:0> , totalProgress ) <EOL> progress . setWindowTitle ( pTitle ) <EOL> progress . setWindowModality ( QtCore . Qt . WindowModal ) <EOL> progress . show ( ) <EOL> def moduleExecuted ( objId ) : <EOL> if not progress . wasCanceled ( ) : <EOL> progress . setValue ( progress . value ( ) + <NUM_LIT:1> ) <EOL> QtCore . QCoreApplication . processEvents ( ) <EOL> else : <EOL> withoutCancel = False <EOL> interpreter = get_default_interpreter ( ) <EOL> if kwargs . has_key ( '<STR_LIT>' ) : <EOL> kwargs [ '<STR_LIT>' ] . append ( moduleExecuted ) <EOL> else : <EOL> kwargs [ '<STR_LIT>' ] = [ moduleExecuted ] <EOL> kwargs [ '<STR_LIT>' ] = DummyView ( ) <EOL> interpreter . execute ( pipeline , ** kwargs ) <EOL> progress . setValue ( totalProgress ) <EOL> return withoutCancel </s>
