From d0f4ba8f01eb2587023e126f1f958376f8079c7c Mon Sep 17 00:00:00 2001 From: n07070 Date: Fri, 13 Nov 2026 19:15:59 +0100 Subject: [PATCH] Add more configuration and printing options --- src/main.py | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main.py b/src/main.py index 31b459d..92f8805 100644 --- a/src/main.py +++ b/src/main.py @@ -111,7 +111,7 @@ web = Web(app, print_queue) # Create a pool of printers try: # comment: Find all printers connected to the system - printers_pool = Printers(app) + printers_pool = Printers(app, configuration_file) except Exception as e: app.logger.error("Could not create a pool of printers because %s", str(e)) sys.exit(-1) @@ -179,7 +179,13 @@ def web_print_sms(): do_cut = False try: - web.print_sms(txt, sign, do_cut) + # Clamp value between 1 and + many = max(1, min(int(request.form["many"]), 20)) + except werkzeug.exceptions.BadRequestKeyError: + many = 1 + + try: + web.print_sms(txt, sign, do_cut, many) except RuntimeError as 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") @@ -233,9 +239,15 @@ def web_print_img(): except werkzeug.exceptions.BadRequestKeyError: process_image = False + try: + # Clamp value between 1 and + many = max(1, min(int(request.form["many"]), 20)) + except werkzeug.exceptions.BadRequestKeyError: + many = 1 + try: app.logger.debug("Sending the image to the printer.") - web.print_image(file, sign, do_cut, process_image) + web.print_image(file, sign, do_cut, process_image, many) except RuntimeError as e: app.logger.error("The image could not be printed because : %s ", str(e)) flash("The image could not be printed because : " + str(e), "error") @@ -286,9 +298,15 @@ def api_print_sms(): except werkzeug.exceptions.BadRequestKeyError: do_cut = False + try: + # Clamp value between 1 and + many = max(1, min(int(request.form["many"]), 20)) + except werkzeug.exceptions.BadRequestKeyError: + many = 1 + try: # comment: We try to print the SMS - web.print_sms(txt, sign, do_cut) + web.print_sms(txt, sign, do_cut, many) except RuntimeError as e: return str(e), 500 # end try @@ -331,9 +349,15 @@ def api_print_image(): except werkzeug.exceptions.BadRequestKeyError: process_image = False + try: + # Clamp value between 1 and + many = max(1, min(int(request.form["many"]), 20)) + except werkzeug.exceptions.BadRequestKeyError: + many = 1 + try: app.logger.debug("Sending the image to the printer.") - web.print_image(file, sign, do_cut, process_image) + web.print_image(file, sign, do_cut, process_image, many) except RuntimeError as e: return str(e), 500