Multi-printers #32

Open
n07070 wants to merge 80 commits from multi-printers into master
pull from: multi-printers
6 changed files with 82 additions and 20 deletions
Showing only changes of commit 85b1c307a8 - Show all commits

No files matched your search

+11 -1
View File
@@ -238,7 +238,17 @@ def web_print_sms():
many = 1 many = 1
try: try:
web.print_sms(txt, sign, do_cut, many) align = str(request.form["text_align"])
except werkzeug.exceptions.BadRequestKeyError:
align = "center"
try:
font_size = int(request.form["font_size"])
except werkzeug.exceptions.BadRequestKeyError:
font_size = 20
try:
web.print_sms(txt, sign, do_cut, align=align, font_size=font_size)
except RuntimeError as e: except RuntimeError as e:
app.logger.error("Whoops, we could not print an SMS because : %s ", str(e)) app.logger.error("Whoops, we could not print an SMS because : %s ", str(e))
flash("Whoops, we could not print an SMS because :" + str(e), "error") flash("Whoops, we could not print an SMS because :" + str(e), "error")
-1
View File
@@ -7,7 +7,6 @@ the methods expected from printers.
from collections.abc import Set from collections.abc import Set
import time import time
import threading
import usb.core import usb.core
import usb.util import usb.util
from printer import Printer, EscPosPrinter, BrotherPrinter from printer import Printer, EscPosPrinter, BrotherPrinter
+4 -2
View File
@@ -61,13 +61,15 @@ class TextTask(PrintTask):
This tasks represents a texte content, and it's signature. This tasks represents a texte content, and it's signature.
""" """
def __init__(self, content, signature="", do_cut=False): def __init__(self, content, signature="", do_cut=False, align="center",font_size=20):
super().__init__(TaskType.TEXT, do_cut) super().__init__(TaskType.TEXT, do_cut)
self.content = content self.content = content
self.signature = signature self.signature = signature
self.align = align
self.font_size = font_size
def get_print_data(self): def get_print_data(self):
return {"txt": self.content, "sign": self.signature, "do_cut": self.do_cut} return {"txt": self.content, "sign": self.signature, "do_cut": self.do_cut, "align": self.align, "font_size": self.font_size}
class QRTask(TextTask): class QRTask(TextTask):
+3 -3
View File
@@ -26,10 +26,10 @@
</li> </li>
</ul> </ul>
<div class="border border-2 bg-subtle-inverse nav-item"> <div class="nav-item">
<button type="button" class="btn-styled btn btn-outline theme-primary position-relative"> <button type="button" class="btn btn-outline theme-primary position-relative">
<a href="/queue">🖶</a> <a href="/queue">🖶</a>
<span class="badge position-absolute top-0 start-100 translate-middle bg-danger border border-bg rounded-circle" id="status-printers" title="Javascript is disabled, could not get printer status."><span id="number-task">0</span> <span class="badge position-absolute top-0 start-100 translate-middle bg-danger rounded-circle" id="status-printers" title="Javascript is disabled, could not get printer status."><span id="number-task">0</span>
<span class="visually-hidden"></span> <span class="visually-hidden"></span>
</span> </span>
</button> </button>
+62 -11
View File
@@ -6,19 +6,67 @@
<h3 class="card-header">Print a short message</h3> <h3 class="card-header">Print a short message</h3>
<div class="card-body"> <div class="card-body">
<form class="form-group" action="/web/print/sms" method="post"> <form class="form-group" action="/web/print/sms" method="post">
<textarea class="form-control" type="text" name="txt" placeholder="4096 caractères maximum " maxlength="4096"></textarea> <div class="row g-3">
<br> <textarea class="form-control col" type="text" name="txt" placeholder="4096 caractères maximum " maxlength="4096"></textarea>
<input class="form-control" type="text" name="signature" placeholder="Signature ou pseudo" maxlength="200"><br> <input class="form-control" type="text" name="signature" placeholder="Signature ou pseudo" maxlength="200"><br>
<div class="input-group">
<span class="input-group-text">Combien ?</span>
<input type="number" aria-label="how-many" class="form-control" name="many" max="20" min="1" value="1">
<input class="btn btn-primary float-right" type="submit" value="Imprimer" name="imprimer">
</div> </div>
<div class="grid">
<div class="md:g-col-4 g-col-12">
<div class="input-group">
<label class="input-group-text">Taille du texte</label>
<input
type="number"
aria-label="how-many"
class="form-control"
name="font_size"
max="40"
min="1"
value="20"
>
</div>
</div>
<div class="input-group d-grid md:g-col-4 g-col-12 align-items-center">
<div class="btn-group btn-group-divider" role="group" aria-label="Text alignment">
<label class="btn-check btn-solid theme-secondary">
<input type="radio" name="text_align" value="left" checked>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-left" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M2 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m0-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/>
</svg> Left
</label>
<label class="btn-check btn-solid theme-secondary">
<input type="radio" name="text_align" value="center">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-center" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M4 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/>
</svg> Center
</label>
<label class="btn-check btn-solid theme-secondary">
<input type="radio" name="text_align" value="right">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-right" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M6 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m4-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/>
</svg> Right
</label>
</div>
</div>
<div class="md:g-col-4 g-col-12">
<div class="input-group">
<span class="input-group-text">Quantité</span>
<input type="number" aria-label="how-many" class="form-control" name="many" max="20" min="1" value="1">
</div>
</div>
</div>
<br>
<input class="g-4 btn btn-solid theme-primary" type="submit" value="Imprimer" name="imprimer">
<br> <br>
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="checkbox" value="True" id="flexCheckDefault" name="cut" checked> <input class="form-check-input" type="checkbox" value="True" id="flexCheckDefault" name="cut" checked>
<label class="form-check-label" for="flexCheckDefault"> <label class="form-check-label" for="flexCheckDefault">
Couper après impression ? Couper après impression
</label> </label>
</div> </div>
@@ -36,21 +84,24 @@
<input class="form-control" type="file" name="img" required><br> <input class="form-control" type="file" name="img" required><br>
<input class="form-control" type="text" name="signature" placeholder="Signature ou pseudo" maxlength="200"><br> <input class="form-control" type="text" name="signature" placeholder="Signature ou pseudo" maxlength="200"><br>
<div class="input-group"> <div class="input-group">
<span class="input-group-text">Combien ?</span> <span class="input-group-text">Quantité</span>
<input type="number" aria-label="how-many" class="form-control" name="many" max="20" min="1" value="1"> <input type="number" aria-label="how-many" class="form-control" name="many" max="20" min="1" value="1">
<input class="btn btn-primary float-right" type="submit" value="Imprimer" name="imprimer"> <input class="btn btn-solid theme-primary float-right" type="submit" value="Imprimer" name="imprimer">
</div> </div>
<br> <br>
<div class="form-check .form-check-inline"> <div class="form-check .form-check-inline">
<input class="form-check-input" type="checkbox" value="True" id="flexCheckDefault" name="cut" checked> <input class="form-check-input" type="checkbox" value="True" id="flexCheckDefault" name="cut" checked>
<label class="form-check-label" for="flexCheckDefault"> <label class="form-check-label" for="flexCheckDefault">
Couper après impression ? Couper après impression
</label> </label>
</div> </div>
<div class="form-check .form-check-inline"> <div class="form-check .form-check-inline">
<input class="form-check-input" type="checkbox" value="True" id="flexCheckDefault" name="process"> <input class="form-check-input" type="checkbox" value="True" id="flexCheckDefault" name="process">
<label class="form-check-label" for="flexCheckDefault" title="Essayer d'augmenter le contraste de l'image pour une meilleur définition d'impression en noir et blanc"> <label class="form-check-label" for="flexCheckDefault" title="Essayer d'augmenter le contraste de l'image pour une meilleur définition d'impression en noir et blanc">
Traiter l'image ? <details>
<summary>Traiter l'image ?</summary>
Un algorithme de traitement d'image va essayer d'augmenter le contraste de l'image pour qu'elle rendent mieux en impression noir et blanc. Mais cela risque de provoquer une perte de détails de l'image.
</details>
</label> </label>
</div> </div>
+2 -2
View File
@@ -17,7 +17,7 @@ class Web:
self.print_queue = print_queue self.print_queue = print_queue
self.app = app self.app = app
def print_sms(self, texte, sign: str, do_cut: bool, many: int = 1) -> bool: def print_sms(self, texte, sign: str, do_cut: bool, many: int = 1, align: str = "center", font_size: int = 20) -> bool:
""" """
Get text and a signature, prints the text and cuts after that. Get text and a signature, prints the text and cuts after that.
""" """
@@ -26,7 +26,7 @@ class Web:
try: try:
for i in range(many): for i in range(many):
sms = self.print_queue.enqueue( sms = self.print_queue.enqueue(
TextTask(content=texte, signature=sign, do_cut=do_cut) TextTask(content=texte, signature=sign, do_cut=do_cut, align=align,font_size=font_size)
) )
self.app.logger.info( self.app.logger.info(
"Added a SMS task at position %s, it should %scut", "Added a SMS task at position %s, it should %scut",