44import barcode
55from 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
109from . import bp
1110from 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
1615
1716LINE_SPACINGS = (100 , 150 , 200 , 250 , 300 )
1817
19- # Don't change as brother_ql is using this DPI value
2018DEFAULT_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 ('/' )
3222def 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
167158def 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