kivy_comment_faire_un_tas_de_chose
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| kivy_comment_faire_un_tas_de_chose [2020/01/16 17:07] – [Comment changer la couleur d'un Rectangle ?] serge | kivy_comment_faire_un_tas_de_chose [2022/11/19 09:49] (Version actuelle) – [Sur internet] serge | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ======Kivy: Comment faire un tas de chose====== | + | ======Kivy: Comment |
| <WRAP center round box 60% centeralign> | <WRAP center round box 60% centeralign> | ||
| **{{tagpage> | **{{tagpage> | ||
| **[[http:// | **[[http:// | ||
| </ | </ | ||
| - | ===== Pourquoi | + | <WRAP center round box 40% centeralign> |
| + | **[[les_pages_kivy_en_details|Les pages Kivy en détails]]** | ||
| + | </ | ||
| + | ===== Comment chercher ? ===== | ||
| + | ====Sur internet==== | ||
| + | * Dans la **[[https:// | ||
| + | * Dans un moteur de recherche: ça finit souvent par des posts sur stackoverflow, | ||
| + | * **[[https:// | ||
| + | ====Une bonne solution: Les exemples des sources de kivy==== | ||
| + | * Télécharger les sources sur [[https:// | ||
| + | * Dans votre EDI créer un projet avec uniquement les [[https:// | ||
| + | * Rechercher dans les fichiers: si vous chercher " | ||
| - | **Kivy masque | + | ====Gallery of Examples==== |
| + | **[[https:// | ||
| + | =====Des explications avec les exemples | ||
| + | Une liste de scripts qui explique bien: | ||
| + | |||
| + | * **pos_hint** : [[https:// | ||
| + | * **bubble** : [[https:// | ||
| + | * **camera** : [[https:// | ||
| + | * **carousel** : [[https:// | ||
| + | * **mipmap** : [[https:// | ||
| + | * **text_size = textwrap** : [[https:// | ||
| + | * **text with markup** : [[https:// | ||
| + | * **popup** : [[https:// | ||
| + | * **scatter** : [[https:// | ||
| + | * **scrollview** : [[https:// | ||
| + | * **splitter** : [[https:// | ||
| + | * **tabbed panel = onglet** : [[https:// | ||
| + | * **text align** : [[https:// | ||
| + | * **video player** : [[https:// | ||
| + | * **ErrorPopup(Popup)** : [[https:// | ||
| + | * **Slider** : [[https:// | ||
| + | * **Clock** : [[https:// | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | =====Adapter la résolution dpi sur son PC===== | ||
| + | * Sur votre PC, définir la taille de votre fenêtre | ||
| + | < | ||
| + | from plyer import utils | ||
| + | |||
| + | from oscpy.client import OSCClient | ||
| + | from oscpy.server import OSCThreadServer | ||
| + | |||
| + | print(" | ||
| + | ANDROID = utils.platform._platform_android | ||
| + | print(" | ||
| + | if not ANDROID: | ||
| + | from kivy.core.window import Window | ||
| + | # Simulation de l' | ||
| + | k = 0.8 | ||
| + | WS = (int(720*k), int(1280*k)) | ||
| + | Window.size = WS | ||
| + | os.environ[' | ||
| + | |||
| + | from jnius import autoclass | ||
| + | </ | ||
| - | Par exemple: | + | Lancer le main.py avec: |
| + | KIVY_METRICS_FONTSCALE=1.2 python3 main.py | ||
| + | avec une valeur " | ||
| - | * un argument qui manque dans un appel de méthode lève une erreur pour du python habituel, mais pas dans kivy. D'où un débogage rusé nécessaire ! | ||
| =====Comment lister tous les widgets dans le python===== | =====Comment lister tous les widgets dans le python===== | ||
| Ligne 22: | Ligne 80: | ||
| print([type(widget) for widget in f.walk(loopback=True)]) | print([type(widget) for widget in f.walk(loopback=True)]) | ||
| | | ||
| - | Sortie de [type(widget) for widget in self.walk(loopback=True)] | + | Sortie de [type(widget) for widget in self.walk(loopback=True)] |
| < | < | ||
| <class ' | <class ' | ||
| Ligne 34: | Ligne 92: | ||
| <class ' | <class ' | ||
| <class ' | <class ' | ||
| - | <class 'kivy.uix.boxlayout.BoxLayout'>, | + | ...... |
| - | <class 'kivy.uix.gridlayout.GridLayout'>, | + | |
| - | <class ' | + | |
| - | <class ' | + | |
| - | <class ' | + | |
| - | <class ' | + | |
| </ | </ | ||
| - | =====Comment passer d'une class à une autre===== | + | =====Comment passer |
| En fait, **comment passer d'un objet à un autre !** | En fait, **comment passer d'un objet à un autre !** | ||
| Ligne 48: | Ligne 101: | ||
| puis dans la liste des méthodes et attributs, ayez de nez. Si app est dans la liste: | puis dans la liste des méthodes et attributs, ayez de nez. Si app est dans la liste: | ||
| print(dir(self.app)) | print(dir(self.app)) | ||
| - | | + | |
| + | ====Comment récupérer self.app dans tous les objets==== | ||
| + | Une solution élégante est utilisée dans **[[https:// | ||
| + | <code python> | ||
| + | class AccelerometerApp(App): | ||
| + | def build(self): | ||
| + | return Accelerometer(self) | ||
| + | |||
| + | class Accelerometer(BoxLayout): | ||
| + | def __init__(self, | ||
| + | super().__init__(**kwargs) | ||
| + | self.app = app | ||
| + | self.app.osc = OSC() | ||
| + | |||
| + | class OSC: | ||
| + | def __init__(self): | ||
| + | self.histo = [] | ||
| + | self.server = OSCThreadServer() | ||
| + | self.server.bind(b'/ | ||
| + | |||
| + | def on_histo(self, | ||
| + | self.histo = .... | ||
| + | |||
| + | class Screen2: | ||
| + | def __init__(self): | ||
| + | self.app = App.get_running_app() | ||
| + | # et appel de l' | ||
| + | self.app.osc.histo | ||
| + | Clock.schedule_once(self._once, | ||
| + | def _once(self, dt): | ||
| + | Clock.schedule_interval(self.update, | ||
| + | | ||
| + | def update(self, | ||
| + | blabla = self.app.osc.histo | ||
| + | # blabla retrouve la valeur de histo de OSC !!!! | ||
| + | </ | ||
| - | ===== La commande magique ===== | ||
| - | |||
| - | Dans Blender, le raccourcis magique c'est: | ||
| - | **Ctrl + A** Apply the object' | ||
| - | |||
| - | Dans le *.kv, c'est: [[https:// | ||
| - | |||
| - | <code python> | ||
| - | canvas: | ||
| - | Clear | ||
| - | </ | ||
| Ligne 134: | Ligne 211: | ||
| </ | </ | ||
| + | =====Button background_color===== | ||
| + | <code python> | ||
| + | Button: | ||
| + | background_normal: | ||
| + | background_color: | ||
| + | </ | ||
| + | Pour avoir des couleurs flashy, mettre des valeurs supérieures à 1: exemple\\ | ||
| + | background_color: | ||
| + | {{ : | ||
| =====Texte en gras dans un label===== | =====Texte en gras dans un label===== | ||
| + | * **[[https:// | ||
| <code python> | <code python> | ||
| Label: | Label: | ||
| Ligne 148: | Ligne 235: | ||
| color: 1, 0, 0.5, 1 | color: 1, 0, 0.5, 1 | ||
| </ | </ | ||
| + | |||
| + | |||
| ===== Factory ===== | ===== Factory ===== | ||
| Factory peut être utilisée pour enregistrer automatiquement toute classe ou module et en instancier des classes n' | Factory peut être utilisée pour enregistrer automatiquement toute classe ou module et en instancier des classes n' | ||
| - | * **[[http:// | + | * **[[http:// |
| ===== Réception sur Android en Multicast ===== | ===== Réception sur Android en Multicast ===== | ||
| Ligne 159: | Ligne 248: | ||
| android.permissions = INTERNET, | android.permissions = INTERNET, | ||
| </ | </ | ||
| + | Les permissions définies dans buildozer.spec crée le bouton enable/ | ||
| ===== Twisted dans kivy ===== | ===== Twisted dans kivy ===== | ||
| * **[[https:// | * **[[https:// | ||
| * **Exemple** avec [[apprendre_kivy|Apprendre Kivy]] | * **Exemple** avec [[apprendre_kivy|Apprendre Kivy]] | ||
| + | |||
| + | =====Comment éviter ou résoudre des bugs à la compilation avec buildozer===== | ||
| + | ===Comment commenter dans buildozer.spec ?=== | ||
| + | Ne pas faire: | ||
| + | <code python> | ||
| + | requirements = python3, | ||
| + | ni | ||
| + | requirements = python3, | ||
| + | </ | ||
| + | mais | ||
| + | <code python> | ||
| + | requirements = python3, | ||
| + | #,jnius | ||
| + | </ | ||
| + | Le buildozer.spec est seulement presque du python. Ce commentaire maltapropo m'a donné des messages d' | ||
| + | |||
| + | =====Bugs===== | ||
| + | ====Novembre 2020==== | ||
| + | Voir [[https:// | ||
| + | [CRITICAL] [Cutbuffer | ||
| + | |||
| + | résolu avec | ||
| + | sudo apt install xclip | ||
| + | | ||
| + | =====Comment avoir une action maintenue si maintien d'un Button===== | ||
| + | <code python accelerometer.kv> | ||
| + | Button: | ||
| + | id: recul | ||
| + | markup: True | ||
| + | background_color: | ||
| + | font_size: " | ||
| + | text: ' | ||
| + | on_press: root.do_back_forward(-1) | ||
| + | on_release: root.do_end() | ||
| + | Button: | ||
| + | id: avance | ||
| + | markup: True | ||
| + | background_color: | ||
| + | font_size: " | ||
| + | text: ' | ||
| + | on_press: root.do_back_forward(1) | ||
| + | on_release: root.do_end() | ||
| + | </ | ||
| + | |||
| + | <code python main.py> | ||
| + | def do_back_forward(self, | ||
| + | self.bf = 1 | ||
| + | bt = Thread(target=self.back_forward_loop, | ||
| + | bt.start() | ||
| + | |||
| + | def back_forward_loop(self, | ||
| + | while self.bf: | ||
| + | sleep(0.1) | ||
| + | self.gap = self.gap + sens*10 | ||
| + | if self.gap > 0: self.gap = 0 | ||
| + | l = len(self.app.osc.histo_xyz) | ||
| + | if self.gap < -l + 500: self.gap = -l + 500 | ||
| + | print(" | ||
| + | |||
| + | def do_end(self): | ||
| + | self.bf = 0 | ||
| + | </ | ||
| - | {{tag> | + | {{tag> kivy python |
kivy_comment_faire_un_tas_de_chose.1579194433.txt.gz · Dernière modification : de serge
