Esempio n. 1
0
 def __init__(self, tabWidget, row=None, col=None):
     """ StandardWidgetSheet(tabWidget: QTabWidget,
                             row: int,
                             col: int) -> StandardWidgetSheet
     Initialize with a toolbar and a sheet widget
                             
     """
     QtGui.QWidget.__init__(self, None)
     StandardWidgetSheetTabInterface.__init__(self)
     if not row:
         row = configuration.rowCount
     if not col:
         col = configuration.columnCount
     self.type = 'StandardWidgetSheetTab'
     self.tabWidget = tabWidget
     self.sheet = StandardWidgetSheet(row, col, self)
     self.sheet.setFitToWindow(True)
     self.toolBar = StandardWidgetToolBar(self)
     self.vLayout = QtGui.QVBoxLayout()
     self.vLayout.setSpacing(0)
     self.vLayout.setMargin(0)
     self.vLayout.addWidget(self.toolBar, 0)
     self.vLayout.addWidget(self.sheet, 1)
     self.setLayout(self.vLayout)
     self.pipelineInfo = {}
     self.setAcceptDrops(True)
Esempio n. 2
0
 def __init__(self, tabWidget,row=None , col=None):
     """ StandardWidgetSheet(tabWidget: QTabWidget,
                             row: int,
                             col: int) -> StandardWidgetSheet
     Initialize with a toolbar and a sheet widget
                             
     """
     QtGui.QWidget.__init__(self, None)
     StandardWidgetSheetTabInterface.__init__(self)
     if not row:
         row = configuration.rowCount
     if not col:
         col = configuration.columnCount
     self.type = 'StandardWidgetSheetTab'
     self.tabWidget = tabWidget
     self.sheet = StandardWidgetSheet(row, col, self)
     self.sheet.setFitToWindow(True)
     self.toolBar = StandardWidgetToolBar(self)
     self.vLayout = QtGui.QVBoxLayout()
     self.vLayout.setSpacing(0)
     self.vLayout.setMargin(0)
     self.vLayout.addWidget(self.toolBar, 0)
     self.vLayout.addWidget(self.sheet, 1)
     self.setLayout(self.vLayout)
     self.pipelineInfo = {}
     self.setAcceptDrops(True)
Esempio n. 3
0
class StandardWidgetSheetTab(QtGui.QWidget, StandardWidgetSheetTabInterface):
    """
    StandardWidgetSheetTab is a container of StandardWidgetSheet with
    a toolbar on top. This will be added directly to a QTabWidget for
    displaying the spreadsheet.
    
    """
    def __init__(self, tabWidget,row=None , col=None):
        """ StandardWidgetSheet(tabWidget: QTabWidget,
                                row: int,
                                col: int) -> StandardWidgetSheet
        Initialize with a toolbar and a sheet widget
                                
        """
        QtGui.QWidget.__init__(self, None)
        StandardWidgetSheetTabInterface.__init__(self)
        if not row:
            row = configuration.rowCount
        if not col:
            col = configuration.columnCount
        self.type = 'StandardWidgetSheetTab'
        self.tabWidget = tabWidget
        self.sheet = StandardWidgetSheet(row, col, self)
        self.sheet.setFitToWindow(True)
        self.toolBar = StandardWidgetToolBar(self)
        self.vLayout = QtGui.QVBoxLayout()
        self.vLayout.setSpacing(0)
        self.vLayout.setMargin(0)
        self.vLayout.addWidget(self.toolBar, 0)
        self.vLayout.addWidget(self.sheet, 1)
        self.setLayout(self.vLayout)
        self.pipelineInfo = {}
        self.setAcceptDrops(True)

    def rowSpinBoxChanged(self):
        """ rowSpinBoxChanged() -> None
        Handle the number of row changed
        
        """
        if self.toolBar.rowSpinBox.value()!=self.sheet.rowCount():
            self.sheet.setRowCount(self.toolBar.rowSpinBox.value())
            self.sheet.stretchCells()
            self.setEditingMode(self.tabWidget.editingMode)
        
    def colSpinBoxChanged(self):
        """ colSpinBoxChanged() -> None
        Handle the number of row changed
        
        """
        if self.toolBar.colSpinBox.value()!=self.sheet.columnCount():
            self.sheet.setColumnCount(self.toolBar.colSpinBox.value())
            self.sheet.stretchCells()
            self.setEditingMode(self.tabWidget.editingMode)

    ### Belows are API Wrappers to connect to self.sheet

    def getDimension(self):
        """ getDimension() -> tuple
        Get the sheet dimensions
        
        """
        return (self.sheet.rowCount(), self.sheet.columnCount())
            
    def setDimension(self, rc, cc):
        """ setDimension(rc: int, cc: int) -> None
        Set the sheet dimensions
        
        """
        self.toolBar.rowCountSpinBox().setValue(rc)
        self.toolBar.colCountSpinBox().setValue(cc)
            
    def getCellWidget(self, row, col):
        """ getCellWidget(row: int, col: int) -> QWidget
        Get cell at a specific row and column.
        
        """
        return self.sheet.getCell(row, col)

    def getCellRect(self, row, col):
        """ getCellRect(row: int, col: int) -> QRect
        Return the rectangle surrounding the cell at location (row, col)
        in parent coordinates
        
        """
        return self.sheet.getCellRect(row, col)

    def getCellGlobalRect(self, row, col):
        """ getCellGlobalRect(row: int, col: int) -> QRect
        Return the rectangle surrounding the cell at location (row, col)
        in global coordinates
        
        """
        return self.sheet.getCellGlobalRect(row, col)

    def showHelpers(self, show, globalPos):
        """ showHelpers(show: boolean, globalPos: QPoint) -> None        
        Show/hide the helpers (toolbar, resizer) depending on the
        status of show and the global position of the cursor
        
        """
        localPos = self.sheet.viewport().mapFromGlobal(QtGui.QCursor.pos())
        row = self.sheet.rowAt(localPos.y())
        col = self.sheet.columnAt(localPos.x())
        rect = self.sheet.getCellRect(row, col)
        show =  show and (rect.x()+rect.width()-localPos.x()<100 and
                          rect.y()+rect.height()-localPos.y()<100)
        self.sheet.showHelpers(show, row, col)
        
    def getSelectedLocations(self):
        """ getSelectedLocations() -> list
        Return the selected locations (row, col) of the current sheet
        
        """
        indexes = self.sheet.selectedIndexes()
        return [(idx.row(), idx.column()) for idx in indexes]

    def clearSelection(self):
        """ clearSelection() -> None
        Clear all the selection in the current sheet
        
        """
        self.sheet.clearSelection()
    
    def setCellWidget(self, row, col, cellWidget):
        """ setCellWidget(row: int,
                            col: int,                            
                            cellWidget: QWidget) -> None                            
        Replace the current location (row, col) with a cell widget
        
        """
        self.sheet.setCellByWidget(row, col, cellWidget)

    def dragEnterEvent(self, event):
        """ dragEnterEvent(event: QDragEnterEvent) -> None
        Set to accept drops from the version tree
        
        """
        mimeData = event.mimeData()
        if hasattr(mimeData, 'versionId'):
            event.accept()
        else:
            event.ignore()

    def dragMoveEvent(self, event):
        """ dragEnterEvent(event: QDragEnterEvent) -> None
        Set to accept drops while moving from the version tree
        
        """
        mimeData = event.mimeData()
        if (hasattr(mimeData, 'versionId') and
            hasattr(mimeData, 'controller')):
            event.accept()
        else:
            event.ignore()

    def dropEvent(self, event):
        """ Execute the pipeline at the particular location """
        mimeData = event.mimeData()        
        if (hasattr(mimeData, 'versionId') and
            hasattr(mimeData, 'controller')):
            event.accept()
            versionId = mimeData.versionId
            controller = mimeData.controller
            pipeline = controller.vistrail.getPipeline(versionId)

            inspector = PipelineInspector()
            inspector.inspect_spreadsheet_cells(pipeline)
            inspector.inspect_ambiguous_modules(pipeline)
            if len(inspector.spreadsheet_cells)==1:
                localPos = self.sheet.viewport().mapFromGlobal(QtGui.QCursor.pos())
                row = self.sheet.rowAt(localPos.y())
                col = self.sheet.columnAt(localPos.x())
                if (row!=-1 and col!=-1):
                    pipeline = self.setPipelineToLocateAt(row, col, pipeline)
            executePipelineWithProgress(pipeline, 'Execute Cell',
                                        controller=controller,
                                        locator=controller.locator,
                                        current_version=versionId,
                                        reason='Drop Version')
        else:
            event.ignore()

    def setSpan(self, row, col, rowSpan, colSpan):
        """ setSpan(row, col, rowSpan, colSpan: int) -> None
        Set the spanning at location (row, col).
        
        """
        colSpan = max(colSpan, 1)
        rowSpan = max(rowSpan, 1)
        (curRowSpan, curColSpan) = self.getSpan(row, col)
        if rowSpan!=curRowSpan or colSpan!=curColSpan:
            # Need to remove all cell except the top-left
            for r in xrange(rowSpan):
                for c in xrange(colSpan):
                    if r!=0 or c!=0:
                        self.deleteCell(row+r, col+c)
                        
            # Take the current widget out
            curWidget = self.takeCell(row, col)

            #  ... before setting the span
            self.sheet.setSpan(row, col, rowSpan, colSpan)

            # Then put it back in
            if curWidget:
                self.setCellByWidget(row, col, curWidget)

    def getSpan(self, row, col):
        """ setSpan(row, col: int) -> (rowSpan, colSpan: int)
        Return the spanning at location (row, col). This is only a
        place holder. Subclasses should implement this and setSpan for
        a fully functioning spanning feature.
        
        """
        return (self.sheet.rowSpan(row, col), self.sheet.columnSpan(row, col))
Esempio n. 4
0
class StandardWidgetSheetTab(QtGui.QWidget, StandardWidgetSheetTabInterface):
    """
    StandardWidgetSheetTab is a container of StandardWidgetSheet with
    a toolbar on top. This will be added directly to a QTabWidget for
    displaying the spreadsheet.
    
    """
    def __init__(self, tabWidget, row=None, col=None):
        """ StandardWidgetSheet(tabWidget: QTabWidget,
                                row: int,
                                col: int) -> StandardWidgetSheet
        Initialize with a toolbar and a sheet widget
                                
        """
        QtGui.QWidget.__init__(self, None)
        StandardWidgetSheetTabInterface.__init__(self)
        if not row:
            row = configuration.rowCount
        if not col:
            col = configuration.columnCount
        self.type = 'StandardWidgetSheetTab'
        self.tabWidget = tabWidget
        self.sheet = StandardWidgetSheet(row, col, self)
        self.sheet.setFitToWindow(True)
        self.toolBar = StandardWidgetToolBar(self)
        self.vLayout = QtGui.QVBoxLayout()
        self.vLayout.setSpacing(0)
        self.vLayout.setMargin(0)
        self.vLayout.addWidget(self.toolBar, 0)
        self.vLayout.addWidget(self.sheet, 1)
        self.setLayout(self.vLayout)
        self.pipelineInfo = {}
        self.setAcceptDrops(True)

    def rowSpinBoxChanged(self):
        """ rowSpinBoxChanged() -> None
        Handle the number of row changed
        
        """
        if self.toolBar.rowSpinBox.value() != self.sheet.rowCount():
            self.sheet.setRowCount(self.toolBar.rowSpinBox.value())
            self.sheet.stretchCells()
            self.setEditingMode(self.tabWidget.editingMode)

    def colSpinBoxChanged(self):
        """ colSpinBoxChanged() -> None
        Handle the number of row changed
        
        """
        if self.toolBar.colSpinBox.value() != self.sheet.columnCount():
            self.sheet.setColumnCount(self.toolBar.colSpinBox.value())
            self.sheet.stretchCells()
            self.setEditingMode(self.tabWidget.editingMode)

    ### Belows are API Wrappers to connect to self.sheet

    def getDimension(self):
        """ getDimension() -> tuple
        Get the sheet dimensions
        
        """
        return (self.sheet.rowCount(), self.sheet.columnCount())

    def setDimension(self, rc, cc):
        """ setDimension(rc: int, cc: int) -> None
        Set the sheet dimensions
        
        """
        self.toolBar.rowCountSpinBox().setValue(rc)
        self.toolBar.colCountSpinBox().setValue(cc)

    def getCellWidget(self, row, col):
        """ getCellWidget(row: int, col: int) -> QWidget
        Get cell at a specific row and column.
        
        """
        return self.sheet.getCell(row, col)

    def getCellRect(self, row, col):
        """ getCellRect(row: int, col: int) -> QRect
        Return the rectangle surrounding the cell at location (row, col)
        in parent coordinates
        
        """
        return self.sheet.getCellRect(row, col)

    def getCellGlobalRect(self, row, col):
        """ getCellGlobalRect(row: int, col: int) -> QRect
        Return the rectangle surrounding the cell at location (row, col)
        in global coordinates
        
        """
        return self.sheet.getCellGlobalRect(row, col)

    def showHelpers(self, show, globalPos):
        """ showHelpers(show: boolean, globalPos: QPoint) -> None        
        Show/hide the helpers (toolbar, resizer) depending on the
        status of show and the global position of the cursor
        
        """
        localPos = self.sheet.viewport().mapFromGlobal(QtGui.QCursor.pos())
        row = self.sheet.rowAt(localPos.y())
        col = self.sheet.columnAt(localPos.x())
        rect = self.sheet.getCellRect(row, col)
        show = show and (rect.x() + rect.width() - localPos.x() < 100
                         and rect.y() + rect.height() - localPos.y() < 100)
        self.sheet.showHelpers(show, row, col)

    def getSelectedLocations(self):
        """ getSelectedLocations() -> list
        Return the selected locations (row, col) of the current sheet
        
        """
        indexes = self.sheet.selectedIndexes()
        return [(idx.row(), idx.column()) for idx in indexes]

    def clearSelection(self):
        """ clearSelection() -> None
        Clear all the selection in the current sheet
        
        """
        self.sheet.clearSelection()

    def setCellWidget(self, row, col, cellWidget):
        """ setCellWidget(row: int,
                            col: int,                            
                            cellWidget: QWidget) -> None                            
        Replace the current location (row, col) with a cell widget
        
        """
        self.sheet.setCellByWidget(row, col, cellWidget)

    def dragEnterEvent(self, event):
        """ dragEnterEvent(event: QDragEnterEvent) -> None
        Set to accept drops from the version tree
        
        """
        mimeData = event.mimeData()
        if hasattr(mimeData, 'versionId'):
            event.accept()
        else:
            event.ignore()

    def dragMoveEvent(self, event):
        """ dragEnterEvent(event: QDragEnterEvent) -> None
        Set to accept drops while moving from the version tree
        
        """
        mimeData = event.mimeData()
        if (hasattr(mimeData, 'versionId')
                and hasattr(mimeData, 'controller')):
            event.accept()
        else:
            event.ignore()

    def dropEvent(self, event):
        """ Execute the pipeline at the particular location """
        mimeData = event.mimeData()
        if (hasattr(mimeData, 'versionId')
                and hasattr(mimeData, 'controller')):
            event.accept()
            versionId = mimeData.versionId
            controller = mimeData.controller
            pipeline = controller.vistrail.getPipeline(versionId)

            inspector = PipelineInspector()
            inspector.inspect_spreadsheet_cells(pipeline)
            inspector.inspect_ambiguous_modules(pipeline)
            if len(inspector.spreadsheet_cells) == 1:
                localPos = self.sheet.viewport().mapFromGlobal(
                    QtGui.QCursor.pos())
                row = self.sheet.rowAt(localPos.y())
                col = self.sheet.columnAt(localPos.x())
                if (row != -1 and col != -1):
                    pipeline = self.setPipelineToLocateAt(row, col, pipeline)
            executePipelineWithProgress(pipeline,
                                        'Execute Cell',
                                        controller=controller,
                                        locator=controller.locator,
                                        current_version=versionId,
                                        reason='Drop Version')
        else:
            event.ignore()

    def setSpan(self, row, col, rowSpan, colSpan):
        """ setSpan(row, col, rowSpan, colSpan: int) -> None
        Set the spanning at location (row, col).
        
        """
        colSpan = max(colSpan, 1)
        rowSpan = max(rowSpan, 1)
        (curRowSpan, curColSpan) = self.getSpan(row, col)
        if rowSpan != curRowSpan or colSpan != curColSpan:
            # Need to remove all cell except the top-left
            for r in xrange(rowSpan):
                for c in xrange(colSpan):
                    if r != 0 or c != 0:
                        self.deleteCell(row + r, col + c)

            # Take the current widget out
            curWidget = self.takeCell(row, col)

            #  ... before setting the span
            self.sheet.setSpan(row, col, rowSpan, colSpan)

            # Then put it back in
            if curWidget:
                self.setCellByWidget(row, col, curWidget)

    def getSpan(self, row, col):
        """ setSpan(row, col: int) -> (rowSpan, colSpan: int)
        Return the spanning at location (row, col). This is only a
        place holder. Subclasses should implement this and setSpan for
        a fully functioning spanning feature.
        
        """
        return (self.sheet.rowSpan(row, col), self.sheet.columnSpan(row, col))