micetoilet-labelgen/shimatta_label/brother_ql_wrapper.py

22 lines
714 B
Python

import subprocess, os
class BrotherQlPrinter():
def __init__(self, model='QL-800', printer_connection='usb://0x04f9:0x209b'):
self.model = model
self.printer = printer_connection
def print_image(self, image, label='12', rotation=90, cut=True):
env_vars = os.environ
env_vars['BROTHER_QL_MODEL'] = self.model
env_vars['BROTHER_QL_PRINTER'] = self.printer
cutstr = ''
cmdline = ['brother_ql', 'print', '-l', f'{label}', '-r', f'{rotation}']
if not cut:
cmdline.append('--no-cut')
cmdline.append(f'{image}')
print(cmdline)
res = subprocess.run(cmdline, env=env_vars)
return res.returncode