Imprimante : bouton Couper papier (micro-job blanc déclenche le cutter K60)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -566,6 +566,34 @@ async def api_evacuer_bourrage():
|
|||||||
return {"succes": True, "message": msg}
|
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")
|
@app.post("/api/imprimante/reset-usb")
|
||||||
async def api_reset_usb():
|
async def api_reset_usb():
|
||||||
"""Réinitialise la connexion USB de l'imprimante (unbind/rebind driver)."""
|
"""Réinitialise la connexion USB de l'imprimante (unbind/rebind driver)."""
|
||||||
|
|||||||
@@ -405,6 +405,7 @@
|
|||||||
<div class="champ" style="margin-top:1rem;display:flex;gap:0.8rem;flex-wrap:wrap">
|
<div class="champ" style="margin-top:1rem;display:flex;gap:0.8rem;flex-wrap:wrap">
|
||||||
<button class="btn-danger" onclick="evacuerBourrage()">⚠ Annuler jobs</button>
|
<button class="btn-danger" onclick="evacuerBourrage()">⚠ Annuler jobs</button>
|
||||||
<button class="btn-secondaire" onclick="resetUsb()">↻ Réinit. USB</button>
|
<button class="btn-secondaire" onclick="resetUsb()">↻ Réinit. USB</button>
|
||||||
|
<button class="btn-secondaire" onclick="couperPapier()">✄ Couper papier</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="imprimante-statut-detail" class="champ" style="display:none">
|
<div id="imprimante-statut-detail" class="champ" style="display:none">
|
||||||
<div id="imprimante-erreur-msg" style="background:rgba(244,67,54,0.1);border-radius:8px;padding:0.8rem;color:#f44336;font-size:0.85rem;margin-top:0.5rem"></div>
|
<div id="imprimante-erreur-msg" style="background:rgba(244,67,54,0.1);border-radius:8px;padding:0.8rem;color:#f44336;font-size:0.85rem;margin-top:0.5rem"></div>
|
||||||
|
|||||||
@@ -92,6 +92,12 @@ function _getOrientations() {
|
|||||||
return { ...existing, [fmt]: orient };
|
return { ...existing, [fmt]: orient };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function couperPapier() {
|
||||||
|
afficherStatut('Envoi commande coupe...', 'succes');
|
||||||
|
const r = await apiPost('/api/imprimante/couper', {});
|
||||||
|
afficherStatut(r.message, r.succes ? 'succes' : 'erreur');
|
||||||
|
}
|
||||||
|
|
||||||
async function resetUsb() {
|
async function resetUsb() {
|
||||||
afficherStatut('Réinitialisation USB...', 'succes');
|
afficherStatut('Réinitialisation USB...', 'succes');
|
||||||
const r = await apiPost('/api/imprimante/reset-usb', {});
|
const r = await apiPost('/api/imprimante/reset-usb', {});
|
||||||
|
|||||||
Reference in New Issue
Block a user