Ajout des modules d'interface pygame / pywiiuse.
[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_accels(1) # turn on acceleration reporting
26
27 w,h = size = (512,512)
28 screen = pygame.display.set_mode(size)
29
30 run = True
31
32 old = [h/2] * 6
33 maxA = 2.0
34
35 colors = [ (255,0,0), (0,255,0), (0,0,255), (255,255,0), (255, 0, 255), (0,255,255) ]
36
37 while run:
38 for event in pygame.event.get():
39 if event.type == pygame.QUIT:
40 print 'quiting'
41 run = False
42 break
43 elif event.type in [ pygame_wiimote.WIIMOTE_BUTTON_PRESS,
44 pygame_wiimote.NUNCHUK_BUTTON_PRESS ]:
45 print event.button, 'pressed on', event.id
46 elif event.type in [ pygame_wiimote.WIIMOTE_BUTTON_RELEASE,
47 pygame_wiimote.NUNCHUK_BUTTON_RELEASE ]:
48 print event.button, 'released on', event.id
49 elif event.type in [ pygame_wiimote.WIIMOTE_ACCEL, pygame_wiimote.NUNCHUK_ACCEL ]:
50 if event.type == pygame_wiimote.WIIMOTE_ACCEL:
51 b = 0
52 else:
53 b = 3
54 for c in range(3):
55 s = int((event.accel[c] * h / maxA + h)/2)
56 s = max(0, min(h-1, s))
57 pygame.draw.line(screen, colors[b+c], (w-3, old[b+c]), (w-2, s))
58 old[b+c] = s
59 screen.blit(screen, (-1, 0))
60 elif event.type == pygame_wiimote.WIIMOTE_STATUS:
61 print 'status', event.dict
62 elif event.type == pygame_wiimote.WIIMOTE_DISCONNECT:
63 print 'disconnected'
64 run = False
65 break
66
67 pygame.display.flip()
68 pygame.time.wait(10)
69 pygame_wiimote.quit()
70
71