kivy_plyer
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
kivy_plyer [2020/01/02 13:48] – créée serge | kivy_plyer [2020/12/01 17:43] (Version actuelle) – ↷ Liens modifiés en raison d'un déplacement. serge | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== Kivy: plyer====== | ====== Kivy: plyer====== | ||
- | |||
<WRAP center round box 60% centeralign> | <WRAP center round box 60% centeralign> | ||
**{{tagpage> | **{{tagpage> | ||
**[[http:// | **[[http:// | ||
+ | </ | ||
+ | <WRAP center round box 40% centeralign> | ||
+ | **[[les_pages_kivy_en_details|Les pages Kivy en détails]]** | ||
</ | </ | ||
+ | **Plyer** fournit des façades pour accéder facilement à des fonctionnalités Android. C'est une alternative simple à **[[kivy_jnius|jnuis]]** | ||
=====Installation===== | =====Installation===== | ||
- | |||
sudo pip3 install plyer | sudo pip3 install plyer | ||
+ | =====Ressources===== | ||
+ | Très pauvres ! | ||
+ | * **[[https:// | ||
+ | * **[[https:// | ||
+ | * **[[https:// | ||
+ | =====Possiblité d' | ||
+ | ===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' | ||
+ | |||
+ | <code python main.py> | ||
+ | #! / | ||
+ | # -*- 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(" | ||
+ | |||
+ | if self.sensorEnabled: | ||
+ | Clock.schedule_interval(self.get_acceleration, | ||
+ | else: | ||
+ | accelerometer.disable() | ||
+ | status = " | ||
+ | self.ids.toggle_button.text = status | ||
+ | else: | ||
+ | # Stop de la capture | ||
+ | accelerometer.disable() | ||
+ | Clock.unschedule(self.get_acceleration) | ||
+ | |||
+ | # Retour à l' | ||
+ | self.sensorEnabled = False | ||
+ | self.ids.toggle_button.text = "Start Accelerometer" | ||
+ | |||
+ | def get_acceleration(self, | ||
+ | if self.sensorEnabled: | ||
+ | val = accelerometer.acceleration[: | ||
+ | |||
+ | 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__ == ' | ||
+ | AccelerometerTestApp().run() | ||
+ | </ | ||
+ | |||
+ | <code python accelerometertest.kv> | ||
+ | #:kivy 1.8.0 | ||
+ | < | ||
+ | BoxLayout: | ||
+ | orientation: | ||
+ | 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: | ||
+ | height: ' | ||
+ | padding: ' | ||
+ | |||
+ | ToggleButton: | ||
+ | id: toggle_button | ||
+ | text: 'Start accelerometer' | ||
+ | on_press: root.do_toggle() | ||
+ | </ | ||
+ | |||
+ | ===Le *apk=== | ||
+ | * {{media_08: | ||
+ | =====android.permissions===== | ||
+ | * [[https:// | ||
+ | Les permissions définies dans buildozer.spec crée le bouton enable/ | ||
+ | =====Exemple Envoi de Sms===== | ||
+ | <code python main.py> | ||
+ | #! / | ||
+ | # -*- coding: utf-8 -*- | ||
+ | |||
+ | from kivy.app import App | ||
+ | from kivy.uix.boxlayout import BoxLayout | ||
+ | from kivy.uix.button import Button | ||
+ | from kivy.properties import StringProperty | ||
+ | |||
+ | from plyer import sms | ||
+ | |||
+ | class SmsInterface(BoxLayout): | ||
+ | pass | ||
+ | |||
+ | class IntentButton(Button): | ||
+ | sms_recipient = StringProperty() | ||
+ | sms_message = StringProperty() | ||
+ | |||
+ | def send_sms(self, | ||
+ | sms.send(recipient=self.sms_recipient, | ||
+ | |||
+ | class SmsApp(App): | ||
+ | def build(self): | ||
+ | return SmsInterface() | ||
+ | |||
+ | def on_pause(self): | ||
+ | return True | ||
+ | |||
+ | if __name__ == " | ||
+ | SmsApp().run() | ||
+ | </ | ||
+ | |||
+ | <code python sms.kv> | ||
+ | < | ||
+ | orientation: | ||
+ | BoxLayout: | ||
+ | size_hint_y: | ||
+ | height: sp(30) | ||
+ | Label: | ||
+ | text: ' | ||
+ | TextInput: | ||
+ | id: recipient | ||
+ | multiline: False | ||
+ | on_text_validate: | ||
+ | BoxLayout: | ||
+ | Label: | ||
+ | text: ' | ||
+ | TextInput: | ||
+ | id: message | ||
+ | IntentButton: | ||
+ | sms_recipient: | ||
+ | sms_message: | ||
+ | text: 'Send SMS' | ||
+ | size_hint_y: | ||
+ | height: sp(40) | ||
+ | on_release: self.send_sms() | ||
+ | </ | ||
+ | |||
+ | <code python buildozer.spec> | ||
+ | [app] | ||
+ | title = Sms | ||
+ | package.name = sms | ||
+ | package.domain = org.test | ||
+ | source.dir = . | ||
+ | source.include_exts = py, | ||
+ | version = 0.3 | ||
+ | requirements = python3, | ||
+ | orientation = portrait | ||
+ | fullscreen = 0 | ||
+ | android.arch = armeabi-v7a | ||
+ | android.permissions = READ_PHONE_STATE, | ||
+ | |||
+ | [buildozer] | ||
+ | log_level = 2 | ||
+ | warn_on_root = 1 | ||
+ | </ | ||
+ | ===Le *.apk=== | ||
+ | * {{ media_12: | ||
+ | ===La permission SEND_SMS n'est pas acceptée par Android=== | ||
+ | < | ||
+ | 01-04 09: | ||
+ | </ | ||
- | =====Utilisation===== | + | Les permissions définies dans buildozer.spec crée le bouton enable/ |
- | {{tag> | + | {{tag> kivy python |
kivy_plyer.1577972927.txt.gz · Dernière modification : 2020/01/02 13:48 de serge