Add/Improve documentation of the new connectors
This commit is contained in:
parent
69e9dca761
commit
ea61f287cb
|
@ -1,9 +1,9 @@
|
||||||
********
|
********
|
||||||
Printers
|
Printers
|
||||||
********
|
********
|
||||||
:Last Reviewed: 2017-01-25
|
:Last Reviewed: 2022-11-25
|
||||||
|
|
||||||
As of now there are 5 different type of printer implementations.
|
As of now there are 7 different type of printer implementations.
|
||||||
|
|
||||||
USB
|
USB
|
||||||
---
|
---
|
||||||
|
@ -75,3 +75,30 @@ all of the "output" as raw ESC/POS in a string and returns that.
|
||||||
:member-order: bysource
|
:member-order: bysource
|
||||||
:noindex:
|
:noindex:
|
||||||
|
|
||||||
|
CUPS
|
||||||
|
----
|
||||||
|
This driver uses `pycups` in order to communicate with a CUPS server.
|
||||||
|
Supports both local and remote CUPS printers and servers.
|
||||||
|
The printer must be properly configured in CUPS administration.
|
||||||
|
The connector generates a print job that is added to the CUPS queue.
|
||||||
|
|
||||||
|
.. autoclass:: escpos.printer.CupsPrinter
|
||||||
|
:members:
|
||||||
|
:special-members:
|
||||||
|
:member-order: bysource
|
||||||
|
:noindex:
|
||||||
|
|
||||||
|
LP
|
||||||
|
----
|
||||||
|
This driver uses the UNIX command `lp` in order to communicate with a CUPS server.
|
||||||
|
Supports local and remote CUPS printers.
|
||||||
|
The printer must be properly configured in CUPS administration.
|
||||||
|
The connector spawns a new sub-process where the command lp is executed.
|
||||||
|
|
||||||
|
No dependencies required, but somehow the print queue will affect some print job such as barcode.
|
||||||
|
|
||||||
|
.. autoclass:: escpos.printer.LP
|
||||||
|
:members:
|
||||||
|
:special-members:
|
||||||
|
:member-order: bysource
|
||||||
|
:noindex:
|
||||||
|
|
|
@ -437,10 +437,16 @@ if _WIN32PRINT:
|
||||||
if _CUPSPRINT:
|
if _CUPSPRINT:
|
||||||
|
|
||||||
class CupsPrinter(Escpos):
|
class CupsPrinter(Escpos):
|
||||||
"""Simple CUPS printer connector."""
|
"""Simple CUPS printer connector.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
Requires _pycups_ which in turn needs the cups development library package:
|
||||||
|
- Ubuntu/Debian: _libcups2-dev_
|
||||||
|
- OpenSuse/Fedora: _cups-devel_
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, printer_name=None, *args, **kwargs):
|
def __init__(self, printer_name=None, *args, **kwargs):
|
||||||
"""CupsPrinter constructor.
|
"""CupsPrinter class constructor.
|
||||||
|
|
||||||
:param printer_name: CUPS printer name (Optional)
|
:param printer_name: CUPS printer name (Optional)
|
||||||
:type printer_name: str
|
:type printer_name: str
|
||||||
|
@ -532,18 +538,26 @@ if _CUPSPRINT:
|
||||||
if not sys.platform.startswith("win"):
|
if not sys.platform.startswith("win"):
|
||||||
|
|
||||||
class LP(Escpos):
|
class LP(Escpos):
|
||||||
"""Simple UNIX lp raw printing.
|
"""Simple UNIX lp command raw printing.
|
||||||
|
|
||||||
From https://github.com/python-escpos/python-escpos/pull/348#issuecomment-549558316
|
Thanks to `Oyami-Srk comment <https://github.com/python-escpos/python-escpos/pull/348#issuecomment-549558316>`_.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, printer_name: str, *args, **kwargs):
|
def __init__(self, printer_name: str, *args, **kwargs):
|
||||||
|
"""LP class constructor.
|
||||||
|
|
||||||
|
:param printer_name: CUPS printer name (Optional)
|
||||||
|
:type printer_name: str
|
||||||
|
:param auto_flush: Automatic flush after every _raw() (Optional)
|
||||||
|
:type auto_flush: bool
|
||||||
|
"""
|
||||||
Escpos.__init__(self, *args, **kwargs)
|
Escpos.__init__(self, *args, **kwargs)
|
||||||
self.printer_name = printer_name
|
self.printer_name = printer_name
|
||||||
self.auto_flush = kwargs.get("auto_flush", True)
|
self.auto_flush = kwargs.get("auto_flush", True)
|
||||||
self.open()
|
self.open()
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
|
"""Invoke _lp_ in a new subprocess and wait for commands."""
|
||||||
self.lp = subprocess.Popen(
|
self.lp = subprocess.Popen(
|
||||||
["lp", "-d", self.printer_name, "-o", "raw"],
|
["lp", "-d", self.printer_name, "-o", "raw"],
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
|
@ -551,9 +565,11 @@ if not sys.platform.startswith("win"):
|
||||||
)
|
)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
"""Stop the subprocess."""
|
||||||
self.lp.terminate()
|
self.lp.terminate()
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
|
"""End line and wait for new commands"""
|
||||||
if self.lp.stdin.writable():
|
if self.lp.stdin.writable():
|
||||||
self.lp.stdin.write(b"\n")
|
self.lp.stdin.write(b"\n")
|
||||||
if self.lp.stdin.closed is False:
|
if self.lp.stdin.closed is False:
|
||||||
|
@ -562,6 +578,11 @@ if not sys.platform.startswith("win"):
|
||||||
self.open()
|
self.open()
|
||||||
|
|
||||||
def _raw(self, msg):
|
def _raw(self, msg):
|
||||||
|
"""Write raw command(s) to the printer.
|
||||||
|
|
||||||
|
:param msg: arbitrary code to be printed
|
||||||
|
:type msg: bytes
|
||||||
|
"""
|
||||||
if self.lp.stdin.writable():
|
if self.lp.stdin.writable():
|
||||||
self.lp.stdin.write(msg)
|
self.lp.stdin.write(msg)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue