Пример #1
0
 def append(self, text):
     """Append line to the end
     """
     cursor = QTextCursor(self._doc)
     cursor.movePosition(QTextCursor.End)
     cursor.insertBlock()
     cursor.insertText(text)
Пример #2
0
 def append(self, text):
     """Append line to the end
     """
     cursor = QTextCursor(self._doc)
     cursor.movePosition(QTextCursor.End)
     cursor.insertBlock()
     cursor.insertText(text)
Пример #3
0
 def put_some_text_in(self):
     c = QTextCursor(self.text.document())
     c.insertText("sat")
     c.insertBlock()
     c.insertImage(self.load_an_image(), 'image')
     c.insertBlock()
     c.insertText("unsat")
     # Move back to head of document
     self.text.setTextCursor(QTextCursor(self.text.document()))
Пример #4
0
    def insert(self, index, text):
        """Insert line to the document
        """
        if index < 0 or index > self._doc.blockCount():
            raise IndexError('Invalid block index', index)

        if index == 0:  # first
            cursor = QTextCursor(self._doc.firstBlock())
            cursor.insertText(text)
            cursor.insertBlock()
        elif index != self._doc.blockCount():  # not the last
            cursor = QTextCursor(self._doc.findBlockByNumber(index).previous())
            cursor.movePosition(QTextCursor.EndOfBlock)
            cursor.insertBlock()
            cursor.insertText(text)
        else:  # last append to the end
            self.append(text)
Пример #5
0
    def insert(self, index, text):
        """Insert line to the document
        """
        if index < 0 or index > self._doc.blockCount():
            raise IndexError('Invalid block index', index)

        if index == 0:  # first
            cursor = QTextCursor(self._doc.firstBlock())
            cursor.insertText(text)
            cursor.insertBlock()
        elif index != self._doc.blockCount():  # not the last
            cursor = QTextCursor(self._doc.findBlockByNumber(index).previous())
            cursor.movePosition(QTextCursor.EndOfBlock)
            cursor.insertBlock()
            cursor.insertText(text)
        else:  # last append to the end
            self.append(text)
Пример #6
0
    def printDocument2(self):
        dialog = QPrintDialog()
        if not dialog.exec_():
            return
        self.printer = dialog.printer()
        headFormat = QTextBlockFormat()
        headFormat.setAlignment(Qt.AlignLeft)
        headFormat.setTextIndent(
            self.printer.pageRect().width()-216)
        bodyFormat = QTextBlockFormat()
        bodyFormat.setAlignment(Qt.AlignJustify)
        lastParaBodyFormat = QTextBlockFormat(bodyFormat)
        lastParaBodyFormat.setPageBreakPolicy(QTextFormat.PageBreak_AlwaysAfter)
        rightBodyFormat = QTextBlockFormat()
        rightBodyFormat.setAlignment(Qt.AlignRight)
        headCharFormat = QTextCharFormat()
        headCharFormat.setFont(QFont("Helvetica",10))
        bodyCharFormat = QTextCharFormat()
        bodyCharFormat.setFont(QFont("Times",11))
        redBodyCharFormat = QTextCharFormat(bodyCharFormat)
        redBodyCharFormat.setForeground(Qt.red)
        tableFormat = QTextTableFormat()
        tableFormat.setBorder(1)
        tableFormat.setCellPadding(2)
        
        document = QTextDocument()
        cursor = QTextCursor(document)
        mainFrame = cursor.currentFrame()
        page = 1
        
        cursor.insertBlock(headFormat, headCharFormat)
        
        for text in ("Greasy Hands Ltd.", "New Lombard Street","London" , "WC13", QDate.currentDate().toString(self.DATE_FORMAT)):
            cursor.insertBlock(headFormat,headCharFormat)
            cursor.insertText(text)
        
        cursor.insertBlock(bodyFormat,bodyCharFormat)
        cursor.insertText("Barrio Francisco Meza")
        
        
        cursor.insertBlock(bodyFormat)
        cursor.insertBlock(bodyFormat,bodyCharFormat)
        cursor.insertText("Dear Lyuis")
        cursor.insertBlock(bodyFormat)
        cursor.insertBlock(bodyFormat,bodyCharFormat)
        cursor.insertText(QString("The balance of your account is $ %L1.").arg(float(500.987),0,"f",2))
        
        cursor.insertBlock(bodyFormat,redBodyCharFormat)
        cursor.insertText("Please remit the amount")
        
        cursor.insertBlock(bodyFormat,bodyCharFormat)
        cursor.insertText("Transaction")

        transactions = [
                        (QDate.currentDate(),500),
                        (QDate.currentDate(),500),
                        (QDate.currentDate(),-500),
                        (QDate.currentDate(),500)
                        ]
        
        
        table = cursor.insertTable(len(transactions), 3, tableFormat)
        
        row = 0
        for date, amount in transactions:
            cellCursor = table.cellAt(row,0).firstCursorPosition()
            cellCursor.setBlockFormat(rightBodyFormat)
            cellCursor.insertText(date.toString(self.DATE_FORMAT),bodyCharFormat)
            
            cellCursor = table.cellAt(row,1).firstCursorPosition()
            cellCursor.insertText("Credit",bodyCharFormat)
            
            cellCursor = table.cellAt(row,2).firstCursorPosition()
            cellCursor.setBlockFormat(rightBodyFormat)
            
            cellCursor.insertText(QString("The balance of your account is $ %L1.").arg(float(amount),0,"f",2),redBodyCharFormat)
            
            row += 1
            
        cursor.setPosition(mainFrame.lastPosition())
        cursor.insertBlock(bodyFormat,bodyCharFormat)
        cursor.insertText("We hope")
        document.print_(self.printer)
Пример #7
0
    def printDocument2(self):
        dialog = QPrintDialog()
        if not dialog.exec_():
            return
        self.printer = dialog.printer()
        headFormat = QTextBlockFormat()
        headFormat.setAlignment(Qt.AlignLeft)
        headFormat.setTextIndent(self.printer.pageRect().width() - 216)
        bodyFormat = QTextBlockFormat()
        bodyFormat.setAlignment(Qt.AlignJustify)
        lastParaBodyFormat = QTextBlockFormat(bodyFormat)
        lastParaBodyFormat.setPageBreakPolicy(
            QTextFormat.PageBreak_AlwaysAfter)
        rightBodyFormat = QTextBlockFormat()
        rightBodyFormat.setAlignment(Qt.AlignRight)
        headCharFormat = QTextCharFormat()
        headCharFormat.setFont(QFont("Helvetica", 10))
        bodyCharFormat = QTextCharFormat()
        bodyCharFormat.setFont(QFont("Times", 11))
        redBodyCharFormat = QTextCharFormat(bodyCharFormat)
        redBodyCharFormat.setForeground(Qt.red)
        tableFormat = QTextTableFormat()
        tableFormat.setBorder(1)
        tableFormat.setCellPadding(2)

        document = QTextDocument()
        cursor = QTextCursor(document)
        mainFrame = cursor.currentFrame()
        page = 1

        cursor.insertBlock(headFormat, headCharFormat)

        for text in ("Greasy Hands Ltd.", "New Lombard Street", "London",
                     "WC13", QDate.currentDate().toString(self.DATE_FORMAT)):
            cursor.insertBlock(headFormat, headCharFormat)
            cursor.insertText(text)

        cursor.insertBlock(bodyFormat, bodyCharFormat)
        cursor.insertText("Barrio Francisco Meza")

        cursor.insertBlock(bodyFormat)
        cursor.insertBlock(bodyFormat, bodyCharFormat)
        cursor.insertText("Dear Lyuis")
        cursor.insertBlock(bodyFormat)
        cursor.insertBlock(bodyFormat, bodyCharFormat)
        cursor.insertText(
            QString("The balance of your account is $ %L1.").arg(
                float(500.987), 0, "f", 2))

        cursor.insertBlock(bodyFormat, redBodyCharFormat)
        cursor.insertText("Please remit the amount")

        cursor.insertBlock(bodyFormat, bodyCharFormat)
        cursor.insertText("Transaction")

        transactions = [(QDate.currentDate(), 500), (QDate.currentDate(), 500),
                        (QDate.currentDate(), -500),
                        (QDate.currentDate(), 500)]

        table = cursor.insertTable(len(transactions), 3, tableFormat)

        row = 0
        for date, amount in transactions:
            cellCursor = table.cellAt(row, 0).firstCursorPosition()
            cellCursor.setBlockFormat(rightBodyFormat)
            cellCursor.insertText(date.toString(self.DATE_FORMAT),
                                  bodyCharFormat)

            cellCursor = table.cellAt(row, 1).firstCursorPosition()
            cellCursor.insertText("Credit", bodyCharFormat)

            cellCursor = table.cellAt(row, 2).firstCursorPosition()
            cellCursor.setBlockFormat(rightBodyFormat)

            cellCursor.insertText(
                QString("The balance of your account is $ %L1.").arg(
                    float(amount), 0, "f", 2), redBodyCharFormat)

            row += 1

        cursor.setPosition(mainFrame.lastPosition())
        cursor.insertBlock(bodyFormat, bodyCharFormat)
        cursor.insertText("We hope")
        document.print_(self.printer)