blob: da4bacbb63a85f6abf41d910ec20cb412c8810ce [file] [log] [blame]
Guido van Rossume4bddea1991-10-30 11:52:48 +00001import string
2
3from socket import *
4from gl import *
5from GL import *
6from DEVICE import *
7from time import millisleep, millitimer
8
9PORT = 5555
10
11PF = 2 # packfactor
12HS = 40 # Header size
13
14def testimage():
15 RGBcolor(0, 0, 0)
16 clear()
17 RGBcolor(0, 255, 0)
18 cmov2i(10, 10)
19 charstr('Waiting...')
20
21def reshape():
22 reshapeviewport()
23 w, h = getsize()
24 ortho2(0, w, 0, h)
25 testimage()
26 return w, h
27
28def main():
29 s = socket(AF_INET, SOCK_DGRAM)
30 s.bind('', PORT)
31
32 foreground()
33 wid = winopen('tv')
34 RGBmode()
35 gconfig()
36 qdevice(ESCKEY)
37
38 oldw, oldh = getsize()
39 ortho2(0, oldw, 0, oldh)
40 testimage()
41
42 t1 = millitimer()
43
44 while 1:
45 if qtest():
46 dev, val = qread()
Guido van Rossumf47d0481992-02-11 14:50:22 +000047 if dev == ESCKEY:
Guido van Rossume4bddea1991-10-30 11:52:48 +000048 winclose(wid)
49 return
Guido van Rossumf47d0481992-02-11 14:50:22 +000050 elif dev == REDRAW:
Guido van Rossume4bddea1991-10-30 11:52:48 +000051 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)
75
76 winclose(wid)
77 return data
78
79main()