Merge branch 'master' into belono/issue245
This commit is contained in:
commit
6e9548ce0d
13
.github/PULL_REQUEST_TEMPLATE.md
vendored
13
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -1,10 +1,5 @@
|
||||
### Contributor checklist
|
||||
<!-- mark with x between the brackets -->
|
||||
- [ ] I have read the CONTRIBUTING.rst
|
||||
- [ ] I have tested my contribution on these devices:
|
||||
* e.g. Epson TM-T88II
|
||||
- [ ] My contribution is ready to be merged as is
|
||||
|
||||
----------
|
||||
|
||||
### Description
|
||||
|
||||
|
||||
### Tested with
|
||||
_If applicable, please describe with which device you have tested._
|
5
.github/workflows/codeql-analysis.yml
vendored
5
.github/workflows/codeql-analysis.yml
vendored
@ -36,11 +36,6 @@ jobs:
|
||||
# a pull request then we can checkout the head.
|
||||
fetch-depth: 2
|
||||
|
||||
# If this run was triggered by a pull request event, then checkout
|
||||
# the head of the pull request instead of the merge commit.
|
||||
- run: git checkout HEAD^2
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
|
2
.github/workflows/pythonpackage.yml
vendored
2
.github/workflows/pythonpackage.yml
vendored
@ -22,7 +22,7 @@ jobs:
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v4.5.0
|
||||
uses: actions/setup-python@v4.6.1
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install dependencies
|
||||
|
1
.mailmap
1
.mailmap
@ -13,6 +13,7 @@ csoft2k <csoft2k@hotmail.com>
|
||||
Sergio Pulgarin <sergio.pulgarin@gmail.com>
|
||||
reck31 <rakesh.gunduka@gmail.com>
|
||||
Alex Debiasio <alex.debiasio@thinkin.io> <alex.debiasio@studenti.unitn.it>
|
||||
白月秋见心 <ourweijiang@gmail.com>
|
||||
Maximilian Wagenbach <maximilian.wagenbach@native-instruments.de>
|
||||
<belono@users.noreply.github.com> <tiotil.lindeman@gmail.com>
|
||||
belono <belono@users.noreply.github.com> Benito López <belono@users.noreply.github.com>
|
||||
|
27
.readthedocs.yml
Normal file
27
.readthedocs.yml
Normal file
@ -0,0 +1,27 @@
|
||||
version: 2
|
||||
formats:
|
||||
- pdf
|
||||
- epub
|
||||
build:
|
||||
os: ubuntu-22.04
|
||||
tools:
|
||||
python: "3.11"
|
||||
apt_packages:
|
||||
- graphviz
|
||||
- libenchant-2-2
|
||||
- gcc
|
||||
- libcups2-dev
|
||||
- python3-dev
|
||||
sphinx:
|
||||
configuration: doc/conf.py
|
||||
submodules:
|
||||
include:
|
||||
- capabilities-data
|
||||
recursive: true
|
||||
|
||||
python:
|
||||
install:
|
||||
- requirements: doc/requirements.txt
|
||||
- method: pip
|
||||
path: .
|
||||
system_packages: true
|
5
AUTHORS
5
AUTHORS
@ -1,9 +1,11 @@
|
||||
Ahmed Tahri
|
||||
akeonly
|
||||
Alejandro Hernández
|
||||
Alexander Bougakov
|
||||
Alex Debiasio
|
||||
Asuki Kono
|
||||
belono
|
||||
B. Howell
|
||||
Brian
|
||||
Christoph Heuel
|
||||
Cody (Quantified Code Bot)
|
||||
@ -11,6 +13,7 @@ csoft2k
|
||||
Curtis // mashedkeyboard
|
||||
Davis Goglin
|
||||
Dean Rispin
|
||||
dependabot[bot]
|
||||
Dmytro Katyukha
|
||||
Gerard Marull-Paretas
|
||||
Hark
|
||||
@ -21,6 +24,7 @@ Kristi
|
||||
ldos
|
||||
Lucy Linder
|
||||
Manuel F Martinez
|
||||
Mathieu Poussin
|
||||
Maximilian Wagenbach
|
||||
Michael Billington
|
||||
Michael Elsdörfer
|
||||
@ -41,3 +45,4 @@ Thijs Triemstra
|
||||
Thomas van den Berg
|
||||
Yaisel Hurtado
|
||||
ysuolmai
|
||||
白月秋见心
|
||||
|
@ -1,6 +1,28 @@
|
||||
*********
|
||||
Changelog
|
||||
*********
|
||||
2023-05-11 - Version 3.0a9 - "Pride Comes Before A Fall"
|
||||
--------------------------------------------------------
|
||||
This release is the 10th alpha release of the new version 3.0.
|
||||
After three years hiatus, a new release is in work in order to
|
||||
finally get a version 3.0 out.
|
||||
|
||||
changes
|
||||
^^^^^^^
|
||||
- Include support for CUPS based printer interfaces
|
||||
- Move the build toolchain to GitHub
|
||||
|
||||
contributors
|
||||
^^^^^^^^^^^^
|
||||
- belono
|
||||
- brendanhowell
|
||||
- AlexandroJaez
|
||||
- NullYing
|
||||
- kedare
|
||||
- Foaly
|
||||
- patkan
|
||||
- and others
|
||||
|
||||
2020-05-12 - Version 3.0a8 - "Only Slightly Bent"
|
||||
-------------------------------------------------
|
||||
This release is the ninth alpha release of the new version 3.0.
|
||||
|
@ -17,23 +17,20 @@ Author-list
|
||||
|
||||
This project keeps a list of authors. This can be auto-generated by calling `./doc/generate-authors.sh`.
|
||||
When contributing the first time, please include a commit with the output of this script in place.
|
||||
Otherwise the integration-check will fail.
|
||||
|
||||
When you change your username or mail-address, please also update the `.mailmap` and the authors-list.
|
||||
You can find a good documentation on the mapping-feature in the `documentation of git-shortlog <https://git-scm.com/docs/git-shortlog#_mapping_authors>`_.
|
||||
You can find a good documentation on the mapping-feature in the
|
||||
`documentation of git-shortlog <https://git-scm.com/docs/git-shortlog#_mapping_authors>`_.
|
||||
|
||||
Style-Guide
|
||||
-----------
|
||||
|
||||
When writing code please try to stick to these rules.
|
||||
|
||||
PEP8
|
||||
^^^^
|
||||
The entire codebase adheres to the rules of PEP8.
|
||||
These rules are enforced by running `flake8` in the integration-checks.
|
||||
Please adhere to these rules as your contribution can only be merged if the check succeeds.
|
||||
You can use flake8 or similar tools locally in order to check your code.
|
||||
Apart from that the travis-log and the check by Landscape will provide you with hints.
|
||||
Black Code Style
|
||||
^^^^^^^^^^^^^^^^
|
||||
This project is formatted with the auto formatter `black <https://github.com/psf/black>`_.
|
||||
Please format your contributions with black, otherwise they will be rejected.
|
||||
|
||||
GIT
|
||||
^^^
|
||||
|
18
README.rst
18
README.rst
@ -2,14 +2,6 @@
|
||||
python-escpos - Python library to manipulate ESC/POS Printers
|
||||
#############################################################
|
||||
|
||||
.. image:: https://travis-ci.org/python-escpos/python-escpos.svg?branch=master
|
||||
:target: https://travis-ci.org/python-escpos/python-escpos
|
||||
:alt: Continous Integration
|
||||
|
||||
.. image:: https://codecov.io/github/python-escpos/python-escpos/coverage.svg?branch=master
|
||||
:target: https://codecov.io/github/python-escpos/python-escpos?branch=master
|
||||
:alt: Code Coverage
|
||||
|
||||
.. image:: https://readthedocs.org/projects/python-escpos/badge/?version=latest
|
||||
:target: https://python-escpos.readthedocs.io/en/latest/?badge=latest
|
||||
:alt: Documentation Status
|
||||
@ -93,16 +85,20 @@ Another example based on the Serial printer class:
|
||||
p.cut()
|
||||
|
||||
|
||||
The full project-documentation is available on `Read the Docs <https://python-escpos.readthedocs.io>`_.
|
||||
The full project-documentation is available on
|
||||
`Read the Docs <https://python-escpos.readthedocs.io>`_.
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
This project is open for any contribution! Please see `CONTRIBUTING.rst <https://python-escpos.readthedocs.io/en/latest/dev/contributing.html>`_ for more information.
|
||||
This project is open for any contribution! Please see
|
||||
`CONTRIBUTING.rst <https://python-escpos.readthedocs.io/en/latest/dev/contributing.html>`_
|
||||
for more information.
|
||||
|
||||
|
||||
Disclaimer
|
||||
----------
|
||||
|
||||
None of the vendors cited in this project agree or endorse any of the patterns or implementations.
|
||||
None of the vendors cited in this project agree or endorse any of the
|
||||
patterns or implementations.
|
||||
Its names are used only to maintain context.
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 3612db407d02a08acd93a1540f2b4823be3f020e
|
||||
Subproject commit 1bf6a482bd62c2093b6501db189008961e2509de
|
@ -122,6 +122,7 @@ pygments_style = "sphinx"
|
||||
# a list of builtin themes.
|
||||
if on_rtd:
|
||||
html_theme = "default"
|
||||
print("recognized execution on RTD")
|
||||
else:
|
||||
try:
|
||||
import sphinx_rtd_theme
|
||||
|
@ -2,9 +2,10 @@ pyusb
|
||||
Pillow>=2.0
|
||||
qrcode>=4.0
|
||||
pyserial
|
||||
sphinx-rtd-theme
|
||||
sphinx-rtd-theme==1.2.1
|
||||
setuptools
|
||||
setuptools-scm
|
||||
docutils>=0.12
|
||||
sphinxcontrib-spelling>=7.2.0
|
||||
python-barcode>=0.11.0,<1
|
||||
importlib-metadata
|
||||
|
28
examples/docker-flask/Dockerfile
Normal file
28
examples/docker-flask/Dockerfile
Normal file
@ -0,0 +1,28 @@
|
||||
# Use the official Python image as the base image
|
||||
FROM python:3.9-slim
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the requirements file
|
||||
COPY requirements.txt .
|
||||
|
||||
#Install the libcups library
|
||||
RUN apt-get update -y && apt-get install libcups2-dev -y
|
||||
# Install the Python packages
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
RUN pip install python-escpos --pre
|
||||
|
||||
# Install Git
|
||||
RUN apt-get update && \
|
||||
apt-get install -y git && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy the Flask app
|
||||
COPY app.py .
|
||||
|
||||
# Expose the port the Flask app will run on
|
||||
EXPOSE 8080
|
||||
|
||||
# Run the Flask app
|
||||
CMD ["python", "app.py"]
|
6
examples/docker-flask/README.md
Normal file
6
examples/docker-flask/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
Simple example on how to use it inside a web service
|
||||
|
||||
```
|
||||
docker build . -t escpos-web
|
||||
docker run --network=host -p 9999:9999 escpos
|
||||
```
|
22
examples/docker-flask/app.py
Normal file
22
examples/docker-flask/app.py
Normal file
@ -0,0 +1,22 @@
|
||||
import escpos
|
||||
from escpos.printer import *
|
||||
from flask import Flask, jsonify, request, redirect, session, url_for
|
||||
import sys
|
||||
from io import BytesIO
|
||||
|
||||
# Initialize Flask app
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route("/", methods=["GET"])
|
||||
def do_print():
|
||||
# p = Usb(0x04b8, 0x0e28, 0)
|
||||
p = CupsPrinter(host="localhost", port=631, printer_name="TM-T20III")
|
||||
p.text("Hello World\n")
|
||||
p.cut()
|
||||
p.close()
|
||||
return "OK"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=False, host="0.0.0.0", port=9999)
|
21
examples/docker-flask/requirements.txt
Normal file
21
examples/docker-flask/requirements.txt
Normal file
@ -0,0 +1,21 @@
|
||||
appdirs==1.4.4
|
||||
argcomplete==3.0.8
|
||||
blinker==1.6.2
|
||||
click==8.1.3
|
||||
Flask==2.3.2
|
||||
future==0.18.3
|
||||
itsdangerous==2.1.2
|
||||
Jinja2==3.1.2
|
||||
MarkupSafe==2.1.2
|
||||
Pillow==9.5.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==2.3.4
|
@ -1,7 +0,0 @@
|
||||
formats:
|
||||
- pdf
|
||||
- epub
|
||||
requirements_file: doc/requirements.txt
|
||||
python:
|
||||
version: 3
|
||||
setup_py_install: true
|
@ -77,6 +77,16 @@ LINE_DISPLAY_CLOSE = ESC + b"\x3d\x01"
|
||||
SHEET_SLIP_MODE = ESC + b"\x63\x30\x04" # slip paper
|
||||
SHEET_ROLL_MODE = ESC + b"\x63\x30\x01" # paper roll
|
||||
|
||||
# Slip specific codes
|
||||
SLIP_EJECT = ESC + b"\x4b\xc0" # Eject the slip or cheque
|
||||
SLIP_SELECT = FS # Select the slip station as default station
|
||||
SLIP_SET_WAIT_TIME = (
|
||||
ESC + b"\x1b\x66"
|
||||
) # Set timeout waiting for a slip/cheque to be inserted
|
||||
SLIP_PRINT_AND_EJECT = (
|
||||
b"\x0c" # Print the buffer and eject (after waiting for the paper to be inserted)
|
||||
)
|
||||
|
||||
# Text format
|
||||
# TODO: Acquire the "ESC/POS Application Programming Guide for Paper Roll
|
||||
# Printers" and tidy up this stuff too.
|
||||
|
@ -30,6 +30,11 @@ from .constants import (
|
||||
QR_ECLEVEL_M,
|
||||
QR_ECLEVEL_H,
|
||||
QR_ECLEVEL_Q,
|
||||
SHEET_ROLL_MODE,
|
||||
SHEET_SLIP_MODE,
|
||||
SLIP_PRINT_AND_EJECT,
|
||||
SLIP_SELECT,
|
||||
SLIP_EJECT,
|
||||
)
|
||||
from .constants import (
|
||||
QR_MODEL_1,
|
||||
@ -794,21 +799,19 @@ class Escpos(object):
|
||||
)
|
||||
)
|
||||
|
||||
# Render the barcode to a fake file
|
||||
# Render the barcode
|
||||
barcode_class = barcode.get_barcode_class(barcode_type)
|
||||
my_code = barcode_class(data, writer=image_writer)
|
||||
|
||||
with open(os.devnull, "wb") as nullfile:
|
||||
my_code.write(
|
||||
nullfile,
|
||||
{
|
||||
"module_height": module_height,
|
||||
"module_width": module_width,
|
||||
"quiet_zone": 0, # horizontal padding
|
||||
"text_distance": text_distance,
|
||||
"font_size": font_size,
|
||||
},
|
||||
)
|
||||
my_code.render(
|
||||
writer_options={
|
||||
"module_height": module_height,
|
||||
"module_width": module_width,
|
||||
"quiet_zone": 0, # horizontal padding
|
||||
"text_distance": text_distance,
|
||||
"font_size": font_size,
|
||||
}
|
||||
)
|
||||
|
||||
# Retrieve the Pillow image and print it
|
||||
image = my_code.writer._image
|
||||
@ -1208,6 +1211,41 @@ class Escpos(object):
|
||||
if status[0] & RT_MASK_PAPER == RT_MASK_PAPER:
|
||||
return 2
|
||||
|
||||
def target(self, type="ROLL"):
|
||||
"""Select where to print to
|
||||
|
||||
Print to the thermal printer by default (ROLL) or
|
||||
print to the slip dot matrix printer if supported (SLIP)
|
||||
"""
|
||||
if type.upper() == "ROLL":
|
||||
self._raw(SHEET_ROLL_MODE)
|
||||
elif type.upper() == "SLIP":
|
||||
self._raw(SHEET_SLIP_MODE)
|
||||
else:
|
||||
raise ValueError("Unsupported target")
|
||||
|
||||
def eject_slip(self):
|
||||
"""Eject the slip/cheque"""
|
||||
self._raw(SLIP_EJECT)
|
||||
|
||||
def print_and_eject_slip(self):
|
||||
"""Print and eject
|
||||
|
||||
Prints data from the buffer to the slip station and if the paper
|
||||
sensor is covered, reverses the slip out the front of the printer
|
||||
far enough to be accessible to the operator.
|
||||
The impact station opens the platen in all cases.
|
||||
"""
|
||||
self._raw(SLIP_PRINT_AND_EJECT)
|
||||
|
||||
def use_slip_only(self):
|
||||
"""Selects the Slip Station for all functions.
|
||||
|
||||
The receipt station is the default setting after the printer
|
||||
is initialized or the Clear Printer (0x10) command is received
|
||||
"""
|
||||
self._raw(SLIP_SELECT)
|
||||
|
||||
|
||||
class EscposIO(object):
|
||||
"""ESC/POS Printer IO object
|
||||
|
@ -18,6 +18,7 @@ from .constants import CODEPAGE_CHANGE
|
||||
from .exceptions import Error
|
||||
from .codepages import CodePages
|
||||
import six
|
||||
import re
|
||||
|
||||
|
||||
class Encoder(object):
|
||||
@ -252,6 +253,10 @@ class MagicEncode(object):
|
||||
self.write_with_encoding(self.encoding, text)
|
||||
return
|
||||
|
||||
if re.findall(r"[\u4e00-\u9fa5]", text):
|
||||
self.driver._raw(text.encode("GB18030"))
|
||||
return
|
||||
|
||||
# See how far we can go into the text with the current encoding
|
||||
to_write, text = split_writable_text(self.encoder, text, self.encoding)
|
||||
if to_write:
|
||||
|
Loading…
x
Reference in New Issue
Block a user