Prise en charge de la touche « esc » pour quitter les écrans de sélectien d'instrumen...
[minwii.git] / src / pywiiuse / pygame_wiitest.py
1 '''Test thw wiimote extension for pygame
2
3 I stole the graphing from wiiewer and then hacked it to work without Numeric
4
5 '''
6
7 import pygame
8 import pygame_wiimote # ideally something like this would be part of pygame so the _ would become .
9 import sys
10 import time
11 import os
12
13 pygame.init()
14
15 # initialze the wiimotes
16 if os.name != 'nt': print 'press 1&2'
17 pygame_wiimote.init(1, 5) # look for 1, wait 5 seconds
18 n = pygame_wiimote.get_count() # how many did we get?
19
20 if n == 0:
21 print 'no wiimotes found'
22 sys.exit(1)
23
24 wm = pygame_wiimote.Wiimote(0) # access the wiimote object
25 wm.enable_ir(1)
26 wm.enable_accels(1) # turn on acceleration reporting
27
28 w,h = size = (512,512)
29 screen = pygame.display.set_mode(size)
30
31 run = True
32
33 old = [h/2] * 6
34 maxA = 2.0
35
36 colors = [ (255,0,0), (0,255,0), (0,0,255), (255,255,0), (255, 0, 255), (0,255,255) ]
37
38 while run:
39 for event in pygame.event.get():
40 if event.type == pygame.QUIT:
41 print 'quiting'
42 run = False
43 break
44 elif event.type in [ pygame_wiimote.WIIMOTE_BUTTON_PRESS,
45 pygame_wiimote.NUNCHUK_BUTTON_PRESS ]:
46 print event.button, 'pressed on', event.id
47 elif event.type in [ pygame_wiimote.WIIMOTE_BUTTON_RELEASE,
48 pygame_wiimote.NUNCHUK_BUTTON_RELEASE ]:
49 print event.button, 'released on', event.id
50 elif event.type in [ pygame_wiimote.WIIMOTE_ACCEL, pygame_wiimote.NUNCHUK_ACCEL ]:
51 if event.type == pygame_wiimote.WIIMOTE_ACCEL:
52 b = 0
53 else:
54 b = 3
55 for c in range(3):
56 s = int((event.accel[c] * h / maxA + h)/2)
57 s = max(0, min(h-1, s))
58 pygame.draw.line(screen, colors[b+c], (w-3, old[b+c]), (w-2, s))
59 old[b+c] = s
60 screen.blit(screen, (-1, 0))
61 elif event.type == pygame_wiimote.WIIMOTE_STATUS:
62 print 'status', event.dict
63 elif event.type == pygame_wiimote.WIIMOTE_DISCONNECT:
64 print 'disconnected'
65 run = False
66 break
67
68 pygame.display.flip()
69 pygame.time.wait(10)
70 pygame_wiimote.quit()
71
72