Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / simulator / pgu-0.18 / examples / gui17.py
1 """an example a python console"""
2
3 import pygame
4 from pygame.locals import *
5
6 # the following line is not needed if pgu is installed
7 import sys; sys.path.insert(0, "..")
8
9 import traceback
10
11 from pgu import gui
12 from pgu import html
13
14 class StringStream:
15     def __init__(self):
16         self._data = ''
17     def write(self,data):
18         self._data = self._data+data
19         _lines = self._data.split("\n")
20         for line in _lines[:-1]:
21             lines.tr()
22             lines.td(gui.Label(str(line)),align=-1)
23         self._data = _lines[-1:][0]
24         
25 _locals = {}
26 def lkey(_event):
27     e = _event
28     if e.key == K_RETURN:
29         _stdout = sys.stdout
30         s = sys.stdout = StringStream()
31         
32         val = line.value
33         line.value = ''
34         line.focus()
35         print('>>> '+val)
36         try:
37             code = compile(val,'<string>','single')
38             eval(code,globals(),_locals)
39         except: 
40             e_type,e_value,e_traceback = sys.exc_info()
41             print('Traceback (most recent call last):')
42             traceback.print_tb(e_traceback,None,s)
43             print(e_type,e_value)
44
45         sys.stdout = _stdout
46
47 app = gui.Desktop()
48 t = gui.Table(width=500,height=400)
49
50 t.tr()
51 lines = gui.Table()
52 box = gui.ScrollArea(lines,500,380)
53 t.td(box)
54
55 t.tr()
56 line = gui.Input(size=49)
57 line.connect(gui.KEYDOWN,lkey)
58 t.td(line)
59
60 t.tr()
61 class Hack(gui.Spacer):
62     def resize(self,width=None,height=None):
63         box.set_vertical_scroll(65535)
64         return 1,1
65 t.td(Hack(1,1))
66
67 app.connect(gui.QUIT,app.quit,None)
68 app.run(t)

UCC git Repository :: git.ucc.asn.au