Quick update to the README file. For intros and books we now point to
[python/dscho.git] / Demo / sgi / video / tv.py
blobda4bacbb63a85f6abf41d910ec20cb412c8810ce
1 import string
3 from socket import *
4 from gl import *
5 from GL import *
6 from DEVICE import *
7 from time import millisleep, millitimer
9 PORT = 5555
11 PF = 2 # packfactor
12 HS = 40 # Header size
14 def testimage():
15 RGBcolor(0, 0, 0)
16 clear()
17 RGBcolor(0, 255, 0)
18 cmov2i(10, 10)
19 charstr('Waiting...')
21 def reshape():
22 reshapeviewport()
23 w, h = getsize()
24 ortho2(0, w, 0, h)
25 testimage()
26 return w, h
28 def main():
29 s = socket(AF_INET, SOCK_DGRAM)
30 s.bind('', PORT)
32 foreground()
33 wid = winopen('tv')
34 RGBmode()
35 gconfig()
36 qdevice(ESCKEY)
38 oldw, oldh = getsize()
39 ortho2(0, oldw, 0, oldh)
40 testimage()
42 t1 = millitimer()
44 while 1:
45 if qtest():
46 dev, val = qread()
47 if dev == ESCKEY:
48 winclose(wid)
49 return
50 elif dev == REDRAW:
51 oldw, oldh = reshape()
52 elif s.avail():
53 data = s.recv(17000)
54 header = string.strip(data[:HS])
55 w, h, pf, x1, y1, x2, y2 = eval(header)
56 if (w, h) <> (oldw, oldh):
57 x, y = getorigin()
58 x, y = x-1, y+21 # TWM correction
59 winposition(x, x+w-1, y+oldh-h, y+oldh-1)
60 oldw, oldh = reshape()
61 data2 = data[HS:]
62 dx = (x2-x1+1)/pf
63 dy = (y2-y1+1)/pf
64 data3 = unpackrect(dx, dy, 1, data2)
65 rectzoom(pf, pf)
66 lrectwrite(x1, y1, x1+dx-1, y1+dy-1, data3)
67 t1 = millitimer()
68 else:
69 t2 = millitimer()
70 if t2-t1 >= 5000:
71 testimage()
72 t1 = t2
73 else:
74 millisleep(10)
76 winclose(wid)
77 return data
79 main()