示例#1
0
 def do_gesture_recognition(self, gesture_hand, mouse_hand):
     if len(gesture_hand.fingers.extended()
            ) == 5:  #Five open fingers on gesture hand (swipe mode)
         self.gesture_debouncer.signal(
             5)  #Tell the debouncer we've seen this gesture
     elif len(
             gesture_hand.fingers.extended()
     ) == 4 and self.gesture_debouncer.state != 7:  #Three open fingers on gesture hand (scroll mode)
         self.gesture_debouncer.signal(4)
     elif len(gesture_hand.fingers.extended()
              ) == 3:  #Three open fingers on gesture hand (scroll mode)
         self.gesture_debouncer.signal(3)
     elif len(
             gesture_hand.fingers.extended()
     ) == 2 and self.gesture_debouncer.state != 6:  #Two open fingers on gesture hand (right click)
         self.gesture_debouncer.signal(2)
     elif len(gesture_hand.fingers.extended()
              ) == 1:  #One open finger on gesture hand (click down)
         self.gesture_debouncer.signal(1)
     elif len(gesture_hand.fingers.extended()
              ) == 0:  #No open fingers (click up/no action)
         self.gesture_debouncer.signal(0)
     #Now that we've told the debouncer what we *think* the current gesture is, we must act
     #On what the debouncer thinks the gesture is^%{DOWN}
     if self.gesture_debouncer.state == 5:  #Swipe mode
         for gesture in frame.gestures():
             if gesture.type is Leap.Gesture.TYPE_SWIPE:
                 swipe = Leap.SwipeGesture(gesture)
                 if swipe.start_position.x < swipe.position.x:
                     SendKeys.SendKeys("^${RIGHT}")
                 else:
                     SendKeys.SendKeys("^${LEFT}")
     elif self.gesture_debouncer.state == 4:  #Right click
         SendKeys.SendKeys("%{TABS}")
         self.gesture_debouncer.signal(
             7)  #Dummy class so it doesn't right click again
     elif self.gesture_debouncer.state == 3:  #Scroll mode
         y_scroll_amount = self.velocity_to_scroll_amount(
             mouse_hand.palm_velocity.y)  #Mouse hand controls scroll amount
         x_scroll_amount = self.velocity_to_scroll_amount(
             mouse_hand.palm_velocity.x)
         self.cursor.scroll(x_scroll_amount, y_scroll_amount)
     elif self.gesture_debouncer.state == 2:  #Right click
         if self.cursor.left_button_pressed:
             self.cursor.click_up(
             )  #You can't left and right click at the same time
         self.cursor.rightClick()  #Right click
         self.gesture_debouncer.signal(
             6)  #Dummy class so it doesn't right click again
     elif self.gesture_debouncer.state == 1:  #Click/drag mode
         if not self.cursor.left_button_pressed:
             self.cursor.click_down()  #Click down (if needed)
         self.do_mouse_stuff(mouse_hand)  #We may want to click and drag
     elif self.gesture_debouncer.state == 0:  #Move cursor mode
         if self.cursor.left_button_pressed:
             self.cursor.click_up()  #Click up (if needed)
         self.do_mouse_stuff(mouse_hand)
示例#2
0
    def watch_params_in_gesture(self, gesture):
        if len(gesture.hands) > 0:  #FIX hands ?
            gesture_params = {}
            if gesture.type == 1:
                gesture = Leap.SwipeGesture(gesture)

                gesture.direction_name = self.get_direction_name(
                    gesture.direction)

                gesture.current_position_name = self.get_position_name(
                    gesture.hands[0].palm_position)
                gesture.start_position_name = self.get_position_name(
                    gesture.start_position)

                watched_params = GLOBALS['WATCHED_PARAMS_IN_SWIPE']
            if gesture.type == 4:
                gesture = Leap.CircleGesture(gesture)
                if gesture.pointable.direction.angle_to(
                        gesture.normal) <= Leap.PI / 2:
                    gesture.clockwiseness = "clockwise"
                else:
                    gesture.clockwiseness = "counterclockwise"

                gesture.position_name = self.get_position_name(gesture.center)

                watched_params = GLOBALS['WATCHED_PARAMS_IN_CIRCLE']
            if gesture.type == 5:
                gesture.activated = True
                watched_params = GLOBALS['WATCHED_PARAMS_IN_SCREEN_TAP']
            if gesture.type == 6:
                gesture.activated = True
                watched_params = GLOBALS['WATCHED_PARAMS_IN_KEY_TAP']

            for path, api in watched_params.items():
                try:
                    gesture_params[path] = eval('gesture.' + api)
                except:
                    print "%s\t%s not found. Valid api ?" % (path, api)

            if gesture.type == 1:
                self.actor.on_swipe(gesture_params)
            if gesture.type == 4:
                self.actor.on_circle(gesture_params)
            if gesture.type == 5:
                self.actor.on_screen_tap(gesture_params)
            if gesture.type == 6:
                self.actor.on_key_tap(gesture_params)
示例#3
0
    def watch_params_in_gesture(self, gesture):
        if len(gesture.hands) > 0:  #FIX hands ?
            gesture_params = {}
            if gesture.type == 1:
                gesture = Leap.SwipeGesture(gesture)
                d = gesture.direction
                gesture.direction_name = 'not sure'
                if d.x > 0.7: gesture.direction_name = 'right'
                if d.x <= -0.7: gesture.direction_name = 'left'
                if d.y > 0.7: gesture.direction_name = 'top'
                if d.y <= -0.7: gesture.direction_name = 'bottom'
                if d.z > 0.7: gesture.direction_name = 'back'
                if d.z <= -0.7: gesture.direction_name = 'front'

                if circle.pointable.direction.angle_to(
                        circle.normal) <= Leap.PI / 2:
                    gesture.clockwiseness = "clockwise"
                else:
                    gesture.clockwiseness = "counterclockwise"

                watched_params = WATCHED_PARAMS_IN_SWIPE
            if gesture.type == 4:
                gesture = Leap.CircleGesture(gesture)
                watched_params = WATCHED_PARAMS_IN_CIRCLE
            if gesture.type == 5:
                gesture.activated = True
                watched_params = WATCHED_PARAMS_IN_SCREEN_TAP
            if gesture.type == 6:
                gesture.activated = True
                watched_params = WATCHED_PARAMS_IN_KEY_TAP

            for path, api in watched_params.items():
                try:
                    gesture_params[path] = eval('gesture.' + api)
                except:
                    print "%s\t%s not found. Valid api ?" % (path, api)
            self.sender.send_gesture(gesture_params)