def start_editor(self): glyph = self.editor_info glyph_rect = glyph.rect glyph.input(PAGES['editor']) glyph.update() editor = self.editor editor_rect = editor.rect SCREEN.blit(EDITOR_BKGSCREEN, (0, 0)) SCREEN.blit(glyph.image, glyph_rect) SCREEN.blit(editor.image, editor_rect) editor_focus = False while 1: mouse_pos = mouse.get_pos() link = glyph.get_collisions(mouse_pos) if link: mouse.set_cursor(*HAND_CURSOR) else: mouse.set_cursor(*DEFAULT_CURSOR) for ev in event.get(): if ev.type == MOUSEBUTTONDOWN: if link: pass if editor.rect.collidepoint(mouse_pos): editor_focus = True else: editor_focus = False if ev.type == KEYDOWN: if ev.key == K_ESCAPE: exit() if editor_focus == True: editor.input(ev) cursor = editor.get_cursor() editor.image.fill((255, 205, 0), cursor) SCREEN.blit(editor.image, editor_rect) display.update()
def click_hand_cursor(): clickhand = ( #24x24 " .. ", " .XX. ", " .XX. ", " .XX. ", " .XX. ", " .XX... ", " .XX.XX... ", " .XX.XX.XX.. ", " .XX.XX.XX.X. ", " ... .XX.XX.XX.XX. ", " .XXX..XXXXXXXX.XX. ", " .XXX.XXXXXXXXXXX. ", " .XX.XXXXXXXXXXX. ", " .XXXXXXXXXXXXX. ", " .XXXXXXXXXXXX. ", " .XXXXXXXXXXXX. ", " .XXXXXXXXXX. ", " .XXXXXXXXXX. ", " .XXXXXXXX. ", " .XXXXXXXX. ", " ........ ", " ", " ", " ", ) curs, mask = pygame.cursors.compile(clickhand, 'X', '.') set_cursor((24, 24), (7, 0), curs, mask)
def grab_hand_cursor(): grabhand = ( #24x24 " ", " ", " ", " ", " ", " ......... ", " .XX..XX.XX... ", " .XX.XX.XX.XX. ", " .XXXXXXXX.XX. ", " ..XXXXXXXXXXX. ", " .X.XXXXXXXXXX. ", " .XXXXXXXXXXXXX. ", " .XXXXXXXXXXXX. ", " .XXXXXXXXXX. ", " .XXXXXXXXXX. ", " .XXXXXXXX. ", " .XXXXXX. ", " .XXXXXX. ", " . . ", " ", " ", " ", " ", " ", ) curs, mask = pygame.cursors.compile(grabhand, 'X', '.') set_cursor((24, 24), (7, 0), curs, mask)
def loop_end(self): """ Cyclical function called at the end of Game._main_loop() Sets the mouse cursor based on the state of the "may_click" flag. """ if self.may_click: mouse.set_cursor(*arrow) else: mouse.set_cursor(*broken_x)
def set(size, hotspot, xormasks, andmasks): """Sets new cursor image. Predefined cursors are tuples containing the 4 needed arguments, so you can type cursors.set(*cursors.arrow). Custom cursors must be first compiled by cursors.compile() to create the needed args. Public.""" if size is None: _mouse.set_visible(False) else: _mouse.set_visible(True) _mouse.set_cursor(size, hotspot, xormasks, andmasks)
def build(self): EventLoop.ensure_window() if EventLoop.window.__class__.__name__.endswith('Pygame'): try: from pygame import mouse # pygame_compile_cursor is a fixed version of # pygame.cursors.compile a, b = pygame_compile_cursor() mouse.set_cursor((24, 24), (9, 9), a, b) except: pass return CanvasWidget()
def build(self): EventLoop.ensure_window() if EventLoop.window.__class__.__name__.endswith('Pygame'): try: from pygame import mouse from pygame import cursors a, b = cursors.compile(CURSOR, black='@', white='-') mouse.set_cursor((24, 24), (9, 9), a, b) except ImportError: pass self.canvas_widget = CanvasWidget() self.canvas_widget.set_color(get_color_from_hex('#2980B9')) return self.canvas_widget
def build(self): EventLoop.ensure_window() if EventLoop.window.__class__.__name__.endswith('Pygame'): try: from pygame import mouse a, b = pygame_compile_cursor() mouse.set_cursor((24, 24), (9, 9), a, b) except: pass self.canvas_widget = CanvasWidget() self.canvas_widget.set_color(get_color_from_hex('#2980b9')) return self.canvas_widget
def build(self): EventLoop.ensure_window() if EventLoop.window.__class__.__name__.endswith("Pygame"): try: from pygame import mouse a, b = pygame_compile_cursor() mouse.set_cursor((24, 24), (9, 9), a, b) except: pass self.canvas_widget = CanvasWidget() self.canvas_widget.set_color(get_color_from_hex("#2980b9")) return self.canvas_widget
def menuEnter(): set_cursor(*game.stdCursor) hideGrids() if 'gameOver' in game.sm.flags: game.menu.disable('Resume') game.menu.disable('Save') else: game.menu.enable('Resume') game.menu.enable('Save') if isfile(game.saveFile): game.menu.enable('Load') else: game.menu.disable('Load') game.menu.enter(display.screen)
def set_cursor(self, cursor): """cursor can be either None, image name, Image, Sprite or HWCursor)""" if cursor is None: mouse.set_visible(False) self._sprite = None self._cursor = None elif isinstance(cursor, HWCursor): self._cursor = cursor self._sprite = None mouse.set_cursor(*cursor._data) mouse.set_visible(True) elif isinstance(cursor, Sprite): mouse.set_visible(False) self._sprite = cursor self._cursor = self.sprite else: s = Sprite(cursor) mouse.set_visible(False) self._sprite = s self._cursor = s
def start(self): chdir(DIRNAME) glyph = self.glyph start_editor = self.start_editor editor = None editors = glyph.editors glyph_rect = glyph.rect glyph.input(PAGES['0'], justify = 'justified') glyph.update() SCREEN.blit(BKGSCREEN, (0, 0)) SCREEN.blit(glyph.image, glyph_rect) while 1: link = glyph.get_collisions(mouse.get_pos()) if link: mouse.set_cursor(*HAND_CURSOR) else: mouse.set_cursor(*DEFAULT_CURSOR) for ev in event.get(): if ev.type == MOUSEBUTTONDOWN: if link: if link == 'editor': start_editor() elif link in editors: if editor: editor.redraw() #clear the cursor editor = editors[link] else: glyph.clear(SCREEN, BKGSCREEN) glyph.input(PAGES[link], justify = 'justified') glyph.update() for _editor in glyph.editors.values(): draw.rect(glyph.image, GREEN, _editor.rect.inflate(2, 2), 1) if ev.type == KEYDOWN: if ev.key == K_ESCAPE: exit() elif editor: editor.input(ev) if editor: #if it has editors, glyph must be updated each loop cursor = editor.get_cursor() editor.image.fill((255, 205, 0), cursor) glyph.update() SCREEN.blit(glyph.image, glyph_rect) display.update()
def start(self): chdir(DIRNAME) glyph = self.glyph start_editor = self.start_editor glyph_rect = glyph.rect glyph.input(PAGES['0'], justify = 'justified') glyph.update() SCREEN.blit(BKGSCREEN, (0, 0)) SCREEN.blit(glyph.image, glyph_rect) while 1: link = glyph.get_collisions(mouse.get_pos()) if link: mouse.set_cursor(*HAND_CURSOR) else: mouse.set_cursor(*DEFAULT_CURSOR) for ev in event.get(): if ev.type == MOUSEBUTTONDOWN: if link: if link == 'editor': start_editor() else: glyph.clear(SCREEN, BKGSCREEN) glyph.input(PAGES[link], justify = 'justified') glyph.update() if ev.type == KEYDOWN: exit() SCREEN.blit(glyph.image, glyph_rect) display.update()
def game_intro(): intro = True main_text = pygame.font.Font('data/fonts/coders_crux.ttf', 70) option_text = pygame.font.Font('data/fonts/coders_crux.ttf', 35) start_game_name_surf, start_game_name_rect = create_text( 'START GAME', option_text, black) quit_game_name_surf, quit_game_name_rect = create_text( 'QUIT', option_text, black) while intro: mouse_pos = mouse.get_pos() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() game_name_surf, game_name_text_rect = create_text( 'METHOLKA KINGDOM', main_text, black) game_name_text_rect.center = ((screen_width / 2), (screen_height / 3)) start_game_name_rect.center = ((screen_width / 2), (screen_height / 1.8)) quit_game_name_rect.center = ((screen_width / 2), (screen_height / 1.5)) screen.blit(background_start_menu, (0, 0)) screen.blit(game_name_surf, game_name_text_rect) screen.blit(start_game_name_surf, start_game_name_rect) screen.blit(quit_game_name_surf, quit_game_name_rect) if ((start_game_name_rect.right >= mouse_pos[0] >= start_game_name_rect.left) and (start_game_name_rect.bottom >= mouse_pos[1] >= start_game_name_rect.top)) or ( (quit_game_name_rect.right >= mouse_pos[0] >= quit_game_name_rect.left) and (quit_game_name_rect.bottom >= mouse_pos[1] >= quit_game_name_rect.top)): mouse.set_cursor(*HAND_CURSOR) if event.type == MOUSEBUTTONDOWN: mouse.set_cursor(*DEFAULT_CURSOR) game_loop(player) else: mouse.set_cursor(*DEFAULT_CURSOR) pygame.display.update() clock.tick(FPS)
def wait_cursor(): set_cursor(*pygame.cursors.diamond)
def _on_hover_enter(self) -> None: """Change the mouse cursor when the mouse moves over the animated grid. """ mouse.set_cursor(*BUTTON_CURSOR) self._redraw()
def normal_cursor(): pygame.init()# set_cursor(*pygame.cursors.tri_left)
def pygame_set_cursor(): from pygame import mouse a, b = compile_cursor() mouse.set_cursor((24, 24), (0, 0), a, b)
def setup_cursor(self, event): global current_cursor cursor = self.get_cursor(event) or arrow_cursor if cursor is not current_cursor: set_cursor(*cursor) current_cursor = cursor
def _on_hover_exit(self) -> None: """Reset the mouse cursor when the mouse moves off the animated grid. """ mouse.set_cursor(*cursors.arrow) self._redraw()
def setup_cursor(self, event): cursor = self.get_cursor(event) or arrow_cursor if cursor is not Widget.current_cursor: set_cursor(*cursor) Widget.current_cursor = cursor
if knuckleRatio>1: newMouseModeValue=int(knuckleRatio*mouseModeValue) newClickValue=int(knuckleRatio*clickValue) else: newMouseModeValue=mouseModeValue newClickValue=clickValue #Switching Modes if 10<=dista[0]<=newMouseModeValue and inrange==1: contDist+=1 if contDist>=timeHold and mouse_flg==0 and drag_flg==0: print('Mouse mode activated') mouse_flg=1 contDist=0 mouse.set_cursor(*HAND_CURSOR) if contDist>=timeHold and mouse_flg==1 and drag_flg==0: print('Mouse mode deactivated') mouse_flg=0 contDist=0 mouse.set_cursor(*DEFAULT_CURSOR) #Adjusting MaxBuff with respect to thumbtip and index knuckle if mouse_flg: a=40*newClickValue maxBuff=a/distClick[0] if maxBuff<20: maxBuff=20 elif maxBuff>40: maxBuff=40 #Clicking if distClick[0]<newClickValue and inrange and mouse_flg and not click_flg:
def capture(self): #Initialization of parameters contDist=0 inrange=0 red = (255,0,0,120) green = (0,255,0) blue = (0,0,255) darkBlue = (0,0,128) white = (255,255,255) black = (0,0,0) yellow = (255,255,0) gray= (205,200, 177) rpt=[ [0,0] for i in range(4)] X=0 Y=0 t=[] ir_x=[] ir_y=[] ir_s=[] t_i = time.time() m = PyMouse() k = PyKeyboard() running=False buff=[[],[]] maxBuff=20 buff[0]=q.miniQueue(maxBuff) buff[1]=q.miniQueue(maxBuff) gestures=[[6,2,8,2,8],[9,3,9]] gestures=[ [str(i2) for i2 in i]for i in gestures] #recording flags rec_flg =0 flg=True mouse_flg=0 click_flg=0 doubleClick_flg=0 drag_flg=0 dragX=0 dragY=0 wait_flg=0 timeHold=80 #in milliseconds #calibration mouseModeValue=80 clickValue=80 lagValue=100 calibration=False mouseModeCalib=False startMouseModeCalib=False clickingCalib=False startClickModeCalib=False mouseModeCalibList=[] clickingCalibList=[] rightClickValue=180 #Gesture gestureRightThreshHold=1000 gestureLeftThreshHold=300 gestureDownThreshHold=720 gestureUpThreshHold=400 gesture_flg_UD=0 gesture_flg_DU=0 gesture_flg_LR=0 gesture_flg_RL=0 #Check inrange LED1=[] LED2=[] LED3=[] LED4=[] rptList=[] #Intialization of GUI os.environ['SDL_VIDEO_iWINDOW_POS'] = "%d,%d" % (0,0) pygame.init() myfont=pygame.font.SysFont("monospace",15) calibFont=pygame.font.SysFont(",monospace",20) #the default cursor DEFAULT_CURSOR = mouse.get_cursor() #the hand cursor _HAND_CURSOR = ( " XX ", " X..X ", " X..X ", " X..X ", " X..XXXXX ", " X..X..X.XX ", " XX X..X..X.X.X ", "X..XX.........X ", "X...X.........X ", " X.....X.X.X..X ", " X....X.X.X..X ", " X....X.X.X.X ", " X...X.X.X.X ", " X.......X ", " X....X.X ", " XXXXX XX ") _HCURS, _HMASK = pygame.cursors.compile(_HAND_CURSOR, ".", "X") HAND_CURSOR = ((16, 16), (5, 1), _HCURS, _HMASK) infoObject = pygame.display.Info() width=infoObject.current_w height=infoObject.current_h screen=pygame.display.set_mode((width/2,height/2)) #screen=pygame.display.set_mode((1200/3,760/3)) print('press "c" to calibrate, then') print('press "r" to start recording') while flg==True: if calibration: #do calibration newList=self.findDegrees(rpt) #[(theta1,i1),(theta2,i2)....)] tipIndex, tipIndexAngle, kIndex,kIndexAngle=self.indexData(newList) tipThumb,tipThumbAngle,kThumb,kThumbAngle=self.thumbData(newList) averageX,averageY=self.centerFind(rpt) #GUI section screen.fill(black) #Drawing the Circles pygame.draw.circle(screen, yellow, (rpt[tipIndex][0]/3,rpt[tipIndex][1]/3),10) pygame.draw.circle(screen, red, (rpt[kIndex][0]/3,rpt[kIndex][1]/3),10) pygame.draw.circle(screen, green, (rpt[tipThumb][0]/3,rpt[tipThumb][1]/3),10) pygame.draw.circle(screen, blue, (rpt[kThumb][0]/3,rpt[kThumb][1]/3),10) pygame.draw.circle(screen, white, (averageX/3,averageY/3),10) mouseModeDistance=fun.distanceVec(\ [rpt[tipIndex][0]],\ [rpt[tipIndex][1]],\ [rpt[tipThumb][0]],\ [rpt[tipThumb][1]]) clickingDistance=fun.distanceVec(\ [rpt[kIndex][0]],\ [rpt[kIndex][1]],\ [rpt[tipThumb][0]],\ [rpt[tipThumb][1]]) pygame.draw.rect(screen, gray, (0,5,500,60)) if not (mouseModeCalib or startClickModeCalib or startMouseModeCalib or clickingCalib): Calib1=calibFont.render("Press H to start",1,black) screen.blit(Calib1,(0,15)) if startMouseModeCalib and not mouseModeCalib: Calib1=calibFont.render("Tap tip of thumb and tip of index",1,black) screen.blit(Calib1,(0,15)) Calib2=calibFont.render("Press H to complete",1,black) screen.blit(Calib2,(0,35)) pygame.draw.line(screen,white,(rpt[tipThumb][0]/3,rpt[tipThumb][1]/3),(rpt[tipIndex][0]/3,rpt[tipIndex][1]/3),5 ) mouseModeCalibList.append(mouseModeDistance[0]) if startClickModeCalib and not clickingCalib: Calib1=calibFont.render("Tap tip of thumb and knuckle of index",1,black) screen.blit(Calib1,(0,15)) Calib2=calibFont.render("Press H to complete",1,black) screen.blit(Calib2,(0,35)) pygame.draw.line(screen,white,(rpt[tipThumb][0]/3,rpt[tipThumb][1]/3),(rpt[kIndex][0]/3,rpt[kIndex][1]/3),5 ) clickingCalibList.append(clickingDistance[0]) if mouseModeCalib and clickingCalib: calibrationDone=1 Calib1=calibFont.render("Calibration Completed",1,black) screen.blit(Calib1,(0,15)) Calib2=calibFont.render("Press r to start recording",1,black) screen.blit(Calib2,(0,35)) #Recording if rec_flg==1: newList=self.findDegrees(rpt) #[(theta1,i1),(theta2,i2)....)] tipIndex, tipIndexAngle, kIndex,kIndexAngle=self.indexData(newList) tipThumb,tipThumbAngle,kThumb,kThumbAngle=self.thumbData(newList) averageX,averageY=self.centerFind(rpt) #GUI section screen.fill(black) #Drawing the Circles pygame.draw.circle(screen, yellow, (rpt[tipIndex][0]/3,rpt[tipIndex][1]/3),10) pygame.draw.circle(screen, red, (rpt[kIndex][0]/3,rpt[kIndex][1]/3),10) pygame.draw.circle(screen, green, (rpt[tipThumb][0]/3,rpt[tipThumb][1]/3),10) pygame.draw.circle(screen, blue, (rpt[kThumb][0]/3,rpt[kThumb][1]/3),10) pygame.draw.circle(screen, white, (averageX/3,averageY/3),10) #Drawing the Information Text ITLabel=myfont.render( "IndexTip"+" "+str(tipIndexAngle),1,(25,255,255)) screen.blit(ITLabel,(rpt[tipIndex][0]/3,rpt[tipIndex][1]/3)) IKLabel=myfont.render( "IndexKnuck"+" "+str(kIndexAngle) ,1,(255,255,255)) screen.blit(IKLabel,(rpt[kIndex][0]/3,rpt[kIndex][1]/3)) TTLabel=myfont.render( "ThumbTip"+" "+str(tipThumbAngle) ,1,(255,255,255)) screen.blit(TTLabel,(rpt[tipThumb][0]/3,rpt[tipThumb][1]/3)) TKLabel=myfont.render( "ThumbKnuck"+" "+str(kThumbAngle) ,1,(255,255,255)) screen.blit(TKLabel,(rpt[kThumb][0]/3,rpt[kThumb][1]/3)) speedLabel=myfont.render("Increase:z, Decrease:x",1,(255,255,255)) screen.blit(speedLabel,(0,65)) mouseLabel=myfont.render("Mouse:"+" "+str(mouseModeValue) ,1,(255,255,255)) screen.blit(mouseLabel,(0,80)) clickLabel=myfont.render("Click:"+" "+str(clickValue) ,1,(255,255,255)) screen.blit(clickLabel,(0,95)) #Mouse Events #Drawing the mode if mouse_flg: MouseKeyboard=myfont.render( "Mouse mode",1,(255,255,255)) else: MouseKeyboard=myfont.render( "Keyboard mode",1,(255,255,255)) screen.blit(MouseKeyboard,(0,50)) #Distance for switching modes dista=fun.distanceVec(\ [rpt[tipIndex][0]],\ [rpt[tipIndex][1]],\ [rpt[tipThumb][0]],\ [rpt[tipThumb][1]]) #Distance for clicking - thumb tip to index knuckle distClick=fun.distanceVec(\ [rpt[kIndex][0]],\ [rpt[kIndex][1]],\ [rpt[tipThumb][0]],\ [rpt[tipThumb][1]]) #Switching Modes if 10<=dista[0]<=mouseModeValue and inrange==1: contDist+=1 if contDist>=timeHold and mouse_flg==0 and drag_flg==0: print('Mouse mode activated') mouse_flg=1 contDist=0 mouse.set_cursor(*HAND_CURSOR) if contDist>=timeHold and mouse_flg==1 and drag_flg==0: print('Mouse mode deactivated') mouse_flg=0 contDist=0 mouse.set_cursor(*DEFAULT_CURSOR) #Adjusting MaxBuff with respect to thumbtip and index knuckle if mouse_flg: a=40*clickValue maxBuff=a/distClick[0] if maxBuff<20: maxBuff=20 elif maxBuff>40: maxBuff=40 #Clicking if distClick[0]<clickValue and inrange and mouse_flg and not click_flg: click_flg=1 stime=time.time() m.click(buff[0].mean(),buff[1].mean()) dragX, dragY=buff[0].mean(),buff[1].mean() print('Click') print distClick[0] if (click_flg and (time.time()-stime)*1000>=lagValue and not drag_flg): #so its been 1/2 second, if (distClick[0]>=clickValue): #if finger is up, then delete flag. Else click_flg=0 drag_flg=0 print("reset") print distClick[0] elif ((dragX-buff[0].mean()>5) or (dragY-buff[1].mean()>5)): #Drag situation m.press(dragX,dragY) drag_flg=1 print ("dragging") print distClick[0] if drag_flg and distClick[0]>=int(1.2*clickValue): #released the drag drag_flg=0 m.release(buff[0].mean(),buff[1].mean()) dragX,dragY=0,0 print("release drag") print distClick[0] #right click needs improvement #tried using the thumb #if mouse_flg and rightClick[0]>rightClickValue: # m.click(buff[0].mean(),buff[1].mean(),2) #Gestures #The gesture bounds # pygame.draw.line(screen,white, (gestureRightThreshHold/3,0),(gestureRightThreshHold/3,800)) # pygame.draw.line(screen,red, (gestureLeftThreshHold/3,0),(gestureLeftThreshHold/3,800)) # pygame.draw.line(screen,blue, (0,gestureDownThreshHold/3),(10000,gestureDownThreshHold/3)) # pygame.draw.line(screen,yellow, (0,gestureUpThreshHold/3),(10000,gestureUpThreshHold/3)) #Swipe Right to Left if self.allAboveGestureRight(rpt,gestureRightThreshHold) and not gesture_flg_RL: gestureTime=time.time() gesture_flg_RL=1 print("ready to gesture") if gesture_flg_RL and (time.time()-gestureTime)<1: if self.allAboveGestureLeft(rpt, gestureLeftThreshHold): k.press_key(k.control_key) k.press_key(k.alt_key) k.press_key(k.left_key) k.release_key(k.control_key) k.release_key(k.alt_key) k.release_key(k.left_key) gesture_flg_RL=0 #Swipe Left to Right if self.allAboveGestureLeft(rpt,gestureLeftThreshHold) and not gesture_flg_LR: gestureTime=time.time() gesture_flg_LR=1 print("ready to gesture") if gesture_flg_LR and (time.time()-gestureTime)<1: if self.allAboveGestureRight(rpt, gestureRightThreshHold): k.press_key(k.control_key) k.press_key(k.alt_key) k.press_key(k.right_key) k.release_key(k.control_key) k.release_key(k.alt_key) k.release_key(k.right_key) gesture_flg_LR=0 #Swipe Down to Up if self.allAboveGestureDown(rpt,gestureDownThreshHold) and not gesture_flg_DU: gestureTime=time.time() gesture_flg_DU=1 print("ready to gesture") if gesture_flg_DU and (time.time()-gestureTime)<1: if self.allAboveGestureUp(rpt, gestureUpThreshHold): k.press_key(k.control_key) k.press_key(k.alt_key) k.press_key(k.up_key) k.release_key(k.control_key) k.release_key(k.alt_key) k.release_key(k.up_key) gesture_flg_DU=0 #Swipe Up to Down if self.allAboveGestureUp(rpt,gestureUpThreshHold) and not gesture_flg_UD: gestureTime=time.time() gesture_flg_UD=1 print("ready to gesture") if gesture_flg_UD and (time.time()-gestureTime)<1: if self.allAboveGestureDown(rpt, gestureDownThreshHold): k.press_key(k.control_key) k.press_key(k.alt_key) k.press_key(k.down_key) k.release_key(k.control_key) k.release_key(k.alt_key) k.release_key(k.down_key) gesture_flg_UD=0 if gesture_flg_RL and (time.time()-gestureTime)>=1: gesture_flg_RL=0 if gesture_flg_LR and (time.time()-gestureTime)>=1: gesture_flg_LR=0 if gesture_flg_UD and (time.time()-gestureTime)>=1: gesture_flg_UD=0 if gesture_flg_DU and (time.time()-gestureTime)>=1: gesture_flg_DU=0 #Capturing keyboard events for event in pygame.event.get(): if event.type==KEYDOWN: if event.key==pygame.K_r: #start recording rec_flg=1 calibration=False elif event.key==pygame.K_c: #start calibration calibration=1 elif event.key==pygame.K_s: #pauses the recording rec_flg=False break elif event.key==pygame.K_q: #quits entirely flg=False break if rec_flg: #if recording, can change the lag time if event.key==pygame.K_z: lagValue+=100 elif event.key==pygame.K_x: lagValue-=100 #Mouse events for calibration mode if calibration: if not mouseModeCalib: if not startMouseModeCalib and event.key==pygame.K_h: startMouseModeCalib=True elif startMouseModeCalib and event.key==pygame.K_h: mouseModeCalib=True while min(mouseModeCalibList)<50: mouseModeCalibList.remove(min(mouseModeCalibList)) mouseModeValue=int(1.2*min(mouseModeCalibList)) mouseModeCalib=True if mouseModeCalib: if not startClickModeCalib and event.key==pygame.K_h: startClickModeCalib=True elif startClickModeCalib and event.key==pygame.K_h: while min(clickingCalibList)<30: clickingCalibList.remove(min(clickingCalibList)) clickValue=int(1.2*min(clickingCalibList)) clickingCalib=True if event.type==QUIT: flg=False pygame.quit() break #Capturing wii data messages = self.wii.get_mesg() for mesg in messages: # Loop through Wiimote Messages if mesg[0] == cwiid.MESG_IR: # If message is IR data #while recording data if rec_flg == 1 or calibration: # If recording cont=-1 for s in mesg[1]: # Loop through IR LED sources cont+=1 if s: # If a source exists t.append(time.time()-t_i) rpt[cont][0]=(1200-s['pos'][0]) rpt[cont][1]=s['pos'][1] #Check inrange newRpt=copy.deepcopy(rpt) rptList.append(newRpt) inrange, LED1,LED2,LED3,LED4=self.rangeChecker(rptList, LED1, LED2,LED3,LED4) #while in mouse mode if mouse_flg==1: X=rpt[tipIndex][0] mouseX=(X-600)*width/400 Y=rpt[tipIndex][1] mouseY=(Y-150)*height/290 """Currently we have the setting such that if there is a single LED that is out of range then the mouse wont move. The problem with this is that the range of the mouse gets limited, and some places (such as corners) are difficult/impossible to click. If we eliminate the if statement then this problem won't exist, but then it may start to recognize the knuckle LED as the tip and vice versa. So this is a give or take until we have a better filtering method.""" if inrange: buff[0].put(mouseX) buff[1].put(mouseY) smoothX=np.mean(fun.smooth(buff[0].data, window_len=len(buff[0].data))) smoothY=np.mean(fun.smooth(buff[1].data, window_len=len(buff[1].data))) m.move(smoothX,smoothY) #I can also control using the wiimote elif mesg[0] == cwiid.MESG_BTN: # If Message is Button data if mesg[1] & cwiid.BTN_PLUS: # Start Recording rec_flg = 1 print "Recording..." elif mesg[1] & cwiid.BTN_MINUS: # Stop Recording flg=False break pygame.display.update() pygame.quit()