Apply formating, light linting

This commit is contained in:
n07070 committed 2026-11-13 19:51:32 +01:00
1 parent adb5e9422d
commit 070f037449
4 files changed
+74 -48

No files matched your search

+39 -33
View File
@@ -10,9 +10,9 @@ import time
from enum import Enum
import uuid
import threading
import usb.core
from pathlib import Path
from uuid import uuid4
import usb.core
from PIL import Image, ImageEnhance, ImageDraw, ImageFont
import numpy as np
@@ -124,7 +124,9 @@ class EscPosPrinter(Printer):
try:
# This also calls open(), which we need to close()
# or else the device will appear as busy.
p = escpos.printer.Usb(self.vendor_id, self.device_id, 0, profile=configuration_file["profile"])
p = escpos.printer.Usb(
self.vendor_id, self.device_id, 0, profile=configuration_file["profile"]
)
except escpos.exceptions.DeviceNotFoundError as e:
self.app.logger.error(
"The USB device is not plugged in : %s",
@@ -221,7 +223,8 @@ class EscPosPrinter(Printer):
raise RuntimeError(
"Could not print message of this length :"
+ str(len(clean_msg))
+ ", needs to be below %s caracters long.", str(self.configuration_file["text_max_length"])
+ ", needs to be below %s caracters long.",
str(self.configuration_file["text_max_length"]),
)
if len(signature) > int(self.configuration_file["signature_max_length"]):
self.app.logger.warning(
@@ -230,7 +233,8 @@ class EscPosPrinter(Printer):
raise RuntimeError(
"Could not print signature of this length :"
+ str(len(clean_signature))
+ ", needs to be below %s caracters long.", str(self.configuration_file["signature_max_length"])
+ ", needs to be below %s caracters long.",
str(self.configuration_file["signature_max_length"]),
)
# Do the actual printing
@@ -262,10 +266,10 @@ class EscPosPrinter(Printer):
raise RuntimeError(
"Could not print signature of this length :"
+ str(len(clean_signature))
+ ", needs to be below %s caracters long.", str(self.configuration_file["signature_max_length"])
+ ", needs to be below %s caracters long.",
str(self.configuration_file["signature_max_length"]),
)
if not os.path.isfile(str(path)):
self.app.logger.warning("File does not exist : " + str(path))
raise OSError(
@@ -310,9 +314,7 @@ class EscPosPrinter(Printer):
try:
self.printer.close()
except Exception as e:
self.app.logger.error(
"Could not close the printer connexion %s", str(e)
)
self.app.logger.error("Could not close the printer connexion %s", str(e))
raise RuntimeError("Could not close the printer connexion. ") from e
self.app.logger.info("Printed a picture")
@@ -456,7 +458,9 @@ class BrotherPrinter(Printer):
vendor_id=vendor_id,
product_id=self.device_id,
serial_number=serial_number,
label_type=configuration_file["label_type"], # TODO: Implement automatic label type detection : https://framagit.org/stickoeur/diagnostickoeur/-/blob/no-masters/printit.py?ref_type=heads#L239
label_type=configuration_file[
"label_type"
], # TODO: Implement automatic label type detection : https://framagit.org/stickoeur/diagnostickoeur/-/blob/no-masters/printit.py?ref_type=heads#L239
)
self.app.logger.debug("Created a Brother printer !")
self.ready = True
@@ -472,7 +476,12 @@ class BrotherPrinter(Printer):
self._print_img(text_to_image(msg))
self._print_img(text_to_image(signature))
def _print_img(self, data, signature="", process=False,):
def _print_img(
self,
data,
signature="",
process=False,
):
"""
Print a raster image via a Brother QL printer
"""
@@ -512,20 +521,20 @@ class BrotherPrinter(Printer):
# del be
instructions = convert(
qlr=qlr,
images=[im],
label=self.printer_info.label_type,
dither=True,
compress=False,
dpi_600=False,
cut=False,
)
qlr=qlr,
images=[im],
label=self.printer_info.label_type,
dither=True,
compress=False,
dpi_600=False,
cut=False,
)
success = send(
instructions=instructions,
printer_identifier=BACKEND_STRING_DESCR,
backend_identifier="pyusb",
blocking=False
blocking=False,
)
self.app.logger.debug(str(success))
@@ -534,7 +543,7 @@ class BrotherPrinter(Printer):
except usb.core.USBError as e:
if "timeout error" in str(e):
self.app.logger.error("USB Timeout Error %s", str(e) )
self.app.logger.error("USB Timeout Error %s", str(e))
except Exception as e:
raise e
# finally:
@@ -560,27 +569,25 @@ class BrotherPrinter(Printer):
# be.dispose()
# del be
instructions = convert(
qlr=qlr,
images=[signature_file],
label=self.printer_info.label_type,
dither=True,
compress=False,
dpi_600=False,
cut=False,
)
qlr=qlr,
images=[signature_file],
label=self.printer_info.label_type,
dither=True,
compress=False,
dpi_600=False,
cut=False,
)
success = send(
instructions=instructions,
printer_identifier=BACKEND_STRING_DESCR,
backend_identifier="pyusb",
blocking=False
blocking=False,
)
self.app.logger.debug(str(success))
self.app.logger.debug("Printed signature")
time.sleep(2)
except Exception as e:
raise e
finally:
@@ -619,7 +626,6 @@ class BrotherPrinter(Printer):
except Exception as e:
raise e
def _qr(self):
# This should not be reached by a print on a BrotherQL
raise NotImplementedError()