Add more configuration and printing options
This commit is contained in:
34
src/main.py
34
src/main.py
@@ -111,7 +111,7 @@ web = Web(app, print_queue)
|
|||||||
# Create a pool of printers
|
# Create a pool of printers
|
||||||
try:
|
try:
|
||||||
# comment: Find all printers connected to the system
|
# comment: Find all printers connected to the system
|
||||||
printers_pool = Printers(app)
|
printers_pool = Printers(app, configuration_file)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
app.logger.error("Could not create a pool of printers because %s", str(e))
|
app.logger.error("Could not create a pool of printers because %s", str(e))
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
@@ -179,7 +179,13 @@ def web_print_sms():
|
|||||||
do_cut = False
|
do_cut = False
|
||||||
|
|
||||||
try:
|
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:
|
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")
|
||||||
@@ -233,9 +239,15 @@ def web_print_img():
|
|||||||
except werkzeug.exceptions.BadRequestKeyError:
|
except werkzeug.exceptions.BadRequestKeyError:
|
||||||
process_image = False
|
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:
|
try:
|
||||||
app.logger.debug("Sending the image to the printer.")
|
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:
|
except RuntimeError as e:
|
||||||
app.logger.error("The image could not be printed because : %s ", str(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")
|
flash("The image could not be printed because : " + str(e), "error")
|
||||||
@@ -286,9 +298,15 @@ def api_print_sms():
|
|||||||
except werkzeug.exceptions.BadRequestKeyError:
|
except werkzeug.exceptions.BadRequestKeyError:
|
||||||
do_cut = False
|
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:
|
try:
|
||||||
# comment: We try to print the SMS
|
# 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:
|
except RuntimeError as e:
|
||||||
return str(e), 500
|
return str(e), 500
|
||||||
# end try
|
# end try
|
||||||
@@ -331,9 +349,15 @@ def api_print_image():
|
|||||||
except werkzeug.exceptions.BadRequestKeyError:
|
except werkzeug.exceptions.BadRequestKeyError:
|
||||||
process_image = False
|
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:
|
try:
|
||||||
app.logger.debug("Sending the image to the printer.")
|
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:
|
except RuntimeError as e:
|
||||||
return str(e), 500
|
return str(e), 500
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user