Add error checking on width and height fields:
This commit is contained in:
parent
8d00e63b87
commit
e48755f7d0
|
@ -492,17 +492,21 @@ class Escpos(object):
|
|||
self._raw(TXT_2WIDTH)
|
||||
elif width == 1 and height == 1:
|
||||
self._raw(TXT_NORMAL)
|
||||
else:
|
||||
elif width >= 1 and width <= 8 and height >= 1 and height <= 8 and isinstance(width, int) and isinstance(height, int):
|
||||
self._raw(TXT_SIZE + chr(TXT_WIDTH[width] + TXT_HEIGHT[height]))
|
||||
# Type
|
||||
else:
|
||||
raise SetVariableError()
|
||||
# Upside down
|
||||
if flip == True:
|
||||
self._raw(TXT_FLIP_ON)
|
||||
else:
|
||||
self._raw(TXT_FLIP_OFF)
|
||||
# Smoothing
|
||||
if smooth == True:
|
||||
self._raw(TXT_SMOOTH_ON)
|
||||
else:
|
||||
self._raw(TXT_SMOOTH_OFF)
|
||||
# Type
|
||||
if text_type.upper() == "B":
|
||||
self._raw(TXT_BOLD_ON)
|
||||
self._raw(TXT_UNDERL_OFF)
|
||||
|
|
|
@ -12,6 +12,7 @@ Result/Exit codes:
|
|||
- `70` = Invalid number of tab positions :py:exc:`~escpos.exceptions.TabPosError`
|
||||
- `80` = Invalid char code :py:exc:`~escpos.exceptions.CharCodeError`
|
||||
- `90` = USB device not found :py:exc:`~escpos.exceptions.USBNotFoundError`
|
||||
- `100` = Set variable out of range :py:exc:`~escpos.exceptions.SetVariableError`
|
||||
|
||||
:author: `Manuel F Martinez <manpaz@bashlinux.com>`_ and others
|
||||
:organization: Bashlinux and `python-escpos <https://github.com/python-escpos>`_
|
||||
|
@ -167,3 +168,18 @@ class USBNotFoundError(Error):
|
|||
|
||||
def __str__(self):
|
||||
return "USB device not found"
|
||||
|
||||
|
||||
class SetVariableError(Error):
|
||||
""" A set method variable was out of range
|
||||
|
||||
Check set variables against minimum and maximum values
|
||||
Ths returncode for this exception is `100`.
|
||||
"""
|
||||
def __init__(self, msg=""):
|
||||
Error.__init__(self, msg)
|
||||
self.msg = msg
|
||||
self.resultcode = 100
|
||||
|
||||
def __str__(self):
|
||||
return "Set variable out of range"
|
||||
|
|
Loading…
Reference in New Issue