issue65: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édenteProchaine révision | Révision précédente | ||
issue65:python [2012/10/18 21:29] – fredphil91 | issue65:python [2012/10/21 15:29] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 13: | Ligne 13: | ||
Ce mois-ci, nous allons terminer le programme de transposition que nous avons écrit dans Kivy. J' | Ce mois-ci, nous allons terminer le programme de transposition que nous avons écrit dans Kivy. J' | ||
- | Commençons par récapituler ce que nous avons fait le mois dernier. Nous avons créé une application qui permet à un guitariste de transposer rapidement d'une clé à une autre. Le but ultime est de pouvoir exécuter cette application non seulement sous Linux ou Windows, mais également sur un appareil Android. | + | Commençons par récapituler ce que nous avons fait le mois dernier. Nous avons créé une application qui permet à un guitariste de transposer rapidement d'une clé à une autre. Le but ultime est de pouvoir exécuter cette application non seulement sous Linux ou Windows, mais également sur un appareil Android. |
L' | L' | ||
Ligne 25: | Ligne 25: | ||
The first two lines are required. They basically say what version of Kivy to expect. Next we create a new type of label called ‘BoundedLabel’. The color is set with RGB values (between 0 and 1, which can be considered as 100 percent), and as you can see the blue value is set at 100 percent. We will also create a rectangle which is the actual label. Save this as “transpose.kv”. You must use the name of the class that will be using it.** | The first two lines are required. They basically say what version of Kivy to expect. Next we create a new type of label called ‘BoundedLabel’. The color is set with RGB values (between 0 and 1, which can be considered as 100 percent), and as you can see the blue value is set at 100 percent. We will also create a rectangle which is the actual label. Save this as “transpose.kv”. You must use the name of the class that will be using it.** | ||
- | La première chose que vous remarquerez est qu' | + | La première chose que vous remarquerez est qu' |
Nous allons commencer par créer un fichier .kv (en haut à droite). C'est ce qui va nous donner les étiquettes colorées. C'est un fichier très simple. | Nous allons commencer par créer un fichier .kv (en haut à droite). C'est ce qui va nous donner les étiquettes colorées. C'est un fichier très simple. | ||
- | Les deux premières lignes sont nécessaires. Elles indiquent simplement quelle version de Kivy est requise. Ensuite, nous créons un nouveau type d' | + | Les deux premières lignes sont nécessaires. Elles indiquent simplement quelle version de Kivy est requise. Ensuite, nous créons un nouveau type d' |
**Now that you have that completed, add the following lines just before the transpose class to the source file from last time: | **Now that you have that completed, add the following lines just before the transpose class to the source file from last time: | ||
Ligne 45: | Ligne 45: | ||
pass | pass | ||
- | Pour que ça fonctionne, il suffit d'une définition. Avant d' | + | Pour que cela fonctionne, il suffit d'une définition. Avant d' |
from kivy.uix.popup import Popup | from kivy.uix.popup import Popup | ||
Ligne 57: | Ligne 57: | ||
Be sure to save your work at this point, since we are going to be making a lot of changes from here on.** | Be sure to save your work at this point, since we are going to be making a lot of changes from here on.** | ||
- | Cela nous permet de créer | + | Cela nous permet de créer la popup plus tard. Maintenant, dans la classe Transpose, juste à l' |
- | La routine | + | La routine |
- | Vous pouvez voir que cette routine est assez explicite. Nous utilisons une variable (self.whichway) pour déterminer | + | Vous pouvez voir que cette routine est assez explicite. Nous utilisons une variable (self.quelsens) pour déterminer |
- | Assurez-vous de sauvegarder votre travail maintenant, car nous allons faire beaucoup de changements à partir de là. | + | Assurez-vous de sauvegarder votre travail maintenant, car nous allons faire beaucoup de changements à partir de maintenant. |
- | Replace the lines defining text1 and text two with the lines shown above. | + | **Replace the lines defining text1 and text two with the lines shown above. |
We set self.whichway to 0 which will be our default for the swap procedure. Then we define four strings instead of the two we had last time. You might notice that strings text3 and text4 are simple reversals of text1 and text2. | We set self.whichway to 0 which will be our default for the swap procedure. Then we define four strings instead of the two we had last time. You might notice that strings text3 and text4 are simple reversals of text1 and text2. | ||
Ligne 77: | Ligne 77: | ||
root = GridLayout(orientation=' | root = GridLayout(orientation=' | ||
- | We’ve changed the spacing from 10 to 6 and set the default row height to 40 pixels. Change the text for the label (next line) to “text=' | + | We’ve changed the spacing from 10 to 6 and set the default row height to 40 pixels. Change the text for the label (next line) to “text=' |
- | Now change the button definition line from... | + | Remplacez les lignes définissant texte1 et texte2 avec les lignes ci-dessus. |
+ | |||
+ | Nous réglons self.quelsens à 0 qui sera notre valeur par défaut pour la procédure d' | ||
+ | |||
+ | Maintenant, nous allons adapter la définition de la ligne racine. Changez-le de : | ||
+ | |||
+ | root = GridLayout(orientation=' | ||
+ | |||
+ | à : | ||
+ | |||
+ | root = GridLayout(orientation=' | ||
+ | |||
+ | Nous avons changé l' | ||
+ | |||
+ | **Now change the button definition line from... | ||
btn1 = Button(text = " | btn1 = Button(text = " | ||
Ligne 99: | Ligne 113: | ||
font_name=' | font_name=' | ||
+ | padding=(20, | ||
+ | background_color=[0.39, | ||
+ | |||
+ | Maintenant changez la définition du bouton de : | ||
+ | |||
+ | btn1 = Button(text = " | ||
+ | size_hint=(None, | ||
+ | halign=' | ||
+ | font_name=' | ||
+ | padding=(20, | ||
+ | |||
+ | à : | ||
+ | |||
+ | btn1 = Button(text = " | ||
+ | size_hint=(None, | ||
+ | halign=' | ||
+ | font_name=' | ||
padding=(20, | padding=(20, | ||
background_color=[0.39, | background_color=[0.39, | ||
- | Notice that I’ve changed the formatting of the first definition for clarity. The big changes are the size change from 680,40 to 780,20 and the background color for the button. Remember, we can change the background color for buttons, not “standard” labels. | + | **Notice that I’ve changed the formatting of the first definition for clarity. The big changes are the size change from 680,40 to 780,20 and the background color for the button. Remember, we can change the background color for buttons, not “standard” labels. |
Next, we will define three AnchorLayout widgets for the three buttons that we will add in later. I named them al0 (AnchorLayout0), | Next, we will define three AnchorLayout widgets for the three buttons that we will add in later. I named them al0 (AnchorLayout0), | ||
Ligne 110: | Ligne 141: | ||
LoadLabels(0) | LoadLabels(0) | ||
- | This calls the LoadLabels routine with our default “which” of 0. | + | This calls the LoadLabels routine with our default “which” of 0.** |
- | Next, comment out the entire for loop code. This starts with “for i in range(0, | + | Remarquez que j'ai changé le format de la première définition pour plus de clarté. Les gros changements sont la taille qui passe de 680,40 à 780,20 et la couleur de fond du bouton. Rappelez-vous, |
+ | |||
+ | Ensuite, nous allons définir trois widgets AnchorLayout pour les trois boutons que nous ajouterons plus tard. Je les ai nommés al0 (AnchorLayout0), | ||
+ | |||
+ | Trouvez la ligne « s = GridLayout » et modifiez l' | ||
+ | |||
+ | ChargeEtiquettes(0) | ||
+ | |||
+ | Ceci appelle la routine ChargeEtiquettes avec notre « quelsens » par défaut qui vaut 0. | ||
+ | |||
+ | **Next, comment out the entire for loop code. This starts with “for i in range(0, | ||
Now, save your code and try to run it. You should see a deep purple button at the top, and our pretty blue BoundLabels. Plus, you will notice that the BoundLabels in the scroll window are closer together, which makes it much easier to read. | Now, save your code and try to run it. You should see a deep purple button at the top, and our pretty blue BoundLabels. Plus, you will notice that the BoundLabels in the scroll window are closer together, which makes it much easier to read. | ||
Ligne 118: | Ligne 159: | ||
We are almost through with our code, but we still have a few things to do. After the “sv = ScrollView” line add the following line... | We are almost through with our code, but we still have a few things to do. After the “sv = ScrollView” line add the following line... | ||
- | sv.size = (720, 320) | + | sv.size = (720, 320)** |
- | This sets the size of the ScrollView widget to 720 by 320 – which makes it wider within the root window. Now, before the “return root” line, add the code shown top right. | + | Ensuite, commentez la totalité du code de la boucle for. Cela commence par « for i in range(0, |
+ | |||
+ | Maintenant, enregistrez votre code et essayez de l' | ||
+ | |||
+ | Nous sommes presque au bout de notre code, mais il nous reste quelques petites choses à faire. Après la ligne « sv = ScrollView », ajoutez la ligne suivante : | ||
+ | |||
+ | sv.size = (720, 320) | ||
+ | |||
+ | **This sets the size of the ScrollView widget to 720 by 320 – which makes it wider within the root window. Now, before the “return root” line, add the code shown top right. | ||
Here we add the three buttons to the AnchorLayout widgets, create a GridLayout to hold the AnchorLayouts, | Here we add the three buttons to the AnchorLayout widgets, create a GridLayout to hold the AnchorLayouts, | ||
Ligne 130: | Ligne 179: | ||
popup.open() | popup.open() | ||
- | That’s it. Save and run the code. If you click on the About button, you will see the simple popup. Just click anywhere outside of the popup to make it go away. | + | That’s it. Save and run the code. If you click on the About button, you will see the simple popup. Just click anywhere outside of the popup to make it go away.** |
- | Now our code is written. You can find the full code at http:// | + | Cela définit la taille du widget ScrollView à 720 sur 320, ce qui le rend plus large à l' |
+ | |||
+ | Ici nous ajoutons les trois boutons aux widgets AnchorLayout, | ||
+ | |||
+ | Retournez juste en dessous de la routine « def Echange » et ajoutez ce qui suit : | ||
+ | |||
+ | def AfficheAPropos(instance): | ||
+ | popup.open() | ||
+ | |||
+ | C'est tout. Enregistrez et exécutez le code. Si vous cliquez sur le bouton « À propos », vous verrez le popup tout simple. Cliquez n' | ||
+ | |||
+ | **Now our code is written. You can find the full code at http:// | ||
Next, we need to create our android package... but that will have to wait for next time. | Next, we need to create our android package... but that will have to wait for next time. | ||
Ligne 138: | Ligne 198: | ||
If you want to get set up and try packaging for Android before next month, you should go to http:// | If you want to get set up and try packaging for Android before next month, you should go to http:// | ||
- | See you next month. | + | See you next month.** |
+ | |||
+ | Maintenant, notre code est écrit. Vous pouvez trouver le code complet ici : http:// | ||
+ | |||
+ | Ensuite, nous devons créer notre paquet android... mais cela devra attendre la prochaine fois. | ||
+ | |||
+ | Si vous voulez vous préparer et essayer d' | ||
+ | |||
+ | Rendez-vous le mois prochain. |
issue65/python.1350588590.txt.gz · Dernière modification : 2012/10/18 21:29 de fredphil91