|
8 | 8 | <script type="text/python3" src="app.py"></script>
|
9 | 9 | <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.7.5/brython.js"></script>
|
10 | 10 | <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.7.5/brython_stdlib.js"></script>
|
11 |
| - <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ace.js" |
12 |
| - charset="utf-8"></script> |
13 |
| - <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ext-language_tools.js" |
14 |
| - charset="utf-8"></script> |
| 11 | + <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ace.js" charset="utf-8"></script> |
| 12 | + <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ext-language_tools.js" charset="utf-8"></script> |
15 | 13 | <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/theme-monokai.js"></script>
|
| 14 | + <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.js"></script> |
16 | 15 | <script>
|
17 | 16 | // Workaround to allow brython to handle AttributeErrors correctly
|
18 | 17 | window.$raise = () => null;
|
19 | 18 | </script>
|
| 19 | + <script> |
| 20 | + function configure() { |
| 21 | + brython({debug:1}) |
| 22 | + |
| 23 | + document.querySelector("#export_button") |
| 24 | + .addEventListener("click", () => { |
| 25 | + saveAs( |
| 26 | + new Blob([ window.ace.edit("editor").getValue() ]), |
| 27 | + "bot.py" |
| 28 | + ) |
| 29 | + }) |
| 30 | + |
| 31 | + document.querySelector("#import") |
| 32 | + .addEventListener("change", function(e) { |
| 33 | + const file = e.target.files[0]; |
| 34 | + if (!file) return; |
| 35 | + |
| 36 | + const reader = new FileReader(); |
| 37 | + reader.onload = e => window.ace.edit("editor").setValue(e.target.result); |
| 38 | + reader.readAsText(file); |
| 39 | + }) |
| 40 | + } |
| 41 | + </script> |
20 | 42 | </head>
|
21 | 43 |
|
22 |
| -<body onload="brython({debug:1})"> |
| 44 | +<body onload="configure()"> |
23 | 45 | <div class="app">
|
24 | 46 | <div class="editor-panel">
|
25 | 47 | <div id="editor">
|
|
29 | 51 | </div>
|
30 | 52 | </div>
|
31 | 53 | <div class="button-container">
|
| 54 | + <div> |
| 55 | + <button id="import_button" class="option-button"> |
| 56 | + <label for="import"> |
| 57 | + <span>Import</span> |
| 58 | + <i class="fa fa-upload"></i> |
| 59 | + </label> |
| 60 | + <input id="import" type="file" onchange="onImportSelected(this)"/> |
| 61 | + </button> |
| 62 | + </div> |
| 63 | + <div> |
| 64 | + <button id="export_button" class="option-button" onclick="onExportClick()"> |
| 65 | + <span>Export</span> |
| 66 | + <i class="fa fa-download"></i> |
| 67 | + </button> |
| 68 | + </div> |
32 | 69 | <div>
|
33 | 70 | <button id="reset_button" class="option-button">
|
34 | 71 | <span>Reset</span>
|
|
0 commit comments