| 1 |
|
| 2 |
from attr import attrs, attrib |
| 3 |
from typing import List, Tuple |
| 4 |
from enum import Enum |
| 5 |
|
| 6 |
import copy |
| 7 |
|
| 8 |
from brother_ql.helpers import ElementsManager |
| 9 |
|
| 10 |
class FormFactor(Enum): |
| 11 |
""" |
| 12 |
Enumeration representing the form factor of a label. |
| 13 |
The labels for the Brother QL series are supplied either as die-cut (pre-sized), or for more flexibility the |
| 14 |
continuous label tapes offer the ability to vary the label length. |
| 15 |
""" |
| 16 |
#: rectangular die-cut labels |
| 17 |
DIE_CUT = 1 |
| 18 |
#: endless (continouse) labels |
| 19 |
ENDLESS = 2 |
| 20 |
#: round die-cut labels |
| 21 |
ROUND_DIE_CUT = 3 |
| 22 |
|
| 23 |
class Color(Enum): |
| 24 |
""" |
| 25 |
Enumeration representing the colors to be printed on a label. Most labels only support printing black on white. |
| 26 |
Some newer ones can also print in black and red on white. |
| 27 |
""" |
| 28 |
#: The label can be printed in black & white. |
| 29 |
BLACK_WHITE = 0 |
| 30 |
#: The label can be printed in black, white & red. |
| 31 |
BLACK_RED_WHITE = 1 |
| 32 |
|
| 33 |
@attrs |
| 34 |
class Label(object): |
| 35 |
""" |
| 36 |
This class represents a label. All specifics of a certain label |
| 37 |
and what the rasterizer needs to take care of depending on the |
| 38 |
label choosen, should be contained in this class. |
| 39 |
""" |
| 40 |
#: A string identifier given to each label that can be selected. Eg. '29'. |
| 41 |
identifier = attrib(type=str) |
| 42 |
#: The tape size of a single label (width, lenght) in mm. For endless labels, the length is 0 by definition. |
| 43 |
tape_size = attrib(type=Tuple[int, int]) |
| 44 |
#: The type of label |
| 45 |
form_factor = attrib(type=FormFactor) |
| 46 |
#: The total area (width, length) of the label in dots (@300dpi). |
| 47 |
dots_total = attrib(type=Tuple[int, int]) |
| 48 |
#: The printable area (width, length) of the label in dots (@300dpi). |
| 49 |
dots_printable = attrib(type=Tuple[int, int]) |
| 50 |
#: The required offset from the right side of the label in dots to obtain a centered printout. |
| 51 |
offset_r = attrib(type=int) |
| 52 |
#: An additional amount of feeding when printing the label. |
| 53 |
#: This is non-zero for some smaller label sizes and for endless labels. |
| 54 |
feed_margin = attrib(type=int, default=0) |
| 55 |
#: If a label can only be printed with certain label printers, this member variable lists the allowed ones. |
| 56 |
#: Otherwise it's an empty list. |
| 57 |
restricted_to_models = attrib(type=List[str], factory=list) |
| 58 |
#: Some labels allow printing in red, most don't. |
| 59 |
color = attrib(type=Color, default=Color.BLACK_WHITE) |
| 60 |
|
| 61 |
def works_with_model(self, model): # type: bool |
| 62 |
""" |
| 63 |
Method to determine if certain label can be printed by the specified printer model. |
| 64 |
""" |
| 65 |
if self.restricted_to_models and model not in models: return False |
| 66 |
else: return True |
| 67 |
|
| 68 |
@property |
| 69 |
def name(self): # type: str |
| 70 |
out = "" |
| 71 |
if 'x' in self.identifier: |
| 72 |
out = '{0}mm x {1}mm die-cut'.format(*self.tape_size) |
| 73 |
elif self.identifier.startswith('d'): |
| 74 |
out = '{0}mm round die-cut'.format(self.tape_size[0]) |
| 75 |
else: |
| 76 |
out = '{0}mm endless'.format(self.tape_size[0]) |
| 77 |
if self.color == Color.BLACK_RED_WHITE: |
| 78 |
out += ' (black/red/white)' |
| 79 |
return out |
| 80 |
|
| 81 |
ALL_LABELS = ( |
| 82 |
Label("12", ( 12, 0), FormFactor.ENDLESS, ( 142, 0), ( 106, 0), 29 , feed_margin=35), |
| 83 |
Label("29", ( 29, 0), FormFactor.ENDLESS, ( 342, 0), ( 306, 0), 6 , feed_margin=35), |
| 84 |
Label("38", ( 38, 0), FormFactor.ENDLESS, ( 449, 0), ( 413, 0), 12 , feed_margin=35), |
| 85 |
Label("50", ( 50, 0), FormFactor.ENDLESS, ( 590, 0), ( 554, 0), 12 , feed_margin=35), |
| 86 |
Label("54", ( 54, 0), FormFactor.ENDLESS, ( 636, 0), ( 590, 0), 0 , feed_margin=35), |
| 87 |
Label("62", ( 62, 0), FormFactor.ENDLESS, ( 732, 0), ( 696, 0), 12 , feed_margin=35), |
| 88 |
Label("62red", ( 62, 0), FormFactor.ENDLESS, ( 732, 0), ( 696, 0), 12 , feed_margin=35, color=Color.BLACK_RED_WHITE), |
| 89 |
Label("102", (102, 0), FormFactor.ENDLESS, (1200, 0), (1164, 0), 12 , feed_margin=35, restricted_to_models=['QL-1050', 'QL-1060N']), |
| 90 |
Label("17x54", ( 17, 54), FormFactor.DIE_CUT, ( 201, 636), ( 165, 566), 0 ), |
| 91 |
Label("17x87", ( 17, 87), FormFactor.DIE_CUT, ( 201, 1026), ( 165, 956), 0 ), |
| 92 |
Label("23x23", ( 23, 23), FormFactor.DIE_CUT, ( 272, 272), ( 202, 202), 42 ), |
| 93 |
Label("29x42", ( 29, 42), FormFactor.DIE_CUT, ( 342, 495), ( 306, 425), 6 ), |
| 94 |
Label("29x90", ( 29, 90), FormFactor.DIE_CUT, ( 342, 1061), ( 306, 991), 6 ), |
| 95 |
Label("39x90", ( 38, 90), FormFactor.DIE_CUT, ( 449, 1061), ( 413, 991), 12 ), |
| 96 |
Label("39x48", ( 39, 48), FormFactor.DIE_CUT, ( 461, 565), ( 425, 495), 6 ), |
| 97 |
Label("52x29", ( 52, 29), FormFactor.DIE_CUT, ( 614, 341), ( 578, 271), 0 ), |
| 98 |
Label("62x29", ( 62, 29), FormFactor.DIE_CUT, ( 732, 341), ( 696, 271), 12 ), |
| 99 |
Label("62x100", ( 62, 100), FormFactor.DIE_CUT, ( 732, 1179), ( 696, 1109), 12 ), |
| 100 |
Label("102x51", (102, 51), FormFactor.DIE_CUT, (1200, 596), (1164, 526), 12 , restricted_to_models=['QL-1050', 'QL-1060N']), |
| 101 |
Label("102x152",(102, 153), FormFactor.DIE_CUT, (1200, 1804), (1164, 1660), 12 , restricted_to_models=['QL-1050', 'QL-1060N']), |
| 102 |
Label("d12", ( 12, 12), FormFactor.ROUND_DIE_CUT, ( 142, 142), ( 94, 94), 113 , feed_margin=35), |
| 103 |
Label("d24", ( 24, 24), FormFactor.ROUND_DIE_CUT, ( 284, 284), ( 236, 236), 42 ), |
| 104 |
Label("d58", ( 58, 58), FormFactor.ROUND_DIE_CUT, ( 688, 688), ( 618, 618), 51 ), |
| 105 |
) |
| 106 |
|
| 107 |
class LabelsManager(ElementsManager): |
| 108 |
DEFAULT_ELEMENTS = copy.copy(ALL_LABELS) |
| 109 |
ELEMENT_NAME = "label" |