Skip to content

Commit cb6acb9

Browse files
updated
1 parent 18c2359 commit cb6acb9

3 files changed

Lines changed: 34 additions & 24 deletions

File tree

docs/css/style.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,14 @@ body {
480480
background: #1e1e1e;
481481
color: #d4d4d4;
482482
resize: vertical;
483+
line-height: 1.5;
484+
tab-size: 4;
485+
-moz-tab-size: 4;
486+
}
487+
488+
.code-editor:focus {
489+
outline: 2px solid var(--primary-color);
490+
outline-offset: -2px;
483491
}
484492

485493
.output-section {

docs/editor.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ <h2><i class="fas fa-code"></i> Code Editor</h2>
9191
</div>
9292
</div>
9393

94-
<textarea id="code-editor" class="code-editor" spellcheck="false"># Write your Python code here
94+
<textarea id="code-editor" class="code-editor" spellcheck="false" autocomplete="off" autocorrect="off" autocapitalize="off"># Write your Python code here
9595
print("Hello World")
9696
</textarea>
9797

@@ -125,10 +125,11 @@ <h3><i class="fas fa-terminal"></i> Output</h3>
125125
</div>
126126

127127
<!-- PyScript code execution -->
128-
<script type="py" config='{"packages": ["numpy"]}' id="python-runner" style="display: none;">
128+
<script type="py" config='{"packages": []}' id="python-runner" style="display: none;">
129129
from js import document, console
130130
import sys
131131
from io import StringIO
132+
import traceback
132133

133134
def run_user_code():
134135
output_div = document.getElementById("output")
@@ -147,7 +148,7 @@ <h3><i class="fas fa-terminal"></i> Output</h3>
147148

148149
try:
149150
# Execute the code
150-
exec(code, globals())
151+
exec(code, {})
151152

152153
# Get output
153154
output = sys.stdout.getvalue()
@@ -159,13 +160,17 @@ <h3><i class="fas fa-terminal"></i> Output</h3>
159160
output_div.innerHTML = '<div class="output-info">Code executed successfully (no output)</div>'
160161

161162
except Exception as e:
162-
# Display error
163-
output_div.innerHTML = f'<pre class="output-error"><strong>Error:</strong>\n{str(e)}</pre>'
163+
# Display error with traceback
164+
error_msg = traceback.format_exc()
165+
output_div.innerHTML = f'<pre class="output-error"><strong>Error:</strong>\n{error_msg}</pre>'
164166

165167
finally:
166168
# Restore stdout
167169
sys.stdout = old_stdout
168170
loading_div.style.display = "none"
171+
172+
# Make function available globally
173+
window.run_user_code = run_user_code
169174
</script>
170175

171176
<script src="js/progress.js"></script>

docs/js/editor.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,23 @@ document.addEventListener('DOMContentLoaded', function() {
2929
});
3030

3131
function runCode() {
32-
// This triggers the PyScript execution
33-
try {
34-
const code = document.getElementById('code-editor').value;
35-
const outputDiv = document.getElementById('output');
36-
const loadingDiv = document.getElementById('loading');
37-
38-
// Show loading
39-
loadingDiv.style.display = 'block';
40-
outputDiv.innerHTML = '';
41-
42-
// PyScript will handle execution
43-
// The python-runner script will capture and display output
44-
45-
// Note: PyScript execution is handled by the embedded Python code in editor.html
46-
// This function just triggers the UI updates
47-
48-
} catch (error) {
32+
// Check if PyScript is loaded
33+
if (typeof window.run_user_code === 'function') {
34+
// Call PyScript function
35+
window.run_user_code();
36+
} else if (typeof pyscript !== 'undefined') {
37+
// PyScript is available, try to run
38+
try {
39+
pyscript.run_user_code();
40+
} catch (e) {
41+
// Fallback: show that PyScript is loading
42+
document.getElementById('output').innerHTML =
43+
'<div class="output-info">⏳ PyScript is still loading... Please wait a moment and try again.</div>';
44+
}
45+
} else {
46+
// PyScript not loaded yet
4947
document.getElementById('output').innerHTML =
50-
`<pre class="output-error">Error: ${error.message}</pre>`;
51-
document.getElementById('loading').style.display = 'none';
48+
'<div class="output-info">⏳ Python runtime is loading... This may take a few seconds on first visit. Please wait and try again.</div>';
5249
}
5350
}
5451

0 commit comments

Comments
 (0)