Outils pour utilisateurs

Outils du site


issue155:python

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
Prochaine révisionLes deux révisions suivantes
issue155:python [2020/04/03 08:51] d52frissue155:python [2020/04/03 14:37] d52fr
Ligne 147: Ligne 147:
  
 Now we’ll look at the child program. It is a bit more complicated, but not overly so. Again, I’m going to provide the code here for only the child_support.py module.** Now we’ll look at the child program. It is a bit more complicated, but not overly so. Again, I’m going to provide the code here for only the child_support.py module.**
 +
 +La seule ligne que nous avons besoin de saisir ici est le dernière. Comme nous aovns déjà importé le fichier d'affichage graphique child.py en haut du code, nous devons simplement appeler la fonction create_Toplevel1(). C'et le point d'entrée du programme quand il est appelé par un autre programme.
 +
 +Enfin, j'ai mis destroy_window() (ci-dessous), fournie par Page, jouste pour que vous la voyez.
 +
 +Maintenant, nous regardons le programme enfant. Il est un peut plus compliqué, mais pas trop. Ici encore, je vais fournir le code uniquement pour le module child_support.py.
  
 **Again, we’ll start with the import section. Notice here, that we need to import only the shared module, since we don’t need to call any functions from the parent. **Again, we’ll start with the import section. Notice here, that we need to import only the shared module, since we don’t need to call any functions from the parent.
Ligne 157: 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'importer que le module partagé, car nous besoin d'appeler aucune fonction du pavé numérique.
 +
 +import sys
 +
 +import shared
 +
 +En haut à droite, voici la définition de l'étiquette qui montre la valeur courante venant des saisies sur les boutons du clavier.
 +
 +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 163: 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'arranger avec les choses d'ici (ci-dessous) plutôt que d'essayer de le faire dans Page par le biais de l'attribut de commande.
 +
 +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 179: 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'habitude, j'ai mis le code des programmes sur Pastebin. Voici les liens ci-dessous :
 +
 +parent.py - https://pastebin.com/AZXXvuAU
 +
 +parent_support.py - https://pastebin.com/3iBHgCN0
 +
 +child.py - https://pastebin.com/bwZLnkHc
 +
 +child_support.py - https://pastebin.com/Vg0K1w5G
 +
 +J'espère que cet article vous a nourri et vous aidera à penser à quoi cela peut servir dans votre propre programmation.
 +
 +Jusqu'à la prochaine fois, continuez à coder !
 +
 +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'interroger.
 +
 +**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'étiquette d'affichage, et, ensuite, positionne le drapeau ReadyToRead à True.
 +
 +**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'affichons, la passons au module partagé et positionnons le drapeau de sorte que le programme parent la lise.
 +
issue155/python.txt · Dernière modification : 2020/04/04 18:00 de andre_domenech