From b96cd35ea133bc8602f48e0c563bd6ac598147db Mon Sep 17 00:00:00 2001 From: Philipp Klaus Date: Tue, 19 Sep 2017 14:23:18 +0200 Subject: [PATCH] prevent using --red (two color printing) if not supported by model --- brother_ql/brother_ql_create.py | 3 +++ brother_ql/devicedependent.py | 6 ++++++ brother_ql/raster.py | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/brother_ql/brother_ql_create.py b/brother_ql/brother_ql_create.py index 9230e22..9008cbd 100755 --- a/brother_ql/brother_ql_create.py +++ b/brother_ql/brother_ql_create.py @@ -71,6 +71,9 @@ def create_label(qlr, image, label_size, threshold=70, cut=True, dither=False, c threshold = 100.0 - threshold threshold = min(255, max(0, int(threshold/100.0 * 255))) # from percent to pixel val + if red and not qlr.two_color_support: + raise BrotherQLUnsupportedCmd('Printing in red is not supported with the selected model.') + if isinstance(image, Image.Image): im = image elif isinstance(image, (unicode, str)): diff --git a/brother_ql/devicedependent.py b/brother_ql/devicedependent.py index 7445e37..827586a 100644 --- a/brother_ql/devicedependent.py +++ b/brother_ql/devicedependent.py @@ -171,3 +171,9 @@ compressionsupport = [ 'QL-810W', 'QL-820NWB', ] + +two_color_support = [ + 'QL-800', + 'QL-810W', + 'QL-820NWB', +] diff --git a/brother_ql/raster.py b/brother_ql/raster.py index 77827ba..b7f3c6a 100644 --- a/brother_ql/raster.py +++ b/brother_ql/raster.py @@ -16,6 +16,7 @@ from .devicedependent import models, \ compressionsupport, \ cuttingsupport, \ expandedmode, \ + two_color_support, \ modesetting from . import BrotherQLError, BrotherQLUnsupportedCmd, BrotherQLUnknownModel, BrotherQLRasterError @@ -66,6 +67,10 @@ class BrotherQLRaster(object): """ self._warn(problem, kind=BrotherQLUnsupportedCmd) + @property + def two_color_support(self): + return self.model in two_color_support + def add_initialize(self): self.page_number = 0 self.data += b'\x1B\x40' # ESC @ @@ -150,6 +155,9 @@ class BrotherQLRaster(object): if self.model not in expandedmode: self.unsupported("Trying to set expanded mode (dpi/cutting at end) on a printer that doesn't support it") return + if self.two_color_printing and not self.two_color_support: + self.unsupported("Trying to set two_color_printing in expanded mode on a printer that doesn't support it.") + return self.data += b'\x1B\x69\x4B' # ESC i K flags = 0x00 flags |= self.cut_at_end << 3