Move platform dependent printers' guard to init

This commit is contained in:
belono 2023-10-14 01:35:37 +02:00
parent 8f54dfed00
commit dfd48e229d
3 changed files with 1 additions and 6 deletions

View File

@ -176,7 +176,6 @@ class CupsPrinter(Escpos):
self.pending_job = False self.pending_job = False
raise ValueError("Printer job not opened") raise ValueError("Printer job not opened")
@dependency_pycups
def send(self): def send(self):
"""Send the print job to the printer.""" """Send the print job to the printer."""
if self.pending_job: if self.pending_job:

View File

@ -63,6 +63,7 @@ class LP(Escpos):
""" """
return is_usable() return is_usable()
@dependency_linux_lp
def __init__(self, printer_name: str = "", *args, **kwargs): def __init__(self, printer_name: str = "", *args, **kwargs):
"""LP class constructor. """LP class constructor.
@ -108,7 +109,6 @@ class LP(Escpos):
return "" return ""
return name return name
@dependency_linux_lp
def open( def open(
self, self,
job_name: str = "python-escpos", job_name: str = "python-escpos",

View File

@ -87,7 +87,6 @@ class Win32Raw(Escpos):
] = False ] = False
@property @property
@dependency_win32print
def printers(self) -> dict: def printers(self) -> dict:
"""Available Windows printers.""" """Available Windows printers."""
return { return {
@ -95,7 +94,6 @@ class Win32Raw(Escpos):
for printer in win32print.EnumPrinters(win32print.PRINTER_ENUM_NAME, "", 4) for printer in win32print.EnumPrinters(win32print.PRINTER_ENUM_NAME, "", 4)
} }
@dependency_win32print
def open( def open(
self, job_name: str = "python-escpos", raise_not_found: bool = True self, job_name: str = "python-escpos", raise_not_found: bool = True
) -> None: ) -> None:
@ -138,7 +136,6 @@ class Win32Raw(Escpos):
return return
logging.info("Win32Raw printer enabled") logging.info("Win32Raw printer enabled")
@dependency_win32print
def close(self) -> None: def close(self) -> None:
"""Close connection to default printer.""" """Close connection to default printer."""
if not self._device: if not self._device:
@ -149,7 +146,6 @@ class Win32Raw(Escpos):
win32print.ClosePrinter(self._device) win32print.ClosePrinter(self._device)
self._device = False self._device = False
@dependency_win32print
def _raw(self, msg): def _raw(self, msg):
"""Print any command sent in raw format. """Print any command sent in raw format.