font tab git add app.py git add app.py

This commit is contained in:
Doriane 2024-03-28 13:58:58 +01:00
parent 53f6843553
commit 9f93a839f5
2 changed files with 64 additions and 14 deletions

60
app.py
View File

@ -165,11 +165,21 @@ def drawing(id):
params = params, params = params,
svg = svg) svg = svg)
# __ _ _ _
# / _| ___ _ __ | |_ _ __ ___ __ _| | _(_)_ __ __ _
# | |_ / _ \| '_ \| __| | '_ ` _ \ / _` | |/ / | '_ \ / _` |
# | _| (_) | | | | |_ | | | | | | (_| | <| | | | | (_| |
# |_| \___/|_| |_|\__| |_| |_| |_|\__,_|_|\_\_|_| |_|\__, |
# |___/
#
# EDITING A FIGGONT ON A PAD TO THEN USE IT
@app.route("/font.html") @app.route("/font.html")
def font(): def font():
params = { params = {
'pad': request.args.get('p') or 'default', 'text': request.args.get('t') or 'Cobbled Paths',
'pad': request.args.get('p') or 'standard',
'weight': request.args.get('w') or '3', 'weight': request.args.get('w') or '3',
} }
params['pad-full'] = etherpad + prefix + params['pad'] params['pad-full'] = etherpad + prefix + params['pad']
@ -179,6 +189,42 @@ def font():
title = title, title = title,
params = params) params = params)
@app.route("/writing/<id>")
def writing(id):
params = {
'text': request.args.get('t') or 'Cobbled Paths',
'pad': id or 'standard',
'weight': request.args.get('w') or '3',
}
params['pad-full'] = etherpad + prefix + params['pad']
# get pad content
print(' getting ' + params['pad-full'])
pad_export = requests.get(params['pad-full'] + '/export/txt')
ascii_input = pad_export.text
# store as a temporary file
print('--- saving figfont as temp ---')
(figfont_file, figfont_path) = tempfile.mkstemp(suffix='.flf')
print(figfont_path)
with open(figfont_path, 'w') as figfont_file:
figfont_file.write(ascii_input)
print('--- opening the figfont ---')
f = {}
f['ascii'] = text2figlet(params['text'], figfont_path)
print(f['ascii'])
print('--- rendering to svg ---')
svg = ascii2svg(f['ascii'], params['weight'])
return render_template(
'drawing.html',
title = title,
params = params,
svg = svg)
# _ _ # _ _
# ___ __ _| |_ __ _| | ___ __ _ _ _ ___ # ___ __ _| |_ __ _| | ___ __ _ _ _ ___
# / __/ _` | __/ _` | |/ _ \ / _` | | | |/ _ \ # / __/ _` | __/ _` | |/ _ \ / _` | | | |/ _ \
@ -235,12 +281,12 @@ def catalogue():
params = params) params = params)
# _ _ # _ _ _
# ___ __ _| |_ __ _| | ___ __ _ _ _ ___ # | |__ _ __ __ _| | _____ ___ __ ___ _ __| |_
# / __/ _` | __/ _` | |/ _ \ / _` | | | |/ _ \ # | '_ \| '_ \ / _` | | / _ \ \/ / '_ \ / _ \| '__| __|
# | (_| (_| | || (_| | | (_) | (_| | |_| | __/ # | | | | |_) | (_| | | | __/> <| |_) | (_) | | | |_
# \___\__,_|\__\__,_|_|\___/ \__, |\__,_|\___| # |_| |_| .__/ \__, |_| \___/_/\_\ .__/ \___/|_| \__|
# |___/ # |_| |___/ |_|
# #
# FIGLET 2 SVGBOB INTERACTIVE CATALOGUE # FIGLET 2 SVGBOB INTERACTIVE CATALOGUE

View File

@ -10,11 +10,11 @@
<button id="button-pad" data-use="pad-name">go</button> <button id="button-pad" data-use="pad-name">go</button>
<hr> <hr>
<input class="get-input" type="text" value="{{params['text']}}" data-name="t"/>
<button id="button-svg">generate</button> <button id="button-svg">generate</button>
<input class="get-input" type="text" value="{{params['text']}}" data-name="t" data-frame="svg-iframe"/>
<label>weight</label> <label>weight</label>
<input class="get-input" type="range" min="1" max="8" value="{{params['weight']}}" data-name="w" data-frame="svg-iframe"/> <input class="get-input" type="range" min="1" max="8" value="{{params['weight']}}" data-name="w" data-frame="svg-iframe"/>
@ -64,23 +64,27 @@
// --- svg generation button // --- svg generation button
button_svg.addEventListener('click', function(){ button_svg.addEventListener('click', function(){
let svg_iframe = document.getElementById('svg-iframe'); let svg_iframe = document.getElementById('svg-iframe');
svg_iframe.contentWindow.location.reload(); console.log("IFRAME RELOAD");
svg_iframe.contentWindow.location.reload();
}); });
// --- get-input but on the pad and checkbox but on the pad // --- get-input but on the pad and checkbox but on the pad
let inputs = document.getElementsByClassName('get-input'); let inputs = document.getElementsByClassName('get-input');
for(let input of inputs){ for(let input of inputs){
input.addEventListener('change', function(){ input.addEventListener('input', function(){
let frame = document.getElementById(input.dataset.frame); let frame = document.getElementById(input.dataset.frame);
const url = new URL(frame.src); const url = new URL(frame.src);
if(input.type == 'checkbox'){ if(input.type == 'checkbox'){
url.searchParams.set(input.dataset.name, input.checked); url.searchParams.set(input.dataset.name, input.checked);
} }
else{ else{
url.searchParams.set(input.dataset.name, input.value); url.searchParams.set(input.dataset.name, input.value);
} }
frame.src = url; console.log(url);
// frame.contentWindow.history.replaceState(null, null, url);
frame.src = url
}); });
} }
</script> </script>
@ -90,7 +94,7 @@
<iframe class="f-ascii" id="pad-iframe" src="{{params['pad-full']}}"> <iframe class="f-ascii" id="pad-iframe" src="{{params['pad-full']}}">
</iframe> </iframe>
<div class="f-svg"> <div class="f-svg">
<iframe id="svg-iframe" src="/drawing/{{params['pad']}}"> <iframe id="svg-iframe" src="/writing/{{params['pad']}}">
</iframe> </iframe>
</div> </div>
</div> </div>