format code with black

This commit is contained in:
2023-08-29 23:50:34 +02:00
parent 88d855a951
commit c219fa61ba
30 changed files with 1514 additions and 1124 deletions

View File

@@ -10,35 +10,41 @@ from PIL import Image, ImageDraw, ImageFont
from .barcode_helpers import BrotherLabelWriter
def print_name_label(text, margin=10, rotate=False, label_type="62", printer_type="QL-700",):
def print_name_label(
text,
margin=10,
rotate=False,
label_type="62",
printer_type="QL-700",
):
if not rotate:
width, height = label_type_specs[label_type]['dots_printable']
width, height = label_type_specs[label_type]["dots_printable"]
else:
height, width = label_type_specs[label_type]['dots_printable']
height, width = label_type_specs[label_type]["dots_printable"]
font_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ChopinScript.ttf")
fs = 2000
tw, th = width, height
if width == 0:
while th + 2*margin > height:
while th + 2 * margin > height:
font = ImageFont.truetype(font_path, fs)
tw, th = font.getsize(text)
fs -= 1
width = tw+2*margin
width = tw + 2 * margin
elif height == 0:
while tw + 2*margin > width:
while tw + 2 * margin > width:
font = ImageFont.truetype(font_path, fs)
tw, th = font.getsize(text)
fs -= 1
height = th+2*margin
height = th + 2 * margin
else:
while tw + 2*margin > width or th + 2*margin > height:
while tw + 2 * margin > width or th + 2 * margin > height:
font = ImageFont.truetype(font_path, fs)
tw, th = font.getsize(text)
fs -= 1
xp = (width//2)-(tw//2)
yp = (height//2)-(th//2)
xp = (width // 2) - (tw // 2)
yp = (height // 2) - (th // 2)
im = Image.new("RGB", (width, height), (255, 255, 255))
dr = ImageDraw.Draw(im)
@@ -55,8 +61,14 @@ def print_name_label(text, margin=10, rotate=False, label_type="62", printer_typ
print_image(fn, printer_type, label_type)
def print_bar_code(barcode_value, barcode_text, barcode_type="ean13", rotate=False, printer_type="QL-700",
label_type="62"):
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, text=barcode_text, max_height=1000)
@@ -72,12 +84,12 @@ def print_image(fn, printer_type="QL-700", label_type="62"):
create_label(qlr, fn, label_type, threshold=70, cut=True)
be = backend_factory("pyusb")
list_available_devices = be['list_available_devices']
BrotherQLBackend = be['backend_class']
list_available_devices = be["list_available_devices"]
BrotherQLBackend = be["backend_class"]
ad = list_available_devices()
assert ad
string_descr = ad[0]['string_descr']
string_descr = ad[0]["string_descr"]
printer = BrotherQLBackend(string_descr)