Skip to content
Snippets Groups Projects
Commit 03193ade authored by Dave Kliczbor's avatar Dave Kliczbor
Browse files

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

parent 2c77d52c
No related branches found
No related tags found
No related merge requests found
*.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'
# Image data directory (needs to be writeable)
imagedir = datadir + '/images'
# Cache dir (needs to be writable)
cachedir = datadir + '/cache'
# Upload temp directory (needs to be writeable)
uploaddir = datadir + '/upload'
......
*.pdf*
\ No newline at end of file
......@@ -85,11 +85,13 @@ def edit_one(filename):
formdata = json.load(infile)
return edit(form=formdata)
def run_pdflatex(context, outputfilename):
def run_pdflatex(context, outputfilename, overwrite=True):
if not context.has_key('textemplate'):
context['textemplate'] = "text-image-quer.tex"
genshitex = TemplateLoader([config.textemplatedir])
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)
if context.has_key('img') and context['img'] and context['img'] != '__none':
try:
......@@ -109,10 +111,12 @@ def run_pdflatex(context, outputfilename):
try:
texlog = check_output(['pdflatex', '--halt-on-error', tmptexfile], stderr=STDOUT)
except CalledProcessError as e:
if overwrite:
flash(Markup("<p>PDFLaTeX Output:</p><pre>%s</pre>" % e.output), 'log')
raise SyntaxWarning("PDFLaTeX bailed out")
finally:
os.chdir(cwd)
if overwrite:
flash(Markup("<p>PDFLaTeX Output:</p><pre>%s</pre>" % texlog), 'log')
shutil.copy(tmppdffile, outputfilename)
shutil.rmtree(tmpdir)
......@@ -229,6 +233,24 @@ def pdfthumbnail(pdfname, maxgeometry):
with open(thumbpath, 'r') as imgfile:
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>')
def pdfdownload(pdfname):
pdfpath = os.path.join(config.pdfdir, secure_filename(pdfname))
......
......@@ -82,6 +82,9 @@ form {
margin-top:1em;
margin-bottom:1em;
}
form ul {
padding: 0;
}
form li {
list-style-type:none;
display: inline-block;
......@@ -89,17 +92,17 @@ form li {
input[type="radio"] {
position:relative;
z-index:5;
margin-bottom:1em;
margin-bottom:0;
}
input[type="radio"]+label > img {
position:relative;
z-index:4;
top:0.5em;
left:-1.5em;
top:0;
left:-1.4em;
margin-right:-1.2em;
max-width: 100%;
max-height: 10em;
border:3px solid #eee;
border:3px solid lightgray;
border-radius: 5px;
}
input[type="radio"]:checked+label > img {
......@@ -114,3 +117,14 @@ input[type="radio"]:checked + input[type="file"] {
input[type="radio"]:checked + input[type="file"] + label {
display:none;
}
textarea {
display: block;
}
.box {
display: inline-block;
background: #eee;
border: 1px solid lightgray;
border-radius: 5px;
padding: 0.5em;
margin: 1em 0;
}
......@@ -15,32 +15,42 @@
<a href="${ url_for('index') }">Liste der fertigen Schilder</a>
<form method="post" action="${ url_for('create') }" enctype="multipart/form-data">
<label for="form:headline">Großer Text</label>
<textarea name="headline" id="form:headline" cols="35" rows="5"><py:if test="defined('form')">${form.headline}</py:if></textarea>
<label for="form:text">Zusatztext</label>
<textarea name="text" id="form:text" cols="35" rows="5"><py:if test="defined('form')">${form.text}</py:if></textarea>
<label for="form:template">TeX-Vorlage</label>
<select name="textemplate" id="form:template">
<div class="box">
<label for="form:template">Wähle eine TeX-Vorlage:</label>
<ul>
<li py:for="textemplate in templates">
<py:choose>
<py:when test="defined('form')">
<py:for each="template in templates">
<py:choose>
<py:when test="template == form.textemplate">
<option label="${template}" value="${template}" selected="selected">${template}</option>
<py:when test="textemplate == form.textemplate">
<input type="radio" name="textemplate" id="tpl:${textemplate}" value="${textemplate}" checked="True"/>
</py:when>
<py:otherwise>
<option label="${template}" value="${template}">${template}</option>
<input type="radio" name="textemplate" id="tpl:${textemplate}" value="${textemplate}"/>
</py:otherwise>
</py:choose>
</py:for>
</py:when>
<py:otherwise>
<option py:for="tpl in templates" label="${tpl}" value="${tpl}">${tpl}</option>
<input type="radio" name="textemplate" id="tpl:${textemplate}" value="${textemplate}"/>
</py:otherwise>
</py:choose>
</select>
<label for="tpl:${textemplate}"><img src="${ url_for('tplthumbnail', tplname=textemplate, maxgeometry=72) }" alt="${textemplate}" title="${textemplate}"/></label>
</li>
</ul>
</div><br/>
<div class="box">
<label for="form:headline">Überschrift</label>
<textarea name="headline" id="form:headline" cols="35" rows="5"><py:if test="defined('form')">${form.headline}</py:if></textarea>
</div>
<div class="box">
<label for="form:text">Text</label>
<textarea name="text" id="form:text" cols="35" rows="5"><py:if test="defined('form')">${form.text}</py:if></textarea>
</div><br/>
<div class="box">
<input type="submit" value="Schild erstellen"/>
</div><br/>
<div class="box">
<label for="form:img">Wähle ein Bild (falls auf Vorlage anwendbar):</label>
<ul>
<li>
<py:choose>
......@@ -76,10 +86,13 @@
<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}"/></label>
<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>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment