示例#1
1
 def _print(self):
     dialog = QPrintDialog(self)
     if dialog.exec_() != QPrintDialog.Accepted:
         return
     printer = dialog.printer()
     currentView = self.mainView.currentWidget()
     viewPrinter = ViewPrinter(printer, currentView)
     currentView.fitViewsForPrint(viewPrinter)
     viewPrinter.render()
示例#2
0
    def printHandler(self):

        # Open printing dialog
        dialog = QPrintDialog()

        if dialog.exec_() == QDialog.Accepted:
            self.noteContentEdit.document().print_(dialog.printer())
示例#3
0
 def printer(self):
     prnt_dialog = QPrintDialog(self)
     if not prnt_dialog.exec():
         prnt_dialog.deleteLater()
         return
     self.page().print(prnt_dialog.printer(),
                       lambda status: prnt_dialog.deleteLater())
示例#4
0
 def _print(self):
     dialog = QPrintDialog(self)
     if dialog.exec_() != QPrintDialog.Accepted:
         return
     printer = dialog.printer()
     currentView = self.mainView.currentWidget()
     viewPrinter = ViewPrinter(printer, currentView)
     currentView.fitViewsForPrint(viewPrinter)
     viewPrinter.render()
示例#5
0
 def on_print_requested(self, frame):
     """Handle printing when requested via javascript."""
     if not qtutils.check_print_compat():
         message.error(self._win_id, "Printing on Qt < 5.3.0 on Windows is "
                       "broken, please upgrade!", immediately=True)
         return
     printdiag = QPrintDialog()
     printdiag.setAttribute(Qt.WA_DeleteOnClose)
     printdiag.open(lambda: frame.print(printdiag.printer()))
示例#6
0
 def on_print_requested(self, frame):
     """Handle printing when requested via javascript."""
     if not qtutils.check_print_compat():
         message.error(self._win_id, "Printing on Qt < 5.3.0 on Windows is "
                       "broken, please upgrade!", immediately=True)
         return
     printdiag = QPrintDialog()
     printdiag.setAttribute(Qt.WA_DeleteOnClose)
     printdiag.open(lambda: frame.print(printdiag.printer()))
示例#7
0
    def print_proof(self):
        printer = QPrinter(96)
        printer.setOrientation(QPrinter.Landscape)
        printer.setOutputFileName('tmp.pdf')
        printer.setPageMargins(16, 12, 20, 12, QPrinter.Millimeter)

        text = "Date:\n{}\n\n".format(time.strftime("%d/%m/%Y"))
        text += "Address:\n{}\n\n".format(self.api.get_main_address())
        text += "Current Blockhash:\n{}".format(self.api.get_actual_hash())

        document = QTextDocument()
        document.setPageSize(QSizeF(printer.pageRect().size()))
        document.setDefaultFont(QFont("Arial", 30))
        document.setPlainText(text)

        dialog = QPrintDialog()
        if dialog.exec_() == QDialog.Accepted:
            dialog.printer().setOrientation(QPrinter.Landscape)
            document.print_(dialog.printer())
示例#8
0
 def printCsv(self):
     """
         This is used open the print diaglog to select the printer and
         other properties to print the csv file currently viewed
         or edited in the application
     :return: 
     """
     printer = QPrinter(QPrinter.HighResolution)
     dialog = QPrintDialog(printer,self)
     if dialog.exec_() == QPrintDialog.Accepted:
         self.handlePaintRequest(dialog.printer())
示例#9
0
    def print_func(self):
        from PyQt5.QtPrintSupport import QPrintDialog
        dialog = QPrintDialog()

        from PyQt5.QtGui import QTextDocument

        doc = QTextDocument()
        doc.setHtml(self.bill_html)

        if dialog.exec_() == QPrintDialog.Accepted:
            doc.print_(dialog.printer())
            self.history_class.MW.mess('Printing Done')
        else:
            self.history_class.MW.mess('Printing Rejected')
示例#10
0
    def printing_bill():
        from backend import CommonFunctions
        data_to_print = CommonFunctions().convert_to_bill(
            var.th_fetch_bill.bill_doc, var.th_fetch_bill.fetch_dict)

        from PyQt5.QtPrintSupport import QPrintDialog
        dialog = QPrintDialog()

        from PyQt5.QtGui import QTextDocument

        doc = QTextDocument()
        doc.setHtml(data_to_print)

        if dialog.exec_() == QPrintDialog.Accepted:
            doc.print_(dialog.printer())
            MW.mess('Printing Done')
        else:
            MW.mess('Printing Rejected')
示例#11
0
def printMessageTE(textEd):
    """ Print qtextedit or global widget,
        Uses QPrintDialog
    """

    debug = False
    if debug:
        print("  -- in printLog")

    printer = QPrinter()

    printer.Letter
    printer.HighResolution
    printer.Color

    anotherWidget = QPrintDialog(printer)
    if (anotherWidget.exec_() == QDialog.Accepted):
        textEd.document().print_(anotherWidget.printer())
    def prt_row_data(self):

        printdialog = QPrintDialog(self.printer, self)

        if QDialog.Accepted == printdialog.exec_():
            c = sqlite3.connect('cmdb.sqlite')
            cur = c.cursor()
            cur.execute(self.queryCondition2)
            test = cur.fetchall()
            template = Template("""
            <table border="1" cellspacing="0" cellpadding="2">
              <tr>
                <th>Auditor</th>
                <th>Rectification</th>
                <th>Date</th>
                <th>Document name</th>
                <th>Document number</th>
                <th>Situation</th>
                <th>Remarks</th>
              </tr> 
              {% for row in test %}
              <tr>
                <td> {{ row[1] if row[1] != None }}</td>
                <td max-width="50%"> {{ row[2] if row[2] != None }}</td>
                <td> {{ row[3] if row[3] != None }}</td>
                <td max-width="50%"> {{ row[4] if row[4] != None }}</td>
                <td> {{ row[5] if row[5] != None }}</td>
                <td> {{ row[6] if row[6] != None }}</td>
              </tr> 
              {% endfor %}
            </table>
            """)
            text = template.render(test=test)
            self.editor.setHtml(text)
            self.editor.document().print_(printdialog.printer())
            cur.close()
            c.close()
            QMessageBox.question(
                self, "Success",
                "The rectification opinion form has been submitted for printing!",
                QMessageBox.Ok)
def html_to_image(StrPrintHtml="", printer_name="", widthPage=300, heightPage=100, leftPage=-15, topPage=-15 ):
    """
    Функция вывода текста на принтер
    :param StrPrintHtml: - Текст HTML
    :param printer_name: - имя принтера
    :return:
    """
    requestMessage = {}
    try:
        app = QApplication(['mainApp'])
        printer = QPrinter()
        requestMessage = {}
        label = QLabel()
        # '<img width="300"  height="100"  alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALQAAAB2CAIAAADujy7aAAABuUlEQVR42u3YwY7CIBRAUZj4/7/MLEgIFlqf1YwOPWdlsKlVrlDNqVNKSSnlnNvjqo6MR47PjuP9OSNniJw/foWRa4tc7d45n32tyDvtRyLjkWuIfErjGX4S7BAH4kAciANxIA7EgTgQB+JAHCAOxIE4EAfiQByIA3EgDsQB4kAciANxIA7EgTgQB+JAHCAOxIE4EAfiQByIA3EgDsSBOEAciANxIA7EgTgQB+JAHIgDxIE4EAfiQByIA3EgDsSBOEAciANxIA7EgTgQB+JAHIgDcYA4EAfiQByIA3EgDsSBOBAHiANxIA7EgTgQB+JAHIgDcYA4EAfiQByIg0/LpRSfAlYOxMGb3FbbJvPdRplzbo/b+CuD/Ugbnw6K4+vKOA6lTuQrg5tZr684HbStfO+a8alX/PvLEMdjwSmZHtZvDW12T8zxSmVc6IZ0utT3c1n72JvdcXw6stKesuAN6d56ML1tnE726W9/fxvrhvR/7zX9FI5LyHgruvD2ccVt5WCpiM9u5MiVtpKL3nOcWPaX/z3y4O0v8z43X9/Nf1bT/7WmR6bD/7sOinn2d5M4sK0gDsQB4uDQLyTS/Ojjiz5LAAAAAElFTkSuQmCC" />'
        label.setText(StrPrintHtml)
        label.resize(int(widthPage), int(heightPage))
        printer = QPrinter()
        if printer_name == "":
            print_dialog = QPrintDialog(printer)
            if print_dialog.exec() != QDialog.Accepted:
                requestMessage["Error"] = "Printer no select"
                return requestMessage
            printer_name = print_dialog.printer().printerName()
            # printer_name = GetDefaultPrinter()
        printer.setPrinterName(printer_name)
        # printer.setPrinterName("Brother QL-810W")
        printer.setPageMargins(0, 0, 0, 0, QPrinter.DevicePixel)
        # printer.setOutputFileName("C:\\AppServ\\www\\QtPrint\\PrinterFileName.pdf")
        painter = QPainter()
        painter.begin(printer)
        painter.drawPixmap(int(leftPage),int(topPage), label.grab())
        painter.end()
    except Exception:
        requestMessage["Error"] = "%s" % (format_exc())
        return requestMessage
    return requestMessage
class App(QMainWindow):
    def __init__(self):
        super(App, self).__init__()
        self.mainUI()
        self.mainLayout()
        self.action()
        self.toolBarsSurvey()
        self.addToolBar(self.toolBarHome)
        self.addToolBar(self.toolBarForm)

    def mainUI(self):
        self.login = loginSurvey()
        self.form = formSurvey()
        self.result = Result()
        self.stackedLayout = QStackedLayout()
        self.stackedLayout.addWidget(self.login)
        self.stackedLayout.addWidget(self.form)
        self.stackedLayout.addWidget(self.result)
        self.stackedLayout.addWidget(self.chart())
        self.favoriteItem = ""

        self.form.comboBox1.activated.connect(self.valueCombo1)

    def mainLayout(self):
        self.layout = QWidget()
        self.layout.setLayout(self.stackedLayout)
        self.setCentralWidget(self.layout)

    def toolBarsSurvey(self):
        self.toolBarForm = QToolBar()
        buttonToolbar = QAction(QIcon("icon/market.png"), "test", self)
        self.toolBarForm.addAction(buttonToolbar)
        buttonToolbar.triggered.connect(self.tab_chart)

        self.toolBarHome = QToolBar()
        buttonToolbar = QAction(QIcon("icon/person.png"), "test", self)
        self.toolBarHome.addAction(buttonToolbar)
        buttonToolbar.triggered.connect(self.tab_home)

    def tab_chart(self):
        self.stackedLayout.setCurrentIndex(3)

    def tab_home(self):
        self.stackedLayout.setCurrentIndex(0)

    def getDataJson(self):
        with open('survey.json', 'r') as respon:
            data = json.load(respon)
        return data

    def chart(self):
        respon = requests.get(
            "https://res.cloudinary.com/sivadass/raw/upload/v1535817394/json/products.json"
        )
        json = respon.json()

        harga = list(map(lambda a: a['price'], json))
        barset0 = QBarSet("Harga Buah")
        for i in harga:
            barset0.append(i)

        series = QBarSeries()
        series.append(barset0)

        chart = QChart()
        chart.addSeries(series)
        chart.setAnimationOptions(QChart.SeriesAnimations)

        name = list(map(lambda a: a['name'], json))
        axisX = QBarCategoryAxis()
        axisX.append(name)

        axisY = QValueAxis()
        axisY.setRange(0, 200)

        chart.addAxis(axisX, Qt.AlignBottom)
        chart.addAxis(axisY, Qt.AlignLeft)
        chartView = QChartView(chart)
        chartView.setFixedSize(1200, 800)
        return chartView

    def valueCombo1(self, index):
        self.favoriteItem = self.form.comboBox1.itemText(index)

    def values(self):
        favoriteItem = self.favoriteItem
        kelengkapanStok = self.form.spinBox1.value()
        toilet = self.form.spinBox_2.value()
        rakMakanan = self.form.spinBox_3.value()
        rakBuah = self.form.spinBox_4.value()
        rakSusun = self.form.spinBox_5.value()
        refrigator = self.form.spinBox_6.value()
        lantaiToko = self.form.spinBox_7.value()
        lokasiStrategis = self.form.horizontalSlider1.value()
        saranMasukan = self.form.lineEdit.text()
        lahanParkir = ""
        if self.form.checkBox.isChecked():
            lahanParkir = self.form.checkBox.text()
        elif self.form.checkBox_2.isChecked():
            lahanParkir = self.form.checkBox_2.text()
        elif self.form.checkBox_3.isChecked():
            lahanParkir = self.form.checkBox_3.text()

        self.data = {
            "favorite_item": favoriteItem,
            "kelengkapan_stok": kelengkapanStok,
            "toilet": toilet,
            "rak_makanan": rakMakanan,
            "rak_buah": rakBuah,
            "rak_pecah_belah": rakSusun,
            "refrigator": refrigator,
            "lantai_toko": lantaiToko,
            "lokasi_strategis": lokasiStrategis,
            "lahan_parkir": lahanParkir,
            "saran_masukan": saranMasukan
        }

        return self.data

    def resultsResponse(self):
        data = self.values()
        Item = self.result.findChild(QLabel, "label_21")
        Item.setText(data["favorite_item"])
        Stok = self.result.findChild(QLabel, "label_22")
        Stok.setText(str(data["kelengkapan_stok"]))
        Toilet = self.result.findChild(QLabel, "label_2")
        Toilet.setText(str(data["toilet"]))
        RakMakanan = self.result.findChild(QLabel, "label_11")
        RakMakanan.setText(str(data["rak_makanan"]))
        RakBuah = self.result.findChild(QLabel, "label_16")
        RakBuah.setText(str(data["rak_buah"]))
        RakSusun = self.result.findChild(QLabel, "label_12")
        RakSusun.setText(str(data["rak_pecah_belah"]))
        Refrigator = self.result.findChild(QLabel, "label_13")
        Refrigator.setText(str(data["refrigator"]))
        LantaiToko = self.result.findChild(QLabel, "label_14")
        LantaiToko.setText(str(data["lantai_toko"]))
        LokasiStrategis = self.result.findChild(QLabel, "label_18")
        LokasiStrategis.setText(str(data["lokasi_strategis"]))
        lokasi = self.result.findChild(QLabel, "label_19")
        lokasi.setText(data["lahan_parkir"])
        saranMasukan = self.result.findChild(QLabel, "label_32")
        saranMasukan.setText(data["saran_masukan"])

    # show to login page

    def act_login(self):
        self.stackedLayout.setCurrentIndex(1)

    # show to form page

    def act_form(self):
        self.resultsResponse()
        self.stackedLayout.setCurrentIndex(2)

    def addToJson(self):
        data = self.values()
        toJson = json.dumps(data, indent=4)
        fwrite = open('survey.json', 'w')
        fwrite.write(toJson)
        QMessageBox.information(self, "About", "Survey Berhasil Di Export")

    # pdf print
    def getToPrint(self):
        data = self.values()
        text = """
                    Hasil Survey Supermarket 

            Item Favorite: {}
            Kelengkapan Stok: {}
            Toilet: {}
            Rak Makanan: {}
            Rak Buah: {}
            Rak Susun: {}
            Refrigator: {}
            Lantai Toko: {}
            Lokasi Strategis: {}
            Lahan Parkir: {}
            Saran Masukan Anda :{}

            Semoga Harimu Menyenangkan 
        """.format(data["favorite_item"], data["kelengkapan_stok"],
                   data["toilet"], data['rak_makanan'], data["rak_buah"],
                   data["rak_pecah_belah"], data["refrigator"],
                   data["lantai_toko"], data["lokasi_strategis"],
                   data["lahan_parkir"], data["saran_masukan"])
        self.textArea = QTextEdit()
        self.textArea.setText(text)
        self.button = QPushButton("Print")
        self.layout = QVBoxLayout()
        self.layout.addWidget(self.textArea)
        self.layout.addWidget(self.button)
        self.widget = QWidget()
        self.widget.setLayout(self.layout)
        self.setCentralWidget(self.widget)
        self.button.clicked.connect(self.printTo)

    # print dialog
    def printTo(self):
        self.printer = QPrinter()
        self.dialog = QPrintDialog(self.printer)
        if self.dialog.exec_() == QDialog.Accepted:
            self.textArea.document().print_(self.dialog.printer())

    def action(self):
        self.username = self.login.findChild(QLineEdit, "lineEdit1")
        self.password = self.login.findChild(QLineEdit, "lineEdit_2")
        self.login.pushButton.clicked.connect(self.act_login)
        self.form.pushButton.clicked.connect(self.act_form)
        self.result.pushButton.clicked.connect(self.addToJson)
        btnPrint = self.result.findChild(QPushButton, "pushButton_2")
        btnPrint.clicked.connect(self.getToPrint)
示例#15
0
 def prints(self):
     # Метод печати
     dialog = QPrintDialog()
     if dialog.exec_() == QDialog.Accepted:
         self.NotePlace.document().print_(dialog.printer())
示例#16
0
 def file_print(self):
     dlg = QPrintDialog()
     if dlg.exec_():
         self.editor.print_(dlg.printer())
示例#17
0
 def print_file(self):
     printDialog = QPrintDialog()
     if printDialog.exec_():
         self.editor.print_(printDialog.printer())
示例#18
0
 def handlePrint(self):
     dialog = QPrintDialog()
     dialog.setWindowFlags(Qt.WindowStaysOnTopHint)
     if dialog.exec_() == QDialog.Accepted:
         self.handlePaintRequest(dialog.printer())
示例#19
0
	def print_document(self):
		print_dialog = QPrintDialog()
		if print_dialog.exec_() == QDialog.Accepted:
			self.current_editor.document().print_(print_dialog.printer())
示例#20
0
 def Print(self):
     dialog = QPrintDialog()
     if dialog.exec_() == QDialog.Accepted:
         self.ui.textEdit.document().print_(dialog.printer())
示例#21
0
 def file_print(self):
     """Displays a print dialog for the text file."""
     print_dialog = QPrintDialog()
     if print_dialog.exec_():
         self.text_editor.print_(print_dialog.printer())
示例#22
0
    def save_to_pdf(self, filename):
        dialog = QPrintDialog()
        self.document().print_(dialog.printer())


# if __name__ == "__main__":
#     import sys
#
#     class Examination:
#         def __init__(self, patient, modality):
#             self.patient = patient
#             self.modality = modality
#             self.annotations = []
#
#         def add_annotation(self, annotation):
#             self.annotations += [annotation]
#
#         def get_annotation(self, annot_id):
#             for annot in self.annotations:
#                 if annot.annot_id == annot_id:
#                     return annot
#             return None
#
#     class Patient:
#         def __init__(self, first_name, last_name, age):
#             self.first_name = first_name
#             self.last_name = last_name
#             self.age = age
#
#     class Annotation:
#         def __init__(self, annot_id, location, finding, color):
#             self.location = location
#             self.finding = finding
#             self.color = color
#             self.annot_id = annot_id
#
#         def __str__(self):
#             return "Location: {}\n" \
#                    "Finding: {}\n" \
#                    "Annotation ID: {}".format(self.location, self.finding, self.annot_id)
#
#     class Window(QWidget):
#         def __init__(self):
#             super().__init__()
#
#             self.title = "PyQt5 Plain TextEdit"
#             self.top = 200
#             self.left = 500
#             self.width = 400
#             self.height = 300
#
#             self.InitWindow()
#
#         def InitWindow(self):
#             self.setWindowIcon(QtGui.QIcon("icon.png"))
#             self.setWindowTitle(self.title)
#             self.setGeometry(self.left, self.top, self.width, self.height)
#
#             vbox = QVBoxLayout()
#
#             patient = Patient("Nils", "Gehlin", 26)
#             exam = Examination(patient, "CT")
#             exam.add_annotation(Annotation(1, "Brain Parenchyma", "T2 hyperintense white matter lesions", (255, 0, 0)))
#             exam.add_annotation(Annotation(2, "Skull", "Huge fracture", (0, 255, 0)))
#             self.report = Report("radiologist", exam)
#             vbox.addWidget(self.report)
#             self.setLayout(vbox)
#             self.show()
#
#         def keyPressEvent(self, event):
#             print(event)
#             # Press S to save as pdf
#             if event.key() == 83:
#                 self.report.save_to_pdf("test_pdf.pdf")
#
#             # Press N to add a new dummy annotation dynamically
#             if event.key() == 78:
#                 self.report.examination.add_annotation(Annotation(3, "Heart", "Blown up", (0, 0, 255)))
#                 print(self.report.examination.annotations[-1])
#                 self.report.update()
#
#
#     App = QApplication(sys.argv)
#     window = Window()
#     sys.exit(App.exec())
示例#23
0
 def print(self):
     dialog = QPrintDialog()
     if dialog.exec_() == QDialog.Accepted:
         self.outputText.document().print_(dialog.printer())
示例#24
0
 def print_file(self):
     # Диалоговое окно выбора принтера и согласия печатания
     ask_printer = QPrintDialog()
     if ask_printer.exec():
         self.text_editor.print(ask_printer.printer())
示例#25
0
 def on_print_requested(self, frame):
     """Handle printing when requested via javascript."""
     printdiag = QPrintDialog()
     printdiag.setAttribute(Qt.WA_DeleteOnClose)
     printdiag.open(lambda: frame.print(printdiag.printer()))
示例#26
0
 def on_print_requested(self, frame):
     """Handle printing when requested via javascript."""
     printdiag = QPrintDialog()
     printdiag.setAttribute(Qt.WA_DeleteOnClose)
     printdiag.open(lambda: frame.print(printdiag.printer()))
示例#27
0
文件: assistant.py 项目: rhoef/afw
 def onPrint(self):
     #
     printer = QPrinter()
     dlg = QPrintDialog(printer, parent=self)
     if dlg.exec_() == dlg.Accepted:
         self.hbrowser.print_(dlg.printer())