mirror of
https://github.com/pklaus/brother_ql_web.git
synced 2024-05-25 11:56:53 +03:00
initial support for different label types
This commit is contained in:
parent
c9307a9463
commit
c8b3c501f0
|
@ -30,6 +30,14 @@ DEFAULT_FONTS = [
|
|||
{'family': 'DejaVu Serif', 'style': 'Book'},
|
||||
]
|
||||
|
||||
LABEL_SIZES = [
|
||||
('62', '62mm endless'),
|
||||
('29x90', '29mm x 90mm die-cut'),
|
||||
('62x29', '62mm x 29mm die-cut'),
|
||||
('17x54', '17mm x 54mm die-cut'),
|
||||
('17x87', '17mm x 87mm die-cut'),
|
||||
]
|
||||
|
||||
@route('/')
|
||||
def index():
|
||||
redirect('/labeldesigner')
|
||||
|
@ -42,7 +50,8 @@ def serve_static(filename):
|
|||
@view('labeldesigner.jinja2')
|
||||
def labeldesigner():
|
||||
fonts = sorted(list(FONTS.keys()))
|
||||
return {'title': 'Labeldesigner', 'message': '', 'fonts': fonts}
|
||||
label_sizes = LABEL_SIZES
|
||||
return {'title': 'Labeldesigner', 'message': '', 'fonts': fonts, 'label_sizes': label_sizes}
|
||||
|
||||
def get_label_context(request):
|
||||
""" might raise LookupError() """
|
||||
|
@ -89,6 +98,10 @@ def get_label_context(request):
|
|||
def create_label_im(text, **kwargs):
|
||||
im_font = ImageFont.truetype(kwargs['font_path'], kwargs['font_size'])
|
||||
textsize = im_font.getsize(text)
|
||||
if 'x' in kwargs['label_size']:
|
||||
# die-cut labels
|
||||
height = kwargs['height']
|
||||
else:
|
||||
height = max(textsize[1] * (text.count('\n')+1), kwargs['height'])
|
||||
im = Image.new('L', (kwargs['width'], height), 'white')
|
||||
draw = ImageDraw.Draw(im)
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<fieldset class="form-group">
|
||||
<select class="form-control" id="labelSize" onChange="preview()">
|
||||
{% for label_size in label_sizes %}<option value="{{label_size[0]}}">{{label_size[1]}}</option>{% endfor %}
|
||||
</select>
|
||||
<label for="labelText">Label Text:</label>
|
||||
<textarea rows="4" id="labelText" class="form-control" onChange="preview()" onInput="preview()"></textarea>
|
||||
<label for="fontFamily">Font Selection:</label>
|
||||
|
@ -58,8 +61,9 @@ function last_url_part() {
|
|||
text = $('#labelText').val().replace(/\n/g, "%0A");
|
||||
font_family = $('#fontFamily option:selected').text();
|
||||
font_size = $('#fontSize').val();
|
||||
label_size = $('#labelSize option:selected').val();
|
||||
if (text == '') text = '%20';
|
||||
return text + '?font_family=' + font_family + '&font_size=' + font_size;
|
||||
return text + '?font_family=' + font_family + '&font_size=' + font_size + '&label_size=' + label_size;
|
||||
}
|
||||
|
||||
function preview() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user