Réaménagement : on prépare ce qu'il faut pour pouvoir rendre personalisable le compor...
authorpin <pin@fe552daf-6dbe-4428-90eb-1537e0879342>
Fri, 24 Jun 2011 09:13:20 +0000 (09:13 +0000)
committerpin <pin@fe552daf-6dbe-4428-90eb-1537e0879342>
Fri, 24 Jun 2011 09:13:20 +0000 (09:13 +0000)
git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@347 fe552daf-6dbe-4428-90eb-1537e0879342

src/pywiiuse/pygame_wiimouse.py

index f77856c..835bff8 100755 (executable)
@@ -28,6 +28,7 @@ class wiimote_thread(Thread):
         self._paused = False
         self.start()
         self.startup.get(True) # wait for the thread to get started and acquire the motes
         self._paused = False
         self.start()
         self.startup.get(True) # wait for the thread to get started and acquire the motes
+        self.eventCallBack = _default_event_cb
 
     def run(self):
         '''This runs in a separate thread'''
 
     def run(self):
         '''This runs in a separate thread'''
@@ -49,9 +50,10 @@ class wiimote_thread(Thread):
             if self._paused : continue
             try :
                 if wiiuse.poll(self.wiimotes, self.nmotes) :
             if self._paused : continue
             try :
                 if wiiuse.poll(self.wiimotes, self.nmotes) :
-                    m = self.wiimotes[self.selectedWiimoteIndex]
-                    if m[0].event == wiiuse.EVENT:
-                        self.event_cb(m)
+                    for i in range(self.nmotes) :
+                        m = self.wiimotes[i]
+                        if m[0].event == wiiuse.EVENT:
+                            self.eventCallBack(self, i, m)
             except :
                 pass
                 
             except :
                 pass
                 
@@ -73,31 +75,7 @@ class wiimote_thread(Thread):
 
     def do(self, func, *args):
         '''Run the function in the thread handling the wiimote'''
 
     def do(self, func, *args):
         '''Run the function in the thread handling the wiimote'''
-        self.queue.put((func, args))
-
-    def event_cb(self, wmp):
-        '''Called when the library has some data for the user.'''
-        wm = wmp[0]
-        pos = (wm.ir.x, wm.ir.y)
-        pygame.mouse.set_pos(pos)
-        
-        eventType = None
-
-        if wm.btns and \
-            wiiuse.is_just_pressed(wm, wiiuse.button['B']) :
-                event = pygame.event.Event(pygame.MOUSEBUTTONDOWN,
-                                           pos = pos,
-                                           button = 1)
-                pygame.event.post(event)
-
-        if wm.btns_released and \
-            wiiuse.is_released(wm, wiiuse.button['B']):
-                event = pygame.event.Event(pygame.MOUSEBUTTONUP,
-                                           pos = pos,
-                                           button = 1)
-                pygame.event.post(event)
-                    
-                    
+        self.queue.put((func, args))                    
 
     def control_cb(self, wmp, attachment, speaker, ir, led, battery):
         '''Could check the battery level and such here'''
 
     def control_cb(self, wmp, attachment, speaker, ir, led, battery):
         '''Could check the battery level and such here'''
@@ -125,6 +103,31 @@ class wiimote_thread(Thread):
         return self.actual_nmotes
 
 
         return self.actual_nmotes
 
 
+def _default_event_cb(self, id, wmp):
+    '''Called when the library has some data for the user.'''
+    if id != self.selectedWiimoteIndex : return
+    wm = wmp[0]
+    pos = (wm.ir.x, wm.ir.y)
+    pygame.mouse.set_pos(pos)
+
+    eventType = None
+
+    if wm.btns and \
+        wiiuse.is_just_pressed(wm, wiiuse.button['B']) :
+            event = pygame.event.Event(pygame.MOUSEBUTTONDOWN,
+                                       pos = pos,
+                                       button = 1)
+            pygame.event.post(event)
+
+    if wm.btns_released and \
+        wiiuse.is_released(wm, wiiuse.button['B']):
+            event = pygame.event.Event(pygame.MOUSEBUTTONUP,
+                                       pos = pos,
+                                       button = 1)
+            pygame.event.post(event)
+
+
+
 WT = None
 
 def init(nmotes, timeout, screenResolution=(660, 370), position='ABOVE'):
 WT = None
 
 def init(nmotes, timeout, screenResolution=(660, 370), position='ABOVE'):