-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrendering.py
54 lines (42 loc) · 1.4 KB
/
rendering.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import tempfile
import time
import imgkit
import jinja2
from brother_ql.conversion import convert
from brother_ql.backends.helpers import send
from brother_ql.raster import BrotherQLRaster
TEMPLATE_FILE = os.path.join(os.path.dirname(__file__), 'templates/zettel.html.j2')
WKHTML_OPTIONS = options = {
'format': 'png',
#'viewport-size': '732x366',
'width': '732',
# , 366,
#'disable-smart-width': '',
'encoding': "UTF-8",
'custom-header' : [
('Accept-Encoding', 'gzip')
],
# 'no-outline': None
}
def make_zettel(context, tmpdir, do_open=False):
with open(TEMPLATE_FILE, 'r') as tpl_fh:
template = jinja2.Template(tpl_fh.read())
html = template.render(**context)
tmpfile = str(os.path.join(tmpdir, 'out.png'))
imgkit.from_string(html, tmpfile, options=WKHTML_OPTIONS)
if do_open is True:
os.system('open %s' % tmpfile)
time.sleep(1.0)
return tmpfile
def print_zettel(context, tmpdir, backend, model, printer):
tmp_filename = make_zettel(context, tmpdir)
qlr = BrotherQLRaster(model)
qlr.exception_on_warning = True
kwargs = {}
kwargs['label'] = '62'
kwargs['cut'] = True
kwargs['dither'] = True
kwargs['images'] = [tmp_filename, ]
instructions = convert(qlr=qlr, **kwargs)
send(instructions=instructions, printer_identifier=printer, backend_identifier=backend, blocking=True)