issue155:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédente | Prochaine révisionLes deux révisions suivantes | ||
issue155:python [2020/04/03 08:58] – d52fr | issue155:python [2020/04/03 14:37] – d52fr | ||
---|---|---|---|
Ligne 163: | Ligne 163: | ||
The first thing we do is set up a global variable to hold the accumulated value of the keypad entries. We then call the function setup_bindings() that attaches the callback function to all of the buttons of the keypad. Finally, we set the shared.child_active flag to True.** | The first thing we do is set up a global variable to hold the accumulated value of the keypad entries. We then call the function setup_bindings() that attaches the callback function to all of the buttons of the keypad. Finally, we set the shared.child_active flag to True.** | ||
+ | |||
+ | À nouveau, nous commencerons par la section des imports. Notez ici, que nos devons n' | ||
+ | |||
+ | import sys | ||
+ | |||
+ | import shared | ||
+ | |||
+ | En haut à droite, voici la définition de l' | ||
+ | |||
+ | La première chose que nous faisons est de paramétrer une variable globale pour garder la valeur cumulative des saisie du pavé. Ensuite, nous appelons la fonction setup_bindings() qui relie la fonction de rappel à tous les boutons du pavé. Enfin, nous paramétrons le drapeau shared.child_active à True. | ||
**Since we are going to pass parameters to the callback for the keypad buttons, it’s much easier to deal with things here (below) than to try to do it within Page through the command attribute. | **Since we are going to pass parameters to the callback for the keypad buttons, it’s much easier to deal with things here (below) than to try to do it within Page through the command attribute. | ||
Ligne 169: | Ligne 179: | ||
In the callback, we simply take the value (which is the number of the button) and append it, as a string, to the valu variable. We also check to see if the period key (value 10) was pressed, and if it was, then we add the period into the display value. Finally, we put the data into the DisplayLabel through the .set() method, and set shared.ReadyToRead to True, so the parent knows to pull the data.** | In the callback, we simply take the value (which is the number of the button) and append it, as a string, to the valu variable. We also check to see if the period key (value 10) was pressed, and if it was, then we add the period into the display value. Finally, we put the data into the DisplayLabel through the .set() method, and set shared.ReadyToRead to True, so the parent knows to pull the data.** | ||
+ | |||
+ | Comme nous allons passer des paramètres à la fonction de rappel pour les boutons du pavé, il est plus facile de s' | ||
+ | |||
+ | Maintenant, nous défiinissons le code de la routine de rappel (page suivante, en haut à gauche) dans le cas où un bouton du pavé serait cliqué. Notez que c'est mieux fait à partir de zéro, car Page n'a aucune idée des besoins pour cette fonction. | ||
+ | |||
+ | Dans la fonction de rappel, nous prenons simplement la valeur (qui est le numéro du bouton) et le rajoutons, sous forme de chaîne, à la variable valu. Nous vérifions aussi si la touche du point (valeur 10) a été pressée, et, si c'est la cas, nous ajoutons le point à la valeur affichée. Enfin, nous mettonsla valeur dans DisplayLabel par la méthode .set(), et réglons shared.ReadyToRead à True, de sorte que le parent saist qu'il peut prendre les données. | ||
**We don’t do anything with the Enter button, so we just leave the skeleton for later use (far right). | **We don’t do anything with the Enter button, so we just leave the skeleton for later use (far right). | ||
Ligne 185: | Ligne 201: | ||
Until next time, keep coding.** | Until next time, keep coding.** | ||
+ | |||
+ | Nous ne faisons rien du bouton Entrée ; aussi, nous gardons juste la structure pour un usage utérieur (à droite,en haut). | ||
+ | |||
+ | Comme d' | ||
+ | |||
+ | parent.py - https:// | ||
+ | |||
+ | parent_support.py - https:// | ||
+ | |||
+ | child.py - https:// | ||
+ | |||
+ | child_support.py - https:// | ||
+ | |||
+ | J' | ||
+ | |||
+ | Jusqu' | ||
+ | |||
+ | p 26, col 4, encart, lignes noires : | ||
+ | |||
+ | **Here is the init function from the child program. Again, you can see where my code starts.* | ||
+ | |||
+ | Voici la fonction init du programme enfant. À nouveau, vous pouvez voir où commence mon code. | ||
+ | |||
+ | p 25, col 4, encart, 3 § noirs : | ||
+ | |||
+ | **The callback for the Exit button is mostly the same as for the parent, but we also set shared.child_active to False, so the Parent knows to change the status square from Green to Red and not to try to poll.** | ||
+ | |||
+ | la fonction de rappel du bouton Exit est principalement identique que pour le parent, mais nous réglons aussi shared.child_active à False, de sorte que le parent sache qu'il doit changer le carré deu vert au rouge et ne plus essayer d' | ||
+ | |||
+ | **The btnClear callback function sets the global valu to an empty string, sets data into the shared module and the display label, and then sets the shared.ReadyToRead flag to True.** | ||
+ | |||
+ | La fonction de rappel btnClear charge la globale valu avec une chaîne vide, règle les données dans le module partagé et l' | ||
+ | |||
+ | **Finally, we deal with the callback for the Backspace button. We simply strip the last character from the valu string, display it, pass it to the shared module, and set the flag so that the parent program will read it.** | ||
+ | |||
+ | Enfin, nous nous occupons de la fonctiond e rapple du bouton Retour Arrière. Nous supprimons juste dernier caractère de la chaîne, l' | ||
+ |
issue155/python.txt · Dernière modification : 2020/04/04 18:00 de andre_domenech