Skip to content

Commit 87df943

Browse files
committed
Move away from the deprecated brother_ql.devicedependent class
Signed-off-by: DL6ER <[email protected]>
1 parent 847457c commit 87df943

3 files changed

Lines changed: 14 additions & 22 deletions

File tree

app/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
from flask import Flask
1313
from flask_bootstrap import Bootstrap
14-
15-
from brother_ql.devicedependent import models
14+
from brother_ql.models import ALL_MODELS
1615

1716
from . import fonts
1817
from config import Config
@@ -78,6 +77,7 @@ def init_fonts_and_args(app):
7877

7978

8079
def parse_args(app):
80+
models = [model.identifier for model in ALL_MODELS]
8181
parser = argparse.ArgumentParser(description=__doc__)
8282
parser.add_argument('--default-label-size', default=False,
8383
help='Label size inserted in your printer. Defaults to 62.')

app/labeldesigner/printer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import logging
22
from brother_ql.backends.helpers import send
33
from brother_ql import BrotherQLRaster, create_label
4-
from brother_ql.devicedependent import two_color_support
54
from brother_ql.backends.helpers import get_printer, get_status
65
from .label import LabelOrientation, LabelType, LabelContent
6+
from brother_ql.models import ALL_MODELS
77

88
logger = logging.getLogger(__name__)
99

@@ -121,7 +121,7 @@ def get_ptr_status(device_specifier):
121121
for key in printer_state:
122122
status[key] = printer_state.get(key, status[key])
123123
if key == 'model':
124-
status['red_support'] = printer_state['model'] in two_color_support
124+
status['red_support'] = printer_state['model'] in [model.identifier for model in ALL_MODELS if model.two_color]
125125
return status
126126
except Exception as e:
127127
logger.exception(e)

app/labeldesigner/routes.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import barcode
55
from flask import current_app, json, jsonify, render_template, request, make_response
66

7-
from brother_ql.devicedependent import label_type_specs, label_sizes
8-
from brother_ql.devicedependent import ENDLESS_LABEL, DIE_CUT_LABEL, ROUND_DIE_CUT_LABEL
7+
from brother_ql.labels import ALL_LABELS, FormFactor, Label
98

109
from . import bp
1110
from app.utils import convert_image_to_bw, convert_image_to_grayscale, convert_image_to_red_and_black, pdffile_to_image, imgfile_to_image, image_to_png_bytes
@@ -16,20 +15,12 @@
1615

1716
LINE_SPACINGS = (100, 150, 200, 250, 300)
1817

19-
# Don't change as brother_ql is using this DPI value
2018
DEFAULT_DPI = 300
21-
22-
LABEL_SIZES = [(
23-
name,
24-
label_type_specs[name]['name'],
25-
(label_type_specs[name]['kind'] in (
26-
ROUND_DIE_CUT_LABEL,)), # True if round label
27-
label_type_specs[name]['tape_size'],
28-
) for name in label_sizes]
29-
19+
HIGH_RES_DPI = 600
3020

3121
@bp.route('/')
3222
def index():
23+
LABEL_SIZES = [ (label.identifier, label.name, label.form_factor == FormFactor.ROUND_DIE_CUT, label.tape_size) for label in ALL_LABELS ]
3324
return render_template('labeldesigner.html',
3425
font_family_names=FONTS.fontlist(),
3526
label_sizes=LABEL_SIZES,
@@ -166,11 +157,13 @@ def parse_text_form(input):
166157

167158
def create_label_from_request(request):
168159
d=request.values
160+
label_size = d.get('label_size', "62")
161+
kind = [label.form_factor for label in ALL_LABELS if label.identifier == label_size][0]
169162
context={
170-
'label_size': d.get('label_size', '62'),
163+
'label_size': label_size,
171164
'print_type': d.get('print_type', 'text'),
172165
'label_orientation': d.get('orientation', 'standard'),
173-
'kind': label_type_specs[d.get('label_size', "62")]['kind'],
166+
'kind': kind,
174167
'margin_top': int(d.get('margin_top', 12)),
175168
'margin_bottom': int(d.get('margin_bottom', 12)),
176169
'margin_left': int(d.get('margin_left', 20)),
@@ -193,10 +186,9 @@ def create_label_from_request(request):
193186

194187
def get_label_dimensions(label_size):
195188
try:
196-
ls = label_type_specs[context['label_size']]
189+
return [label.dots_printable for label in ALL_LABELS if label.identifier == label_size][0]
197190
except KeyError:
198191
raise LookupError("Unknown label_size")
199-
return ls['dots_printable']
200192

201193
def get_font_path(font_family_name, font_style_name):
202194
try:
@@ -258,9 +250,9 @@ def get_uploaded_image(image):
258250
else:
259251
label_orientation = LabelOrientation.STANDARD
260252

261-
if context['kind'] == ENDLESS_LABEL:
253+
if context['kind'] == FormFactor.ENDLESS:
262254
label_type = LabelType.ENDLESS_LABEL
263-
elif context['kind'] == DIE_CUT_LABEL:
255+
elif context['kind'] == FormFactor.DIE_CUT:
264256
label_type = LabelType.DIE_CUT_LABEL
265257
else:
266258
label_type = LabelType.ROUND_DIE_CUT_LABEL

0 commit comments

Comments
 (0)