From f781e28a698fad736c1e84952b0f0c87b4f77762 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 00:03:22 +0200 Subject: [PATCH 01/11] Bump actions/setup-python from 5.0.0 to 5.1.0 (#632) Bumps [actions/setup-python](https://github.com/actions/setup-python) from 5.0.0 to 5.1.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v5.0.0...v5.1.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/pythonpackage-windows.yml | 2 +- .github/workflows/pythonpackage.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pythonpackage-windows.yml b/.github/workflows/pythonpackage-windows.yml index bf51b33..9fe6c04 100644 --- a/.github/workflows/pythonpackage-windows.yml +++ b/.github/workflows/pythonpackage-windows.yml @@ -19,7 +19,7 @@ jobs: with: submodules: 'recursive' - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5.0.0 + uses: actions/setup-python@v5.1.0 with: python-version: ${{ matrix.python-version }} - name: Install dependencies diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 4fb2bf4..f8412aa 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -22,7 +22,7 @@ jobs: with: submodules: 'recursive' - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5.0.0 + uses: actions/setup-python@v5.1.0 with: python-version: ${{ matrix.python-version }} - name: Install dependencies From a8a9d0f0adc24545aa5b4d340012a73c2ba36489 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 01:23:56 +0200 Subject: [PATCH 02/11] Bump codecov/codecov-action from 3 to 4 (#625) * Bump codecov/codecov-action from 3 to 4 Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3 to 4. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v3...v4) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] * add codecov token * add codecov token * remove directory config * adapt excludes * exclude mypy_cache * glob * exclude --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Patrick Kanzler <4189642+patkan@users.noreply.github.com> Co-authored-by: Patrick Kanzler --- .github/workflows/pythonpackage-windows.yml | 8 +++++--- .github/workflows/pythonpackage.yml | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pythonpackage-windows.yml b/.github/workflows/pythonpackage-windows.yml index 9fe6c04..29bf3e6 100644 --- a/.github/workflows/pythonpackage-windows.yml +++ b/.github/workflows/pythonpackage-windows.yml @@ -44,12 +44,14 @@ jobs: env: ESCPOS_CAPABILITIES_FILE: D:\a\python-escpos\python-escpos\capabilities-data\dist\capabilities.json - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: - directory: ./coverage/reports/ env_vars: OS,PYTHON fail_ci_if_error: true - files: ./coverage.xml,!./cache + files: ./coverage.xml + exclude: "**/.mypy_cache" flags: unittests name: coverage-tox-${{ matrix.python-version }} verbose: true diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index f8412aa..609aa82 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -54,12 +54,14 @@ jobs: env: ESCPOS_CAPABILITIES_FILE: /home/runner/work/python-escpos/python-escpos/capabilities-data/dist/capabilities.json - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: - directory: ./coverage/reports/ env_vars: OS,PYTHON fail_ci_if_error: true - files: ./coverage.xml,!./cache + files: ./coverage.xml + exclude: "**/.mypy_cache" flags: unittests name: coverage-tox-${{ matrix.python-version }} verbose: true From 640f6089ac2fd476e390d168c03d8e64968d30e8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 3 Apr 2024 21:04:35 +0200 Subject: [PATCH 03/11] Bump pillow from 10.2.0 to 10.3.0 in /examples/docker-flask (#634) Bumps [pillow](https://github.com/python-pillow/Pillow) from 10.2.0 to 10.3.0. - [Release notes](https://github.com/python-pillow/Pillow/releases) - [Changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst) - [Commits](https://github.com/python-pillow/Pillow/compare/10.2.0...10.3.0) --- updated-dependencies: - dependency-name: pillow dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- examples/docker-flask/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/docker-flask/requirements.txt b/examples/docker-flask/requirements.txt index 18d5582..8c9be67 100644 --- a/examples/docker-flask/requirements.txt +++ b/examples/docker-flask/requirements.txt @@ -6,7 +6,7 @@ Flask==2.3.2 itsdangerous==2.1.2 Jinja2==3.1.3 MarkupSafe==2.1.2 -Pillow==10.2.0 +Pillow==10.3.0 pycups==2.0.1 pypng==0.20220715.0 pyserial==3.5 From 1e9adb80f3e6376dde3068a9346ec698302cb366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benito=20L=C3=B3pez?= Date: Mon, 29 Apr 2024 23:50:52 +0200 Subject: [PATCH 04/11] Fix CLI not working for some connectors Fixes #639 (#640) --- src/escpos/config.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/escpos/config.py b/src/escpos/config.py index 17a2328..9ca5b7e 100644 --- a/src/escpos/config.py +++ b/src/escpos/config.py @@ -76,7 +76,18 @@ class Config: if "printer" in config: self._printer_config = config["printer"] - self._printer_name = self._printer_config.pop("type").title() + printer_name = self._printer_config.pop("type") + class_names = { + "usb": "Usb", + "serial": "Serial", + "network": "Network", + "file": "File", + "dummy": "Dummy", + "cupsprinter": "CupsPrinter", + "lp": "LP", + "win32raw": "Win32Raw", + } + self._printer_name = class_names.get(printer_name.lower(), printer_name) if not self._printer_name or not hasattr(printer, self._printer_name): raise exceptions.ConfigSyntaxError( From 82f5a00b8db7ea3f36617b13bd0724a2175c75f2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 May 2024 21:40:03 +0200 Subject: [PATCH 05/11] Bump werkzeug from 3.0.1 to 3.0.3 in /examples/docker-flask (#641) Bumps [werkzeug](https://github.com/pallets/werkzeug) from 3.0.1 to 3.0.3. - [Release notes](https://github.com/pallets/werkzeug/releases) - [Changelog](https://github.com/pallets/werkzeug/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/werkzeug/compare/3.0.1...3.0.3) --- updated-dependencies: - dependency-name: werkzeug dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- examples/docker-flask/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/docker-flask/requirements.txt b/examples/docker-flask/requirements.txt index 8c9be67..8fa6cee 100644 --- a/examples/docker-flask/requirements.txt +++ b/examples/docker-flask/requirements.txt @@ -17,4 +17,4 @@ PyYAML==6.0 qrcode==7.4.2 six==1.16.0 typing_extensions==4.5.0 -Werkzeug==3.0.1 \ No newline at end of file +Werkzeug==3.0.3 \ No newline at end of file From 4c02881fe7bfa19728a316e1884e2b1eea2a53e9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 May 2024 22:54:24 +0200 Subject: [PATCH 06/11] Bump jinja2 from 3.1.3 to 3.1.4 in /examples/docker-flask (#642) Bumps [jinja2](https://github.com/pallets/jinja) from 3.1.3 to 3.1.4. - [Release notes](https://github.com/pallets/jinja/releases) - [Changelog](https://github.com/pallets/jinja/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/jinja/compare/3.1.3...3.1.4) --- updated-dependencies: - dependency-name: jinja2 dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- examples/docker-flask/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/docker-flask/requirements.txt b/examples/docker-flask/requirements.txt index 8fa6cee..ce8f94e 100644 --- a/examples/docker-flask/requirements.txt +++ b/examples/docker-flask/requirements.txt @@ -4,7 +4,7 @@ blinker==1.6.2 click==8.1.3 Flask==2.3.2 itsdangerous==2.1.2 -Jinja2==3.1.3 +Jinja2==3.1.4 MarkupSafe==2.1.2 Pillow==10.3.0 pycups==2.0.1 From fe3cdde424597c2dd40394cdb15e01c3d53b4931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benito=20L=C3=B3pez?= Date: Fri, 24 May 2024 23:21:54 +0200 Subject: [PATCH 07/11] Clarify set() width and height documentation (#644) --- src/escpos/escpos.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index ada52ec..f9f6e4e 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -934,8 +934,8 @@ class Escpos(object, metaclass=ABCMeta): :param double_width: doubles the width of the text :param custom_size: uses custom size specified by width and height parameters. Cannot be used with double_width or double_height. - :param width: text width multiplier when custom_size is used, decimal range 1-8 - :param height: text height multiplier when custom_size is used, decimal range 1-8 + :param width: requires custom_size=True, text width multiplier when custom_size is used, decimal range 1-8 + :param height: requires custom_size=True, text height multiplier when custom_size is used, decimal range 1-8 :param density: print density, value from 0-8, if something else is supplied the density remains unchanged :param invert: True enables white on black printing :param smooth: True enables text smoothing. Effective on 4x4 size text and larger From 5af01641d95da11abb70b03f332d258aca7fa495 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 Jul 2024 16:41:42 +0200 Subject: [PATCH 08/11] Bump actions/setup-python from 5.1.0 to 5.1.1 (#648) Bumps [actions/setup-python](https://github.com/actions/setup-python) from 5.1.0 to 5.1.1. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v5.1.0...v5.1.1) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/pythonpackage-windows.yml | 2 +- .github/workflows/pythonpackage.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pythonpackage-windows.yml b/.github/workflows/pythonpackage-windows.yml index 29bf3e6..edd1bd9 100644 --- a/.github/workflows/pythonpackage-windows.yml +++ b/.github/workflows/pythonpackage-windows.yml @@ -19,7 +19,7 @@ jobs: with: submodules: 'recursive' - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5.1.0 + uses: actions/setup-python@v5.1.1 with: python-version: ${{ matrix.python-version }} - name: Install dependencies diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 609aa82..992465e 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -22,7 +22,7 @@ jobs: with: submodules: 'recursive' - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5.1.0 + uses: actions/setup-python@v5.1.1 with: python-version: ${{ matrix.python-version }} - name: Install dependencies From a8753a1121fcfdd1903d13c80937105c83073812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benito=20L=C3=B3pez?= Date: Thu, 11 Jul 2024 17:13:34 +0200 Subject: [PATCH 09/11] New feature: Software columns (#645) * add type hint Alignment * Add static method padding() * Add static method truncate() * Add static method _repeat_last() * Add private method _rearrange_into_cols() * Add private method _add_padding_into_cols() * Add public method software_columns * Make truncate and padding private staticmethods * Revert "add type hint Alignment" This reverts commit 546391cb9c3d246d536cb5abb269ed4d36e175ce. * Add type hint Alignment * Fix typo in docstring --------- Co-authored-by: Patrick Kanzler <4189642+patkan@users.noreply.github.com> --- src/escpos/escpos.py | 111 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index f9f6e4e..daad90d 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -107,6 +107,8 @@ SW_BARCODE_NAMES = { for name in barcode.PROVIDED_BARCODES } +Alignment = Union[Literal["center", "left", "right"], str] + class Escpos(object, metaclass=ABCMeta): """ESC/POS Printer object. @@ -897,6 +899,115 @@ class Escpos(object, metaclass=ABCMeta): col_count = self.profile.get_columns(font) if columns is None else columns self.text(textwrap.fill(txt, col_count)) + @staticmethod + def _padding( + text: str, + width: int, + align: Alignment = "center", + ) -> str: + """Add fill space to meet the width. + + The align parameter sets the alignment of the text in space. + """ + align = align.lower() + if align == "center": + text = f"{text:^{width}}" + elif align == "left": + text = f"{text:<{width}}" + elif align == "right": + text = f"{text:>{width}}" + + return text + + @staticmethod + def _truncate(text: str, width: int, placeholder: str = ".") -> str: + """Truncate an string at a max width or leave it untouched. + + Add a placeholder at the end of the output text if it has been truncated. + """ + ph_len = len(placeholder) + max_len = width - ph_len + return f"{text[:max_len]}{placeholder}" if len(text) > width else text + + @staticmethod + def _repeat_last(iterable, max_iterations: int = 1000): + """Iterate over the items of a list repeating the last one until max_iterations.""" + i = 0 + while i < max_iterations: + try: + yield iterable[i] + except IndexError: + yield iterable[-1] + i += 1 + + def _rearrange_into_cols(self, text_list: list, widths: list[int]) -> list: + """Wrap and convert a list of strings into an array of text columns. + + Set the width of each column by passing a list of widths. + Wrap if possible and|or truncate strings longer than its column width. + Reorder the wrapped items into an array of text columns. + """ + n_cols = len(text_list) + wrapped = [ + textwrap.wrap(text, widths[i], break_long_words=False) + for i, text in enumerate(text_list) + ] + max_len = max(*[len(text_group) for text_group in wrapped]) + text_colums = [] + for i in range(max_len): + row = ["" for _ in range(n_cols)] + for j, item in enumerate(wrapped): + if i in range(len(item)): + row[j] = self._truncate(item[i], widths[j]) + text_colums.append(row) + return text_colums + + def _add_padding_into_cols( + self, + text_list: list[str], + widths: list[int], + align: list[Alignment], + ) -> list: + """Add padding, width and alignment into the items of a list of strings.""" + return [ + self._padding(text, widths[i], align[i]) for i, text in enumerate(text_list) + ] + + def software_columns( + self, + text_list: list, + widths: Union[list[int], int], + align: Union[list[Alignment], Alignment], + ) -> None: + """Print a list of strings arranged horizontally in columns. + + :param text_list: list of strings, each item in the list will be printed as a column. + + :param widths: width of each column by passing a list of widths, + or a single total width to arrange columns of the same size. + If the list of width items is shorter than the list of strings then + the last width of the list will be applied till the last string (column). + + :param align: alignment of the text into each column by passing a list of alignments, + or a single alignment for all the columns. + If the list of alignment items is shorter than the list of strings then + the last alignment of the list will be applied till the last string (column). + """ + n_cols = len(text_list) + + if isinstance(widths, int): + widths = [round(widths / n_cols)] + widths = list(self._repeat_last(widths, max_iterations=n_cols)) + + if isinstance(align, str): + align = [align] + align = list(self._repeat_last(align, max_iterations=n_cols)) + + columns = self._rearrange_into_cols(text_list, widths) + for row in columns: + padded = self._add_padding_into_cols(row, widths, align) + self.textln("".join(padded)) + def set( self, align: Optional[str] = None, From 3aaf203cebda39750fb1380689469f1724e18f65 Mon Sep 17 00:00:00 2001 From: Psychpsyo <60073468+Psychpsyo@users.noreply.github.com> Date: Fri, 19 Jul 2024 22:18:09 +0200 Subject: [PATCH 10/11] Fix typo in README (#650) --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 0e2121c..cfcebc2 100644 --- a/README.rst +++ b/README.rst @@ -100,4 +100,4 @@ Disclaimer 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. +Their names are used only to maintain context. From 99501cc2c1d21ea156b8b8b530ad66c9c9d00fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benito=20L=C3=B3pez?= Date: Fri, 19 Jul 2024 22:23:52 +0200 Subject: [PATCH 11/11] New feature: Software columns - Part 2: CLI (#649) * Add software_columns CLI parameter * Fix sorting --------- Co-authored-by: Patrick Kanzler <4189642+patkan@users.noreply.github.com> --- src/escpos/cli.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/escpos/cli.py b/src/escpos/cli.py index f70d922..2906c16 100644 --- a/src/escpos/cli.py +++ b/src/escpos/cli.py @@ -209,6 +209,38 @@ ESCPOS_COMMANDS: List[Dict[str, Any]] = [ }, ], }, + { + "parser": { + "name": "software_columns", + "help": "Print a list of texts arranged into columns", + }, + "defaults": { + "func": "software_columns", + }, + "arguments": [ + { + "option_strings": ("--text_list",), + "help": "list of texts to print", + "nargs": "+", + "type": str, + "required": True, + }, + { + "option_strings": ("--widths",), + "help": "list of column widths", + "nargs": "+", + "type": int, + "required": True, + }, + { + "option_strings": ("--align",), + "help": "list of column alignments", + "nargs": "+", + "type": str, + "required": True, + }, + ], + }, { "parser": { "name": "cut",