print_storage_matrix_code.py 954 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/python
  2. import shimatta_label.label_image as li
  3. import shimatta_label.brother_ql_wrapper as ql_wrapper
  4. import sys
  5. import treepoem
  6. class DotmatrixLabel(li.Label):
  7. pixels_x = 120
  8. pixels_y = 106
  9. def put_matrix_code(self, qr):
  10. code = treepoem.generate_barcode('datamatrix', qr).convert('1')
  11. box = (int(self.pixels_x/2 -code.size[0]/2), int(self.pixels_y/2 - code.size[1]/2))
  12. self.img.paste(code, box=box)
  13. printer_model = 'QL-800'
  14. printer_connection = 'usb://0x04f9:0x209b'
  15. if len(sys.argv) >= 2:
  16. qr_data = sys.argv[1]
  17. else:
  18. qr_data = input('Scan QR Code: ')
  19. while qr_data:
  20. label = DotmatrixLabel()
  21. label.put_matrix_code(qr_data)
  22. #label.save('/tmp/foo.png')
  23. printer = ql_wrapper.BrotherQlPrinter(model=printer_model, printer_connection=printer_connection, label_format='12')
  24. printer.print_image(label.get_pillow_image(), cut=True, rotation=90)
  25. qr_data = input('Scan QR Code: ')