1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
Builder.load_string('''
#:import vibrator plyer.vibrator
<VibrationInterface>:
orientation: 'vertical'
Label:
size_hint_y: None
height: sp(40)
text: 'vibrator exists: ' + str(vibrator.exists())
Button:
text: 'vibrate 10s'
on_release: vibrator.vibrate(10)
Button:
text: 'vibrate 1s'
on_release: vibrator.vibrate(1)
Button:
text: 'vibrate 0.1s'
on_release: vibrator.vibrate(0.1)
Button:
text: 'cancel vibration'
on_release: vibrator.cancel()
TextInput:
id: ti
text: '0.5,0.5,1,2,0.1,0.1,0.1,0.1,0.1,0.1'
Button:
text: 'vibrate pattern'
on_release:
vibrator.pattern([float(n) for n in ti.text.split(',')])
''')
class VibrationInterface(BoxLayout):
'''Root Widget.'''
pass
class VibrationApp(App):
def build(self):
return VibrationInterface()
def on_pause(self):
return True
if __name__ == "__main__":
VibrationApp().run()
|