fix printing?
This commit is contained in:
parent
926aaefd85
commit
b3ebce60f4
3 changed files with 102 additions and 99 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
use python autokanban
|
||||
1
.python-version
Normal file
1
.python-version
Normal file
|
|
@ -0,0 +1 @@
|
|||
3.13
|
||||
15
app/main.py
15
app/main.py
|
|
@ -21,7 +21,7 @@ app.mount("/static", StaticFiles(directory="app/static"), name="static")
|
|||
app.mount("/out", StaticFiles(directory="out"), name="out")
|
||||
|
||||
TASKS_FILE = Path("data/tasks.json")
|
||||
DEBUG_PRINT_TO_IMAGE = True # Set to True to enable card image generation instead of real printing
|
||||
ENABLE_PHYSICAL_PRINTER = True # Set to False to skip physical printing (only generate preview images)
|
||||
OUT_DIR = Path("out")
|
||||
OUT_DIR.mkdir(exist_ok=True)
|
||||
CARD_WIDTH_PX = 354 # 58mm * 300dpi / 25.4
|
||||
|
|
@ -140,8 +140,7 @@ def print_task(request: Request, task_id: str):
|
|||
if task.id == task_id:
|
||||
if (task.status == "approved") or (task.status == "printed" and request.session.get("admin")):
|
||||
try:
|
||||
if DEBUG_PRINT_TO_IMAGE:
|
||||
# Generate styled card image with icon
|
||||
# Always generate preview image
|
||||
img = Image.new("L", (CARD_WIDTH_PX, CARD_HEIGHT_PX), 255)
|
||||
draw = ImageDraw.Draw(img)
|
||||
draw.rectangle([(0,0),(CARD_WIDTH_PX-1,CARD_HEIGHT_PX-1)], outline=0, width=4)
|
||||
|
|
@ -232,15 +231,17 @@ def print_task(request: Request, task_id: str):
|
|||
if font_error_msgs:
|
||||
draw.text((10, CARD_HEIGHT_PX-24), ", ".join(font_error_msgs), font=ImageFont.load_default(), fill=128)
|
||||
|
||||
# Save preview image
|
||||
img_path = OUT_DIR / f"task_{task.id}.png"
|
||||
img.save(img_path)
|
||||
preview_img = str(img_path)
|
||||
msg = "success"
|
||||
task.status = "printed"
|
||||
else:
|
||||
printer = escpos.printer.Serial(devfile="/dev/ttyUSB0", baudrate=19200, timeout=1)
|
||||
|
||||
# Print to physical printer if enabled
|
||||
if ENABLE_PHYSICAL_PRINTER:
|
||||
printer = escpos.printer.Serial(devfile="/dev/serial0", baudrate=19200, timeout=1)
|
||||
printer.text(f"Task: {task.content}\nVon: {task.user}\nPriorität: {task.priority}\n")
|
||||
printer.cut()
|
||||
|
||||
task.status = "printed"
|
||||
msg = "success"
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue