当前位置: 首页>>代码示例>>Python>>正文


Python GestureDatabase.gesture_to_str方法代码示例

本文整理汇总了Python中kivy.gesture.GestureDatabase.gesture_to_str方法的典型用法代码示例。如果您正苦于以下问题:Python GestureDatabase.gesture_to_str方法的具体用法?Python GestureDatabase.gesture_to_str怎么用?Python GestureDatabase.gesture_to_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kivy.gesture.GestureDatabase的用法示例。


在下文中一共展示了GestureDatabase.gesture_to_str方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_touch_up

# 需要导入模块: from kivy.gesture import GestureDatabase [as 别名]
# 或者: from kivy.gesture.GestureDatabase import gesture_to_str [as 别名]
 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)
开发者ID:Anhmike,项目名称:kivy-book-examples,代码行数:9,代码来源:gesturerecorder.py

示例2: cGestureBoard

# 需要导入模块: from kivy.gesture import GestureDatabase [as 别名]
# 或者: from kivy.gesture.GestureDatabase import gesture_to_str [as 别名]
class cGestureBoard(cTouchRectangle):
    ''' base class for recording gestures '''
    def __init__(self, **kwargs):
        super(cGestureBoard, self).__init__(**kwargs)
        self.gdb = GestureDatabase()

    def on_touch_down(self, touch):

        #self.DrawStandardGestures()
        # start collecting points in touch.ud
        # create a line to display the points

        if not self.collide_point(touch.x, touch.y):
            return False
        touch.grab(self)

        userdata = touch.ud
        with self.canvas:
            Color(1, 1, 0)
            d = 10.
            Ellipse(pos=(touch.x - d/2, touch.y - d/2), size=(d, d))
            userdata['line'] = Line(points=(touch.x, touch.y))
        return True

    def on_touch_move(self, touch):

        if touch.grab_current is not self:
            return

        # store points of the touch movement
        try:
            touch.ud['line'].points += [touch.x, touch.y]
            return True
        except KeyError:
            pass
        return True

    def on_touch_up(self, touch):

        if touch.grab_current is not self:
            return

        g = simplegesture('',zip(touch.ud['line'].points[::2], touch.ud['line'].points[1::2]))
        # print "gesture representation:", ':',self.gdb.gesture_to_str(g)
        uLogName=oORCA.uGestureLogName

        oLogFile = open(uLogName, 'a')
        oLogFile.write('Gesturecode:'+self.gdb.gesture_to_str(g)+'\n')
        oLogFile.close()
        return True
开发者ID:thica,项目名称:ORCA-Remote,代码行数:52,代码来源:GestureBoard.py

示例3: GestureBoard

# 需要导入模块: from kivy.gesture import GestureDatabase [as 别名]
# 或者: from kivy.gesture.GestureDatabase import gesture_to_str [as 别名]
class GestureBoard(FloatLayout):
    """
    Our application main widget, derived from touchtracer example, use data
    constructed from touches to match symboles loaded from my_gestures.

    """
    def __init__(self, *args, **kwargs):
        super(GestureBoard, self).__init__()
        self.gdb = GestureDatabase()

        # add pre-recorded gestures to database
        self.gdb.add_gesture(cross)
        self.gdb.add_gesture(check)
        self.gdb.add_gesture(circle)
        self.gdb.add_gesture(square)

    def on_touch_down(self, touch):
        # start collecting points in touch.ud
        # create a line to display the points
        userdata = touch.ud
        with self.canvas:
            Color(1, 1, 0)
            d = 30.
            Ellipse(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d))
            userdata['line'] = Line(points=(touch.x, touch.y))
        return True

    def on_touch_move(self, touch):
        # store points of the touch movement
        try:
            touch.ud['line'].points += [touch.x, touch.y]
            return True
        except (KeyError) as e:
            pass

    def on_touch_up(self, touch):
        # touch is over, display informations, and check if it matches some
        # known gesture.
        g = simplegesture('', list(zip(touch.ud['line'].points[::2],
                                       touch.ud['line'].points[1::2])))
        # gestures to my_gestures.py
        print("gesture representation:", self.gdb.gesture_to_str(g))

        # print match scores between all known gestures
        print("cross:", g.get_score(cross))
        print("check:", g.get_score(check))
        print("circle:", g.get_score(circle))
        print("square:", g.get_score(square))

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

        print(g2)
        if g2:
            if g2[1] == circle:
                print("circle")
            if g2[1] == square:
                print("square")
            if g2[1] == check:
                print("check")
            if g2[1] == cross:
                print("cross")

        # erase the lines on the screen, this is a bit quick&dirty, since we
        # can have another touch event on the way...
        self.canvas.clear()
开发者ID:15huangtimothy,项目名称:kivy,代码行数:68,代码来源:gesture_board.py

示例4: GestureBoard

# 需要导入模块: from kivy.gesture import GestureDatabase [as 别名]
# 或者: from kivy.gesture.GestureDatabase import gesture_to_str [as 别名]
class GestureBoard(FloatLayout):
    ponts = 0

    def __init__(self, *args, **kwargs):
        super(GestureBoard, self).__init__()
        self.gdb = GestureDatabase()

        self.error_sound = SoundLoader.load('error.mp3')
        self.success_sound = SoundLoader.load('success.mp3')

        #Gestures
        for key, ges in gestures.items():
            self.gdb.add_gesture(ges)

        self.sort_letter()


    def sort_letter(self):
        self.letter = random.choice(gestures.keys())
        letter_button = Button(
            text=self.letter,
            size_hint=(.1, .1),
            pos_hint={'x':0, 'y':.9},
            font_size=38,
            line_height=1
        )
        self.add_widget(letter_button)
        ponts_button = Button(
            text=u"Pontos: %s" % self.ponts,
            size_hint=(.3, .1),
            pos_hint={'x':.7, 'y':.9}
        )
        self.add_widget(ponts_button)


    def on_touch_down(self, touch):
        # start collecting points in touch.ud
        # create a line to display the points
        userdata = touch.ud
        with self.canvas:
            Color(1, 1, 0)
            d = 30.
            Ellipse(pos=(touch.x - d/2, touch.y - d/2), size=(d, d))
            userdata['line'] = Line(points=(touch.x, touch.y))
        return True

    def on_touch_move(self, touch):
        # store points of the touch movement
        try:
            touch.ud['line'].points += [touch.x, touch.y]
            return True
        except (KeyError) as e: pass

    def on_touch_up(self, touch):
        # touch is over, display informations, and check if it matches some
        # known gesture.
        g = self.simplegesture(
            '',
            list(zip(touch.ud['line'].points[::2], touch.ud['line'].points[1::2]))
        )
        print("gesture representation:", self.gdb.gesture_to_str(g))

        # use database to find the more alike gesture, if any
        g2 = self.gdb.find(g, minscore=0.70)
        if g2:
            if self._get_key_by_gesture(g2[1]) == self.letter:
                self.ponts += 10
                if self.success_sound.status != 'stop':
                    self.success_sound.stop()
                self.success_sound.play()
        else:
            if self.error_sound.status != 'stop':
                self.error_sound.stop()
            self.error_sound.play()

        # erase the lines on the screen, this is a bit quick&dirty, since we
        # can have another touch event on the way...
        self.canvas.clear()
        self.sort_letter()

    def _get_key_by_gesture(self, g):
        for key, ges in gestures.items():
            if g == ges: return key

    def simplegesture(self, name, point_list):
        """
        A simple helper function
        """
        g = Gesture()
        g.add_stroke(point_list)
        g.normalize()
        g.name = name
        return g
开发者ID:leonardocsantoss,项目名称:kivy-abc,代码行数:95,代码来源:main.py


注:本文中的kivy.gesture.GestureDatabase.gesture_to_str方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。