treewide: fix brother-ql usage

This commit is contained in:
2025-03-19 18:47:16 +01:00
parent b85a6535fe
commit 4bab5e7e21
4 changed files with 16 additions and 10 deletions

View File

@@ -2,7 +2,7 @@ import os
from PIL import ImageFont
from barcode.writer import ImageWriter, mm2px
from brother_ql.devicedependent import label_type_specs
from brother_ql.labels import ALL_LABELS
def px2mm(px, dpi=300):
@@ -12,14 +12,15 @@ def px2mm(px, dpi=300):
class BrotherLabelWriter(ImageWriter):
def __init__(self, typ="62", max_height=350, rot=False, text=None):
super(BrotherLabelWriter, self).__init__()
assert typ in label_type_specs
label = next([l for l in ALL_LABELS if l.identifier == typ])
assert label is not None
self.rot = rot
if self.rot:
self._h, self._w = label_type_specs[typ]["dots_printable"]
self._h, self._w = label.dots_printable
if self._w == 0 or self._w > max_height:
self._w = min(max_height, self._h / 2)
else:
self._w, self._h = label_type_specs[typ]["dots_printable"]
self._w, self._h = label.dots_printable
if self._h == 0 or self._h > max_height:
self._h = min(max_height, self._w / 2)
self._xo = 0.0

View File

@@ -2,9 +2,10 @@ import os
import datetime
import barcode
from brother_ql import BrotherQLRaster, create_label
from brother_ql.brother_ql_create import create_label
from brother_ql.raster import BrotherQLRaster
from brother_ql.backends import backend_factory
from brother_ql.devicedependent import label_type_specs
from brother_ql.labels import ALL_LABELS
from PIL import Image, ImageDraw, ImageFont
from .barcode_helpers import BrotherLabelWriter
@@ -17,10 +18,11 @@ def print_name_label(
label_type="62",
printer_type="QL-700",
):
label = next([l for l in ALL_LABELS if l.identifier == label_type])
if not rotate:
width, height = label_type_specs[label_type]["dots_printable"]
width, height = label.dots_printable
else:
height, width = label_type_specs[label_type]["dots_printable"]
height, width = label.dots_printable
font_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ChopinScript.ttf")
fs = 2000

View File

@@ -9,6 +9,10 @@ python3Packages.buildPythonApplication {
format = "pyproject";
# brother-ql is breaky breaky
# https://github.com/NixOS/nixpkgs/issues/285234
dontCheckRuntimeDeps = true;
nativeBuildInputs = with python3Packages; [ setuptools ];
propagatedBuildInputs = with python3Packages; [
brother-ql

View File

@@ -13,7 +13,7 @@ classifiers = [
]
dependencies = [
"SQLAlchemy >= 2.0, <2.1",
# "brother-ql",
"brother-ql",
"matplotlib",
"psycopg2 >= 2.8, <2.10",
"python-barcode",
@@ -31,4 +31,3 @@ line-length = 100
[tool.ruff]
line-length = 100