Last active
December 17, 2015 19:39
-
-
Save softvar/5662188 to your computer and use it in GitHub Desktop.
testing touch events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#:kivy 1.0 | |
#:import kivy kivy | |
#:import win kivy.core.window | |
<cont>: | |
but: but | |
FloatLayout: | |
size:(600,600) | |
Button: | |
id:but | |
text: 'My first' + str(root.info) | |
size_hint:.2,.2 | |
pos:(200,200) | |
background_color:[.5,.8,.2,1] | |
foreground_color:[.4,.4,.8,.8] | |
font_size:18 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.uix.widget import Widget | |
from kivy.uix.image import Image | |
from kivy.input.motionevent import MotionEvent | |
from kivy.uix.scatter import Scatter | |
from kivy.uix.button import Button | |
from kivy.uix.boxlayout import BoxLayout | |
from kivy.uix.floatlayout import FloatLayout | |
from kivy.properties import StringProperty, ObjectProperty | |
class TestApp(App): | |
title = 'HELLO World' | |
def build(self): | |
#self.r = cont() | |
#self.root = self.r | |
return cont(app=self) | |
class cont(Widget): | |
but = ObjectProperty(None) | |
info=StringProperty(None) | |
app = ObjectProperty(None) | |
double_tap_status = False | |
def on_touch_down(self, touch): | |
if self.but.collide_point(*touch.pos): | |
if touch.is_double_tap: | |
print self.double_tap_status,touch.double_tap_time | |
if (touch.double_tap_time <0.5): | |
self.double_tap_status = True | |
touch.double_tap_time = 0.0 | |
touch.grab(self) | |
def on_touch_move(self, touch): | |
if touch.grab_current is self: | |
print self.double_tap_status | |
if self.double_tap_status==True: | |
print touch.x,touch.y | |
else: | |
print touch.profile | |
print touch.x,touch.y,touch.ud | |
self.but.pos = (touch.x,touch.y) | |
self.but.background_color=[.5,.8,.2,.4] | |
else: | |
pass | |
def on_touch_up(self, touch): | |
if touch.grab_current is self: | |
# i receive my grabbed touch, i must ungrab it ! | |
print 'leave' | |
#touch.double_tap_time = 0.0 | |
self.but.background_color=[.5,.8,.2,1] | |
touch.ungrab(self) | |
else: | |
# it's a normal touch | |
pass | |
self.double_tap_status=False | |
if __name__ == '__main__': | |
TestApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment