android - Kivy gesture is registered on button -
i try make android app using kivy. swiping left , right use screenmanager , gestures instead of carousel. approach derives here , tried make swiping possible in both directions.
while swiping works, however, when pressing button registered gesture shouldn't. means, of time when pressing butten event behind 1 of gestures triggered.
i can somehow reduce probability happens increasing minscore
value, not reliable , makes gestures less sensitive.
is there way avoid happening? e.g. limiting gesture recognition screenmanager only?
i have attached example of app.
many thanks!
main.py
from kivy.app import app kivy.uix.boxlayout import boxlayout kivy.utils import platform kivy.uix.screenmanager import notransition import gesture_box gesture import time import datetime class storage: memory = 0 class demo(gesture.gesturebox): def init(self): today = time.localtime().tm_wday # 0 monday l = ['one', 'two', 'three', 'four', 'five', 'six', 'six'] storage.memory = today return l[today] def screen_up(self): print storage.memory l = ['two', 'three', 'four', 'five', 'six', 'six'] try: in range(6): if storage.memory == 5: return l[storage.memory] if storage.memory == i: storage.memory = + 1 return l[i] except: pass def screen_down(self): print storage.memory l = ['one', 'one', 'two', 'three', 'four', 'five'] try: in range(5, -1, -1): if storage.memory == 0: return l[storage.memory] if storage.memory == i: storage.memory = - 1 return l[i] except: pass def do_something_1(self): print 'something 1 done.' self.display_1 = 'something 1 on monday' self.display_2 = 'something 1 on tuesday' self.display_3 = 'something 1 on wednesday' self.display_4 = 'something 1 on thursday' self.display_5 = 'something 1 on friday' self.display_6 = 'something 1 on weekend' def do_something_2(self): print 'something 2 done.' self.display_1 = 'something 2 on monday' self.display_2 = 'something 2 on tuesday' self.display_3 = 'something 2 on wednesday' self.display_4 = 'something 2 on thursday' self.display_5 = 'something 2 on friday' self.display_6 = 'something 2 on weekend' class mainapp(app): def build(self): return demo() def on_pause(self): # here can save data if needed return true def on_resume(self): # here can check if data needs replacing (usually nothing) pass if __name__ == '__main__': app = mainapp() app.run()
gesture_box.py
from kivy.gesture import gesturedatabase kivy.uix.boxlayout import boxlayout kivy.gesture import gesture gesture_strings = { 'left_to_right_line': 'enqnwnts3uyqfnepmjdqc5/dhycvqeidusscasooniljjp77jgyfpntsscslptvq7xsvzke+evry9m/364fd2+nb62h6ffl9honq/ojt7afnu78pn6yjxt/jf09vt5/etq8vxw5v8admv1+pol39uuq2adprzimp+48vt8+n+byy31zxbvtjzk1hbcuyl/a9bkgabn6dawapwiolwiwvajov6l+zwekwjhckufsptdd09tfd9nmkn6ptw8yjht7vasoxednbqzn99swefuhddzuqfk5cxx1fvkr4hron6ggvcems6r4xlaeqdqnhfxdukfiuir6xl08pz2pytsikiirbcn33hjjwgotvbastopbobed99yyvxmivpi/vqu3lz7b0hiwwksaixkqbmj3ps1wmxwsqbius2txnjjzxuj/7bpflm1rmqxku1crfqjmwgh33obnlhdmnz1ogamacpek+fiblpijppcr1rei1ebpyfqblg+ksgrgofymfw6v9rs+zrgymi65okhivvaxytwp6ga8mxhvlb+tkjoro8ab9/yxxbunfmiugtuivrrqfr2s8mhgv1k417g9+yxrlmf2q6bvepchofi/xrr5mujqylly8u2vfp9pvkxtna2xewnhgbqoq6r5+pqs6pk/rgaagmqbfcvd31tnc9tf1byqxb8l/mecgvmlsty6p1zdc2mgaigtb35mw0rooyspgibbhirebkvp+e2uzri0lg83mnfpnnlrsy6da3/iwwdpysledrcawzikrbdagn8nawllri13yhjlq0yejxtjzw5kdxckxvsaxspey9ajpf4jhgmjxpedxii42ckb45ur4qzxw59g4yomhjfp63rvdshzhgt0sxot+o/am1xlam6gldgddmajridbhsb0nbjwifdvozjjzp8ln18ph+wpwd5sn/xhtr27mrmg6itk6zm9+bdodvux3vzfo64q6e4qvegrmhkrrbjwjcwhf1+5nju5jz1kx5gtibkosyetlfu2g0zrdklhwvsuejlqhke4sbdds3vhqwgvuaizsx+kzpqcsjdq49kjvsm+m0hjpaywc7sklmdas9ma6r0ydmgarwwemp/fodmbawsadmc4w9bdn4then4miwsyr9mgwgj+bpzpfsv+gwrw/b9h3nmuk0ahhsy4b6ffrqpz2yjkly4yvgmu4zihzdlz/g5s0qn53+ojiwidag4py0lq+kew/4onz/ymy5kgeua6stkmxdzvmw+1dwrrn++ijbsekucgxtin1kwcae7nchxi0te+x0hyvfkgufqhaj6yf2m/w+sm60qvdlfs9l4laoaupifqhf/uowm0x+46ynrvydwwn7dfl2nb+l3pwznihwa3tn8zzw8yopaonvxha1hyhfy96qz+4f7tnpmsh9qpd/ilsql5syhc/uglvl11i6ocginiswjrcrynnd1tuenfufpj2appdsuebh0up+0cbh+vct/lrlrjngnrbbvuvo+ad1vz17rw0fvprj2ztvhwihyg3tk9npaglr7m2x4+kfw5hrvfog+knwhuunk2gb1bqo5r1iqu5thvlnwyujevas410g9i8jnughkftvho8pd08nub//yzh96y/a0smc0h59+n+9jim6g9tmwz6evl6el17/nzik54j+ywvg+cfx9ex+2+fm3kjdcrggr0lytpfbx/wpjde/w/qpwu7', 'right_to_left_line': 'enqnwctygzcqvo+pwjeomc88fkc5psofkfjslqxyirekoon/pthprrjlcmfbc6vh7zy6bwoavhv+/vz3z/unw/vpx9th+vx8fkzt3dcjtz8/vtz+dfg0hbn/2d9kev/86f309vr98n7/1enuz6nnd//r5lpdpmoexzx+/ph1+eu0p1bnx9qnx36budorkmgcws/+cph08eu6t6mmxqxcnvtlston9o8mkokh3vsulfysamijk9p7h49xgpuwnj19rncmxwplrzpqa9p709k3aymtfmwskln3fxvlvfa+u085p9jyvstwjpndvbaalampztnu67776u7boptcqwrkkxntkvbdswvanoi+u5ko1lwaq3hzz6c/ppuxqf9jcqxcqitew5n99y4s25h7qynyss2uxbhzuuvetevbbuwlzeaszkmpyed6li4piivk3f7r+rvuxcwvqxg5rqkvke/7d3flufy2zsmfoih0xvwzflfrwbqqlz4cmtna0hjxvwbvpfaxaocvpekpqyud6pk1zwufh3v5dvbe4momao2oactlnx91exvq3tq2s9f2u19dxx3un9lmluf9qa+urw7qmxhd7tzh8kd+rq8o6ts/o7em9ylx2q/axgebunj+ljfjpbfreg1eci1nripk9b7bt8r9ac6y2wiadt65si2v/vvmrrkvwqde6x2s6r7m5jjbgw3qpzatlfslet5fxtlfzqmid13xfnh+os6ucr7vmln/e9ko80aa1zipaswm6wi2798lzqms9+5fb8qd/l3hffz4dk+ivdrtpviuwcrku9d6emg07764wiuu7rnvjukz9aeb1d6nv+5v1vvmqpbf5s0y5r587adzdjawpyulw2zivablayjsl7l7n+8sx94oh5epm0ff1f1qump091bsu0/tq18n/e107lvs42ysg2odudbgmmbmgypnxr7ynkagkweugaxg8+mko7qx8szobiwgy4yxw8gby3fj/kbu9noderuivo3wwrpjturlqktbclcg+tyclojtpbr4kxobabikialmjigcgrncrobtptsiceqbd3bkt330ncyhyqkis2otbxagjauq59vqfegbidj1zq1expzaflmoiawqkf0n1ywk1aaj0ivnt2+kaqtsahciwg7qth2/dujqk0rgvyivyjejdmeur0wdxypyabt9bf59dgspqqmuzadawwsgbejkxanwwgoiablwye61rl3kbkjqguxu6zxv1698e1+ap1g8i6c9xcde4az8kljabjuaahek6dgbcbj5gqgs5qiroghdgqgcsckqgaj0wftwmwt4j5pzqhukylonwqjmvgikwkvqves0ldwplhislfvaashuqzycqkezkkhop1qiqawvkmilsyvrpdwwk0hrbnylymxabjrydexgjwxgl6naydeaygz2kficdlmw/azspiiqs8staibs7hinflv2drke/zizkic67oxyjnjxdtmcormbesiynv3wkf1nlyukvagj0gw70rzdwg7udaxsrlotgf0kii5gn+n2s3it71rtcxgobkgu1ammqhlkasriwknubwgkarjoirsylsbd3my6tageaykccsbbz+aor9h4xi2uj4iaanajcyvbhi03tepxqminj5bt8gifh8u6aldijkflmxexgqnl8lbyqc4yrbcr+fdawkgbpq0vvs8njswkquuqb9qmv9fqm1z5rw288cu4ubhb1oramldw1mzpa0vtdouxtdhvaa2tisiunicg6nlvr1+0hoacsgeefksrdmfh2ujhuajroq3v+vgmwwj0otrwk242lw+ntkbbcozbs7sk7ww3le+4odsr6f5uzev+zvw8lupr2yirrpwt0suqtdv6rzeje4xe0wxywogvxwynjf7r9gsyxrxgctacsveeb5y+hz6fvp3mn7t7+f5h5rib/3n+evrmtt4m+oaiw0+vfx7ehl+++a/g/eg+/1yy289fh/1+fhv9+uol++qn9ge+r4vl5vb7kk9j569h7/8dxj5miw==' } #this database can compare gestures user makes stored gestures #and tell if user input matches of them. gestures = gesturedatabase() name, gesture_string in gesture_strings.items(): gesture = gestures.str_to_gesture(gesture_string) gesture.name = name gestures.add_gesture(gesture) class gesturebox(boxlayout): def __init__(self, **kwargs): name in gesture_strings: self.register_event_type('on_{}'.format(name)) super(gesturebox, self).__init__(**kwargs) def on_left_to_right_line(self): pass def on_right_to_left_line(self): pass #to recognize gesture, need start recording each individual event in #touch_down handler, add data points each call touch_move , , #gesture calculations when data points have been received in touch_up handler. def on_touch_down(self, touch): #create user defined variable , add touch coordinates touch.ud['gesture_path'] = [(touch.x, touch.y)] super(gesturebox, self).on_touch_down(touch) def on_touch_move(self, touch): touch.ud['gesture_path'].append((touch.x, touch.y)) super(gesturebox, self).on_touch_move(touch) def on_touch_up(self, touch): if 'gesture_path' in touch.ud: #create gesture object gesture = gesture() #add movement coordinates gesture.add_stroke(touch.ud['gesture_path']) #normalize thwu willtolerate size variations gesture.normalize() #minscore attained match true, default 0.3 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)
main.kv
#:import notransition kivy.uix.screenmanager.notransition #:import slidetransition kivy.uix.screenmanager.slidetransition <demo>: on_parent: manager.transition = notransition(); manager.current = root.init(); manager.transition = slidetransition() #handling gesture event. on_left_to_right_line: manager.current = root.screen_down(); manager.transition.direction = 'right' on_right_to_left_line: manager.current = root.screen_up(); manager.transition.direction = 'left' display_1: 'monday' display_2: 'tuesday' display_3: 'wednesday' display_4: 'thursday' display_5: 'friday' display_6: 'weekend' boxlayout: orientation: 'vertical' screenmanager: size_hint_y: 80 id: manager screen: name: "one" boxlayout: orientation: 'vertical' label: text: root.display_1 size_hint_y: 80 halign: 'center' text_size: (800, none) color: (1, 1, 0, 1) screen: name: "two" boxlayout: orientation: 'vertical' label: text: root.display_2 size_hint_y: 80 halign: 'center' text_size: (800, none) color: (1, 1, 0, 1) screen: name: "three" boxlayout: orientation: 'vertical' label: text: root.display_3 size_hint_y: 80 halign: 'center' text_size: (800, none) color: (1, 1, 0, 1) screen: name: "four" boxlayout: orientation: 'vertical' label: text: root.display_4 size_hint_y: 80 halign: 'center' text_size: (800, none) color: (1, 1, 0, 1) screen: name: "five" boxlayout: orientation: 'vertical' label: text: root.display_5 size_hint_y: 80 halign: 'center' text_size: (800, none) color: (1, 1, 0, 1) screen: name: "six" boxlayout: orientation: 'vertical' label: text: root.display_6 size_hint_y: 80 halign: 'center' text_size: (800, none) color: (1, 1, 0, 1) button: size_hint_y: 10 text: 'do 1' background_color: (0.5, 0.5, 0.5, 1.0) on_release: root.do_something_1() button: size_hint_y: 10 text: 'do 2' background_color: (0.5, 0.5, 0.5, 1.0) on_release: root.do_something_2()
Comments
Post a Comment