blob: 1a562c2a968cdeecd2b9803f53bf5d9abcf079bb [file] [log] [blame]
Guido van Rossumb3853281992-04-14 11:05:49 +00001# Window interface to (some of) the CD player's vital audio functions
2
Guido van Rossumb9506291992-04-13 18:38:20 +00003import cd
Guido van Rossumd5d19121992-04-15 16:19:23 +00004import CD
Guido van Rossumb9506291992-04-13 18:38:20 +00005import stdwin
6from stdwinevents import *
7import mainloop
8
9def main():
10 player = cd.open()
11 stdwin.setdefscrollbars(0, 0)
12 win = stdwin.open('CD')
13 win.player = player
14 win.dispatch = cddispatch
15 mainloop.register(win)
16 win.settimer(10)
17 mainloop.mainloop()
18
19def cddispatch(type, win, detail):
20 if type == WE_NULL:
21 pass
22 elif type == WE_CLOSE:
23 mainloop.unregister(win)
24 win.close()
25 elif type == WE_DRAW:
26 draw(win)
27 elif type == WE_TIMER:
28 update(win)
29 elif type == WE_MOUSE_UP:
30 left, top, right, bottom, v1, v2 = getgeo(win)
31 h, v = detail[0]
32 if left < h < right:
33 if top < v < v1:
34 but1(win)
35 elif v1 < v < v2:
36 but2(win)
37 elif v2 < v < bottom:
38 but3(win)
39 else:
40 stdwin.fleep()
41
42def but1(win):
43 update(win)
44
45def but2(win):
Guido van Rossumd5d19121992-04-15 16:19:23 +000046 state = win.player.getstatus()[0]
47 if state == CD.READY:
48 win.player.play(1, 1)
49 elif state in (CD.PLAYING, CD.PAUSED):
50 win.player.togglepause()
51 else:
52 stdwin.fleep()
Guido van Rossumb9506291992-04-13 18:38:20 +000053 update(win)
54
55def but3(win):
56 win.player.stop()
57 update(win)
58
59def update(win):
60 d = win.begindrawing()
61 drawstatus(win, d)
62 d.enddrawing()
63 win.settimer(10)
64
65statedict = ['ERROR', 'NODISK', 'READY', 'PLAYING', 'PAUSED', 'STILL']
66
67def draw(win):
68 left, top, right, bottom, v1, v2 = getgeo(win)
69 d = win.begindrawing()
70 drawstatus(win, d)
71 box(d, left, v1, right, v2, 'Play/Pause')
72 box(d, left, v2, right, bottom, 'Stop')
73 d.enddrawing()
74
75def drawstatus(win, d):
76 left, top, right, bottom, v1, v2 = getgeo(win)
Guido van Rossumd5d19121992-04-15 16:19:23 +000077 state, track, curtime, abstime, totaltime, first, last, \
78 scsi_audio, cur_block, dummy = win.player.getstatus()
Guido van Rossumb9506291992-04-13 18:38:20 +000079 if 0 <= state < len(statedict):
80 message = statedict[state]
81 else:
82 message = `status`
Guido van Rossumd5d19121992-04-15 16:19:23 +000083 message = message + ' track ' + `track` + ' of ' + `last`
Guido van Rossumb9506291992-04-13 18:38:20 +000084 d.erase((left, top), (right, v1))
85 box(d, left, top, right, v1, message)
86
87def box(d, left, top, right, bottom, label):
88 R = (left+1, top+1), (right-1, bottom-1)
89 width = d.textwidth(label)
90 height = d.lineheight()
91 h = (left + right - width) / 2
92 v = (top + bottom - height) / 2
93 d.box(R)
94 d.cliprect(R)
95 d.text((h, v), label)
96 d.noclip()
97
98def getgeo(win):
99 (left, top), (right, bottom) = (0, 0), win.getwinsize()
100 v1 = top + (bottom - top) / 3
101 v2 = top + (bottom - top) * 2 / 3
102 return left, top, right, bottom, v1, v2
Guido van Rossumb3853281992-04-14 11:05:49 +0000103
104main()