Bind console
This commit is contained in:
parent
d53cf997a9
commit
c6804949c5
28
python.html
28
python.html
|
@ -20,13 +20,41 @@
|
||||||
<footer>
|
<footer>
|
||||||
Romain de Laage - CC0
|
Romain de Laage - CC0
|
||||||
</footer>
|
</footer>
|
||||||
|
<script type="text/python" id="pyinit">
|
||||||
|
import sys
|
||||||
|
from browser import document
|
||||||
|
|
||||||
|
# Define new class to bind html element with std files
|
||||||
|
class Stdfile() :
|
||||||
|
def __init__(self, elmtId, error = False):
|
||||||
|
self.elmt = document[elmtId]
|
||||||
|
self.error = error
|
||||||
|
def write(self, text):
|
||||||
|
if self.error == True:
|
||||||
|
self.elmt.html = self.elmt.html + '<div class="error">' + text.replace('\n', '<br />') + '</div>'
|
||||||
|
else:
|
||||||
|
self.elmt.html = self.elmt.html + '<div class="message">' + text.replace('\n', '<br />') + '</div>'
|
||||||
|
|
||||||
|
# Bind stderr and stdout with console element of page
|
||||||
|
sys.stderr = Stdfile('console', True)
|
||||||
|
sys.stdout = Stdfile('console')
|
||||||
|
</script>
|
||||||
|
<script type="text/python" id="pyclear">
|
||||||
|
from browser import document
|
||||||
|
|
||||||
|
# Clear console
|
||||||
|
document['console'].html = ''
|
||||||
|
</script>
|
||||||
<script type="text/python" id="pycode"></script>
|
<script type="text/python" id="pycode"></script>
|
||||||
<script src="assets/js/editor.js"></script>
|
<script src="assets/js/editor.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const flask = getEditor("#code", "py")
|
const flask = getEditor("#code", "py")
|
||||||
|
|
||||||
|
brython({ids:["pyinit"]})
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
document.getElementById("pycode").innerHTML = flask.getCode()
|
document.getElementById("pycode").innerHTML = flask.getCode()
|
||||||
|
brython({ids:["pyclear"]})
|
||||||
brython({
|
brython({
|
||||||
debug:1,
|
debug:1,
|
||||||
ids:["pycode"]
|
ids:["pycode"]
|
||||||
|
|
Loading…
Reference in New Issue