From: pin Date: Fri, 24 Jun 2011 09:13:20 +0000 (+0000) Subject: Réaménagement : on prépare ce qu'il faut pour pouvoir rendre personalisable le compor... X-Git-Url: https://scm.cri.mines-paristech.fr/git/minwii.git/commitdiff_plain/756b357fbb605b408bba256d93243cafb5fa6264?ds=sidebyside Réaménagement : on prépare ce qu'il faut pour pouvoir rendre personalisable le comportement de la souris émulée par une wiimote. On est pour l'instant conservatif : une seule wiimote active et le bouton B pour le clic. git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@347 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/pywiiuse/pygame_wiimouse.py b/src/pywiiuse/pygame_wiimouse.py index f77856c..835bff8 100755 --- a/src/pywiiuse/pygame_wiimouse.py +++ b/src/pywiiuse/pygame_wiimouse.py @@ -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.eventCallBack = _default_event_cb 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) : - 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 @@ -73,31 +75,7 @@ class wiimote_thread(Thread): 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''' @@ -125,6 +103,31 @@ class wiimote_thread(Thread): 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'):