From 806c9c35162e26e45e284b7c7ea92a74326c96b6 Mon Sep 17 00:00:00 2001 From: Christoffer Viken Date: Tue, 21 Mar 2017 21:08:19 +0000 Subject: [PATCH] No idae what happened, but rotate in PIL instead of brother --- barcode_helpers.py | 10 ++++++---- printer_helpers.py | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/barcode_helpers.py b/barcode_helpers.py index b25947c..27c2bf5 100644 --- a/barcode_helpers.py +++ b/barcode_helpers.py @@ -8,14 +8,14 @@ def px2mm(px, dpi=300): class BrotherLabelWriter(ImageWriter): - def __init__(self, typ='62', max_height=350, rot=0, text=None): + def __init__(self, typ='62', max_height=350, rot=False, text=None): super(BrotherLabelWriter, self).__init__() assert typ in label_type_specs - if (rot//90) % 2 == 1: + if self.rot: self._h, self._w = label_type_specs[typ]['dots_printable'] if self._w == 0 or self._w > max_height: self._w = max_height - if (rot//90) % 2 == 0: + else: self._w, self._h = label_type_specs[typ]['dots_printable'] if self._h == 0 or self._h > max_height: self._h = max_height @@ -28,7 +28,7 @@ class BrotherLabelWriter(ImageWriter): super(BrotherLabelWriter, self)._init(code) def calculate_size(self, modules_per_line, number_of_lines, dpi=300): - x, y = super(self).calculate_size(modules_per_line, number_of_lines, dpi) + x, y = super(BrotherLabelWriter, self).calculate_size(modules_per_line, number_of_lines, dpi) self._xo = (px2mm(self._w)-px2mm(x))/2 self._yo = (px2mm(self._h)-px2mm(y)) @@ -44,6 +44,8 @@ class BrotherLabelWriter(ImageWriter): super(BrotherLabelWriter, self)._paint_text(xpos+self._xo, ypos+self._yo) def _finish(self): + if self.rot: + self._image.rotate(90) if self._title: width = self._w+1 height = 0 diff --git a/printer_helpers.py b/printer_helpers.py index 96a4abb..7e3011a 100644 --- a/printer_helpers.py +++ b/printer_helpers.py @@ -9,17 +9,17 @@ from barcode_helpers import BrotherLabelWriter def print_bar_code(barcode_value, barcode_text, barcode_type="ean13", rotate=False, printer_type="QL-700", label_type="62"): bar_coder = barcode.get_barcode_class(barcode_type) - wr = BrotherLabelWriter(typ=label_type, rot=rotate*90, text=barcode_text, max_height=1000) + wr = BrotherLabelWriter(typ=label_type, rot=rotate, text=barcode_text, max_height=1000) test = bar_coder(barcode_value, writer=wr) fn = test.save(barcode_value) - print_image(fn, printer_type, label_type, rotate*90) + print_image(fn, printer_type, label_type) -def print_image(fn, printer_type="QL-700", label_type="62", rotate=0): +def print_image(fn, printer_type="QL-700", label_type="62"): qlr = BrotherQLRaster(printer_type) qlr.exception_on_warning = True - create_label(qlr, fn, label_type, threshold=70, cut=True, rotate=rotate) + create_label(qlr, fn, label_type, threshold=70, cut=True) be = backend_factory("pyusb") list_available_devices = be['list_available_devices']