Compare commits
2 Commits
master
...
f2d3d99e8f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2d3d99e8f | ||
|
|
f9831f15c7 |
32
poetry.lock
generated
32
poetry.lock
generated
@@ -75,6 +75,25 @@ files = [
|
|||||||
{file = "blinker-1.9.0.tar.gz", hash = "sha256:b4ce2265a7abece45e7cc896e98dbebe6cead56bcf805a3d23136d145f5445bf"},
|
{file = "blinker-1.9.0.tar.gz", hash = "sha256:b4ce2265a7abece45e7cc896e98dbebe6cead56bcf805a3d23136d145f5445bf"},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "brother-ql-inventree"
|
||||||
|
version = "1.3"
|
||||||
|
description = "Python package to talk to Brother QL label printers"
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
groups = ["main"]
|
||||||
|
files = [
|
||||||
|
{file = "brother_ql_inventree-1.3-py3-none-any.whl", hash = "sha256:0f7e0d78bae04f44bcfe1010ed0d99f98d5b4db1d6179da242d5bd52bb0c9ea4"},
|
||||||
|
{file = "brother_ql_inventree-1.3.tar.gz", hash = "sha256:24335ca5f4b3444c692698b599459a7e6c4bd036dd580074c63d39382914fca3"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
attrs = "*"
|
||||||
|
click = "*"
|
||||||
|
packbits = "*"
|
||||||
|
pillow = ">=10.0.0"
|
||||||
|
pyusb = "*"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "certifi"
|
name = "certifi"
|
||||||
version = "2026.4.22"
|
version = "2026.4.22"
|
||||||
@@ -974,6 +993,17 @@ files = [
|
|||||||
{file = "packaging-26.2.tar.gz", hash = "sha256:ff452ff5a3e828ce110190feff1178bb1f2ea2281fa2075aadb987c2fb221661"},
|
{file = "packaging-26.2.tar.gz", hash = "sha256:ff452ff5a3e828ce110190feff1178bb1f2ea2281fa2075aadb987c2fb221661"},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "packbits"
|
||||||
|
version = "0.6"
|
||||||
|
description = "PackBits encoder/decoder"
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
groups = ["main"]
|
||||||
|
files = [
|
||||||
|
{file = "packbits-0.6.tar.gz", hash = "sha256:bc6b370bb34e04ac8cfa835e06c0484380affc6d593adb8009dd6c0f7bfff034"},
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pep8"
|
name = "pep8"
|
||||||
version = "1.7.1"
|
version = "1.7.1"
|
||||||
@@ -1853,4 +1883,4 @@ h11 = ">=0.16.0,<1"
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.1"
|
lock-version = "2.1"
|
||||||
python-versions = ">=3.14"
|
python-versions = ">=3.14"
|
||||||
content-hash = "fd3fb42c796aaaee4193f31df09bb4c74277855c489bf34a27c4bc1616851dfb"
|
content-hash = "18e1a5c8b085aa639b665279856f9e3c51a734a6a8d1d4dd135ca7e4f67e86ae"
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ dependencies = [
|
|||||||
"python-escpos (>=3.1,<4.0)",
|
"python-escpos (>=3.1,<4.0)",
|
||||||
"pep8 (>=1.7.1,<2.0.0)",
|
"pep8 (>=1.7.1,<2.0.0)",
|
||||||
"pylint (>=4.0.5,<5.0.0)",
|
"pylint (>=4.0.5,<5.0.0)",
|
||||||
|
"brother-ql-inventree (>=1.3,<2.0)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# Importing the module to manage the connection to the printer.
|
# Importing the module to manage the connection to the printer.
|
||||||
import escpos.printer as escp
|
import escpos.printer as escp
|
||||||
|
import brother-ql-inventree
|
||||||
from time import sleep, gmtime, strftime
|
from time import sleep, gmtime, strftime
|
||||||
import os.path
|
import os.path
|
||||||
from PIL import Image, ImageEnhance, ImageOps
|
from PIL import Image, ImageEnhance, ImageOps
|
||||||
@@ -286,3 +287,93 @@ def process_image(self, path):
|
|||||||
original_img.save(jpeg_path, format="JPEG", quality=95, optimize=True)
|
original_img.save(jpeg_path, format="JPEG", quality=95, optimize=True)
|
||||||
|
|
||||||
return jpeg_path
|
return jpeg_path
|
||||||
|
|
||||||
|
def discover_printers():
|
||||||
|
"""
|
||||||
|
We try to find all the connected printers ( 0 or n ) to this system.
|
||||||
|
|
||||||
|
For every type of supported printer, we try to autodiscover them.
|
||||||
|
|
||||||
|
http://www.linux-usb.org/usb.ids A list of USB vendor IDs
|
||||||
|
|
||||||
|
04b8 Seiko Epson Corp.
|
||||||
|
04f9 Brother Industries, Ltd
|
||||||
|
"""
|
||||||
|
|
||||||
|
def find_and_parse_borther_ql_printer():
|
||||||
|
|
||||||
|
|
||||||
|
## We might be able to no use this because there is a `discover` command in https://github.com/pklaus/brother_ql#usage
|
||||||
|
|
||||||
|
## Code stolen from https://framagit.org/stickoeur/diagnostickoeur/-/blob/no-masters/printit.py?ref_type=heads
|
||||||
|
|
||||||
|
"""Find and parse Brother QL printer information."""
|
||||||
|
|
||||||
|
model_manager = ModelsManager()
|
||||||
|
|
||||||
|
# Debug print to show we're searching
|
||||||
|
# print("Searching for Brother QL printer...")
|
||||||
|
|
||||||
|
for backend_name in ["pyusb", "linux_kernel"]:
|
||||||
|
try:
|
||||||
|
#print(f"Trying backend: {backend_name}")
|
||||||
|
backend = backend_factory(backend_name)
|
||||||
|
available_devices = backend["list_available_devices"]()
|
||||||
|
#print(f"Found {len(available_devices)} devices with {backend_name} backend")
|
||||||
|
|
||||||
|
for printer in available_devices:
|
||||||
|
#print(f"Found device: {printer}")
|
||||||
|
identifier = printer["identifier"]
|
||||||
|
parts = identifier.split("/")
|
||||||
|
|
||||||
|
if len(parts) < 4:
|
||||||
|
#print(f"Skipping device with invalid identifier format: {identifier}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
protocol = parts[0]
|
||||||
|
device_info = parts[2]
|
||||||
|
serial_number = parts[3]
|
||||||
|
|
||||||
|
try:
|
||||||
|
vendor_id, product_id = device_info.split(":")
|
||||||
|
except ValueError:
|
||||||
|
#print(f"Invalid device info format: {device_info}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Default model
|
||||||
|
model = "QL-570"
|
||||||
|
|
||||||
|
# Try to match product ID to determine actual model
|
||||||
|
try:
|
||||||
|
product_id_int = int(product_id, 16)
|
||||||
|
for m in model_manager.iter_elements():
|
||||||
|
if m.product_id == product_id_int:
|
||||||
|
model = m.identifier
|
||||||
|
break
|
||||||
|
#print(f"Matched printer model: {model}")
|
||||||
|
except ValueError:
|
||||||
|
#print(f"Invalid product ID format: {product_id}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
printer_info = {
|
||||||
|
"identifier": identifier,
|
||||||
|
"backend": backend_name,
|
||||||
|
"model": model,
|
||||||
|
"protocol": protocol,
|
||||||
|
"vendor_id": vendor_id,
|
||||||
|
"product_id": product_id,
|
||||||
|
"serial_number": serial_number,
|
||||||
|
}
|
||||||
|
#print(f"Found printer: {printer_info}")
|
||||||
|
return printer_info
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
#print(f"Error with backend {backend_name}: {str(e)}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
print("No Brother QL printer found")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def fint_and_parse_epson_printer():
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user