Skip to content

Commit

Permalink
Release v3.0a1 (python-escpos#209 from python-escpos/development)
Browse files Browse the repository at this point in the history
Release v3.0a1
  • Loading branch information
patkan authored Mar 29, 2017
2 parents 4b81a27 + c1a7d71 commit df33945
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ src/escpos/version.py

# testing temporary directories
test/test-cli-output/

# vim swap files
*.swp
*.swn
*.swo
15 changes: 14 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ matrix:
env: TOXENV=docs
- python: 2.7
env: TOXENV=flake8
- python: 3.5
- python: 3.6
env: TOXENV=flake8
allow_failures:
- python: 3.6-dev
Expand All @@ -44,3 +44,16 @@ notifications:
email:
on_success: never
on_failure: change
deploy:
# Github deployment
- provider: releases
api_key:
secure: oiR3r5AIx9ENIRtbUKIxorRx8GMv4BxgVIZcieXbgSTN4DBZdRWdzs1Xxngu/90Xf79G0X+XGxZyXrYN7eFFNp0kUYj8kwZ1aS/dyR88scskumERWi1Hv5WUJrYGrDe7PcjNGsJ2jw0nNnRPKG87Y84aR4lQygyGBSlDcdrOBnBv0sHYJMxRvHSRkGgWpur06QIOGOk4oOipTXR/7E9cg3YQC5nvZAf2QiprwTa8IcOSFlZQPykEVRYSiAgXrgqBYcZzpX0hAGuIBv7DmPI2ORTF+t79Wbhxhnho3gGJleDv7Z96//sf1vQNCG6qOgeIc9ZY08Jm1AwXQoW0p6F1/XcEPxeyPDkXJzlojE9rjYNLCPL4gxb/LESEuUafm0U4JGMsZ6hnsBOw583yTuAdfQuJ9M+QaSyem6OVNkky3+DKAD3z0WJnl9jmGXIXigNSIxD25XhpvY+j9P0XTLBG1GT2Q+wXCIjSYJc2XnYcdgVJcLoxSWk1fKj/KPi7buAWtqwnL3tjeldpMMOZMliPUTWMM14zoGskHztt0JCkAtcotm9AQtvL8eZ2LHLDK/jyLzjv0wAwU5vzSVp14XHLZl7Q0AIoNc20p1EYGa9C/gSPd9CkrWZoG4lMOiAu3tp2PRLVrdXH3ZWSPQq4Ek5MczrUTkmB82XErNbOa8QB1Dw=
file: .tox/dist/python-escpos*.zip
file_glob: true
skip_cleanup: true
on:
tags: true
repo: python-escpos/python-escpos
branch: master
condition: $TRAVIS_PYTHON_VERSION = "3.5"
18 changes: 18 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
Changelog
*********

2017-03-29 - Version 3.0a1 - "Headcrash"
----------------------------------------
This release is the second alpha release of the new version 3.0. Please
be aware that the API will still change until v3.0 is released.

changes
^^^^^^^
- automatically upload releases to GitHub
- add environment variable ESCPOS_CAPABILITIES_FILE
- automatically handle cases where full cut or partial cut is not available
- add print_and_feed

contributors
^^^^^^^^^^^^
- Sam Cheng
- Patrick Kanzler
- Dmytro Katyukha

2017-01-31 - Version 3.0a - "Grey Area"
---------------------------------------
This release is the first alpha release of the new version 3.0. Please
Expand Down
4 changes: 0 additions & 4 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ coverage:
default: # status context
target: auto
threshold: "1%"
patch:
default:
target: auto
threshold: "1%"
range: "60...100"

comment: off
Expand Down
26 changes: 26 additions & 0 deletions doc/user/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,32 @@ Here you can download an example, that will print a set of common barcodes:

* :download:`barcode.bin </download/barcode.bin>` by `@mike42 <https://github.com/mike42>`_

Advanced Usage: change capabilities-profile
-------------------------------------------

Packaged together with the escpos-code is a capabilities-file. This file in
JSON-format describes the capabilities of different printers. It is developed and hosted in
`escpos-printer-db <https://github.com/receipt-print-hq/escpos-printer-db>`_.

Certain applications like the usage of `cx_freeze <https://cx-freeze.readthedocs.io>`_ might change the
packaging structure. This leads to the capabilities-profile not being found.
In this case you can use the environment-variable `ESCPOS_CAPABILITIES_FILE`.
The following code is an example.

.. code-block:: shell
# use packaged capabilities-profile
python-escpos cut
# use capabilities-profile that you have put in /usr/python-escpos
export ESCPOS_CAPABILITIES_FILE=/usr/python-escpos/capabilities.json
python-escpos cut
# use packaged file again
unset ESCPOS_CAPABILITIES_FILE
python-escpos cut
Hint: preprocess printing
-------------------------

Expand Down
9 changes: 7 additions & 2 deletions src/escpos/capabilities.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import re
import six
from os import path
from os import environ, path
import yaml

# Load external printer database
with open(path.join(path.dirname(__file__), 'capabilities.json')) as f:
if 'ESCPOS_CAPABILITIES_FILE' in environ:
file_path = environ['ESCPOS_CAPABILITIES_FILE']
else:
file_path = path.join(path.dirname(__file__), 'capabilities.json')

with open(file_path) as f:
CAPABILITIES = yaml.load(f)

PROFILES = CAPABILITIES['profiles']
Expand Down
6 changes: 6 additions & 0 deletions src/escpos/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def str_to_bool(string):
'option_strings': ('--content',),
'help': 'Text to print as a qr code',
'required': True,
},
{
'option_strings': ('--size',),
'help': 'QR code size (1-16) [default:3]',
'required': False,
'type': int,
}
],
},
Expand Down
53 changes: 39 additions & 14 deletions src/escpos/escpos.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def line_spacing(self, spacing=None, divisor=180):

self._raw(LINESPACING_FUNCS[divisor] + six.int2byte(spacing))

def cut(self, mode=''):
def cut(self, mode='FULL'):
""" Cut paper.
Without any arguments the paper will be cut completely. With 'mode=PART' a partial cut will
Expand All @@ -573,15 +573,25 @@ def cut(self, mode=''):
.. todo:: Check this function on TM-T88II.
:param mode: set to 'PART' for a partial cut
:param mode: set to 'PART' for a partial cut. default: 'FULL'
:raises ValueError: if mode not in ('FULL', 'PART')
"""
# Fix the size between last line and cut
# TODO: handle this with a line feed
self._raw(b"\n\n\n\n\n\n")
if mode.upper() == "PART":
self._raw(PAPER_PART_CUT)
else: # DEFAULT MODE: FULL CUT
self._raw(PAPER_FULL_CUT)
self.print_and_feed(6)

mode = mode.upper()
if mode not in ('FULL', 'PART'):
raise ValueError("Mode must be one of ('FULL', 'PART')")

if mode == "PART":
if self.profile.supports('paperPartCut'):
self._raw(PAPER_PART_CUT)
elif self.profile.supports('paperFullCut'):
self._raw(PAPER_FULL_CUT)
elif mode == "FULL":
if self.profile.supports('paperFullCut'):
self._raw(PAPER_FULL_CUT)
elif self.profile.supports('paperPartCut'):
self._raw(PAPER_PART_CUT)

def cashdraw(self, pin):
""" Send pulse to kick the cash drawer
Expand Down Expand Up @@ -620,6 +630,20 @@ def hw(self, hw):
else: # DEFAULT: DOES NOTHING
pass

def print_and_feed(self, n=1):
""" Print data in print buffer and feed *n* lines
if n not in range (0, 255) then ValueError will be raised
:param n: number of n to feed. 0 <= n <= 255. default: 1
:raises ValueError: if not 0 <= n <= 255
"""
if 0 <= n <= 255:
# ESC d n
self._raw(ESC + b"d" + six.int2byte(n))
else:
raise ValueError("n must be betwen 0 and 255")

def control(self, ctl, pos=4):
""" Feed control sequences
Expand All @@ -634,11 +658,6 @@ def control(self, ctl, pos=4):
:param pos: integer between 1 and 16, controls the horizontal tab position
:raises: :py:exc:`~escpos.exceptions.TabPosError`
"""
# Set tab positions
if not (1 <= pos <= 16):
raise TabPosError()
else:
self._raw(CTL_SET_HT + six.int2byte(pos))
# Set position
if ctl.upper() == "LF":
self._raw(CTL_LF)
Expand All @@ -647,6 +666,12 @@ def control(self, ctl, pos=4):
elif ctl.upper() == "CR":
self._raw(CTL_CR)
elif ctl.upper() == "HT":
if not (1 <= pos <= 16):
raise TabPosError()
else:
# Set tab positions
self._raw(CTL_SET_HT + six.int2byte(pos))

self._raw(CTL_HT)
elif ctl.upper() == "VT":
self._raw(CTL_VT)
Expand Down

0 comments on commit df33945

Please sign in to comment.