Using plyer with kivy. Weird errors.

0 votes
asked Sep 12, 2017 by ricardo-de-paula-soa

I have been trying to figure out what's wrong with this code:

from kivy.app import App
from kivy.properties import ObjectProperty
from kivy.uix.widget import Widget
from kivy.clock import Clock
from plyer.facades import accelerometer



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

    def get_acceleration(self, dt):
        val = accelerometer.acceleration

        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:
            # accelerometer.enable()
                Clock.schedule_interval(self.get_acceleration, 1 / 20.)
                self.sensorEnabled = True
                self.ids.button1.text = "Stop"
            else:
                # accelerometer.disable()
                Clock.unschedule(self.get_acceleration)
                self.sensorEnabled = False
                self.ids.button1.text = "Start"
        except:

            self.ids.status.text = "Accelerometer not supported"


class e3App(App):
    def build(self):
        return Accel()
if __name__ == '__main__':
    e3App().run()

What happens is when I run it and press the START button it crashes and gives me this:

> Traceback (most recent call last):    File
> "/usr/local/lib/python3.5/dist-packages/plyer/platforms/linux/accelerometer.py",
> line 22, in _get_acceleration
>      pos = glob.glob("/sys/devices/platform/*/position")[0]  IndexError: list index out of range    During handling of the above
> exception, another exception occurred:    Traceback (most recent call
> last):    File
> "/home/rickdps/Desktop/KivyCookBook/InputMotionAndTouch/WorkingWithAccelerometer/main.py",
> line 42, in <module>
>      e3App().run()    File "/usr/local/lib/python3.5/dist-packages/kivy/app.py", line 828, in run
>      runTouchApp()    File "/usr/local/lib/python3.5/dist-packages/kivy/base.py", line 504, in
> runTouchApp
>      EventLoop.window.mainloop()    File "/usr/local/lib/python3.5/dist-packages/kivy/core/window/window_sdl2.py",
> line 663, in mainloop
>      self._mainloop()    File "/usr/local/lib/python3.5/dist-packages/kivy/core/window/window_sdl2.py",
> line 405, in _mainloop
>      EventLoop.idle()    File "/usr/local/lib/python3.5/dist-packages/kivy/base.py", line 339, in
> idle
>      Clock.tick()    File "/usr/local/lib/python3.5/dist-packages/kivy/clock.py", line 581, in
> tick
>      self._process_events()    File "kivy/_clock.pyx", line 367, in kivy._clock.CyClockBase._process_events
> (/tmp/pip-build-rau3eo9p/kivy/kivy/_clock.c:7700)    File
> "kivy/_clock.pyx", line 397, in
> kivy._clock.CyClockBase._process_events
> (/tmp/pip-build-rau3eo9p/kivy/kivy/_clock.c:7577)    File
> "kivy/_clock.pyx", line 395, in
> kivy._clock.CyClockBase._process_events
> (/tmp/pip-build-rau3eo9p/kivy/kivy/_clock.c:7498)    File
> "kivy/_clock.pyx", line 167, in kivy._clock.ClockEvent.tick
> (/tmp/pip-build-rau3eo9p/kivy/kivy/_clock.c:3490)    File
> "/home/rickdps/Desktop/KivyCookBook/InputMotionAndTouch/WorkingWithAccelerometer/main.py",
> line 15, in get_acceleration
>      val = accelerometer.acceleration[:3]    File "/usr/local/lib/python3.5/dist-packages/plyer/utils.py", line 103, in
> __getattribute__
>      return getattr(object.__getattribute__(self, '_obj'), name)    File
> "/usr/local/lib/python3.5/dist-packages/plyer/facades/accelerometer.py",
> line 44, in acceleration
>      return self.get_acceleration()    File "/usr/local/lib/python3.5/dist-packages/plyer/facades/accelerometer.py",
> line 60, in get_acceleration
>      return self._get_acceleration()    File "/usr/local/lib/python3.5/dist-packages/plyer/platforms/linux/accelerometer.py",
> line 24, in _get_acceleration
>      raise Exception('Could not enable accelerometer!')  Exception: Could not enable accelerometer!

I am following this book called "Kivy Cook Book", and I've mostly copied and pasted code in order to try it. This one has not worked though.

I'd really appreciate any help.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...