mirror of
https://github.com/pklaus/brother_ql_web.git
synced 2024-05-25 11:56:53 +03:00
allow to select fonts family AND style in web interface
This commit is contained in:
parent
6aada05b22
commit
d1286f014e
|
@ -46,22 +46,24 @@ def serve_static(filename):
|
||||||
@route('/labeldesigner')
|
@route('/labeldesigner')
|
||||||
@view('labeldesigner.jinja2')
|
@view('labeldesigner.jinja2')
|
||||||
def labeldesigner():
|
def labeldesigner():
|
||||||
fonts = sorted(list(FONTS.keys()))
|
font_family_names = sorted(list(FONTS.keys()))
|
||||||
label_sizes = LABEL_SIZES
|
label_sizes = LABEL_SIZES
|
||||||
title = 'Label Designer'
|
title = 'Label Designer'
|
||||||
page_headline = 'Brother QL Label Designer'
|
page_headline = 'Brother QL Label Designer'
|
||||||
return {'title': title, 'page_headline': page_headline, 'message': '', 'fonts': fonts, 'label_sizes': label_sizes, 'default_label_size': DEFAULT_LABEL_SIZE, 'default_orientation': DEFAULT_ORIENTATION}
|
return {'title': title, 'page_headline': page_headline, 'message': '', 'font_family_names': font_family_names, 'fonts': FONTS, 'label_sizes': label_sizes, 'default_label_size': DEFAULT_LABEL_SIZE, 'default_orientation': DEFAULT_ORIENTATION}
|
||||||
|
|
||||||
def get_label_context(request):
|
def get_label_context(request):
|
||||||
""" might raise LookupError() """
|
""" might raise LookupError() """
|
||||||
|
|
||||||
d = request.params.decode() # UTF-8 decoded form data
|
d = request.params.decode() # UTF-8 decoded form data
|
||||||
|
|
||||||
|
font_family = d.get('font_family').rpartition('(')[0].strip()
|
||||||
|
font_style = d.get('font_family').rpartition('(')[2].rstrip(')')
|
||||||
context = {
|
context = {
|
||||||
'text': d.get('text', None),
|
'text': d.get('text', None),
|
||||||
'font_size': int(d.get('font_size', 100)),
|
'font_size': int(d.get('font_size', 100)),
|
||||||
'font_family': d.get('font_family'),
|
'font_family': font_family,
|
||||||
'font_style': d.get('font_style'),
|
'font_style': font_style,
|
||||||
'label_size': d.get('label_size', "62"),
|
'label_size': d.get('label_size', "62"),
|
||||||
'kind': label_type_specs[d.get('label_size', "62")]['kind'],
|
'kind': label_type_specs[d.get('label_size', "62")]['kind'],
|
||||||
'margin': int(d.get('margin', 10)),
|
'margin': int(d.get('margin', 10)),
|
||||||
|
@ -78,14 +80,12 @@ def get_label_context(request):
|
||||||
context['margin_left'] = int(context['font_size']*context['margin_left'])
|
context['margin_left'] = int(context['font_size']*context['margin_left'])
|
||||||
context['margin_right'] = int(context['font_size']*context['margin_right'])
|
context['margin_right'] = int(context['font_size']*context['margin_right'])
|
||||||
|
|
||||||
def get_font_path(font_family, font_style):
|
def get_font_path(font_family_name, font_style_name):
|
||||||
try:
|
try:
|
||||||
if font_family is None:
|
if font_family_name is None or font_style_name is None:
|
||||||
font_family = DEFAULT_FONT['family']
|
font_family_name = DEFAULT_FONT['family']
|
||||||
font_style = DEFAULT_FONT['style']
|
font_style_name = DEFAULT_FONT['style']
|
||||||
if font_style is None:
|
font_path = FONTS[font_family_name][font_style_name]
|
||||||
font_style = 'Regular'
|
|
||||||
font_path = FONTS[font_family][font_style]
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise LookupError("Couln't find the font & style")
|
raise LookupError("Couln't find the font & style")
|
||||||
return font_path
|
return font_path
|
||||||
|
|
|
@ -49,7 +49,11 @@
|
||||||
<div class="chooser panel-body">
|
<div class="chooser panel-body">
|
||||||
<label for="fontFamily">Font Family:</label>
|
<label for="fontFamily">Font Family:</label>
|
||||||
<select class="form-control" id="fontFamily" onChange="preview()">
|
<select class="form-control" id="fontFamily" onChange="preview()">
|
||||||
{% for font in fonts %}<option>{{font}}</option> {% endfor %}
|
{% for font_family_name in font_family_names %}
|
||||||
|
{% for font_style in fonts[font_family_name].keys() %}
|
||||||
|
<option>{{font_family_name}} ({{ font_style }})</option>
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
<label for="fontSize" >Font Size:</label>
|
<label for="fontSize" >Font Size:</label>
|
||||||
<input id="fontSize" class="form-control" type="number" min="1" value="70" onChange="preview()" required>
|
<input id="fontSize" class="form-control" type="number" min="1" value="70" onChange="preview()" required>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user