Exemple #1
0
    def printerList():
        printer = []
        printerInfo = QPrinterInfo()
        print('availablePrinterNames', printerInfo.availablePrinterNames())
        print('defaultPrinterName', printerInfo.defaultPrinterName())

        for item in printerInfo.availablePrinters():
            printer.append(item.printerName())
        return printer, printerInfo.defaultPrinterName()
Exemple #2
0
 def getPrinter(p):
     printer = []
     printerInfo = QPrinterInfo()
     print('availablePrinterNames', printerInfo.availablePrinterNames())
     print('defaultPrinterName', printerInfo.defaultPrinterName())
     for item in printerInfo.availablePrinters():
         printer.append(item.printerName())
     if p in printer:
         print(p)
         return p
     else:
         print(printerInfo.defaultPrinterName())
         return printerInfo.defaultPrinterName()
Exemple #3
0
 def getPrinter(p):
     printer = []
     printerInfo = QPrinterInfo()
     print('availablePrinterNames', printerInfo.availablePrinterNames())
     print('defaultPrinterName', printerInfo.defaultPrinterName())
     for item in printerInfo.availablePrinters():
         printer.append(item.printerName())
         log.write(Printer.getTime() + "--availablePrinterName --" + str(item.printerName()))
     if p in printer:
         print(p)
         return p
     else:
         print(printerInfo.defaultPrinterName())
         log.write(Printer.getTime() + "--defaultPrinterName --" + str(printerInfo.defaultPrinterName()))
         return printerInfo.defaultPrinterName()
Exemple #4
0
    def init_component_content(self):
        # port
        list_port = serial.tools.list_ports.comports()
        for name in list_port:
            self.csm3510_comboBox_port.addItem(name[0])
            self.cc2640_comboBox_port.addItem(name[0])
            self.currenter_comboBox_port.addItem(name[0])
            # self.printer_name.addItem(name[0])

        list_baudrate = [9600, 1200, 4800, 14400, 19200, 28800, 57600, 115200]
        for bd in list_baudrate:
            self.csm3510_comboBox_baudrate.addItem(str(bd))
            self.cc2640_comboBox_baudrate.addItem(str(bd))
            self.currenter_comboBox_baudrate.addItem(str(bd))
            # self.printer_name.addItem(str(bd))
        self.cc2640_comboBox_baudrate.setCurrentText(str(list_baudrate[7]))

        list_dataBit = [8, 5, 6, 7]
        for len in list_dataBit:
            self.csm3510_comboBox_databits.addItem(str(len))
            self.cc2640_comboBox_databits.addItem(str(len))
            self.currenter_comboBox_databits.addItem(str(len))

        printerInfo = QPrinterInfo()
        self.set_green_text(self.printer_head_text)
        self.printer_name.setText("当前默认打印机:" +
                                  printerInfo.defaultPrinterName())
Exemple #5
0
    def print_img_info(str):
        print_Info = QPrinterInfo()
        printer_name = print_Info.defaultPrinterName()
        p = QPrinter()
        for item in print_Info.availablePrinters():
            if printer_name == item.printerName():
                p = QPrinter(item)
                print("匹配到打印机")
        painter = QPainter(p)
        qr_code.GeneateQRCode.gen_qr_code(str)

        image_info = Image.open("mac.png")
        image_logo = Image.open("logo.jpg")
        x, y = image_info.size
        print("resize_logo:", x, y)
        image_logo = image_logo.resize((x, y), Image.ANTIALIAS)

        pre_image = Image.new("RGBA", (2 * x, y))
        pre_image.paste(image_info, (0, 0))
        pre_image.paste(image_logo, (x, 0))
        pre_image.save("result.png")
        image = QImage()
        image.load("result.png")
        rect = painter.viewport()
        size = image.size()
        size.scale(rect.size(), Qt.KeepAspectRatio)
        painter.setViewport(rect.x(), rect.y(), size.width(), size.height())
        print(rect.x(), rect.y(), size.width(), size.height())
        painter.setWindow(image.rect())

        painter.drawImage(0, 0, image)
        painter.end()
Exemple #6
0
 def __init__(self, p):
     printer = []
     printerInfo = QPrinterInfo()
     print('availablePrinterNames', printerInfo.availablePrinterNames())
     print('defaultPrinterName', printerInfo.defaultPrinterName())
     if p is None or p == "":
         self.p = QPrinterInfo.defaultPrinter()
         self.print_device = QPrinter(self.p)
     else:
         for item in printerInfo.availablePrinters():
             printer.append(item.printerName())
         if p in printer:
             self.p = QPrinter(p)
         else:
             self.p = QPrinterInfo.defaultPrinter()
         self.print_device = QPrinter(self.p)  # 指定打印所使用的装置
Exemple #7
0
 def printer_btn_setting_clicked(self):
     pass
     printerInfo = QPrinterInfo()
     printer = printerInfo.defaultPrinter()
     setup = QPrintDialog()
     # /* 打印预览 */
     setup.show()
     #
     try:
         MyPrinter.print_img_info("mac: hello world")
     except Exception as e:
         print(str(e))
     print("正在打印测试信息.")
     # 更新默认打印机信息
     self.set_green_text(self.printer_head_text)
     printerInfo = QPrinterInfo()
     self.printer_name.setText("当前默认打印机:" +
                               printerInfo.defaultPrinterName())
Exemple #8
0
        print(p.physicalDpiX())
        print(p.physicalDpiY())

        p.setOutputFormat(QPrinter.NativeFormat)
        doc.print_(p)

    @staticmethod
    def print_imag(self):
        printerInfo = QPrinterInfo()
        p = QPrinter()
        for item in printerInfo.availablePrinters():
            if printer == item.printerName():
                p = QPrinter(item)
        # pImag =


if __name__ == '__main__':
    import sys
    from PyQt5.QtWidgets import QApplication
    app = QApplication(sys.argv)
    printerInfo = QPrinterInfo()
    printer_jh = Printer()
    printer_jh.printerList()
    p = printerInfo.defaultPrinterName()
    file = open("print.html", 'r')
    html = file.read()
    file.close()
    printer_jh.printing(p, html)
    print("printing ...... ")
    sys.exit(app.exec_())
    input()