def decodeConfiguration(pipeline, cells): """ decodeConfiguration(pipeline: Pipeline, cells: configuration) -> decoded cells Convert cells of type [{(type,id): (row, column)}) to (mId, row, col) in a particular pipeline """ decodedCells = [] inspector = PipelineInspector() inspector.inspect_spreadsheet_cells(pipeline) inspector.inspect_ambiguous_modules(pipeline) orig_pipeline = pipeline for id_list in inspector.spreadsheet_cells: pipeline = orig_pipeline id_iter = iter(id_list) m = pipeline.modules[id_iter.next()] m_id = m.id for m_id in id_iter: pipeline = m.pipeline m = pipeline.modules[m_id] name = m.name if len(id_list) == 1 and m_id in inspector.annotated_modules: idx = inspector.annotated_modules[m_id] elif tuple(id_list) in inspector.annotated_modules: idx = inspector.annotated_modules[tuple(id_list)] else: idx = -1 (vRow, vCol) = cells[(name, idx)] if len(id_list) == 1: decodedCells.append((m_id, vRow, vCol)) else: decodedCells.append((tuple(id_list), vRow, vCol)) return decodedCells
def __init__(self, parent=None): """ QPipelineView(parent: QWidget) -> QPipelineView Initialize the graphics view and its properties """ QPipelineView.__init__(self, parent) self.setWindowTitle('Annotated Pipeline') self.inspector = PipelineInspector()
def __init__(self, parent=None): """ QVirtualCellWindow(parent: QWidget) -> QVirtualCellWindow Initialize the widget """ QtGui.QFrame.__init__(self, parent) self.setFrameShape(QtGui.QFrame.StyledPanel) self.setWindowTitle('Spreadsheet Virtual Cell') vLayout = QtGui.QVBoxLayout(self) vLayout.setMargin(2) vLayout.setSpacing(0) self.setLayout(vLayout) label = QtGui.QLabel('Arrange the cell(s) below to construct' ' a virtual cell') font = QtGui.QFont(label.font()) label.setFont(font) label.setWordWrap(True) vLayout.addWidget(label) hLayout = QtGui.QVBoxLayout() hLayout.setMargin(0) hLayout.setSpacing(0) vLayout.addLayout(hLayout) self.config = QVirtualCellConfiguration() self.config.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Maximum) hLayout.addWidget(self.config) hPadWidget = QtGui.QWidget() hLayout.addWidget(hPadWidget) hPadWidget.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Ignored) vPadWidget = QtGui.QWidget() vLayout.addWidget(vPadWidget) vPadWidget.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.inspector = PipelineInspector() self.pipeline = None
def updateFromPipeline(self, pipeline): """ updateFromPipeline(pipeline: Pipeline) -> None Read the list of aliases and parameters from the pipeline """ self.clear() if not pipeline: return # Update the aliases if len(pipeline.aliases) > 0: aliasRoot = QParameterTreeWidgetItem(None, self, QtCore.QStringList('Aliases')) aliasRoot.setFlags(QtCore.Qt.ItemIsEnabled, ) for (alias, info) in pipeline.aliases.iteritems(): ptype, pId, parentType, parentId, _ = info parameter = pipeline.db_get_object(ptype, pId) v = parameter.strValue aType = parameter.type aIdentifier = parameter.identifier aNamespace = parameter.namespace label = QtCore.QStringList('%s = %s' % (alias, v)) pInfo = ParameterInfo(type=aType, identifier=aIdentifier, namespace=aNamespace, value=v, id=pId, dbtype=ptype, parent_dbtype=parentType, parent_id=parentId, is_alias=True) aliasItem = QParameterTreeWidgetItem((alias, [pInfo]), aliasRoot, label) aliasRoot.setExpanded(True) # Now go through all modules and functions inspector = PipelineInspector() inspector.inspect_ambiguous_modules(pipeline) sortedModules = sorted(pipeline.modules.iteritems(), key=lambda item: item[1].name) for mId, module in sortedModules: if len(module.functions) > 0: mLabel = QtCore.QStringList(module.name) moduleItem = None for fId in xrange(len(module.functions)): function = module.functions[fId] if len(function.params) == 0: continue if moduleItem == None: if inspector.annotated_modules.has_key(mId): annotatedId = inspector.annotated_modules[mId] moduleItem = QParameterTreeWidgetItem( annotatedId, self, mLabel) else: moduleItem = QParameterTreeWidgetItem( None, self, mLabel) v = ', '.join([p.strValue for p in function.params]) label = QtCore.QStringList('%s(%s)' % (function.name, v)) pList = [ ParameterInfo( type=function.params[pId].type, identifier=function.params[pId].identifier, namespace=function.params[pId].namespace, value=function.params[pId].strValue, id=function.params[pId].real_id, dbtype=ModuleParam.vtType, parent_dbtype=function.vtType, parent_id=function.real_id, is_alias=False) for pId in xrange(len(function.params)) ] mName = module.name if moduleItem.parameter != None: mName += '(%d)' % moduleItem.parameter fName = '%s :: %s' % (mName, function.name) mItem = QParameterTreeWidgetItem((fName, pList), moduleItem, label) if moduleItem: moduleItem.setExpanded(True)
def assignPipelineCellLocations(pipeline, sheetName, row, col, cellIds=None, minRowCount=None, minColCount=None): reg = get_module_registry() spreadsheet_cell_desc = \ reg.get_descriptor_by_name('edu.utah.sci.vistrails.spreadsheet', \ 'SpreadsheetCell') create_module = VistrailController.create_module_static create_function = VistrailController.create_function_static create_connection = VistrailController.create_connection_static pipeline = copy.copy(pipeline) root_pipeline = pipeline if cellIds is None: inspector = PipelineInspector() inspector.inspect_spreadsheet_cells(pipeline) inspector.inspect_ambiguous_modules(pipeline) cellIds = inspector.spreadsheet_cells for id_list in cellIds: # find at which depth we need to be working try: id_iter = iter(id_list) m = pipeline.modules[id_iter.next()] for mId in id_iter: pipeline = m.pipeline m = pipeline.modules[mId] except TypeError: mId = id_list m = pipeline.modules[mId] if not reg.is_descriptor_subclass(m.module_descriptor, spreadsheet_cell_desc): continue # Walk through all connections and remove all CellLocation # modules connected to this spreadsheet cell conns_to_delete = [] for (cId, c) in pipeline.connections.iteritems(): if (c.destinationId == mId and pipeline.modules[c.sourceId].name == "CellLocation"): conns_to_delete.append(c.id) for c_id in conns_to_delete: pipeline.delete_connection(c_id) # a hack to first get the id_scope to the local pipeline scope # then make them negative by hacking the getNewId method # all of this is reset at the end of this block id_scope = pipeline.tmp_id orig_getNewId = pipeline.tmp_id.__class__.getNewId def getNewId(self, objType): return -orig_getNewId(self, objType) pipeline.tmp_id.__class__.getNewId = getNewId # Add a sheet reference with a specific name sheetReference = create_module(id_scope, "edu.utah.sci.vistrails.spreadsheet", "SheetReference") sheetNameFunction = create_function(id_scope, sheetReference, "SheetName", [str(sheetName)]) # ["%s %d" % (sheetPrefix, sheet)]) sheetReference.add_function(sheetNameFunction) if minRowCount is not None: minRowFunction = create_function(id_scope, sheetReference, "MinRowCount", [str(minRowCount)]) # [str(rowCount*vRCount)]) sheetReference.add_function(minRowFunction) if minColCount is not None: minColFunction = create_function(id_scope, sheetReference, "MinColumnCount", [str(minColCount)]) # [str(colCount*vCCount)]) sheetReference.add_function(minColFunction) # Add a cell location module with a specific row and column cellLocation = create_module(id_scope, "edu.utah.sci.vistrails.spreadsheet", "CellLocation") rowFunction = create_function(id_scope, cellLocation, "Row", [str(row)]) # [str(row*vRCount+vRow+1)]) colFunction = create_function(id_scope, cellLocation, "Column", [str(col)]) # [str(col*vCCount+vCol+1)]) cellLocation.add_function(rowFunction) cellLocation.add_function(colFunction) # Then connect the SheetReference to the CellLocation sheet_conn = create_connection(id_scope, sheetReference, "self", cellLocation, "SheetReference") # Then connect the CellLocation to the spreadsheet cell cell_module = pipeline.get_module_by_id(mId) cell_conn = create_connection(id_scope, cellLocation, "self", cell_module, "Location") pipeline.add_module(sheetReference) pipeline.add_module(cellLocation) pipeline.add_connection(sheet_conn) pipeline.add_connection(cell_conn) # replace the getNewId method pipeline.tmp_id.__class__.getNewId = orig_getNewId return root_pipeline