Compare commits
3 commits
42062c2eb6
...
c7a2f98421
Author | SHA1 | Date | |
---|---|---|---|
c7a2f98421 | |||
15b40a6905 | |||
9353b6499a |
2 changed files with 30 additions and 5 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,5 +3,7 @@
|
|||
__pycache__/
|
||||
result*
|
||||
|
||||
.env
|
||||
|
||||
scratch.py
|
||||
test.py
|
||||
|
|
33
printer.py
33
printer.py
|
@ -1,6 +1,21 @@
|
|||
from escpos.printer import CupsPrinter
|
||||
import logging
|
||||
import os
|
||||
from itertools import zip_longest
|
||||
|
||||
from dotenv import find_dotenv, load_dotenv
|
||||
from escpos.printer import CupsPrinter
|
||||
|
||||
log = logging.getLogger("receipt-printer")
|
||||
log.setLevel(logging.WARNING)
|
||||
|
||||
if load_dotenv(find_dotenv(usecwd=True)):
|
||||
log.debug("Loaded .env")
|
||||
else:
|
||||
log.debug("Didn't find .env")
|
||||
|
||||
|
||||
RECEIPT_PRINTER = os.getenv("RECEIPT_PRINTER")
|
||||
|
||||
|
||||
class CallbackContext:
|
||||
def __init__(self, enter=None, exit=None):
|
||||
|
@ -72,7 +87,7 @@ class ReceiptPrinter(CupsPrinter):
|
|||
return CallbackContext(exit=super().set_with_default)
|
||||
|
||||
def split(self, left, right, cols=48):
|
||||
self.textln(f"{left:<{cols//2}}{right:<{cols//2}}")
|
||||
self.textln(f"{left:<{cols // 2}}{right:<{cols // 2}}")
|
||||
|
||||
def vsplit(self, *args, **kwargs):
|
||||
return Split2Context(self, *args, **kwargs)
|
||||
|
@ -96,7 +111,15 @@ class ReceiptPrinter(CupsPrinter):
|
|||
def title(self, text, size=6, width=None, height=None):
|
||||
width = width or size
|
||||
height = height or size
|
||||
with self.set(align="center", bold=True, invert=True, smooth=True, custom_size=True, width=width, height=height):
|
||||
with self.set(
|
||||
align="center",
|
||||
bold=True,
|
||||
invert=True,
|
||||
smooth=True,
|
||||
custom_size=True,
|
||||
width=width,
|
||||
height=height,
|
||||
):
|
||||
self.textln(text)
|
||||
self.ln()
|
||||
|
||||
|
@ -104,5 +127,5 @@ class ReceiptPrinter(CupsPrinter):
|
|||
with self.set(align="center", double_height=True, double_width=True):
|
||||
p.textln(text)
|
||||
|
||||
#p = ReceiptPrinter("EPSON-TM-m30", profile="default")
|
||||
p = ReceiptPrinter("EPSON-TM-m30-remote", profile="default")
|
||||
|
||||
p = ReceiptPrinter(RECEIPT_PRINTER, profile="default")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue