-
Notifications
You must be signed in to change notification settings - Fork 107
/
algojammer.py
46 lines (37 loc) · 1.2 KB
/
algojammer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gevent.monkey; gevent.monkey.patch_all()
import eel, state_boxes as sbx, execution as exe, state as sta, time as tme
state = {
'step': 0,
'snapshots': [],
'mode': 'stopped'
}
page_geom = {
'algojammer.html': {'size': (1300, 800), 'position': (610, 200)},
'sheet.html': {'size': ( 500, 800), 'position': (100, 200)}
}
eel.init('web')
@eel.expose
def read_example():
with open('files/example.py', encoding='utf8') as example_file:
eel.set_code(example_file.read())
@eel.expose
def run(code, stdin=''):
while state['mode'] != 'stopped':
state['mode'] = 'interrupt'
eel.sleep(0.01)
state['mode'] = 'running'
sta.execution_start()
exe.bounded_exec(code, 10**7, report)
state['mode'] = 'stopped'
def report(data):
if state['mode'] == 'interrupt':
raise InterruptedError('Code changed during execution')
sta.execution_report(data)
eel.execution_report(data)
@eel.expose
def update_state(n=state['step'], force=False):
if n != state['step'] or force:
state['step'] = n
snapshot, modules = sta.get_state(n)
sbx.update_state_boxes(snapshot, modules)
eel.start('algojammer.html', geometry=page_geom)