From b0ea9aec41d2347b88ee7332260e9d722d96acef Mon Sep 17 00:00:00 2001 From: Romain Porte Date: Mon, 7 Oct 2019 07:25:28 +0200 Subject: [PATCH 1/5] barcodes: replace viivakoodi with python-barcode python-barcode is yet another clone of the PyPI barcode library, but which is still developped compared to viivakoodi. Signed-off-by: Romain Porte --- README.rst | 2 +- doc/requirements.txt | 2 +- setup.cfg | 1 + tox.ini | 3 ++- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index cc1bc7b..86683b0 100644 --- a/README.rst +++ b/README.rst @@ -43,7 +43,7 @@ This library makes use of: * `Pillow `_ for image printing * `qrcode `_ for the generation of QR-codes * `pyserial `_ for serial printers -* `viivakoodi `_ for the generation of barcodes +* `python-barcode `_ for the generation of barcodes Documentation and Usage ----------------------- diff --git a/doc/requirements.txt b/doc/requirements.txt index 9f38356..89cd833 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -5,4 +5,4 @@ pyserial sphinx-rtd-theme setuptools-scm docutils>=0.12 -viivakoodi +python-barcode>=0.11.0,<1 diff --git a/setup.cfg b/setup.cfg index a2dcf83..10e0396 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,6 +39,7 @@ install_requires = Pillow>=2.0 qrcode>=4.0 pyserial + python-barcode>=0.9.1,<1 six appdirs PyYAML diff --git a/tox.ini b/tox.ini index 53211f3..d0f9361 100644 --- a/tox.ini +++ b/tox.ini @@ -18,6 +18,7 @@ deps = nose pytest-cov pytest-mock hypothesis>4 + python-barcode viivakoodi commands = pytest --cov escpos passenv = ESCPOS_CAPABILITIES_PICKLE_DIR ESCPOS_CAPABILITIES_FILE CI TRAVIS TRAVIS_* APPVEYOR APPVEYOR_* CODECOV_* @@ -27,7 +28,7 @@ basepython = python changedir = doc deps = sphinx>=1.5.1 setuptools_scm - viivakoodi + python-barcode commands = sphinx-build -W -b html -d {envtmpdir}/doctrees . {envtmpdir}/html [testenv:flake8] From 1e313cefc6a7c8e9a4ee0a29beae5c214307ab78 Mon Sep 17 00:00:00 2001 From: Romain Porte Date: Sun, 10 May 2020 14:03:43 +0200 Subject: [PATCH 2/5] test_function_barcode.py: remove unused imports --- test/test_function_barcode.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_function_barcode.py b/test/test_function_barcode.py index c3a0c7f..a2db09c 100644 --- a/test/test_function_barcode.py +++ b/test/test_function_barcode.py @@ -1,7 +1,6 @@ #!/usr/bin/python import escpos.printer as printer -from escpos.constants import BARCODE_TYPE_A, BARCODE_TYPE_B from escpos.capabilities import Profile, BARCODE_B from escpos.exceptions import BarcodeTypeError, BarcodeCodeError import pytest From 725f1254aa3f2fc79d9ccf8ec5aafbe6785be8ab Mon Sep 17 00:00:00 2001 From: Romain Porte Date: Sun, 10 May 2020 14:04:25 +0200 Subject: [PATCH 3/5] examples: software_barcode: fix too long code39 for 5890 printer --- examples/software_barcode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/software_barcode.py b/examples/software_barcode.py index 2fd3c18..9bbcc09 100644 --- a/examples/software_barcode.py +++ b/examples/software_barcode.py @@ -6,4 +6,4 @@ p = Usb(0x0416, 0x5011, profile="POS-5890") # Some software barcodes p.soft_barcode('code128', 'Hello') -p.soft_barcode('code39', '123456') +p.soft_barcode('code39', '1234') From ab30ef4a8c98a9e1c5cfaf264fc437bcc82d1859 Mon Sep 17 00:00:00 2001 From: Romain Porte Date: Sun, 10 May 2020 14:05:33 +0200 Subject: [PATCH 4/5] test_function_softbarcode: use pytest fixture --- test/test_function_softbarcode.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/test_function_softbarcode.py b/test/test_function_softbarcode.py index 1bef1cd..f9288f7 100644 --- a/test/test_function_softbarcode.py +++ b/test/test_function_softbarcode.py @@ -4,9 +4,11 @@ import escpos.printer as printer import pytest -def test_soft_barcode(): - """just execute soft_barcode - """ - instance = printer.Dummy() +@pytest.fixture +def instance(): + return printer.Dummy() + + +def test_soft_barcode_ean8(instance): instance.soft_barcode("ean8", "1234") From 8ca682e3acf19f0b599235b22d9fb711c368e047 Mon Sep 17 00:00:00 2001 From: Romain Porte Date: Sun, 10 May 2020 14:06:00 +0200 Subject: [PATCH 5/5] soft_barcode: add new center=True option --- src/escpos/escpos.py | 5 +++-- test/test_function_softbarcode.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index 17e0d12..24f6475 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -479,7 +479,8 @@ class Escpos(object): self._raw(NUL) def soft_barcode(self, barcode_type, data, impl='bitImageColumn', - module_height=5, module_width=0.2, text_distance=1): + module_height=5, module_width=0.2, text_distance=1, + center=True): image_writer = ImageWriter() @@ -502,7 +503,7 @@ class Escpos(object): # Retrieve the Pillow image and print it image = my_code.writer._image - self.image(image, impl=impl) + self.image(image, impl=impl, center=center) def text(self, txt): """ Print alpha-numeric text diff --git a/test/test_function_softbarcode.py b/test/test_function_softbarcode.py index f9288f7..fc702d7 100644 --- a/test/test_function_softbarcode.py +++ b/test/test_function_softbarcode.py @@ -12,3 +12,6 @@ def instance(): def test_soft_barcode_ean8(instance): instance.soft_barcode("ean8", "1234") + +def test_soft_barcode_ean8_nocenter(instance): + instance.soft_barcode("ean8", "1234", center=False)