diff --git a/src/escpos/printer/cups.py b/src/escpos/printer/cups.py index 98885e2..adc35a0 100644 --- a/src/escpos/printer/cups.py +++ b/src/escpos/printer/cups.py @@ -74,8 +74,6 @@ class CupsPrinter(Escpos): """ - _device: Union[Literal[False], Literal[None], cups.Connection] = False - @staticmethod def is_usable() -> bool: """Indicate whether this printer class is usable. @@ -105,6 +103,10 @@ class CupsPrinter(Escpos): self.job_name = "" self.pending_job = False + self._device: Union[ + Literal[False], Literal[None], Type[cups.Connection] + ] = False + @property def printers(self) -> dict: """Available CUPS printers.""" diff --git a/src/escpos/printer/file.py b/src/escpos/printer/file.py index 2eda7d1..67cbe4f 100644 --- a/src/escpos/printer/file.py +++ b/src/escpos/printer/file.py @@ -34,8 +34,6 @@ class File(Escpos): """ - _device: Union[Literal[False], Literal[None], IO[bytes]] = False - @staticmethod def is_usable() -> bool: """Indicate whether this printer class is usable. @@ -55,6 +53,8 @@ class File(Escpos): self.devfile = devfile self.auto_flush = auto_flush + self._device: Union[Literal[False], Literal[None], IO[bytes]] = False + def open(self, raise_not_found: bool = True) -> None: """Open system file. diff --git a/src/escpos/printer/lp.py b/src/escpos/printer/lp.py index 55c1b68..36f1e6b 100644 --- a/src/escpos/printer/lp.py +++ b/src/escpos/printer/lp.py @@ -54,8 +54,6 @@ class LP(Escpos): """ - _device: Union[Literal[False], Literal[None], subprocess.Popen] = False - @staticmethod def is_usable() -> bool: """Indicate whether this printer class is usable. @@ -77,6 +75,8 @@ class LP(Escpos): self.auto_flush = kwargs.get("auto_flush", False) self._flushed = False + self._device: Union[Literal[False], Literal[None], subprocess.Popen] = False + @property def printers(self) -> dict: """Available CUPS printers.""" diff --git a/src/escpos/printer/network.py b/src/escpos/printer/network.py index 67313fd..5b0d0fa 100644 --- a/src/escpos/printer/network.py +++ b/src/escpos/printer/network.py @@ -48,8 +48,6 @@ class Network(Escpos): """ - _device: Union[Literal[False], Literal[None], socket.socket] = False - @staticmethod def is_usable() -> bool: """Indicate whether this printer class is usable. @@ -78,6 +76,8 @@ class Network(Escpos): self.port = port self.timeout = timeout + self._device: Union[Literal[False], Literal[None], socket.socket] = False + def open(self, raise_not_found: bool = True) -> None: """Open TCP socket with ``socket``-library and set it as escpos device. diff --git a/src/escpos/printer/serial.py b/src/escpos/printer/serial.py index bfae5fc..bbe1d25 100644 --- a/src/escpos/printer/serial.py +++ b/src/escpos/printer/serial.py @@ -64,8 +64,6 @@ class Serial(Escpos): """ - _device: Union[Literal[False], Literal[None], serial.Serial] = False - @staticmethod def is_usable() -> bool: """Indicate whether this printer class is usable. @@ -116,6 +114,8 @@ class Serial(Escpos): self.xonxoff = xonxoff self.dsrdtr = dsrdtr + self._device: Union[Literal[False], Literal[None], serial.Serial] = False + @dependency_pyserial def open(self, raise_not_found: bool = True) -> None: """Set up serial port and set is as escpos device. diff --git a/src/escpos/printer/usb.py b/src/escpos/printer/usb.py index 3f45fc4..d07df7b 100644 --- a/src/escpos/printer/usb.py +++ b/src/escpos/printer/usb.py @@ -63,8 +63,6 @@ class Usb(Escpos): """ - _device: Union[Literal[False], Literal[None], Type[usb.core.Device]] = False - @staticmethod def is_usable() -> bool: """Indicate whether this printer class is usable. @@ -105,6 +103,10 @@ class Usb(Escpos): if idProduct: self.usb_args["idProduct"] = idProduct + self._device: Union[ + Literal[False], Literal[None], Type[usb.core.Device] + ] = False + @dependency_usb def open(self, raise_not_found: bool = True) -> None: """Search device on USB tree and set it as escpos device. diff --git a/src/escpos/printer/win32raw.py b/src/escpos/printer/win32raw.py index 79fa3dc..737ce22 100644 --- a/src/escpos/printer/win32raw.py +++ b/src/escpos/printer/win32raw.py @@ -65,10 +65,6 @@ class Win32Raw(Escpos): """ - _device: Union[ - Literal[False], Literal[None], "_win32typing.PyPrinterHANDLE" # noqa: F821 - ] = False - @staticmethod def is_usable() -> bool: """Indicate whether this printer class is usable. @@ -85,6 +81,10 @@ class Win32Raw(Escpos): self.printer_name = printer_name self.job_name = "" + self._device: Union[ + Literal[False], Literal[None], "_win32typing.PyPrinterHANDLE" # noqa: F821 + ] = False + @property @dependency_win32print def printers(self) -> dict: