コード例 #1
0
ファイル: pl2_printer.py プロジェクト: zgp-github/mptool
 def list(self):
     printer = []
     printer_info = QPrinterInfo()
     for item in printer_info.availablePrinters():
         printer.append(item.printerName())
     print("printer list:", printer)
     return printer
コード例 #2
0
ファイル: RYB_PRINTER.py プロジェクト: shqk17/python
 def getPrinterList(self):
     printer = []
     printerInfo = QPrinterInfo()
     for item in printerInfo.availablePrinters():
         printer.append(item.printerName())
         logprint("--availablePrinterName --" + str(item.printerName()))
     return str.join(",", printer)
コード例 #3
0
 def getPrinter(self):
     printerInfo = QPrinterInfo()
     for item in printerInfo.availablePrinters():
         print(str(item.printerName()))
         if str(self.p) == str(item.printerName()):
             self.printer = QPrinter(item)
             break
コード例 #4
0
ファイル: printing.py プロジェクト: umlfri/umlfri2
 def __init__(self):
     if has_printing_support:
         self.__printer = QPrinter(QPrinterInfo.defaultPrinter())
         self.__can_print = any(QPrinterInfo.availablePrinters())
     else:
         self.__printer = None
         self.__can_print = False
コード例 #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()
コード例 #6
0
ファイル: RYB_Printing2.py プロジェクト: shqk17/python
    def printing(printer, context):
        print("当前打印机:" + str(printer))
        printerInfo = QPrinterInfo()
        p = QPrinter()
        for item in printerInfo.availablePrinters():
            if printer == str(item.printerName()):
                p = QPrinter(item)

        doc = QTextDocument()
        doc.setDocumentMargin(0)
        print('physicalDpiX:' + str(p.physicalDpiX()))
        print('resolution:' + str(p.resolution()))
        print('height:' + str(p.height()))
        print('width:' + str(p.width()))
        scale = p.physicalDpiX() / p.resolution()
        print('scale:' + str(scale))
        print('supportedResolutions:' + str(p.supportedResolutions()))
        print('logicalDpiX:' + str(p.logicalDpiX()))
        doc.setPageSize(
            QSizeF(p.logicalDpiX() * (p.width() / 25.4 / scale),
                   p.logicalDpiY() * (p.height() / 25.4 / scale)))
        doc.setHtml(context)
        # new_p = QPrinter()
        print("开始打印")
        p.setOutputFormat(QPrinter.NativeFormat)
        doc.print_(p)
コード例 #7
0
ファイル: RYB_Printing2.py プロジェクト: shqk17/python
 def getPrintList(self):
     printer = []
     printerInfo = QPrinterInfo()
     print('availablePrinterNames', printerInfo.availablePrinterNames())
     print('defaultPrinterName', printerInfo.defaultPrinterName())
     for item in printerInfo.availablePrinters():
         printer.append(item.printerName())
     return printer
コード例 #8
0
ファイル: RYB_Printing2.py プロジェクト: shqk17/python
 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()
コード例 #9
0
 def printing_22(printer, context):
     printerInfo = QPrinterInfo()
     p = QPrinter()
     for item in printerInfo.availablePrinters():
         if printer == item.printerName():
             p = QPrinter(item)
     doc = QTextDocument()
     doc.setHtml(u'%s' % context)
     doc.setPageSize(
         QSizeF(p.logicalDpiX() * (80 / 25.4),
                p.logicalDpiY() * (297 / 25.4)))
     p.setOutputFormat(QPrinter.NativeFormat)
     doc.print_(p)
コード例 #10
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()
コード例 #11
0
ファイル: RYB_Printing2.py プロジェクト: shqk17/python
 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)  # 指定打印所使用的装置
コード例 #12
0
 def printing(self, printer, context):
     printerInfo = QPrinterInfo()
     p = QPrinter()
     for item in printerInfo.availablePrinters():
         if printer == item.printerName():
             p = QPrinter(item, QPrinter.PrinterResolution)
     doc = QTextDocument()
     doc.setPlainText(context)
     #p.setPageSize(QPrinter.QPagedPaintDevice.A4)
     #doc.setPageSize(QSizeF(p.logicalDpiX()*(80/25.4),
     #                            p.logicalDpiY()*(297/25.4)))
     #
     #pagesize = QPrinter.QPagedPaintDevice.A4
     #p.setPageSize(pagesize)
     p.setOutputFormat(QPrinter.NativeFormat)
     doc.print_(p)
     '''
コード例 #13
0
ファイル: gcl_printer.py プロジェクト: zgp-github/mptool
    def printing(self, file):
        print("printer get file:", file)
        printer = self.gcl_printer
        printerInfo = QPrinterInfo()
        p = QPrinter()
        for item in printerInfo.availablePrinters():
            if printer == item.printerName():
                p = QPrinter(item)

        image = QImage()
        image.load(file)
        painter = QPainter()

        # set the printer DPI as 300(POSTEK G-3106)
        p.setResolution(300)
        painter.begin(p)
        painter.drawImage(0, 0, image)
        painter.end()
コード例 #14
0
 def printing_22(printer, context):
     printerInfo = QPrinterInfo()
     p = QPrinter()
     for item in printerInfo.availablePrinters():
         if printer == str(item.printerName()):
             p = QPrinter(item)
             doc = QTextDocument()
             font = doc.defaultFont()
             font.setBold(True)
             font.setPointSize(font.pointSize() + 1)
             doc.setDefaultFont(font)
             font.setPixelSize(5)
             # doc.setPageSize(QSizeF(p.logicalDpiX() * (88 / 25.4),
             #                        p.logicalDpiY() * (297 / 25.4)))
             # x是间距,数字越小间距越大 y是纵长度 越大长度越小
             doc.setPageSize(QSizeF(p.logicalDpiX() * (60 / 25.4), p.logicalDpiY() * (3500 / 25.4)))
             p.setOutputFormat(QPrinter.NativeFormat)
             doc.setHtml(u'%s' % context)
             doc.print_(p)
コード例 #15
0
    def printing(printer, context, log):
        print("selected_printer:" + str(printer))
        printerInfo = QPrinterInfo()
        p = QPrinter()
        for item in printerInfo.availablePrinters():
            if printer == str(item.printerName()):
                p = QPrinter(item)

        try:
            doc = QTextDocument()
            doc.setDocumentMargin(0)
            log.write(Printer.getTime() + "--physicalDpiX --" + str(p.physicalDpiX()) + "\n")
            print('physicalDpiX:' + str(p.physicalDpiX()))
            print('resolution:' + str(p.resolution()))
            log.write(Printer.getTime() + "--resolution --" + str(p.resolution()) + "\n")
            print('height:' + str(p.height()))
            log.write(Printer.getTime() + "--height --" + str(p.height()) + "\n")
            print('width:' + str(p.width()))
            log.write(Printer.getTime() + "--width --" + str(p.width()) + "\n")
            scale = round(p.physicalDpiX() / p.resolution(), 4)
            print('scale:' + str(scale))
            log.write(Printer.getTime() + "--scale --" + str(scale) + "\n")
            print('supportedResolutions:' + str(p.supportedResolutions()))
            log.write(Printer.getTime() + "--supportedResolutions --" + str(p.supportedResolutions()) + "\n")
            print('logicalDpiX:' + str(p.logicalDpiX()))
            log.write(Printer.getTime() + "--logicalDpiX --" + str(p.logicalDpiX()) + "\n")
            doc.setPageSize(
                QSizeF(p.logicalDpiX() * (p.width() / 25.4 / scale),
                       p.logicalDpiY() * (p.height() / 25.4 / scale)))
            doc.setHtml(context)
            print("starting print")
            p.setOutputFormat(QPrinter.NativeFormat)
            doc.print_(p)
        except Exception as ee:
            print(ee)
            log.write(Printer.getTime() + "***print - error****" + str(ee) + "\n")
            log.close()
コード例 #16
0
 def print_imag(self):
     printerInfo = QPrinterInfo()
     p = QPrinter()
     for item in printerInfo.availablePrinters():
         if printer == item.printerName():
             p = QPrinter(item)
コード例 #17
0
 def printerList(self):
     printer = []
     printerInfo = QPrinterInfo()
     for item in printerInfo.availablePrinters():
         printer.append(item.printerName())
     return printer
コード例 #18
0
 def availablePrinters(self):
   return QPrinterInfo.availablePrinters()