Ejemplo n.º 1
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()
Ejemplo n.º 2
0
 def list(self):
     printer = []
     printer_info = QPrinterInfo()
     for item in printer_info.availablePrinters():
         printer.append(item.printerName())
     print("printer list:", printer)
     return printer
Ejemplo n.º 3
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())
Ejemplo n.º 4
0
 def getPrinterList(self):
     printer = []
     printerInfo = QPrinterInfo()
     for item in printerInfo.availablePrinters():
         printer.append(item.printerName())
         logprint("--availablePrinterName --" + str(item.printerName()))
     return str.join(",", printer)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
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
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
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())
Ejemplo n.º 9
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()
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
def printOrder(request):
    app = QApplication(sys.argv)
    data_url=request.POST.get('data_url')
    new_data_url=data_url.replace('data:image/png;base64,', '')
    # print(new_data_url)
    p = "DL-581PW"  # 打印机名称
    # Printer.printing(p, html)
    # Printer.printerList()
    printer = Printer()
    printerInfo = QPrinterInfo()
    printer.print_(new_data_url)
    # printing_22(request,p,  new_data_url)
    # sys.exit(app.exec_())
    return HttpResponse(json.dumps({'result':'ok'}))
Ejemplo n.º 12
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()
Ejemplo n.º 13
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)  # 指定打印所使用的装置
Ejemplo n.º 14
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)
     '''
Ejemplo n.º 15
0
    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()
Ejemplo n.º 16
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)
Ejemplo n.º 17
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()
Ejemplo n.º 18
0
 def printerList(self):
     printer = []
     printerInfo = QPrinterInfo()
     for item in printerInfo.availablePrinters():
         printer.append(item.printerName())
     return printer
Ejemplo n.º 19
0
class Printer:


# 打印机列表
@staticmethod
def printerList():
    printer = []


printerInfo = QPrinterInfo()
print('availablePrinterNames', printerInfo.availablePrinterNames())
print('defaultPrinterName', printerInfo.defaultPrinterName())

for item in printerInfo.availablePrinters():
    printer.append(item.printerName())
return printer


# 打印任务
@staticmethod
def printing(printer, context):


p = QPrinter()

doc = QTextDocument()

htmlStr = context
print('aaaa', htmlStr)
doc.setHtml(htmlStr)
doc.setPageSize(QSizeF(p.logicalDpiX() * (80 / 25.4),
                       p.logicalDpiY() * (297 / 25.4)))
p.setOutputFormat(QPrinter.NativeFormat)
doc.print_(p)


@staticmethod
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)

if __name__ == '__main__':
    import sys
from PyQt5.QtWidgets import QApplication


app = QApplication(sys.argv)
##########################################
html = '<html><head></head><body><h1>55555</h1><b>bold</b></body></html>'
p = "defaultPrinter"  # 打印机名称
# Printer.printing(p, html)
# Printer.printerList()
Printer.printing_22(p, html)

#####################################################
sys.exit(app.exec_())
Ejemplo n.º 20
0
def printing_22(printer, context):
    printerInfo = QPrinterInfo()
Ejemplo n.º 21
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()
Ejemplo n.º 22
0
 def print_imag(self):
     printerInfo = QPrinterInfo()
     p = QPrinter()
     for item in printerInfo.availablePrinters():
         if printer == item.printerName():
             p = QPrinter(item)