display.py 687 Bytes
Newer Older
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
class NullMonitor:
    def state(s, text):
        pass

    def log(s, text):
        pass

class TerminalMonitor(NullMonitor):
    def state(s, text):
        pass

    def log(s, text):
        print(text)

class IPythonMonitor(NullMonitor):
    def __init__(s):
        import ipywidgets as ipw
        import IPython.display as ipd
        s.state_field = ipw.Text(layout=ipw.Layout(width='75%'))
        s.log_field = ipw.Textarea(layout=ipw.Layout(width='75%', height='24ex'))
        ipd.display(ipw.VBox([s.state_field, s.log_field]))

    def state(s, text):
        s.state_field.value = text

    def log(s, text):
        s.log_field.value = s.log_field.value + text + '\n'