from kivy.app import App
from kivy.properties import ObjectProperty
from kivy.uix.widget import Widget

from kivy.clock import Clock
from plyer import gyroscope

class Acce(Widget):
    def __init__(self):
        super(Acce, self).__init__()
        self.sensorEnabled = False

    def get_orientation(self, dt):
        val = gyroscope.orientation

        self.ids.label1.text = "X: " + str(val[0])
        self.ids.label2.text = "Y: " + str(val[1])
        self.ids.label3.text = "Z: " + str(val[2])

    def pressed1(self):
        try:
            if not self.sensorEnabled:
                gyroscope.enable()
                Clock.schedule_interval(self.get_orientation, 1 / 20.)

                self.sensorEnabled = True
                self.ids.button1.text = "Stop"
            else:
                gyroscope.disable()
                Clock.unschedule(self.get_orientation)

                self.sensorEnabled = False
                self.ids.button1.text = "Start"
        except NotImplementedError:
            import traceback; traceback.print_exc()
            self.ids.status.text =\
"Gyroscope is not supported for your   platform"

class e4App(App):
    def build(self):
        return Acce()

if __name__ == '__main__':
    e4App().run()
