diff --git a/escpos/escpos.py b/escpos/escpos.py index 64b31fe..1b90b91 100644 --- a/escpos/escpos.py +++ b/escpos/escpos.py @@ -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) diff --git a/escpos/exceptions.py b/escpos/exceptions.py index e91ed5e..56a30a4 100644 --- a/escpos/exceptions.py +++ b/escpos/exceptions.py @@ -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 `_ and others :organization: Bashlinux and `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"