Refactored `cut` method. added `print_and_feed` method

This commit is contained in:
Dmytro Katyukha 2017-02-06 14:48:15 +00:00 committed by Patrick Kanzler
parent 29cc8baab7
commit abbe32f845
1 changed files with 32 additions and 10 deletions

View File

@ -564,7 +564,7 @@ class Escpos(object):
self._raw(LINESPACING_FUNCS[divisor] + six.int2byte(spacing)) self._raw(LINESPACING_FUNCS[divisor] + six.int2byte(spacing))
def cut(self, mode=''): def cut(self, mode='FULL'):
""" Cut paper. """ Cut paper.
Without any arguments the paper will be cut completely. With 'mode=PART' a partial cut will Without any arguments the paper will be cut completely. With 'mode=PART' a partial cut will
@ -573,17 +573,25 @@ class Escpos(object):
.. todo:: Check this function on TM-T88II. .. 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 self.print_and_feed(6)
# TODO: handle this with a line feed
self._raw(b"\n\n\n\n\n\n")
if mode.upper() == "PART" and self.profile.supports('paperPartCut'): 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) self._raw(PAPER_PART_CUT)
elif mode.upper() != "PART" and self.profile.supports('paperFullCut'): elif self.profile.supports('paperFullCut'):
# DEFAULT MODE: FULL CUT
self._raw(PAPER_FULL_CUT) 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): def cashdraw(self, pin):
""" Send pulse to kick the cash drawer """ Send pulse to kick the cash drawer
@ -622,6 +630,20 @@ class Escpos(object):
else: # DEFAULT: DOES NOTHING else: # DEFAULT: DOES NOTHING
pass pass
def print_and_feed(self, n):
""" 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 lines to feed. 0 <= n <= 255
: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): def control(self, ctl, pos=4):
""" Feed control sequences """ Feed control sequences