Restore types-pywin32 (#591)
* Restore types-pywin32 dependency * Restore pywin32 type annotations in win32raw * Add return type to _raw()
This commit is contained in:
parent
5d3d2ca34b
commit
3b6551004f
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
from typing import Literal, Optional, Type, Union
|
from typing import Any, Literal, Optional, Union
|
||||||
|
|
||||||
from ..escpos import Escpos
|
from ..escpos import Escpos
|
||||||
from ..exceptions import DeviceNotFoundError
|
from ..exceptions import DeviceNotFoundError
|
||||||
|
@ -20,9 +20,11 @@ _DEP_WIN32PRINT = False
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
import pywintypes
|
||||||
import win32print
|
import win32print
|
||||||
|
|
||||||
_DEP_WIN32PRINT = True
|
_DEP_WIN32PRINT = True
|
||||||
|
PyPrinterHANDLE: Any = win32print.OpenPrinter
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -83,7 +85,7 @@ class Win32Raw(Escpos):
|
||||||
self._device: Union[
|
self._device: Union[
|
||||||
Literal[False],
|
Literal[False],
|
||||||
Literal[None],
|
Literal[None],
|
||||||
Type[win32print.OpenPrinter],
|
"PyPrinterHANDLE",
|
||||||
] = False
|
] = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -115,15 +117,15 @@ class Win32Raw(Escpos):
|
||||||
self.printer_name = self.printer_name or win32print.GetDefaultPrinter()
|
self.printer_name = self.printer_name or win32print.GetDefaultPrinter()
|
||||||
assert self.printer_name in self.printers, "Incorrect printer name"
|
assert self.printer_name in self.printers, "Incorrect printer name"
|
||||||
# Open device
|
# Open device
|
||||||
self.device: Optional[
|
self.device: Optional["PyPrinterHANDLE"] = win32print.OpenPrinter(
|
||||||
Type[win32print.OpenPrinter]
|
self.printer_name
|
||||||
] = win32print.OpenPrinter(self.printer_name)
|
)
|
||||||
if self.device:
|
if self.device:
|
||||||
self.current_job = win32print.StartDocPrinter(
|
self.current_job = win32print.StartDocPrinter(
|
||||||
self.device, 1, (job_name, None, "RAW")
|
self.device, 1, (job_name, "", "RAW")
|
||||||
)
|
)
|
||||||
win32print.StartPagePrinter(self.device)
|
win32print.StartPagePrinter(self.device)
|
||||||
except AssertionError as e:
|
except (AssertionError, pywintypes.error) as e:
|
||||||
# Raise exception or log error and cancel
|
# Raise exception or log error and cancel
|
||||||
self.device = None
|
self.device = None
|
||||||
if raise_not_found:
|
if raise_not_found:
|
||||||
|
@ -146,7 +148,7 @@ class Win32Raw(Escpos):
|
||||||
win32print.ClosePrinter(self._device)
|
win32print.ClosePrinter(self._device)
|
||||||
self._device = False
|
self._device = False
|
||||||
|
|
||||||
def _raw(self, msg):
|
def _raw(self, msg) -> None:
|
||||||
"""Print any command sent in raw format.
|
"""Print any command sent in raw format.
|
||||||
|
|
||||||
:param msg: arbitrary code to be printed
|
:param msg: arbitrary code to be printed
|
||||||
|
|
Loading…
Reference in New Issue