Outils pour utilisateurs

Outils du site


kivy_plyer

Ceci est une ancienne révision du document !


Kivy: plyer

Installation

sudo pip3 install plyer

Ressources

Très pauvres !

Possiblité d'accès

Android

Accelerometer Audio recording Barometer Battery Bluetooth Brightness Call Camera (taking picture) Compass Email (open mail client) Flash GPS Gravity Gyroscope Humidity IR Blaster Light Native file chooser Notifications Orientation Proximity SMS (send messages) Spatial Orientation Speech to text Storage Path Temperature Text to speech Unique ID Vibrator

Linux

Accelerometer Battery Brightness CPU count Email (open mail client) Native file chooser Notifications Screenshot Storage Path Text to speech Unique ID Wifi

Exemple

Vous voulez quelque chose, faîtes le vous même !

L'exemple Accelerometer Test pour python3 et corrigé:

main.py
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
 
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
 
from plyer import accelerometer
 
class AccelerometerTest(BoxLayout):
    def __init__(self):
        super().__init__()
        self.sensorEnabled = False
 
    def do_toggle(self):
        if not self.sensorEnabled:
            try:
                accelerometer.enable()
                print(accelerometer.acceleration)
                self.sensorEnabled = True
                self.ids.toggle_button.text = "Stop Accelerometer"
            except:
                print("Accelerometer is not implemented for your platform")
 
            if self.sensorEnabled:
                Clock.schedule_interval(self.get_acceleration, 1 / 20)
            else:
                accelerometer.disable()
                status = "Accelerometer is not implemented for your platform"
                self.ids.toggle_button.text = status
        else:
            # Stop de la capture
            accelerometer.disable()
            Clock.unschedule(self.get_acceleration)
 
            # Retour à l'état arrété
            self.sensorEnabled = False
            self.ids.toggle_button.text = "Start Accelerometer"
 
    def get_acceleration(self, dt):
        if self.sensorEnabled:
            val = accelerometer.acceleration[:3]
 
            if not val == (None, None, None):
                self.ids.x_label.text = "X: " + str(val[0])
                self.ids.y_label.text = "Y: " + str(val[1])
                self.ids.z_label.text = "Z: " + str(val[2])
 
class AccelerometerTestApp(App):
    def build(self):
        return AccelerometerTest()
 
    def on_pause(self):
        return True
 
if __name__ == '__main__':
    AccelerometerTestApp().run()
accelerometertest.kv
#:kivy 1.8.0
<AccelerometerTest>:
    BoxLayout:
        orientation: 'vertical'
        Label:
            id: x_label
            text: 'X: '
        Label:
            id: y_label
            text: 'Y: '
        Label:
            id: z_label
            text: 'Z: '
        Label:
            id: accel_status
            text: ''
        BoxLayout:
            size_hint_y: None
            height: '48dp'
            padding: '4dp'
 
            ToggleButton:
                id: toggle_button
                text: 'Start accelerometer'
                on_press: root.do_toggle()
,
kivy_plyer.1578039558.txt.gz · Dernière modification: 2020/01/03 09:19 de serge