Commit 03193ade authored by Dave Kliczbor's avatar Dave Kliczbor
Browse files

New Feature: Choose TeX template by preview (+ some css changes)

parent 2c77d52c
*.py[co]
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
# backup files
*~
# data files
savegames
config.py
schilder.wsgi
*.png.*
*.schild.*
...@@ -33,6 +33,9 @@ pdfdir = datadir + '/pdf' ...@@ -33,6 +33,9 @@ pdfdir = datadir + '/pdf'
# Image data directory (needs to be writeable) # Image data directory (needs to be writeable)
imagedir = datadir + '/images' imagedir = datadir + '/images'
# Cache dir (needs to be writable)
cachedir = datadir + '/cache'
# Upload temp directory (needs to be writeable) # Upload temp directory (needs to be writeable)
uploaddir = datadir + '/upload' uploaddir = datadir + '/upload'
......
*.pdf*
\ No newline at end of file
...@@ -85,11 +85,13 @@ def edit_one(filename): ...@@ -85,11 +85,13 @@ def edit_one(filename):
formdata = json.load(infile) formdata = json.load(infile)
return edit(form=formdata) return edit(form=formdata)
def run_pdflatex(context, outputfilename): def run_pdflatex(context, outputfilename, overwrite=True):
if not context.has_key('textemplate'): if not context.has_key('textemplate'):
context['textemplate'] = "text-image-quer.tex" context['textemplate'] = "text-image-quer.tex"
genshitex = TemplateLoader([config.textemplatedir]) genshitex = TemplateLoader([config.textemplatedir])
template = genshitex.load(context['textemplate'], cls=NewTextTemplate, encoding='utf8') template = genshitex.load(context['textemplate'], cls=NewTextTemplate, encoding='utf8')
if not overwrite and os.path.isfile(outputfilename) and os.path.getmtime(template.filepath) < os.path.getmtime(outputfilename):
return
tmpdir = tempfile.mkdtemp(dir=config.tmpdir) tmpdir = tempfile.mkdtemp(dir=config.tmpdir)
if context.has_key('img') and context['img'] and context['img'] != '__none': if context.has_key('img') and context['img'] and context['img'] != '__none':
try: try:
...@@ -109,11 +111,13 @@ def run_pdflatex(context, outputfilename): ...@@ -109,11 +111,13 @@ def run_pdflatex(context, outputfilename):
try: try:
texlog = check_output(['pdflatex', '--halt-on-error', tmptexfile], stderr=STDOUT) texlog = check_output(['pdflatex', '--halt-on-error', tmptexfile], stderr=STDOUT)
except CalledProcessError as e: except CalledProcessError as e:
flash(Markup("<p>PDFLaTeX Output:</p><pre>%s</pre>" % e.output), 'log') if overwrite:
flash(Markup("<p>PDFLaTeX Output:</p><pre>%s</pre>" % e.output), 'log')
raise SyntaxWarning("PDFLaTeX bailed out") raise SyntaxWarning("PDFLaTeX bailed out")
finally: finally:
os.chdir(cwd) os.chdir(cwd)
flash(Markup("<p>PDFLaTeX Output:</p><pre>%s</pre>" % texlog), 'log') if overwrite:
flash(Markup("<p>PDFLaTeX Output:</p><pre>%s</pre>" % texlog), 'log')
shutil.copy(tmppdffile, outputfilename) shutil.copy(tmppdffile, outputfilename)
shutil.rmtree(tmpdir) shutil.rmtree(tmpdir)
...@@ -229,6 +233,24 @@ def pdfthumbnail(pdfname, maxgeometry): ...@@ -229,6 +233,24 @@ def pdfthumbnail(pdfname, maxgeometry):
with open(thumbpath, 'r') as imgfile: with open(thumbpath, 'r') as imgfile:
return Response(imgfile.read(), mimetype="image/png") return Response(imgfile.read(), mimetype="image/png")
@app.route('/tplthumb/<tplname>/<int:maxgeometry>')
def tplthumbnail(tplname, maxgeometry):
pdfpath = os.path.join(config.cachedir, secure_filename(tplname)+'.pdf')
try:
run_pdflatex(
{ 'textemplate' : secure_filename(tplname),
'img' : 'pictograms-nps-misc-camera.png',
'headline' : u'Überschrift',
'text' : u'Dies ist der Text, der in der UI als Text bezeichnet ist.',
}, pdfpath, overwrite=False
)
except Exception as e:
return str(e)
else:
thumbpath = make_thumb(pdfpath, maxgeometry)
with open(thumbpath, 'r') as imgfile:
return Response(imgfile.read(), mimetype="image/png")
@app.route('/pdfdownload/<pdfname>') @app.route('/pdfdownload/<pdfname>')
def pdfdownload(pdfname): def pdfdownload(pdfname):
pdfpath = os.path.join(config.pdfdir, secure_filename(pdfname)) pdfpath = os.path.join(config.pdfdir, secure_filename(pdfname))
......
...@@ -82,6 +82,9 @@ form { ...@@ -82,6 +82,9 @@ form {
margin-top:1em; margin-top:1em;
margin-bottom:1em; margin-bottom:1em;
} }
form ul {
padding: 0;
}
form li { form li {
list-style-type:none; list-style-type:none;
display: inline-block; display: inline-block;
...@@ -89,17 +92,17 @@ form li { ...@@ -89,17 +92,17 @@ form li {
input[type="radio"] { input[type="radio"] {
position:relative; position:relative;
z-index:5; z-index:5;
margin-bottom:1em; margin-bottom:0;
} }
input[type="radio"]+label > img { input[type="radio"]+label > img {
position:relative; position:relative;
z-index:4; z-index:4;
top:0.5em; top:0;
left:-1.5em; left:-1.4em;
margin-right:-1.2em; margin-right:-1.2em;
max-width: 100%; max-width: 100%;
max-height: 10em; max-height: 10em;
border:3px solid #eee; border:3px solid lightgray;
border-radius: 5px; border-radius: 5px;
} }
input[type="radio"]:checked+label > img { input[type="radio"]:checked+label > img {
...@@ -114,3 +117,14 @@ input[type="radio"]:checked + input[type="file"] { ...@@ -114,3 +117,14 @@ input[type="radio"]:checked + input[type="file"] {
input[type="radio"]:checked + input[type="file"] + label { input[type="radio"]:checked + input[type="file"] + label {
display:none; display:none;
} }
textarea {
display: block;
}
.box {
display: inline-block;
background: #eee;
border: 1px solid lightgray;
border-radius: 5px;
padding: 0.5em;
margin: 1em 0;
}
...@@ -2,84 +2,97 @@ ...@@ -2,84 +2,97 @@
<!-- <html xmlns="http://www.w3.org/1999/xhtml" > --> <!-- <html xmlns="http://www.w3.org/1999/xhtml" > -->
<html xmlns:py="http://genshi.edgewall.org/"> <html xmlns:py="http://genshi.edgewall.org/">
<head> <head>
<link rel='stylesheet' type='text/css' href="${ url_for('static', filename='main.css') }"/> <link rel='stylesheet' type='text/css' href="${ url_for('static', filename='main.css') }"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/> <meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Schildergenerator</title> <title>Schildergenerator</title>
</head> </head>
<body> <body>
<py:with vars="messages = get_flashed_messages(with_categories=True)"> <py:with vars="messages = get_flashed_messages(with_categories=True)">
<ul class="flashes" py:if="messages"> <ul class="flashes" py:if="messages">
<li class="${ category }" py:for="category,message in messages" tabindex="0">${ message }</li> <li class="${ category }" py:for="category,message in messages" tabindex="0">${ message }</li>
</ul> </ul>
</py:with> </py:with>
<a href="${ url_for('index') }">Liste der fertigen Schilder</a> <a href="${ url_for('index') }">Liste der fertigen Schilder</a>
<form method="post" action="${ url_for('create') }" enctype="multipart/form-data"> <form method="post" action="${ url_for('create') }" enctype="multipart/form-data">
<label for="form:headline">Großer Text</label> <div class="box">
<textarea name="headline" id="form:headline" cols="35" rows="5"><py:if test="defined('form')">${form.headline}</py:if></textarea> <label for="form:template">Wähle eine TeX-Vorlage:</label>
<label for="form:text">Zusatztext</label> <ul>
<textarea name="text" id="form:text" cols="35" rows="5"><py:if test="defined('form')">${form.text}</py:if></textarea> <li py:for="textemplate in templates">
<label for="form:template">TeX-Vorlage</label> <py:choose>
<select name="textemplate" id="form:template"> <py:when test="defined('form')">
<py:choose> <py:choose>
<py:when test="defined('form')"> <py:when test="textemplate == form.textemplate">
<py:for each="template in templates"> <input type="radio" name="textemplate" id="tpl:${textemplate}" value="${textemplate}" checked="True"/>
<py:choose> </py:when>
<py:when test="template == form.textemplate"> <py:otherwise>
<option label="${template}" value="${template}" selected="selected">${template}</option> <input type="radio" name="textemplate" id="tpl:${textemplate}" value="${textemplate}"/>
</py:otherwise>
</py:when> </py:choose>
<py:otherwise> </py:when>
<option label="${template}" value="${template}">${template}</option> <py:otherwise>
<input type="radio" name="textemplate" id="tpl:${textemplate}" value="${textemplate}"/>
</py:otherwise> </py:otherwise>
</py:choose> </py:choose>
</py:for> <label for="tpl:${textemplate}"><img src="${ url_for('tplthumbnail', tplname=textemplate, maxgeometry=72) }" alt="${textemplate}" title="${textemplate}"/></label>
</py:when> </li>
<py:otherwise> </ul>
<option py:for="tpl in templates" label="${tpl}" value="${tpl}">${tpl}</option> </div><br/>
</py:otherwise> <div class="box">
</py:choose> <label for="form:headline">Überschrift</label>
</select> <textarea name="headline" id="form:headline" cols="35" rows="5"><py:if test="defined('form')">${form.headline}</py:if></textarea>
<ul> </div>
<li> <div class="box">
<py:choose> <label for="form:text">Text</label>
<py:when test="defined('form')"> <textarea name="text" id="form:text" cols="35" rows="5"><py:if test="defined('form')">${form.text}</py:if></textarea>
<input type="radio" name="img" id="img--none" value="__none" checked="${form.img == '__none'}"/> </div><br/>
</py:when> <div class="box">
<py:otherwise> <input type="submit" value="Schild erstellen"/>
<input type="radio" name="img" id="img--none" value="__none" checked="checked" /> </div><br/>
</py:otherwise> <div class="box">
</py:choose> <label for="form:img">Wähle ein Bild (falls auf Vorlage anwendbar):</label>
<label for="img--none">Kein Bild</label> <ul>
</li> <li>
<li> <py:choose>
<input type="radio" name="img" id="img--upload" value="__upload"/> <py:when test="defined('form')">
<input type="file" name="imgupload"/> <input type="radio" name="img" id="img--none" value="__none" checked="${form.img == '__none'}"/>
<label for="img--upload">Bild hochladen</label> </py:when>
</li> <py:otherwise>
</ul> <input type="radio" name="img" id="img--none" value="__none" checked="checked" />
<ul> </py:otherwise>
<li py:for="img in images"> </py:choose>
<py:choose> <label for="img--none">Kein Bild</label>
<py:when test="defined('form')"> </li>
<py:choose> <li>
<py:when test="img == form.img"> <input type="radio" name="img" id="img--upload" value="__upload"/>
<input type="radio" name="img" id="img:${img}" value="${img}" checked="True"/> <input type="file" name="imgupload"/>
</py:when> <label for="img--upload">Bild hochladen</label>
<py:otherwise> </li>
<input type="radio" name="img" id="img:${img}" value="${img}"/> </ul>
</py:otherwise> <ul>
</py:choose> <li py:for="img in images">
</py:when> <py:choose>
<py:otherwise> <py:when test="defined('form')">
<input type="radio" name="img" id="img:${img}" value="${img}"/> <py:choose>
</py:otherwise> <py:when test="img == form.img">
</py:choose> <input type="radio" name="img" id="img:${img}" value="${img}" checked="True"/>
<label for="img:${img}"><img src="${ url_for('thumbnail', imgname=img, maxgeometry=100) }" alt="${img}"/></label> </py:when>
</li> <py:otherwise>
</ul> <input type="radio" name="img" id="img:${img}" value="${img}"/>
<input type="submit" value="Schild erstellen"/> </py:otherwise>
</form> </py:choose>
</py:when>
<py:otherwise>
<input type="radio" name="img" id="img:${img}" value="${img}"/>
</py:otherwise>
</py:choose>
<label for="img:${img}"><img src="${ url_for('thumbnail', imgname=img, maxgeometry=100) }" alt="${img}" title="${img}"/></label>
</li>
</ul>
</div>
<div class="box">
<input type="submit" value="Schild erstellen"/>
</div>
</form>
</body> </body>
</html> </html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment