Esempio n. 1
0
    def __init__(self, parent=None):
        super(ProgramaImpressor, self).__init__(parent)
        rotuloNome = QtWidgets.QLabel("Nome: ")
        rotuloEndereco = QtWidgets.QLabel(u"Endereço: ")
        rotuloOutros = QtWidgets.QLabel("Diversos: ")
        self.impressor = QtPrintSupport.QPrinter()
        self.txtnome = QtWidgets.QLineEdit()
        self.txtendereco = QtWidgets.QLineEdit()
        self.txtdiversos = QtWidgets.QTextEdit()
        self.btnimprimir = QtWidgets.QPushButton("&Imprimir")
        layoutHorizontal = QtWidgets.QHBoxLayout()
        layoutHorizontal2 = QtWidgets.QHBoxLayout()
        layoutHorizontal3 = QtWidgets.QHBoxLayout()
        layoutVertical = QtWidgets.QVBoxLayout()
        layoutHorizontal.addWidget(rotuloNome)
        layoutHorizontal.addWidget(self.txtnome)
        layoutHorizontal2.addWidget(rotuloEndereco)
        layoutHorizontal2.addWidget(self.txtendereco)
        layoutHorizontal3.addWidget(rotuloOutros)
        layoutHorizontal3.addWidget(self.txtdiversos)
        layoutVertical.addLayout(layoutHorizontal)
        layoutVertical.addLayout(layoutHorizontal2)
        layoutVertical.addLayout(layoutHorizontal3)
        layoutVertical.addWidget(self.btnimprimir)
        self.setLayout(layoutVertical)

        self.dialogo = QtPrintSupport.QPrintPreviewDialog()
        self.html = u""
        self.documento = QWebEngineView()
        self.dialogo.paintRequested.connect(self.documento.print_)

        self.documento.loadFinished['bool'].connect(self.previaImpressao)
        self.btnimprimir.clicked.connect(self.imprimir)
Esempio n. 2
0
 def handle_preview_handler(self):
     """ """
     self.hide()
     dlg1 = P.QPrintPreviewDialog()
     dlg1.paintRequested.connect(self.handle_paint_request)
     dlg1.exec_()
     self.show()
Esempio n. 3
0
def printPreview(ui):
    printer = QtPrintSupport.QPrinter()
    dialog = QtPrintSupport.QPrintPreviewDialog(printer)
    dialog.paintRequested.connect(lambda:print(printer,ui))
    if( dialog.exec() == 0 ):
        return False
    else:
        return True
 def files(self, action):  # Function open/save files.
     fd = QtWidgets.QFileDialog()  # File dialog instance.
     if action.text() == "Open":  # For opening of the files.
         fdf = fd.getOpenFileNames(self,
                                   caption="Open Files",
                                   directory=QtCore.QDir.homePath())
         if len(fdf[0]) > 0:  # Checks if the file dialog
             self.text_edit.clear()  # has a selected files for
             for of in fdf[0]:  # open. Each file of the
                 self.tabwid.setCurrentIndex(2)  # selected will be open.
                 try:  # Will try to open file as
                     openf = open(of, 'r')  # simple .txt or .html and,
                     self.text_edit.append(str(openf.read()))
                     continue  # read content to text field.
                 except Exception:  # If successfull continue.
                     pass  # If unread or error - pass.
                 try:  # Try to open file in the
                     openf = open(of, 'rb')  # binary mode .py or other.
                     self.text_edit.append(str(openf.read()))
                 except Exception:  # Content to the field, if
                     pass  # error - pass (do nothing).
     if action.text() == "Save":  # For saving of the files.
         fdf = fd.getSaveFileName(self,
                                  caption="Save Files",
                                  directory=QtCore.QDir.homePath())
         if fdf[0] != "":  # Checks if files selected.
             self.tabwid.setCurrentIndex(2)  # Open TabWid with Text Field.
             try:  # Will try to save file as
                 open(fdf[0], 'w').write(self.text_edit.toPlainText())
                 success = True  # .txt file with plain text of
             except Exception:  # text field. And success is
                 pass  # True. An error - pass.
             if success != True:  # If file not saved as .txt
                 try:  # will try to save file in the
                     open(fdf[0], 'wb').write(self.text_edit.toPlainText())
                     success = True  # binary mode, as plain text.
                 except Exception:  # An exception - will pass.
                     pass  # If success is True will
             if success == True:  # shown information message.
                 self.info_message(fpath=fdf[0],
                                   txt="File saved as",
                                   types="info")
             else:  # If not True, critical.
                 self.info_message(fpath=fdf[0],
                                   txt="File don`t saved",
                                   types="critical")
     if action.text() == "Print":
         print_dialog = QtPrintSupport.QPrintDialog(self.print_device)
         if print_dialog.exec_() == QtWidgets.QDialog.Accepted:
             self.text_edit.print_(print_dialog.printer())
     if action.text() == "Print Preview":  # Print preview dialog.
         print_dialog = QtPrintSupport.QPrintPreviewDialog(
             self.print_device)
         print_dialog.setWindowTitle("Print Preview")
         print_dialog.setWindowIcon(QtGui.QIcon("Icons/python1.png"))
         print_dialog.paintRequested.connect(self.text_edit.print_)
         print_dialog.exec_()  # Executes dialog window.
 def previewCall(self):
     dialog = QtPrintSupport.QPrintPreviewDialog()
     dialog.paintRequested.connect(self.ui.textBrowser.print_)
     dialog.exec_()
Esempio n. 6
0
 def print(self):
     dialog = QtPrintSupport.QPrintPreviewDialog()
     dialog.paintRequested.connect(self.text_edit_widget.print_)
     dialog.exec_()