From 0477831679669686245ddd1c41e6cb585bd11b95 Mon Sep 17 00:00:00 2001 From: Jules Date: Thu, 4 Jun 2026 21:19:27 +0200 Subject: [PATCH] =?UTF-8?q?Imprimante=20:=20bouton=20Couper=20papier=20(mi?= =?UTF-8?q?cro-job=20blanc=20d=C3=A9clenche=20le=20cutter=20K60)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- backend/main.py | 28 ++++++++++++++++++++++++++++ frontend/index.html | 1 + frontend/js/admin.js | 6 ++++++ 3 files changed, 35 insertions(+) diff --git a/backend/main.py b/backend/main.py index 9994676..7e393b9 100644 --- a/backend/main.py +++ b/backend/main.py @@ -566,6 +566,34 @@ async def api_evacuer_bourrage(): return {"succes": True, "message": msg} +@app.post("/api/imprimante/couper") +async def api_couper_papier(): + """Déclenche la coupe en envoyant un micro-job blanc (la K60 coupe après chaque impression).""" + import subprocess, tempfile, os + from PIL import Image + config = charger_config() + nom = config.get("impression", {}).get("imprimante", "Mitsubishi") + try: + # Image blanche 1x15cm (la plus petite possible pour la K60) + img = Image.new("RGB", (600, 1800), (255, 255, 255)) + tmp = tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) + img.save(tmp.name, "JPEG", quality=95, dpi=(300, 300)) + tmp.close() + r = subprocess.run( + ["lp", "-d", nom, "-n", "1", + "-o", "PageSize=w288h432-div2", + "-o", "StpiShrinkOutput=Crop", + tmp.name], + capture_output=True, text=True, timeout=15 + ) + os.unlink(tmp.name) + if r.returncode == 0: + return {"succes": True, "message": "Coupe lancée — le papier va être coupé"} + return {"succes": False, "message": f"Erreur : {r.stderr.strip() or r.stdout.strip()}"} + except Exception as e: + return {"succes": False, "message": str(e)} + + @app.post("/api/imprimante/reset-usb") async def api_reset_usb(): """Réinitialise la connexion USB de l'imprimante (unbind/rebind driver).""" diff --git a/frontend/index.html b/frontend/index.html index 61c29ae..dac236d 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -405,6 +405,7 @@
+