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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
from kivy.app import App
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.properties import NumericProperty
from kivy.properties import ObjectProperty
from kivy.uix.boxlayout import BoxLayout
interface = Builder.load_string('''
#:import facade plyer.spatialorientation
<SpOrientationInterface>:
facade: facade
orientation: 'vertical'
padding: '20dp'
spacing: '10dp'
BoxLayout:
orientation: 'vertical'
BoxLayout:
orientation: 'horizontal'
Button:
id: enable_button
text: 'Enable Sensor'
disabled: False
on_release:
root.enable_listener()
disable_button.disabled = not disable_button.disabled
enable_button.disabled = not enable_button.disabled
Button:
id: disable_button
text: 'Disable Sensor'
disabled: True
on_release:
root.disable_listener()
disable_button.disabled = not disable_button.disabled
enable_button.disabled = not enable_button.disabled
BoxLayout:
orientation: 'vertical'
Label:
text: 'Azimuth: ' + str(root.azimuth) + ' radians'
Label:
text: 'Pitch: ' + str(root.pitch) + ' radians'
Label:
text: 'Roll: ' + str(root.roll) + ' radians'
''')
class SpOrientationInterface(BoxLayout):
pitch = NumericProperty(0)
azimuth = NumericProperty(0)
roll = NumericProperty(0)
facade = ObjectProperty()
def enable_listener(self):
self.facade.enable_listener()
Clock.schedule_interval(self.get_orientation, 1 / 20.)
def disable_listener(self):
self.facade.disable_listener()
Clock.unschedule(self.get_orientation)
def get_orientation(self, dt):
if self.facade.orientation != (None, None, None):
self.azimuth, self.pitch, self.roll = self.facade.orientation
class SpOrientationTestApp(App):
def build(self):
return SpOrientationInterface()
if __name__ == "__main__":
SpOrientationTestApp().run()
|