|
15 | 15 | <script src="https://cdnjs.cloudflare.com/ajax/libs/lz-string/1.5.0/lz-string.min.js"></script> |
16 | 16 | <!-- Monaco Editor AMD Loader --> |
17 | 17 | <script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs/loader.js"></script> |
| 18 | + <!-- PyScript Core & Terminal --> |
| 19 | + <link rel="stylesheet" href="https://pyscript.net/releases/2024.11.1/core.css"> |
| 20 | + <script type="module" src="https://pyscript.net/releases/2024.11.1/core.js"></script> |
18 | 21 | </head> |
19 | 22 | <body> |
20 | 23 | <!-- Top Global App Bar --> |
|
63 | 66 | <!-- Runtime Engine Selector --> |
64 | 67 | <div class="sim-select-wrap"> |
65 | 68 | <select id="runtime-select" aria-label="Select Execution Runtime"> |
66 | | - <option value="pyodide" selected>Pyodide (CPython)</option> |
67 | | - <option value="mpy">MicroPython</option> |
| 69 | + <option value="mpy" selected>MicroPython</option> |
| 70 | + <option value="pyodide">Pyodide (CPython)</option> |
68 | 71 | </select> |
69 | 72 | </div> |
70 | 73 | </div> |
|
108 | 111 | </section> |
109 | 112 |
|
110 | 113 | <!-- Vertical Drag Splitter --> |
111 | | - <div class="sim-splitter" id="splitter-v" role="separator" aria-orientation="vertical"></div> |
| 114 | + <div class="sim-splitter-v" id="splitter-v" role="separator" aria-orientation="vertical"></div> |
112 | 115 |
|
113 | | - <!-- Right Pane: Simulator & Console --> |
114 | | - <section class="sim-preview-pane" id="preview-pane" aria-label="Simulator and Console Output"> |
| 116 | + <!-- Right Pane: Device Preview & Interactive REPL --> |
| 117 | + <section class="sim-preview-pane" id="preview-pane" aria-label="Device Preview and Console"> |
115 | 118 | <!-- Top Sub-Pane: Hardware Canvas Bezel Stage --> |
116 | 119 | <div class="sim-device-stage" id="device-stage"> |
117 | 120 | <div class="sim-device-bezel" id="device-bezel"> |
|
123 | 126 | <!-- Horizontal Drag Splitter --> |
124 | 127 | <div class="sim-splitter-h" id="splitter-h" role="separator" aria-orientation="horizontal"></div> |
125 | 128 |
|
126 | | - <!-- Bottom Sub-Pane: Interactive REPL --> |
127 | | - <section class="sim-console-pane" id="console-pane" aria-label="Interactive Python REPL"> |
| 129 | + <!-- Bottom Sub-Pane: Interactive PyScript Terminal REPL --> |
| 130 | + <section class="sim-console-pane" id="console-pane" aria-label="Interactive Python Terminal REPL"> |
128 | 131 | <div class="sim-pane-header"> |
129 | 132 | <div class="sim-tab"> |
130 | 133 | <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg> |
|
134 | 137 | <svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg> |
135 | 138 | </button> |
136 | 139 | </div> |
137 | | - <div class="sim-console-body" id="console-log"></div> |
138 | | - <form class="sim-repl-form" id="repl-form" autocomplete="off"> |
139 | | - <span class="sim-repl-prompt" id="repl-prompt">>>></span> |
140 | | - <input type="text" class="sim-repl-input" id="repl-input" placeholder="Type Python expression or command (e.g. dir(), lv.screen_active()...)" spellcheck="false" autocomplete="off" autocapitalize="off"> |
141 | | - </form> |
| 140 | + <div class="sim-console-body sim-terminal-body" id="console-log"> |
| 141 | + <script id="sim-terminal-script" type="mpy" terminal> |
| 142 | +import sys, os |
| 143 | +from pyscript import window |
| 144 | + |
| 145 | +def _save_main_file(code_content): |
| 146 | + with open("main.py", "w") as f: |
| 147 | + f.write(code_content) |
| 148 | + |
| 149 | +window._save_main_file = _save_main_file |
| 150 | + |
| 151 | +# Write initial main.py from editor / template |
| 152 | +try: |
| 153 | + _initial_code = window.getEditorCode() if hasattr(window, "getEditorCode") else "" |
| 154 | + if _initial_code: |
| 155 | + _save_main_file(_initial_code) |
| 156 | +except Exception: |
| 157 | + pass |
| 158 | + |
| 159 | +# Bootstrap core desktop stack via mip from PyDevices MIP index |
| 160 | +try: |
| 161 | + import mip |
| 162 | + mip.install("pydevices-desktop", index="https://PyDevices.github.io/mip") |
| 163 | + try: |
| 164 | + import utils.path |
| 165 | + except Exception: |
| 166 | + pass |
| 167 | +except Exception as _e: |
| 168 | + print("MIP bootstrap:", _e) |
| 169 | + |
| 170 | +try: |
| 171 | + import main |
| 172 | +except Exception as _e: |
| 173 | + sys.print_exception(_e) if hasattr(sys, "print_exception") else print(_e) |
| 174 | + |
| 175 | +import code |
| 176 | +code.interact(local=globals()) |
| 177 | + </script> |
| 178 | + </div> |
142 | 179 | </section> |
143 | 180 | </section> |
144 | 181 | </main> |
|
0 commit comments