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édenteProchaine révisionLes deux révisions suivantes | ||
kivy_comment_faire_un_tas_de_chose [2019/12/19 13:01] – [La commande magique] serge | kivy_comment_faire_un_tas_de_chose [2020/11/14 09:47] – [Une bonne solution: Les exemples des sources de kivy] 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:// | ||
</ | </ | ||
+ | <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, | ||
- | ===== Pourquoi | + | ====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 des erreurs python** | + | ====Gallery of Examples==== |
+ | **[[https:// | ||
+ | =====Des explications avec les exemples des sources===== | ||
+ | Une liste de scripts qui explique bien: | ||
- | Par exemple: | + | * **pos_hint** |
+ | * **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:// | ||
- | * 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 ! | ||
- | ===== La commande magique ===== | ||
- | Dans Blender, le raccourcis magique c'est: | ||
- | **Ctrl + A** Apply the object' | ||
- | Dans le *.kv, c'est: [[https://kivy.org/ | + | =====Adapter la résolution dpi sur son PC===== |
+ | | ||
+ | <code python> | ||
+ | from kivy.core.window import Window | ||
+ | # Les 3 lignes ci-dessous sont à commenter pour buildozer | ||
+ | # L' | ||
+ | k = 1.0 | ||
+ | WS = (int(1280*k), | ||
+ | Window.size = WS | ||
+ | </ | ||
+ | Lancer le main.py avec: | ||
+ | KIVY_METRICS_FONTSCALE=1.2 python3 main.py | ||
+ | avec une valeur " | ||
+ | |||
+ | |||
+ | =====Comment lister tous les widgets dans le python===== | ||
+ | * **[[https:// | ||
+ | Par exemple, extrait de [[https:// | ||
+ | # Recherche de tous les widgets de self | ||
+ | print([type(widget) for widget in self.walk(loopback=True)]) | ||
+ | # Recherche de tous les widgets de Screen1 | ||
+ | print(self.ids.sm) | ||
+ | f = self.ids.sm.get_screen(" | ||
+ | print([type(widget) for widget in f.walk(loopback=True)]) | ||
+ | | ||
+ | Sortie de [type(widget) for widget in self.walk(loopback=True)] dans SmartCitizen() | ||
+ | < | ||
+ | <class ' | ||
+ | <class ' | ||
+ | <class ' | ||
+ | <class ' | ||
+ | <class ' | ||
+ | <class ' | ||
+ | <class ' | ||
+ | <class ' | ||
+ | <class ' | ||
+ | <class ' | ||
+ | ...... | ||
+ | </ | ||
+ | =====Comment passer un attribut d'une class à une autre===== | ||
+ | En fait, **comment passer d'un objet à un autre !** | ||
+ | |||
+ | Faire des print(de quoi ?). Commencer par | ||
+ | print(dir(self)) | ||
+ | puis dans la liste des méthodes et attributs, ayez de nez. Si app est dans la liste: | ||
+ | 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> | <code python> | ||
- | canvas: | + | 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 | ||
+ | | ||
</ | </ | ||
- | ===== Pourquoi définir les attributs comme attributs de classe ? ===== | + | |
+ | ===== Pourquoi définir les attributs | ||
**Parce que c'est comme ça ? Quand lama fâché, lui toujours faire ainsi !** | **Parce que c'est comme ça ? Quand lama fâché, lui toujours faire ainsi !** | ||
+ | Voir l' | ||
===== Comment changer la couleur d'un Rectangle ? ===== | ===== Comment changer la couleur d'un Rectangle ? ===== | ||
Ligne 93: | Ligne 199: | ||
... | ... | ||
</ | </ | ||
+ | |||
+ | =====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===== | ||
+ | * **[[https:// | ||
+ | <code python> | ||
+ | Label: | ||
+ | canvas.before: | ||
+ | Color: | ||
+ | rgba: 1, 1, 1, 1 | ||
+ | Rectangle: | ||
+ | pos: self.pos | ||
+ | size: self.size | ||
+ | size_hint_y: | ||
+ | markup: True | ||
+ | text: ' | ||
+ | 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:// | + | |
===== Réception sur Android en Multicast ===== | ===== Réception sur Android en Multicast ===== | ||
Ligne 105: | Ligne 237: | ||
android.permissions = INTERNET, | android.permissions = INTERNET, | ||
</ | </ | ||
+ | Les permissions définies dans buildozer.spec crée le bouton enable/ | ||
===== Twisted dans kivy ===== | ===== Twisted dans kivy ===== | ||
- | Les 2 API ont un | + | * **[[https:// |
- | | + | |
- | pour les lancer. | + | |
- | Les deux ne peuvent pas tourner | + | =====Comment éviter ou résoudre des bugs à la compilation avec buildozer===== |
+ | ===Comment commenter | ||
+ | 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' | ||
- | La solution est: [[https://github.com/kivy/ | + | =====Bugs===== |
+ | ====Novembre 2020==== | ||
+ | Voir [[https://duckduckgo.com/?q=kivy+%27xclip%27%3A+xclip++%27xsel%27%3A+xsel& | ||
+ | [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: '[b]<<< | ||
+ | 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 | ||
+ | </ | ||
- | Erreur obtenue | ||
- | _threadselect interface of twisted is not available on Python 3 | ||
- | {{tag> | + | {{tag> kivy python |
kivy_comment_faire_un_tas_de_chose.txt · Dernière modification : 2022/11/19 09:49 de serge