micetoilet-labelgen/shimatta_label/brother_ql_wrapper.py

31 lines
1.0 KiB
Python
Raw Normal View History

2021-12-27 20:25:40 +01:00
import subprocess, os
2021-12-28 18:13:36 +01:00
from brother_ql.conversion import convert
from brother_ql.backends.helpers import send
from brother_ql.raster import BrotherQLRaster
2021-12-27 20:25:40 +01:00
class BrotherQlPrinter():
2021-12-28 18:13:36 +01:00
backend = 'pyusb'
2021-12-27 20:25:40 +01:00
2021-12-28 18:13:36 +01:00
def __init__(self, model='QL-800', printer_connection='usb://0x04f9:0x209b', label_format='12', red_label=False):
self.model = model
self.printer = printer_connection
self.label = label_format
self.red_label = red_label
def print_image(self, image, rotation='Auto', cut=True):
qlr = BrotherQLRaster(self.model)
qlr.exception_on_warning = True
instructions = convert(qlr=qlr,
images = [image],
label=self.label,
rotate = str(rotation),
threshold=70.0,
dither = False,
compress = False,
red = self.red_label,
dpi_600=False,
hq = True,
cut = cut
)
send(instructions=instructions, printer_identifier=self.printer, backend_identifier=self.backend, blocking=True)