From d8e60a3194241a0e87e471ca2c58c16655a4e8ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Elsd=C3=B6rfer?= Date: Wed, 24 Aug 2016 12:07:42 +0200 Subject: [PATCH] Support multiple tab positions I had some trouble understanding how tabs are supposed to work. I'm a ESCPOS newb; that said, here are some changes that make sense to me: - My T88IIIP that I am working with certainly supports multiple tab positions. - They are not limited to 16 either. - It seems unnecessary that for every control(), we generate a command to initialize the tab positions. Now the tab position needs to be explicitly initialized by calling control() with the pos argument. This is a backwards-incompatibility issue. There may still be some Py3/Py2 issues here, but I wanted to get an opinion first. --- src/escpos/escpos.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index c0df537..58f848f 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -617,7 +617,7 @@ class Escpos(object): else: # DEFAULT: DOES NOTHING pass - def control(self, ctl, pos=4): + def control(self, ctl, pos=None): """ Feed control sequences :param ctl: string for the following control sequences: @@ -628,14 +628,16 @@ class Escpos(object): * HT *for Horizontal Tab* * VT *for Vertical Tab* - :param pos: integer between 1 and 16, controls the horizontal tab position + :param pos: controls the horizontal tab positions. an integer + or an iterable of integers. :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)) + if pos: + if not isinstance(pos, (list, tuple)): + pos = (pos,) + self._raw(CTL_SET_HT + b"".join(map(lambda p: six.int2byte(p), pos))) + # Set position if ctl.upper() == "LF": self._raw(CTL_LF)