Example #1
1
 def on_touch_up(self, touch):
     self.points += [touch.pos]
     gesture = Gesture()
     gesture.add_stroke(self.points)
     gesture.normalize()
     gdb = GestureDatabase()
     print "Gesture:", gdb.gesture_to_str(gesture)
Example #2
0
    def on_touch_up(self,touch):
        id = touch.id
        if id in self.touches2.keys() and len(self.touches2) == 2: 
            #still one more touch on bar
            #does the user want to translate the bar to the right or the left ?
            origin = self.touches2[id]#.pos
            current = touch.pos
            dist = Vector(origin).distance( Vector(current) )
            #print len(self.touches2), self.touches2[id], touch.pos, dist  

            #if touch.id in self.touches2.keys() :
            if dist >= self.bar_translation_min_distance : 
                  # try to find a gesture 
                  g = Gesture()
                  g.add_stroke(point_list=[origin,current])
                  g.normalize()
                  gest = self.gdb.find(g)
                  try : 
                    if gest[0] > 0.95 : #gesture found
                        if len(self.touches2) == 2: #no touch left on bar 
                            d = current[0] - origin[0]
                            if d > 0:
                                self.move_bar_to_right()
                            else : 
                                self.move_bar_to_left()              
                  except : 
                    self.move_back()

            else : self.move_back()

        if id in self.touches2.keys():
                del self.touches2[id]
        if len(self.touches2) <= 0 :
                self.set_texture('style/bar/slider-fond.png')      
        return super(AppView, self).on_touch_up(touch) 
Example #3
0
 def create_gesture(self,point_list):
     # Create a gesture
     g = Gesture()
     g.add_stroke(point_list)
     g.normalize()
     # Add it to database
     self.gdb.add_gesture(g)
Example #4
0
    def on_touch_up(self, touch):
        '''(internal) When the touch up occurs, we have to decide if a gesture
        was attempted. If so, we fire the on_gesture event. In all other cases
        we propogate the change to child widget.'''
        if self._get_uid('cavoid') in touch.ud:
            return
        if self in [x() for x in touch.grab_list]:
            touch.ungrab(self)
            self._touch = None
            ud = touch.ud[self._get_uid()]
            if ud['mode'] == 'unknown':
                Clock.unschedule(self._change_touch_mode)
                super(GestureBox, self).on_touch_down(touch)
                Clock.schedule_once(partial(self._do_touch_up, touch), .1)
            else:
                # A gesture was attempted. Did it match?
                gesture = Gesture()
                gesture.add_stroke(
                    zip(touch.ud['gesture_line'].points[::2],
                        touch.ud['gesture_line'].points[1::2]))
                gesture.normalize()
                match = self.gestures.find(gesture, minscore=0.70)
                if match:
                    self.dispatch('on_gesture', match[1].name)
                else:
                    # The gesture wasn't recognized; invoke a normal reaction
                    super(GestureBox, self).on_touch_down(touch)
                    Clock.schedule_once(partial(self._do_touch_up, touch), .1)

                return True

        else:
            if self._touch is not touch and self.uid not in touch.ud:
                super(GestureBox, self).on_touch_up(touch)
        return self._get_uid() in touch.ud
 def on_touch_up(self, touch):
     if 'gesture_path' in touch.ud:
         gesture = Gesture() # <1>
         gesture.add_stroke(touch.ud['gesture_path'])  # <2>
         gesture.normalize()  # <3>
         match = gestures.find(gesture, minscore=0.90)  # <4>
         if match:
             print("{} happened".format(match[1].name))  # <5>
     super(GestureBox, self).on_touch_up(touch)
Example #6
0
 def on_touch_up(self, touch):
     if 'gesture_path' in touch.ud:
         gesture = Gesture()
         gesture.add_stroke(touch.ud['gesture_path'])
         gesture.normalize()
         match = gestures.find(gesture, minscore=0.90)
         # BEGIN FIRE
         if match:
             self.dispatch('on_{}'.format(match[1].name))
         # END FIRE
     super(GestureBox, self).on_touch_up(touch)
    def on_touch_up(self, touch):
        if 'gesture_path' in touch.ud:
            gesture = Gesture()
            gesture.add_stroke(touch.ud['gesture_path'])
            gesture.normalize()
            # match = (score, gesture)
            match = gestures.find(gesture, minscore=0.80)
            if match:
                gesture_name = match[1].name
                self.dispatch('on_{}'.format(gesture_name))

        super(GestureBox, self).on_touch_up(touch)
Example #8
0
	def on_touch_up(self, touch):
		if 'gesture_path' in touch.ud:
			gesture = Gesture()
			gesture.add_stroke(touch.ud['gesture_path'])
			gesture.normalize()
			match = gestures.find(gesture, minscore=0.70)
			if match:
				print("{} gesture occured".format(match[1].name))
			else:
				print("No gesture recognized")
			
				
		super(DictScreen, self).on_touch_up(touch)
Example #9
0
def simplegesture(name, point_list):
    """
    A simple helper function
    Taken from original Kivy examples
    """
    g = Gesture()
    if PY2:
        g.add_stroke(point_list)
    else:
        g.add_stroke(list(point_list))
    g.normalize()
    g.name = name
    return g
Example #10
0
 def simplegesture(self, name, point_list):
     # Pomocná funkce pro rozpoznávání gesta
     g = Gesture()
     g.add_stroke(point_list)
     g.normalize()
     g.name = name
     return g
Example #11
0
 def on_touch_up(self, touch):
     try:
         touch.ud['line'].points = []
     except:
         pass
     if 'gesture_path' in touch.ud:
         #create a gesture object
         gesture = Gesture()    
         #add the movement coordinates 
         gesture.add_stroke(touch.ud['gesture_path'])
         #normalize so thwu willtolerate size variations
         gesture.normalize()
         #minscore to be attained for a match to be true
         match = gestures.find(gesture, minscore=0.8)
         if match:
             print("{} happened".format(match[1].name))
             self.dispatch('on_{}'.format(match[1].name))
     super(GestureBox, self).on_touch_up(touch)
Example #12
0
def simplegesture(name, point_list):
    """
    A simple helper function
    """
    g = Gesture()
    g.add_stroke(point_list)
    g.normalize()
    g.name = name
    return g
Example #13
0
def simplegesture(uName: str, point_list) -> Gesture:
    """
    A simple helper function
    Taken from original Kivy examples
    """
    g = Gesture()
    g.add_stroke(list(point_list))
    g.normalize()
    g.name = uName
    return g
 def add_gesture(self, name, gesture_path):
     gesture = Gesture()
     gesture.add_stroke(gesture_path)
     gesture.normalize()
     if name in self.str_gestures:
         raise ValueError('Cannot overwrite existing gesture in file.')
     gesture.name = name
     self.str_gestures[name] = self.db.gesture_to_str(gesture).decode(
         'utf-8')
     self.db.add_gesture(gesture)
Example #15
0
 def simplegesture(self, name, point_list):
     # Pomocná funkce pro rozpoznávání gesta
     g = Gesture()
     g.add_stroke(point_list)
     g.normalize()
     g.name = name
     return g
Example #16
0
 def on_touch_up(self, touch):
     self.points += [touch.pos]
     gesture = Gesture()
     gesture.add_stroke(self.points)
     gesture.normalize()
     gdb = GestureDatabase()
     print("Gesture:", gdb.gesture_to_str(gesture).decode(encoding='UTF-8'))
Example #17
0
 def on_touch_up(self,touch):
     self.points+=[touch.pos]
     with self.canvas:
         Ellipse(pos=(touch.x-5,touch.y-5),size=(10,10))
     gesture=Gesture()
     gesture.add_stroke(self.points)
     gesture.normalize()
     gdb=GestureDatabase()
def simplegesture(name, point_list):
    """
    A simple helper function
    """
    g = Gesture()
    g.add_stroke(point_list)
    g.normalize()
    g.name = name
    return g
Example #19
0
 def on_touch_up(self, touch):
     if 'gesture_path' in touch.ud:
         gesture = Gesture()  # <1>
         gesture.add_stroke(touch.ud['gesture_path'])  # <2>
         gesture.normalize()  # <3>
         match = gestures.find(gesture, minscore=0.90)  # <4>
         if match:
             print("{} happened".format(match[1].name))  # <5>
     super(GestureBox, self).on_touch_up(touch)
Example #20
0
 def on_touch_up(self, touch):
     if "gesture_path" in touch.ud:
         gesture = Gesture()
         gesture.add_stroke(touch.ud["gesture_path"])
         gesture.normalize()
         match = gestures.find(gesture, minscore=0.90)
         if match:
             self.dispatch("on_{}".format(match[1].name))
     super(GestureBox, self).on_touch_up(touch)
Example #21
0
 def on_touch_up(self, touch):
     if 'gesture_path' in touch.ud:
         gesture = Gesture()
         gesture.add_stroke(touch.ud['gesture_path'])
         gesture.normalize()
         match = gestures.find(gesture, minscore=0.6666660)
         if match:
             print("{} happened".format(match[1].name))
     super(GestureBox, self).on_touch_up(touch)
Example #22
0
def simplegesture(name, point_list):
    '''
    A simple helper function
    Taken from original Kivy examples
    '''
    g = Gesture()
    g.add_stroke(point_list)
    g.normalize()
    g.name = name
    return g
Example #23
0
 def on_touch_up(self, touch):
     if 'gesture_path' in touch.ud:
         gesture = Gesture()
         gesture.add_stroke(touch.ud['gesture_path'])
         gesture.normalize()
         match = gesture_db.find(gesture, minscore=0.7)
         if match:
             print(f'on_{match[1].name}')
             self.dispatch(f'on_{match[1].name}')
     super(MyScreenManager, self).on_touch_up(touch)
Example #24
0
 def on_touch_up(self, touch):
     # print(touch.ud['gesture_path'])
     if 'gesture_path' in touch.ud:
         gesture = Gesture()
         gesture.add_stroke(touch.ud['gesture_path'])
         gesture.normalize()
         match = gestures.find(gesture, minscore=0.9)
         if match:
             print('ha ha:', match[1].name)
     super().on_touch_up(touch)
Example #25
0
 def on_touch_up(self, touch):
     if 'gesture_path' in touch.ud:
         gesture = Gesture()
         gesture.add_stroke(touch.ud['gesture_path'])
         gesture.normalize()
         match = gestures.find(gesture, minscore=0.90)
         # BEGIN FIRE
         if match:
             self.dispatch('on_{}'.format(match[1].name))
         # END FIRE
     super(GestureBox, self).on_touch_up(touch)
Example #26
0
 def on_touch_up(self, touch):
     if 'gesture_path' in touch.ud:
         # create a gesture object
         gesture = Gesture()
         # add the movement coordinates
         gesture.add_stroke(touch.ud['gesture_path'])
         # normalize so thwu willtolerate size variations
         gesture.normalize()
         # minscore to be attained for a match to be true, default 0.3
         g2 = self.gdb.find(gesture, minscore=0.70)
         if g2:
             print 'swipe left'
Example #27
0
    def on_touch_up(self, touch):
        if 'gesture_path' in touch.ud:
            gesture = Gesture()
            gesture.add_stroke(touch.ud['gesture_path'])
            gesture.normalize()
            match = gestures.find(gesture, minscore=0.70)
            if match:
                print("{} gesture occured".format(match[1].name))
            else:
                print("No gesture recognized")

        super(DictScreen, self).on_touch_up(touch)
Example #28
0
 def on_touch_up(self, touch):
     app = App.get_running_app()
     if app.controls == 'button':
         pass
     else:
         if 'gesture_path' in touch.ud:
             gesture = Gesture()
             gesture.add_stroke(touch.ud['gesture_path'])
             gesture.normalize()
             match = gestures.find(gesture, minscore=0.60)
             if match:
                 self.dispatch('on_{}'.format(match[1].name))
         super(Game, self).on_touch_up(touch)
Example #29
0
    def on_touch_up(self, touch):
        super(Box, self).on_touch_up(touch)
        if touch.grab_current is self:
            gesture = Gesture()
            gesture.add_stroke(touch.ud['data points'])
            gesture.normalize()

            match = self.gdb.find(gesture, minscore=0.8)
            if match:
                # print(match[0])
                self.dispatch('on_top_to_button')

            touch.ungrab(self)
 def on_touch_up(self, touch):
     if 'gesture_path' in touch.ud:
         #create a gesture object
         gesture = Gesture()
         #add the movement coordinates
         gesture.add_stroke(touch.ud['gesture_path'])
         #normalize so thwu willtolerate size variations
         gesture.normalize()
         #minscore to be attained for a match to be true
         match = gestures.find(gesture, minscore=0.3)
         if match:
             print("{} happened".format(match[1].name))
             self.dispatch('on_{}'.format(match[1].name))
     super(GestureBox, self).on_touch_up(touch)
Example #31
0
 def on_touch_up(self, touch):
     # 判断是否匹配
     if 'gesture_path' in touch.ud:
         # 创建一个手势
         gesture = Gesture()
         # 添加移动坐标
         gesture.add_stroke(touch.ud['gesture_path'])
         # 标准化大小
         gesture.normalize()
         # 匹配手势,minscore:手势灵敏度
         match = gestures.find(gesture, minscore=0.5)
         if match:
             print("{} happened".format(match[1].name))
             self.dispatch('on_{}'.format(match[1].name))
     super(GestureBox, self).on_touch_up(touch)
Example #32
0
    def on_touch_up(self, touch):
        g = Gesture()
        g.add_stroke(list(zip(
            touch.ud['line'].points[::2],
            touch.ud['line'].points[1::2]
        )))
        g.normalize()
        g.name = ''

        g2 = self.gdb.find(g, minscore=0.70)
        if g2 and g2[1] == self.left_to_right_gesture:
            self.switch_to_left()
        elif g2 and g2[1] == self.right_to_left_gesture:
            self.switch_to_right()

        return super(TabPannel, self).on_touch_up(touch)
Example #33
0
def check_gesture(points, gdb) -> int or None:
    g = Gesture()

    # convert raw DrawPad output to gesture compatible list
    point_list = list(zip(points[0::2], points[1::2]))
    g.add_stroke(point_list)
    g.normalize()

    # check if new gesture matches a known gesture
    g2 = gdb.find(g, minscore=0.70)

    if g2:
        if g2[1] == cun_1:
            return 1
        if g2[1] == cun_10:
            return 10

    return None
Example #34
0
    def on_touch_up(self, touch):
        # Touch is over
        ret = False
        if touch.grab_current is self:

            # Add gesture to database
            try:
                g = Gesture()
                g.add_stroke(
                    list(
                        zip(touch.ud['line'].points[::2],
                            touch.ud['line'].points[1::2])))
                g.normalize()
                g.name = 'try'

                # Delete trace line
                self.canvas.remove_group(touch.ud['group'])

                # Compare gesture to my_gestures.py
                #print("gesture representation:", self.gdb.gesture_to_str(g))
                #print("check:", g.get_score(check))

                # use database to find the more alike gesture, if any
                g2 = self.gdb.find(g, minscore=0.90)

                #print(g2)
                if g2 and g2[1] == check:
                    self.manager.app.open_settings()

                ret = True

            except KeyError:
                ret = super(LockScreen, self).on_touch_up(touch)

            touch.ungrab(self)

        return ret
Example #35
0
    def on_touch_up(self,touch,*args):
        """
        adds the final point to the list and converts it to a gesture
        then finds the gesturen in the database(gdb). If gesture is found,
        depending on the lane, the vehicles on that lane respond to the 
        gesture
        """

        self.gpoints.append(touch.pos)
        if (
            (self.gpoints[-1][0])-(self.gpoints[0][0])==0 
            and 
            (self.gpoints[-1][1])-(self.gpoints[0][1])==0
            ):
            for child in self.children:
                if child.set == True and child.is_moving:
                    child.speed = 0
                    child.set = False
                    self.stop_sound.play()
                elif child.set ==True and not child.is_moving:
                    child.speed = self.default_speed
                    child.set = False

        gesture = Gesture()
        gesture.add_stroke(point_list=self.gpoints)
        gesture.normalize()
        match = gdb.find(gesture, minscore=0.5)
        if match:
            for child in self.children:
                if child.come_from == "lvl" and child.set and match[1].name=="swipe_up":
                    child.speed = 0
                    self.stop_sound.play()
                    child.set = False
                elif child.come_from == "lvl" and child.set and match[1].name=="swipe_down":
                    child.speed = self.running_speed
                    self.speed_sound.play()
                    child.set = False
                    
                elif child.come_from == "rvl" and child.set and match[1].name == "swipe_up":
                    child.speed = self.running_speed
                    self.speed_sound.play()
                    child.set = False
                elif child.come_from == "rvl" and child.set and match[1].name=="swipe_down":
                    child.speed = 0
                    self.stop_sound.play()
                    child.set = False
                    
                elif child.come_from == "lhl" and child.set and match[1].name=="swipe_left":
                    child.speed = self.running_speed
                    self.speed_sound.play()
                    child.set = False
                elif child.come_from == "lhl" and child.set and match[1].name == "swipe_right":
                    child.speed = 0
                    self.stop_sound.play()
                    child.set = False
                elif child.come_from == "rhl" and child.set and match[1].name == "swipe_left":
                    child.speed = 0
                    self.stop_sound.play()
                    child.set = False
                elif child.come_from == "rhl" and child.set and match[1].name == "swipe_right":
                    child.speed = self.running_speed
                    self.speed_sound.play()
                    child.set = False
Example #36
0
 def gesturize(self):
     gesture = Gesture()
     gesture.add_stroke(self.points)
     gesture.normalize()
     return gesture
Example #37
0
 def gesturize(self):
     gesture = Gesture()
     gesture.add_stroke(self.points)
     gesture.normalize()
     return gesture
Example #38
0
 def __init__(self):
     self.uGestureName:str           =  u''
     self.oGesture:Gesture           =  Gesture()
     self.uGestureString:str         =  u''
Example #39
0
def simplegesture(name, point_list):
    g = Gesture()
    g.add_stroke(point_list)
    g.normalize()
    g.name = name
    return g
Example #40
0
from kivy.gesture import Gesture, GestureDatabase

# Create a gesture
g = Gesture()
g.add_stroke(point_list=[(1, 1), (3, 4), (2, 1)])
g.normalize()
g.name = "triangle"

# Add it to database
gdb = GestureDatabase()
gdb.add_gesture(g)

# And for the next gesture, try to find a match!
g2 = Gesture()
g2.add_stroke(point_list=[(1, 1), (3, 4), (2, 1)])
g2.normalize()
print gdb.find(g2).name  # will print "triangle"