Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions examples/barcodes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
# /// script
# requires-python = ">=3.9"
# dependencies = ["python-escpos"]
# [tool.uv.sources]
# python-escpos = { path = "../", editable = true }
# ///
"""Example for printing barcodes."""
from escpos.printer import Usb

# Adapt to your needs
p = Usb(0x0416, 0x5011, profile="TM-T88II")

# Print software and then hardware barcode with the same content
p.barcode("123456", "CODE39", width=2, force_software=True)
p.text("\n")
p.text("\n")
p.barcode("123456", "CODE39")
def main() -> None:
"""Main function."""
p = Usb(0x0416, 0x5011, profile="TM-T88II")

# Print software and then hardware barcode with the same content
p.barcode("123456", "CODE39", width=2, force_software=True)
p.text("\n")
p.text("\n")
p.barcode("123456", "CODE39")


if __name__ == "__main__":
main()
47 changes: 25 additions & 22 deletions examples/codepage_tables.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# /// script
# requires-python = ">=3.9"
# dependencies = ["python-escpos"]
# [tool.uv.sources]
# python-escpos = { path = "../", editable = true }
# ///
"""Prints code page tables."""


import sys

from escpos import printer
from escpos.constants import (
CODEPAGE_CHANGE,
CTL_CR,
Expand All @@ -13,26 +16,10 @@
CTL_VT,
ESC,
)
from escpos.printer import Dummy


def main():
"""Init printer and print codepage tables."""
dummy = printer.Dummy()

dummy.hw("init")

for codepage in sys.argv[1:] or ["USA"]:
dummy.set(height=2, width=2)
dummy._raw(codepage + "\n\n\n")
print_codepage(dummy, codepage)
dummy._raw("\n\n")

dummy.cut()

print(dummy.output)


def print_codepage(printer, codepage):
def print_codepage(printer: Dummy, codepage: str) -> None:
"""Print a code page."""
if codepage.isdigit():
codepage = int(codepage)
Expand Down Expand Up @@ -61,12 +48,28 @@ def print_codepage(printer, codepage):
)

if byte in (ESC, CTL_LF, CTL_FF, CTL_CR, CTL_HT, CTL_VT):
byte = " "
byte = b" "

printer._raw(byte)
printer._raw(sep)
printer._raw("\n")


def main() -> None:
"""Init printer and print codepage tables."""
dummy = Dummy()

dummy.hw("init")

for codepage in sys.argv[1:] or ["USA"]:
dummy.set(height=2, width=2)
dummy._raw(codepage + "\n\n\n")
print_codepage(dummy, codepage)
dummy._raw("\n\n")

dummy.cut()

print(dummy.output)

if __name__ == "__main__":
main()
28 changes: 0 additions & 28 deletions examples/docker-flask/Dockerfile

This file was deleted.

6 changes: 0 additions & 6 deletions examples/docker-flask/README.md

This file was deleted.

20 changes: 0 additions & 20 deletions examples/docker-flask/requirements.txt

This file was deleted.

26 changes: 26 additions & 0 deletions examples/flask-example/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Use the official UV image
FROM ghcr.io/astral-sh/uv:python3.11-bookworm-slim
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy

# Set the working directory to /app
WORKDIR /app

# Copy the uv.lock file and the pyproject.toml file
COPY uv.lock pyproject.toml /app/

# Install the libcups library and Git, then clean up apt lists
RUN apt-get update -y && \
apt-get install -y libcups2-dev git && \
rm -rf /var/lib/apt/lists/*

# Install the dependencies
RUN uv sync --frozen --no-install-project --no-dev

# Copy the rest of the application code to the container
COPY . /app

# Expose the port the application will run on
EXPOSE 8080

# Set the default command to run the application
CMD ["uv", "run", "app.py"]
8 changes: 8 additions & 0 deletions examples/flask-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Flask and Python-ESC/POS example

Simple example on how to use it inside a web service

```sh
docker build . -t flask-example
docker run --network=host -p 9999:9999 flask-example
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

from escpos.printer import CupsPrinter

# Initialize Flask app
# Initialize Flask application
app = Flask(__name__)


@app.route("/", methods=["GET"])
def do_print():
"""Print."""
# p = Usb(0x04b8, 0x0e28, 0)
def index():
"""Print a test message."""
p = CupsPrinter(host="localhost", port=631, printer_name="TM-T20III")
p.text("Hello World\n")
p.cut()
Expand Down
28 changes: 28 additions & 0 deletions examples/flask-example/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[project]
name = "flask-example"
version = "0.1.0"
description = "Flask and Python-ESC/POS example"
readme = "README.md"
requires-python = ">=3.9"
dependencies = [
"platformdirs==4.3.8",
"argcomplete==3.0.8",
"blinker==1.6.2",
"click==8.1.3",
"Flask==2.3.2",
"itsdangerous==2.1.2",
"Jinja2==3.1.6",
"MarkupSafe==2.1.2",
"Pillow==10.3.0",
"pycups==2.0.1",
"pypng==0.20220715.0",
"pyserial==3.5",
"python-barcode==0.14.0",
"python-escpos==3.0a9",
"pyusb==1.2.1",
"PyYAML==6.0",
"qrcode==7.4.2",
"six==1.16.0",
"typing_extensions==4.5.0",
"Werkzeug==3.0.6",
]
Loading
Loading