# Program zum Erstellen ein neu JS-Program
|
import sys
|
import os.path
|
|
|
|
html_template = \
|
"""<html lang="en">
|
<head>
|
<meta charset="UTF-8">
|
<title>{program}</title>
|
<link rel="stylesheet" href="lib/dom-output.css" />
|
<link rel="stylesheet" href="lib/dfhi.css" />
|
<link rel="stylesheet" href="lib/dfhi-plot.css"/>
|
</head>
|
<body>
|
|
<div>
|
<p>
|
(Something about your program here)
|
</p>
|
Instruction to user
|
<input type="text" id="argv" name="argv" />
|
<button name="run" id="run" >Plot Points</button>
|
</div>
|
|
<div class="row">
|
<div id="plotter-container" class="column">
|
<div class="jxgbox" id="plotter"></div>
|
<div>
|
<button id="export">Export to SVG</button>
|
</div>
|
</div>
|
<div id="text-output-container" class="column">
|
<pre id="text-output"></pre>
|
</div>
|
</div>
|
|
|
<script type="module" src="{program}.js"></script>
|
|
</body>
|
</html>
|
"""
|
|
js_template = \
|
"""/*
|
* {program}.js
|
*
|
*/
|
|
import "./lib/dfhi.js";
|
import * as JXG from "jsxgraph" ;
|
import {{exportBoard}} from "./lib/dfhi-plot";
|
|
let board = undefined;
|
function initBoard () {{
|
return JXG.JSXGraph.initBoard('plotter', {{
|
boundingbox: [-2, 9, 3, -1],
|
axis: true
|
}});
|
}}
|
|
window.init = function() {{
|
terminal.printl(`Program {program} initializes ... `);
|
board = initBoard();
|
document.getElementById("export")
|
.addEventListener("click", (event) => exportBoard(board));
|
}};
|
|
|
window.main = function(...argv) {{
|
terminal.printl(`program runs with arguments ${{argv}}`);
|
if (board) {{
|
JXG.JSXGraph.freeBoard(board);
|
board = undefined;
|
}}
|
board = initBoard();
|
}};
|
"""
|
|
def write_program(file_name, template, program_name):
|
code = template.format(program=program_name)
|
print("Write " + code + " to file " + file_name)
|
if os.path.exists(file_name):
|
raise ValueError("File " + file_name + " exist")
|
else:
|
with open(file_name,"w") as f:
|
f.write(code)
|
|
|
if __name__ == "__main__":
|
programm_name = sys.argv[1]
|
write_program("src/" + programm_name + ".html", html_template, programm_name)
|
write_program("src/" + programm_name + ".js", js_template, programm_name)
|