Browse Source

Added button for HPGL export.

master
Gijs 6 months ago
parent
commit
e972ffb387
  1. 2
      app.py
  2. 24
      templates/drawing.html

2
app.py

@ -378,7 +378,7 @@ def hpgl (id):
with open(hpgl_file, 'r') as hpgl_handle: with open(hpgl_file, 'r') as hpgl_handle:
r = Response(hpgl_handle.read(), mimetype='application/hpgl') r = Response(hpgl_handle.read(), mimetype='application/hpgl')
r.headers.extend({ r.headers.extend({
'Content-Disposition': 'attachment; filename="cobbled-paths.hpgl"' 'Content-Disposition': f'attachment; filename="cobbled-paths-{id}.hpgl"'
}) })
# remove tmp file # remove tmp file

24
templates/drawing.html

@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/static/js/FileSaver.js"></script> <script src="/static/js/FileSaver.js"></script>
<style> <style>
#save-svg{ #save-buttons{
position: fixed; position: fixed;
top: 0.5em; top: 0.5em;
right: 0.5em; right: 0.5em;
@ -28,7 +28,10 @@
{{ svg|safe }} {{ svg|safe }}
<div id="save-buttons">
<button id="save-svg">> SVG</button> <button id="save-svg">> SVG</button>
<button id="save-hpgl">> HPGL</button>
</div>
<script> <script>
function get2bodyclass(){ function get2bodyclass(){
@ -58,6 +61,25 @@
let blob = new Blob([source], {type: "text/plain;charset=utf-8"}); let blob = new Blob([source], {type: "text/plain;charset=utf-8"});
saveAs(blob, 'cobbled-paths.svg'); saveAs(blob, 'cobbled-paths.svg');
}); });
let save_button_hpgl = document.getElementById('save-hpgl');
save_button_hpgl.addEventListener('click', function () {
let url = document.URL,
parts = url.split('/'),
name = parts[parts.length-1],
hpgl_url = '/hpgl/' + name,
a = document.createElement('a');
a.href = hpgl_url;
a.setAttribute('download', 'download');
if (document.createEvent) {
const event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
a.dispatchEvent(event);
}
else {
a.click();
}
});
</script> </script>
</body> </body>

Loading…
Cancel
Save