Esempio n. 1
0
    def insertCol(self):
        # Grab the cursor
        cursor = self.text.textCursor()

        # Grab the current table (we assume there is one, since
        # this is checked before calling)
        table = cursor.currentTable()

        # Get the current cell
        cell = table.cellAt(cursor)

        # Insert a new row at the cell's position
        table.insertColumns(cell.row(), 1)
Esempio n. 2
0
    def removeCol(self):
        # Grab the cursor
        cursor = self.text.textCursor()

        # Grab the current table (we assume there is one, since
        # this is checked before calling)
        table = cursor.currentTable()

        # Get the current cell
        cell = table.cellAt(cursor)

        # Delete the cell's column
        table.removeColumns(cell.column(), 1)
Esempio n. 3
0
    def insertCol(self):

        # Grab the cursor
        cursor = self.text.textCursor()

        # Grab the current table (we assume there is one, since
        # this is checked before calling)
        table = cursor.currentTable()

        # Get the current cell
        cell = table.cellAt(cursor)

        # Insert a new row at the cell's position
        table.insertColumns(cell.column(),1)
Esempio n. 4
0
    def removeCol(self):

        # Grab the cursor
        cursor = self.text.textCursor()

        # Grab the current table (we assume there is one, since
        # this is checked before calling)
        table = cursor.currentTable()

        # Get the current cell
        cell = table.cellAt(cursor)

        # Delete the cell's column
        table.removeColumns(cell.column(),1)
Esempio n. 5
0
def showTableContextMenu(table, pos, cursor, self):
    menu = QtWidgets.QMenu(self)

    appendRowAction = QtWidgets.QAction("Append row", self)
    appendRowAction.triggered.connect(lambda: table.appendRows(1))

    appendColAction = QtWidgets.QAction("Append column", self)
    appendColAction.triggered.connect(lambda: table.appendColumns(1))

    removeRowAction = QtWidgets.QAction("Remove row", self)
    removeRowAction.triggered.connect(
        lambda: table.removeRows(table.cellAt(cursor).row(), 1))

    removeColAction = QtWidgets.QAction("Remove column", self)
    removeColAction.triggered.connect(lambda: table.removeColumns(
        table.cellAt(cursor).column(), 1))  # self.removeCol)

    insertRowAction = QtWidgets.QAction("Insert row", self)
    insertRowAction.triggered.connect(lambda: table.insertRows(
        table.cellAt(cursor).row(), 1))  # self.insertRow)

    insertColAction = QtWidgets.QAction("Insert column", self)
    insertColAction.triggered.connect(lambda: table.insertColumns(
        table.cellAt(cursor).column(), 1))  #self.insertCol)

    mergeAction = QtWidgets.QAction("Merge cells", self)
    mergeAction.triggered.connect(lambda: table.mergeCells(cursor))

    # Only allow merging if there is a selection
    if not cursor.hasSelection():
        mergeAction.setEnabled(False)

    splitAction = QtWidgets.QAction("Split cells", self)

    cell = table.cellAt(cursor)

    # Only allow splitting if the current cell is larger
    # than a normal cell
    if cell.rowSpan() > 1 or cell.columnSpan() > 1:
        splitAction.triggered.connect(
            lambda: table.splitCell(cell.row(), cell.column(), 1, 1))
    else:
        splitAction.setEnabled(False)

    menu.addAction(appendRowAction)
    menu.addAction(appendColAction)

    menu.addSeparator()

    menu.addAction(removeRowAction)
    menu.addAction(removeColAction)

    menu.addSeparator()

    menu.addAction(insertRowAction)
    menu.addAction(insertColAction)

    menu.addSeparator()

    menu.addAction(mergeAction)
    menu.addAction(splitAction)

    # Convert the widget coordinates into global coordinates
    pos = self.text.mapToGlobal(pos)

    # Move the menu to the new position
    menu.move(pos)
    menu.show()
Esempio n. 6
0
    def context(self, pos):
        # Grab the cursor
        cursor = self.text.textCursor()

        # Grab the current table, if there is one
        table = cursor.currentTable()

        # Above will return 0 if there is no current table, in whcih case
        # we call the normal context menu. If there is a table, we create
        # our own context menu specific to table interaction
        if table:
            menu = QtWidgets.QMenu(self)

            appendRowAction = QtWidgets.QAction('Append row', self)
            appendRowAction.triggered.connect(lambda: table.appendRows(1))

            appendColAction = QtWidgets.QAction('Append column', self)
            appendColAction.triggered.connect(lambda: table.appendColumns(1))

            removeRowAction = QtWidgets.QAction('Remove row', self)
            removeRowAction.triggered.connect(self.removeRow)

            removeColAction = QtWidgets.QAction('Remove column', self)
            removeColAction.triggered.connect(self.removeCol)

            insertRowAction = QtWidgets.QAction('Insert row', self)
            insertRowAction.triggered.connect(self.insertRow)

            insertColAction = QtWidgets.QAction('Insert column', self)
            insertColAction.triggered.connect(self.insertCol)

            mergeAction = QtWidgets.QAction('Merge cells', self)
            mergeAction.triggered.connect(lambda: table.mergeCells(cursor))

            # Only allow merging if there is a selection
            if not cursor.hasSelection():
                mergeAction.setEnabled(False)

            splitAction = QtWidgets.QAction('Split cells', self)

            cell = table.cellAt(cursor)

            # Only allow splitting if the current cell is larger
            # than a normal cell
            if cell.rowSpan() > 1 or cell.columnSpan() > 1:
                splitAction.triggered.connect(
                    lambda: table.splitCell(cell.row(), cell.column(), 1, 1))
            else:
                splitAction.setEnabled(False)

            menu.addAction(appendRowAction)
            menu.addAction(appendColAction)

            menu.addSeparator()

            menu.addAction(removeRowAction)
            menu.addAction(removeColAction)

            menu.addSeparator()

            menu.addAction(insertRowAction)
            menu.addAction(insertColAction)

            menu.addSeparator()

            menu.addAction(mergeAction)
            menu.addAction(splitAction)

            # Convert the widget coordinates into global coordinates
            pos = self.mapToGlobal(pos)

            # Add pixels for the tool and formatbars, which are not included
            # in mapToGlobal(), but only if the two are currently visible and
            # not toggled by the user
            if self.toolbar.isVisible():
                pos.setY(pos.y() + 45)

            if self.formatbar.isVisible():
                pos.setY(pos.y() + 45)

            # Move the menu to the new position
            menu.move(pos)

            menu.show()
        else:
            # 기존 이벤트 실행
            event = QtGui.QContextMenuEvent(QtGui.QContextMenuEvent.Mouse,
                                            QtCore.QPoint())
            self.text.contextMenuEvent(event)
Esempio n. 7
0
    def context(self,pos):

        # Grab the cursor
        cursor = self.text.textCursor()

        # Grab the current table, if there is one
        table = cursor.currentTable()

        # Above will return 0 if there is no current table, in which case
        # we call the normal context menu. If there is a table, we create
        # our own context menu specific to table interaction
        if table:

            menu = QtGui.QMenu(self)

            appendRowAction = QtGui.QAction("Append row",self)
            appendRowAction.triggered.connect(lambda: table.appendRows(1))

            appendColAction = QtGui.QAction("Append column",self)
            appendColAction.triggered.connect(lambda: table.appendColumns(1))


            removeRowAction = QtGui.QAction("Remove row",self)
            removeRowAction.triggered.connect(self.removeRow)

            removeColAction = QtGui.QAction("Remove column",self)
            removeColAction.triggered.connect(self.removeCol)


            insertRowAction = QtGui.QAction("Insert row",self)
            insertRowAction.triggered.connect(self.insertRow)

            insertColAction = QtGui.QAction("Insert column",self)
            insertColAction.triggered.connect(self.insertCol)


            mergeAction = QtGui.QAction("Merge cells",self)
            mergeAction.triggered.connect(lambda: table.mergeCells(cursor))

            # Only allow merging if there is a selection
            if not cursor.hasSelection():
                mergeAction.setEnabled(False)


            splitAction = QtGui.QAction("Split cells",self)

            cell = table.cellAt(cursor)

            # Only allow splitting if the current cell is larger
            # than a normal cell
            if cell.rowSpan() > 1 or cell.columnSpan() > 1:

                splitAction.triggered.connect(lambda: table.splitCell(cell.row(),cell.column(),1,1))

            else:
                splitAction.setEnabled(False)


            menu.addAction(appendRowAction)
            menu.addAction(appendColAction)

            menu.addSeparator()

            menu.addAction(removeRowAction)
            menu.addAction(removeColAction)

            menu.addSeparator()

            menu.addAction(insertRowAction)
            menu.addAction(insertColAction)

            menu.addSeparator()

            menu.addAction(mergeAction)
            menu.addAction(splitAction)

            # Convert the widget coordinates into global coordinates
            pos = self.mapToGlobal(pos)

            # Add pixels for the tool and formatbars, which are not included
            # in mapToGlobal(), but only if the two are currently visible and
            # not toggled by the user

            if self.toolbar.isVisible():
                pos.setY(pos.y() + 45)

            if self.formatbar.isVisible():
                pos.setY(pos.y() + 45)
                
            # Move the menu to the new position
            menu.move(pos)

            menu.show()

        else:

            event = QtGui.QContextMenuEvent(QtGui.QContextMenuEvent.Mouse,QtCore.QPoint())

            self.text.contextMenuEvent(event)