Add more configuration options to the printers

This commit is contained in:
n07070
2026-11-13 19:16:13 +01:00
parent d0f4ba8f01
commit b50b9abc22
2 changed files with 125 additions and 53 deletions

View File

@@ -18,11 +18,12 @@ class Printers:
Finds and creates a set of Printer that can be used by the Workers to print.
"""
def __init__(self, app):
def __init__(self, app, configuration_file):
"""
Discovers printers connected to the computer
"""
self.app = app
self.configuration_file = configuration_file
self.printers = list(self._discover_printers())
self._lock = threading.Lock()
@@ -42,8 +43,7 @@ class Printers:
printers = set()
# TODO : this could go in the config ?
waiting_time_for_printer = 5
waiting_time_for_printer = self.configuration_file["printer"]["waiting_time"]
while True:
# Find all connected USB devices
@@ -97,9 +97,7 @@ class Printers:
self.app.logger.debug("Trying to create a new EPSON printer")
prid = dev.idProduct
vendir = dev.idVendor
escpos_printer = EscPosPrinter(
self.app, vendor_id=vendir, device_id=prid
)
escpos_printer = EscPosPrinter(self.app, vendir, prid, self.configuration_file["printer"]["epson"] )
except Exception as e:
raise e
@@ -111,9 +109,7 @@ class Printers:
# We create a new BrotherPrinter()
self.app.logger.debug("Trying to create a new BROTHER printer")
brother_printer = BrotherPrinter(
self.app, vendor_id=dev.idVendor, device_id=dev.idProduct
)
brother_printer = BrotherPrinter(self.app, dev.idVendor, dev.idProduct, self.configuration_file["printer"]["brother"] )
except Exception as e:
self.app.logger.error(
"Could not create a %s printer class with %s:%s",
@@ -148,6 +144,8 @@ class Printers:
return None
with self._lock:
# So don't always look at the first printer available if need be
# this allows for a round-robin lookup
for offset in range(len(printers)):
index = (start_index + offset) % len(printers)
printer = printers[index]
@@ -158,9 +156,11 @@ class Printers:
return None
def printers_info(self):
"""Return the current list of printers"""
return self.printers
# def printers_info(self):
# """Return the current list of printers"""
# printers_info_list = {}
# for i in self.printers
# return self.printers
class _FindClass: