Add support for signature on brother printers
This commit is contained in:
@@ -49,10 +49,7 @@ class Printers:
|
||||
# Find all connected USB devices
|
||||
# the find() fnc returns a generator
|
||||
devices = list(
|
||||
usb.core.find(
|
||||
find_all=True,
|
||||
custom_match=_FindClass(self.app,7)
|
||||
)
|
||||
usb.core.find(find_all=True, custom_match=_FindClass(self.app, 7))
|
||||
)
|
||||
|
||||
if devices:
|
||||
@@ -60,15 +57,15 @@ class Printers:
|
||||
|
||||
if waiting_time_for_printer <= 0:
|
||||
self.app.logger.warning(
|
||||
"No USB devices of class 7 ( printers ) found or pyusb could not access the bus."
|
||||
"No USB devices of class 7 ( printers ) found or pyusb could not access the bus."
|
||||
)
|
||||
raise RuntimeError(
|
||||
"No USB devices of class 7 ( printers ) found or pyusb could not access the bus."
|
||||
"No USB devices of class 7 ( printers ) found or pyusb could not access the bus."
|
||||
)
|
||||
|
||||
self.app.logger.warning(
|
||||
"No printers found; waiting for a printer to connect..."
|
||||
)
|
||||
)
|
||||
|
||||
time.sleep(1)
|
||||
waiting_time_for_printer -= 1
|
||||
@@ -120,10 +117,12 @@ class Printers:
|
||||
self.app.logger.debug("Trying to create a new BROTHER printer")
|
||||
|
||||
brother_printer = BrotherPrinter(
|
||||
self.app, vendor_id=dev.idVendor, device_id=dev.idProduct)
|
||||
self.app, vendor_id=dev.idVendor, device_id=dev.idProduct
|
||||
)
|
||||
except Exception as e:
|
||||
self.app.logger.error(
|
||||
"Could not create a %s printer class with %s:%s" , product,
|
||||
"Could not create a %s printer class with %s:%s",
|
||||
product,
|
||||
dev.idVendor,
|
||||
dev.idProduct,
|
||||
)
|
||||
@@ -131,12 +130,14 @@ class Printers:
|
||||
|
||||
# If the object creation is successfull, we add it to the list of Printers
|
||||
printers.add(brother_printer)
|
||||
self.app.logger.debug("Found a %s printer" , manufacturer)
|
||||
self.app.logger.debug("Found a %s printer", manufacturer)
|
||||
|
||||
self.app.logger.debug("Found %s printers" , len(printers))
|
||||
self.app.logger.debug("Found %s printers", len(printers))
|
||||
|
||||
if len(printers) < 1:
|
||||
self.app.logger.warning("Not printers found ! Please plug in a Printer and restart the program.")
|
||||
self.app.logger.warning(
|
||||
"Not printers found ! Please plug in a Printer and restart the program."
|
||||
)
|
||||
raise RuntimeError("No printers found")
|
||||
|
||||
return printers
|
||||
@@ -163,26 +164,32 @@ class Printers:
|
||||
"""Return the current list of printers"""
|
||||
return self.printers
|
||||
|
||||
|
||||
class _FindClass:
|
||||
"""
|
||||
Use by usb.core to modify the way USB devices are found
|
||||
Taken from pyUSB documentation on Github
|
||||
"""
|
||||
|
||||
def __init__(self, app, class_):
|
||||
self._class = class_
|
||||
self.app = app
|
||||
|
||||
def __call__(self, device):
|
||||
# first, let's check the device
|
||||
self.app.logger.debug("Found a USB device of class %s", str(device.bDeviceClass))
|
||||
self.app.logger.debug(
|
||||
"Found a USB device of class %s", str(device.bDeviceClass)
|
||||
)
|
||||
if device.bDeviceClass == self._class:
|
||||
return True
|
||||
# ok, transverse all devices to find an
|
||||
# interface that matches our class
|
||||
for configuration in device:
|
||||
# Every device can have one or more configuration,
|
||||
interface = usb.util.find_descriptor(configuration, bInterfaceClass=self._class)
|
||||
# each config can have several interfaces
|
||||
interface = usb.util.find_descriptor(
|
||||
configuration, bInterfaceClass=self._class
|
||||
)
|
||||
# each config can have several interfaces
|
||||
if interface is not None:
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user