brother_ql_wrapper.py 714 B

12345678910111213141516171819202122
  1. import subprocess, os
  2. class BrotherQlPrinter():
  3. def __init__(self, model='QL-800', printer_connection='usb://0x04f9:0x209b'):
  4. self.model = model
  5. self.printer = printer_connection
  6. def print_image(self, image, label='12', rotation=90, cut=True):
  7. env_vars = os.environ
  8. env_vars['BROTHER_QL_MODEL'] = self.model
  9. env_vars['BROTHER_QL_PRINTER'] = self.printer
  10. cutstr = ''
  11. cmdline = ['brother_ql', 'print', '-l', f'{label}', '-r', f'{rotation}']
  12. if not cut:
  13. cmdline.append('--no-cut')
  14. cmdline.append(f'{image}')
  15. print(cmdline)
  16. res = subprocess.run(cmdline, env=env_vars)
  17. return res.returncode