Align cut options with PT-P700 capabilities

This commit is contained in:
Mikei386
2026-06-22 11:56:27 +02:00
parent b26b9fe123
commit 941c68bbf8
9 changed files with 24 additions and 139 deletions
+8 -49
View File
@@ -36,7 +36,6 @@ DEFAULT_PRINT_COMMAND = "ptouch-print --image {image}"
PRINT_COMMAND = os.environ.get("PRINT_COMMAND", DEFAULT_PRINT_COMMAND)
PRINT_ENABLED = os.environ.get("PRINT_ENABLED", "1").lower() in {"1", "true", "yes", "on"}
DPI = int(os.environ.get("LABEL_DPI", "180"))
PTOUCH_SUPPORTS_HALFCUT: bool | None = None
PTOUCH_SUPPORTS_COPIES: bool | None = None
TAPE_WIDTHS_MM = [3.5, 6, 9, 12, 18, 24]
@@ -284,22 +283,6 @@ def render_design(design: dict[str, Any], copies: int = 1) -> Path:
return output
def ptouch_supports_halfcut() -> bool:
global PTOUCH_SUPPORTS_HALFCUT
if PTOUCH_SUPPORTS_HALFCUT is not None:
return PTOUCH_SUPPORTS_HALFCUT
result = subprocess.run(
["ptouch-print", "--help"],
capture_output=True,
check=False,
text=True,
timeout=10,
)
help_text = f"{result.stdout}\n{result.stderr}"
PTOUCH_SUPPORTS_HALFCUT = "--no-halfcut" in help_text and "--halfcut" in help_text
return PTOUCH_SUPPORTS_HALFCUT
def ptouch_supports_copies() -> bool:
global PTOUCH_SUPPORTS_COPIES
if PTOUCH_SUPPORTS_COPIES is not None:
@@ -316,31 +299,11 @@ def ptouch_supports_copies() -> bool:
return PTOUCH_SUPPORTS_COPIES
def effective_cut_mode(design: dict[str, Any], copies: int) -> str:
cut_mode = str(design.get("cutMode", "auto"))
if copies > 1 and design.get("halfcut", "on") == "on":
if cut_mode == "cutmark":
return "cutmark-chain"
if cut_mode == "auto":
return "chain"
return cut_mode
def cut_args_for_design(design: dict[str, Any], copies: int) -> str:
args = []
if effective_cut_mode(design, copies) in {"chain", "cutmark-chain"}:
cut_mode = str(design.get("cutMode", "auto"))
if cut_mode in {"chain", "cutmark-chain"} and copies <= 1:
args.append("--chain")
halfcut = design.get("halfcut", "on")
if halfcut == "off":
if not ptouch_supports_halfcut():
raise RuntimeError(
"Halbschnitt Aus braucht die gepatchte ptouch-print-Version. "
"Bitte start.sh und patches/ptouch-print-cut-options.patch nach Unraid kopieren, "
"ptouch-print im Container entfernen oder Container neu erstellen und danach neu starten."
)
args.append("--no-halfcut")
elif halfcut == "on" and ptouch_supports_halfcut():
args.append("--halfcut")
return " ".join(args)
@@ -380,15 +343,7 @@ def print_label(image_path: Path, copies: int, design: dict[str, Any]) -> list[s
def should_render_copies_as_strip(design: dict[str, Any], copies: int) -> bool:
if copies <= 1:
return False
if design.get("halfcut", "on") == "on":
if ptouch_supports_copies() or "{copies}" in PRINT_COMMAND:
return False
raise RuntimeError(
"Mehrere Kopien mit Halbschnitt brauchen einen echten Kopien-Druckjob. "
"Ein langes PNG kann keine Halbschnitte zwischen den Etiketten ausloesen. "
"Bitte eine ptouch-print-Version mit --copies verwenden."
)
return True
return str(design.get("cutMode", "auto")) in {"chain", "cutmark-chain"}
def detect_tape_width() -> tuple[float | None, str]:
@@ -494,11 +449,15 @@ def api_print():
render_copies = copies if should_render_copies_as_strip(design, copies) else 1
print_copies = 1 if render_copies > 1 else copies
image_path = render_design(design, render_copies)
print_design = design
if render_copies > 1 and str(design.get("cutMode", "auto")) in {"chain", "cutmark-chain"}:
print_design = dict(design)
print_design["cutMode"] = "cutmark" if design.get("cutMode") == "cutmark-chain" else "auto"
if PRINT_ENABLED:
if not PRINT_LOCK.acquire(blocking=False):
raise RuntimeError("Es laeuft bereits ein Druckjob. Bitte warten oder haengenden ptouch-print-Prozess beenden.")
try:
results = print_label(image_path, print_copies, design)
results = print_label(image_path, print_copies, print_design)
failed = next((result for result in results if result.returncode != 0), None)
if failed:
raise RuntimeError(format_print_error(failed))