Add a note text size option; document the printer cabled to stppi
CI / test (3.10) (push) Failing after 47s
CI / test (3.12) (push) Failing after 54s
CI / test (3.13) (push) Failing after 48s

- note --size 1|2|3 magnifies the text and wraps to 48/24/16 columns,
  then resets the printer to normal size
- Web page gets a Size menu defaulting to Large; the API validates it
- README/CLAUDE.md: the printer has no Wi-Fi (UB-E04 needs an adapter),
  so it is cabled to stppi's eth0 at 192.168.192.168

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-23 21:48:54 +01:00
co-authored by Claude Opus 5.5
parent f55b20fb82
commit 30d1b83817
7 changed files with 70 additions and 14 deletions
+17 -3
View File
@@ -49,6 +49,7 @@ USB_VENDOR_ID = 0x04B8
USB_PRODUCT_ID = 0x0202
PRINT_WIDTH_PX = 576 # printable width of the TM-T20II at 203 dpi
TEXT_COLUMNS = 48 # font A columns on 80mm paper
TEXT_SIZES = (1, 2, 3) # note character magnifications; columns shrink to match
HTTP_TIMEOUT = 15 # seconds
MAX_IMAGE_BYTES = 16 * 1024 * 1024 # cap on a single downloaded or uploaded image
DEFAULT_WEB_LISTEN = "100.107.152.119:8765" # stppi's Tailscale IP; nginx on stpvm proxies here
@@ -126,11 +127,11 @@ def prepare_for_print(img_path: Path | BinaryIO) -> Image.Image:
return ImageOps.autocontrast(resized.convert("L")).convert("1")
def wrap_text(text: str) -> str:
def wrap_text(text: str, columns: int = TEXT_COLUMNS) -> str:
"""Word-wrap text to the printer's column width, preserving blank lines."""
lines = []
for line in text.splitlines():
lines.append(textwrap.fill(line, TEXT_COLUMNS) if line.strip() else "")
lines.append(textwrap.fill(line, columns) if line.strip() else "")
return "\n".join(lines)
@@ -263,7 +264,12 @@ def cmd_note(p: printer.Escpos, args: argparse.Namespace) -> int:
if args.timestamp:
p.textln(datetime.now().strftime("%Y-%m-%d %H:%M"))
p.textln("-" * TEXT_COLUMNS)
p.textln(wrap_text(text))
size = getattr(args, "size", 1)
if size > 1:
p.set(custom_size=True, width=size, height=size)
p.textln(wrap_text(text, TEXT_COLUMNS // size))
if size > 1:
p.set(normal_textsize=True) # the mode outlives this connection
p.cut()
return 0
@@ -483,6 +489,14 @@ def build_parser() -> argparse.ArgumentParser:
action="store_true",
help="Print a date/time header above the note",
)
note_p.add_argument(
"-s",
"--size",
type=int,
choices=TEXT_SIZES,
default=1,
help="Text magnification (default: 1, 48 columns; 2 is 24, 3 is 16)",
)
print_p = subparsers.add_parser("print", help="Print a local image")
print_p.add_argument("path", type=Path, help="Path to the image file")