From 756b357fbb605b408bba256d93243cafb5fa6264 Mon Sep 17 00:00:00 2001 From: pin Date: Fri, 24 Jun 2011 09:13:20 +0000 Subject: [PATCH] =?utf8?q?R=C3=A9am=C3=A9nagement=20:=20on=20pr=C3=A9pare?= =?utf8?q?=20ce=20qu'il=20faut=20pour=20pouvoir=20rendre=20personalisable?= =?utf8?q?=20le=20comportement=20de=20la=20souris=20=C3=A9mul=C3=A9e=20par?= =?utf8?q?=20une=20wiimote.=20On=20est=20pour=20l'instant=20conservatif=20?= =?utf8?q?:=20une=20seule=20wiimote=20active=20et=20le=20bouton=20B=20pour?= =?utf8?q?=20le=20clic.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@347 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/pywiiuse/pygame_wiimouse.py | 59 +++++++++++++++++---------------- 1 file changed, 31 insertions(+), 28 deletions(-) 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'): -- 2.20.1