59:tuto_python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
59:tuto_python [2012/04/10 10:36] – créée auntiee | 59:tuto_python [2012/05/01 14:26] (Version actuelle) – kai23 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | After our last meeting you should have a fairly good idea of how to use Page. If not, please read last month' | + | **After our last meeting you should have a fairly good idea of how to use Page. If not, please read last month' |
This time, the text might seem a bit terse in the design portion. All I'm going to do is give you directions for placement of widgets and the required attributes and values like this... | This time, the text might seem a bit terse in the design portion. All I'm going to do is give you directions for placement of widgets and the required attributes and values like this... | ||
Ligne 5: | Ligne 5: | ||
Widget | Widget | ||
- | Attribute: Value | + | Attribute: Value** |
- | I will only quote text string when it is needed. For example for one of the buttons, the text should be set to “...”. | + | Après notre dernière rencontre, vous devriez avoir une assez bonne idée de la façon d' |
+ | |||
+ | Cette fois, le texte peut sembler un peu laconique dans la partie conception. Tout ce que je vais faire, c'est vous donner des indications pour le placement des widgets, ainsi que les attributs et les valeurs requises, de cette façon... | ||
+ | |||
+ | Widget | ||
+ | |||
+ | Attribut: valeur | ||
+ | |||
+ | **I will only quote text string when it is needed. For example for one of the buttons, the text should be set to “...”. | ||
Here's what the GUI of our application will look like... | Here's what the GUI of our application will look like... | ||
Ligne 16: | Ligne 24: | ||
Alias: Searcher | Alias: Searcher | ||
- | Title: Searcher | + | Title: Searcher** |
- | Be sure to save often. When you save the file, save it as “Searcher”. Remember, Page puts the .tcl extension for you and when you finally generate the python code, it will be saved in the same folder. | + | Je ne citerai les chaînes de texte que lorsque cela sera nécessaire. Par exemple, pour l'un des boutons, le texte doit être réglé sur « ... ». |
+ | |||
+ | Voici à quoi va ressembler l' | ||
+ | |||
+ | Comme vous pouvez le voir, nous avons notre formulaire principal, un bouton pour quitter, une boîte de saisie de texte avec un bouton qui va appeler une boîte de dialogue pour demander le répertoire, | ||
+ | |||
+ | Nous pouvons commencer. Lancez Page et créez un nouveau widget principal. En utilisant l' | ||
+ | |||
+ | Alias : Rechercher | ||
+ | Titre : Rechercher | ||
+ | |||
+ | **Be sure to save often. When you save the file, save it as “Searcher”. Remember, Page puts the .tcl extension for you and when you finally generate the python code, it will be saved in the same folder. | ||
Next add a frame. It should go at the very top of the main frame. Set the attributes as follows. | Next add a frame. It should go at the very top of the main frame. Set the attributes as follows. | ||
Ligne 32: | Ligne 51: | ||
Text: Exit | Text: Exit | ||
- | Move this close to the center of the frame or close to the frame' | + | Move this close to the center of the frame or close to the frame' |
+ | |||
+ | Assurez-vous de sauvegarder souvent. Lorsque vous enregistrez le fichier, donnez-lui le nom « Rechercher ». Rappelez-vous, | ||
+ | |||
+ | Ensuite, ajoutez un cadre. Il devrait se placer tout en haut du cadre principal. Définissez les attributs comme suit : | ||
+ | |||
+ | Largeur : 595 | ||
+ | Hauteur : 55 | ||
+ | Position x : 0 | ||
+ | Position y : 0 | ||
+ | |||
+ | Dans ce cadre, ajoutez un bouton. Ce sera notre bouton Quitter. | ||
+ | |||
+ | Alias : btnQuitter | ||
+ | Texte : Quitter | ||
+ | |||
+ | Déplacez-le au centre de la fenêtre, ou alors sur le côté droit. J'ai mis le mien à X = 530 et Y = 10. | ||
- | Create another frame. | + | **Create another frame. |
Width: 325 | Width: 325 | ||
Ligne 49: | Ligne 84: | ||
Text: FilePath | Text: FilePath | ||
Width: 266 | Width: 266 | ||
- | Height: 21 | + | Height: 21** |
- | Add a button to the right of the entry widget. | + | Créez un autre cadre. |
+ | |||
+ | Largeur : 325 | ||
+ | Hauteur : 185 | ||
+ | Position y : 60 | ||
+ | |||
+ | Voici à quoi ce cadre va ressembler, pour vous guider à travers cette section. | ||
+ | |||
+ | Dans ce cadre, ajoutez une étiquette. Définissez l' | ||
+ | |||
+ | Dans le même cadre, ajoutez un widget de saisie. | ||
+ | |||
+ | Alias : txtChemin | ||
+ | Texte : CheminFichier | ||
+ | Largeur : 266 | ||
+ | Hauteur : 21 | ||
+ | |||
+ | **Add a button to the right of the entry widget. | ||
Alias: btnSearchPath | Alias: btnSearchPath | ||
Ligne 63: | Ligne 115: | ||
x x | x x | ||
- | The three check buttons on the left are for video files and the two on the right are for audio files. We will deal with the three on the left first, then the two on the right. | + | The three check buttons on the left are for video files and the two on the right are for audio files. We will deal with the three on the left first, then the two on the right.** |
+ | |||
+ | Ajoutez un bouton à droite de la zone de saisie. | ||
+ | |||
+ | Alias : btnCheminRecherche | ||
+ | Texte : « ... » (sans guillemets). | ||
+ | |||
+ | Ajoutez cinq (5) cases à cocher. Mettez-les dans l' | ||
+ | |||
+ | |||
+ | x | ||
+ | x x | ||
+ | x x | ||
+ | |||
+ | Les trois cases à cocher de gauche sont pour les fichiers vidéo et les deux de droite sont pour les fichiers audio. Nous allons d' | ||
- | Alias: chkAVI | + | **Alias: chkAVI |
Text: “.avi” (no quotes) | Text: “.avi” (no quotes) | ||
Variable: VchkAVI | Variable: VchkAVI | ||
Ligne 83: | Ligne 149: | ||
Alias: chkOGG | Alias: chkOGG | ||
Text: “.ogg” (no quotes) | Text: “.ogg” (no quotes) | ||
- | Variable: VchkOGG | + | Variable: VchkOGG** |
- | Finally, in this frame add a button somewhere below the five check boxes and somewhat centered within the frame. | + | Alias : chkAVI |
+ | Texte : « .avi » (sans guillemets) | ||
+ | Variable : VchkAVI | ||
+ | |||
+ | Alias : chkMKV | ||
+ | Texte : « .mkv » (sans guillemets) | ||
+ | Variable : VchkMKV | ||
+ | |||
+ | Alias : chkMV4 | ||
+ | Texte : « .mv4 » (sans guillemets) | ||
+ | Variable : VchkMV4 | ||
+ | |||
+ | Alias : chkMP3 | ||
+ | Texte : « .mp3 » (sans guillemets) | ||
+ | Variable : VchkMP3 | ||
+ | |||
+ | Alias : chkOGG | ||
+ | Texte : « .ogg » (sans guillemets) | ||
+ | Variable : VchkOGG | ||
+ | |||
+ | **Finally, in this frame add a button somewhere below the five check boxes and somewhat centered within the frame. | ||
Alias: btnGo | Alias: btnGo | ||
Ligne 100: | Ligne 186: | ||
Height: 254 | Height: 254 | ||
X Position: 10 | X Position: 10 | ||
- | Y Position: 10 | + | Y Position: 10** |
- | There. We've designed our GUI. Now all that is left to do is create our function list and bind the functions to our buttons. | + | Enfin ajoutez dans ce cadre un bouton quelque part en-dessous des cinq cases à cocher et un peu centré à l' |
+ | |||
+ | Alias : btnAller | ||
+ | Texte : ALLER ! | ||
+ | |||
+ | Maintenant, ajoutez un autre cadre en dessous du précédent. | ||
+ | |||
+ | Largeur : 565 | ||
+ | Hauteur : 265 | ||
+ | |||
+ | J'ai placé le mien à environ X = 0 et Y = 250. Vous pourriez avoir à redimensionner votre formulaire principal pour voir l' | ||
+ | |||
+ | Largeur : 550 | ||
+ | Hauteur : 254 | ||
+ | Position x : 10 | ||
+ | Position y : 10 | ||
+ | |||
+ | **There. We've designed our GUI. Now all that is left to do is create our function list and bind the functions to our buttons. | ||
In the Function list window, click the New button (the far left button). This brings up the new function editor. Change the text in the Function entry box from “py: xxx” to “py: | In the Function list window, click the New button (the far left button). This brings up the new function editor. Change the text in the Function entry box from “py: xxx” to “py: | ||
Ligne 110: | Ligne 213: | ||
| | ||
- | Notice that this is not indented. Page will do that for us when it creates the python file. | + | Notice that this is not indented. Page will do that for us when it creates the python file.** |
- | Next create another function called btnGoClick. Remember to add a passed parameter of “p1”. Leave the “pass” statement. We'll change that later. | + | Voilà. Nous avons conçu notre interface graphique. Maintenant tout ce qu'il reste à faire est de créer notre liste de fonctions et de lier ces fonctions à nos boutons. |
+ | |||
+ | Dans la fenêtre de liste des fonctions, cliquez sur le bouton Nouveau (le bouton le plus à gauche). Ceci nous amène à l' | ||
+ | |||
+ | def btnClicQuitter(p1): | ||
+ | |||
+ | sys.exit () | ||
+ | |||
+ | Notez que ce n'est pas indenté. Page le fera pour nous quand il créera le fichier python. | ||
+ | |||
+ | **Next create another function called btnGoClick. Remember to add a passed parameter of “p1”. Leave the “pass” statement. We'll change that later. | ||
Finally, add another function called “btnSearchPath”. Again, leave the pass statement. | Finally, add another function called “btnSearchPath”. Again, leave the pass statement. | ||
Ligne 122: | Ligne 235: | ||
Bind the GO button to btnGoClick and the “...” button to btnSearchPathClick. | Bind the GO button to btnGoClick and the “...” button to btnSearchPathClick. | ||
- | Save your GUI and generate the python code. | + | Save your GUI and generate the python code.** |
- | Now all we have left is to create the code that “glues” the GUI together. | + | Ensuite, créez une autre fonction appelée btnClicAller. N' |
+ | |||
+ | Enfin, ajoutez une autre fonction appelée « btnCheminRecherche ». Encore une fois, laissez l' | ||
+ | |||
+ | En tout dernier lieu, nous devons relier les boutons et les fonctions que nous venons de créer. | ||
+ | |||
+ | Faites un clic droit sur le bouton Quitter que nous avons créé, sélectionnez Lier. Une grande boîte apparaîtra. Cliquez sur le bouton Nouvelle liaison, cliquez sur bouton-1 et remplacez le mot « A FAIRE » dans la boîte de saisie de texte de droite par « btnClicQuitter ». NE METTEZ PAS les parenthèses () ici. | ||
+ | |||
+ | Liez le bouton ALLER à la fonction btnClicAller et le bouton « ... » à btnClicCheminRecherche. | ||
+ | |||
+ | Sauvegardez votre interface graphique et générez le code python. | ||
+ | |||
+ | **Now all we have left is to create the code that “glues” the GUI together. | ||
Open up the code we just generated in your favorite editor. Let's start off by examining what Page created for us. | Open up the code we just generated in your favorite editor. Let's start off by examining what Page created for us. | ||
Ligne 132: | Ligne 257: | ||
We'll be modifying the 2.x code portion to import other tkinter modules in a few moments. | We'll be modifying the 2.x code portion to import other tkinter modules in a few moments. | ||
- | Next is the “vp_start_gui()” routine. This is the program' | + | Next is the “vp_start_gui()” routine. This is the program' |
+ | |||
+ | Maintenant tout ce qu'il reste à faire est de créer le code qui « agglutine » l' | ||
+ | |||
+ | Ouvrez le code que nous venons de générer dans votre éditeur de texte favori. Commençons par examiner ce que Page a créé pour nous. | ||
+ | |||
+ | Au début du fichier se trouve l' | ||
+ | |||
+ | Nous allons modifier la portion de code 2.x dans quelques instants pour importer d' | ||
+ | |||
+ | Arrive ensuite la routine « vp_start_gui() ». C'est la routine principale du programme. Ceci met en place notre interface, définit les variables dont nous avons besoin et appelle ensuite la boucle principale Tkinter. Vous remarquerez peut-être la ligne « w = None » juste en dessous. Elle n'est pas indentée et n'a pas besoin de l' | ||
- | Next are two routines (create_Searcher and destroy_Searcher) that are used to replace the main loop routine if we are calling this application as a library. We don't need to worry about these. | + | **Next are two routines (create_Searcher and destroy_Searcher) that are used to replace the main loop routine if we are calling this application as a library. We don't need to worry about these. |
Next is the “set_Tk_var” routine. We define the tkinter variables used that need to be set up before we create the widgets. You might recognize these as the text variable for the FilePath entry widget and the variables for our check boxes. The next three routines here are the functions we created using the function editor and an “init()” function. | Next is the “set_Tk_var” routine. We define the tkinter variables used that need to be set up before we create the widgets. You might recognize these as the text variable for the FilePath entry widget and the variables for our check boxes. The next three routines here are the functions we created using the function editor and an “init()” function. | ||
Ligne 140: | Ligne 275: | ||
Run the program now. Notice that the check buttons have grayed out checks in them. We don't want that in our “release” app, so we'll create some code to clear them before the form is displayed to the user. The only functioning thing other than the check boxes is the Exit button. | Run the program now. Notice that the check buttons have grayed out checks in them. We don't want that in our “release” app, so we'll create some code to clear them before the form is displayed to the user. The only functioning thing other than the check boxes is the Exit button. | ||
- | Go ahead and end the program. | + | Go ahead and end the program.** |
- | Now, we'll take a look at the class that actually holds the GUI definition. That would be “class Searcher”. Here is where all the widgets are defined and placed in our form. You should be familiar with this by now. | + | Ensuite viennent deux routines (create_Rechercher et destroy_Rechercher) qui sont utilisées pour remplacer la routine principale si nous utilisons cette application comme une bibliothèque. Nous n' |
+ | |||
+ | Arrive ensuite la routine « initialise_var_Tk ». Nous définissons les variables Tkinter utilisées qui doivent être mises en place avant de créer les widgets. Vous pouvez sans doute reconnaître la variable texte pour le widget de saisie CheminFichier et les variables de nos cases à cocher. Les trois routines suivantes sont les fonctions que nous avons créées en utilisant l' | ||
+ | |||
+ | Exécutez le programme maintenant. Notez que les cases à cocher contiennent des coches grisées. Nous ne voulons pas cela dans notre application finale, nous allons donc créer un peu de code pour les faire disparaître avant que le formulaire ne soit affiché à l' | ||
+ | |||
+ | Utilisez-le pour terminer le programme. | ||
+ | |||
+ | **Now, we'll take a look at the class that actually holds the GUI definition. That would be “class Searcher”. Here is where all the widgets are defined and placed in our form. You should be familiar with this by now. | ||
Two more classes are created for us that hold the code to support the scrolled tree view. We don't have to change any of this. It was all created by Page for us. | Two more classes are created for us that hold the code to support the scrolled tree view. We don't have to change any of this. It was all created by Page for us. | ||
Ligne 149: | Ligne 292: | ||
We need to import a few more library modules, so under the “import sys” statement, add... | We need to import a few more library modules, so under the “import sys” statement, add... | ||
+ | |||
+ | import os | ||
+ | |||
+ | from os.path import join, getsize, exists** | ||
+ | |||
+ | Maintenant, nous allons jeter un coup d'oeil à la classe qui contient effectivement la définition de l' | ||
+ | |||
+ | Deux classes de plus sont créées, elles contiennent le code pour gérer l' | ||
+ | |||
+ | Revenons maintenant au début du code et commençons à le modifier. | ||
+ | |||
+ | Nous avons besoin d' | ||
import os | import os | ||
Ligne 154: | Ligne 309: | ||
from os.path import join, getsize, exists | from os.path import join, getsize, exists | ||
- | Now find the section that has the line “py2 = True”. As we said before, this is the section that deals with the tkinter imports for Python version 2.x. Below the “import ttk”, we need to add the following to support the FileDialog library. We also need to import the tkFont module. | + | **Now find the section that has the line “py2 = True”. As we said before, this is the section that deals with the tkinter imports for Python version 2.x. Below the “import ttk”, we need to add the following to support the FileDialog library. We also need to import the tkFont module. |
import tkFileDialog | import tkFileDialog | ||
Ligne 166: | Ligne 321: | ||
exts = [] | exts = [] | ||
- | FileList=[] | + | FileList=[]** |
+ | |||
+ | Maintenant, trouvez la section qui contient la ligne « py2 = True ». Comme nous l' | ||
+ | |||
+ | import tkFileDialog | ||
+ | |||
+ | import tkFont | ||
+ | |||
+ | Ensuite nous devons ajouter quelques variables à la routine « initialise_var_Tk() ». En bas de la routine, ajoutez les lignes suivantes : | ||
+ | |||
+ | global exts, FileList | ||
+ | |||
+ | exts = [] | ||
+ | |||
+ | ListeFichiers=[] | ||
- | Here we create two global variables (exts and FileList) that will be accessed later on in our code. Both are lists. “exts” is a list of the extensions that the user selects from the GUI. “FileList" | + | **Here we create two global variables (exts and FileList) that will be accessed later on in our code. Both are lists. “exts” is a list of the extensions that the user selects from the GUI. “FileList" |
Since our “btnExitClick” is already done for us by Page, we'll deal with the “btnGoClick” routine. Comment out the pass statement and add the code so it looks like this... | Since our “btnExitClick” is already done for us by Page, we'll deal with the “btnGoClick” routine. Comment out the pass statement and add the code so it looks like this... | ||
Ligne 184: | Ligne 353: | ||
Walkit(fp, | Walkit(fp, | ||
- | LoadDataGrid() | + | LoadDataGrid()** |
- | This is the routine that will be called when the user clicks the “GO!” button. We call a routine called “BuildExts” which creates the list of the extensions that the user has selected. Then we get the path that the user has selected from the AskDirectory dialog and assign that to the fp variable. We then create a tuple from the extension list, which is needed when we check for files. We then call a routine called “Walkit”, | + | Ici, nous créons deux variables globales (exts et ListeFichiers) qui seront utilisées plus tard dans notre code. Les deux sont des listes. « exts » est une liste des extensions que l' |
+ | |||
+ | Puisque notre « btnClicQuitter » est déjà créé pour nous par Page, nous allons nous occuper de la routine « btnClicAller ». Commentez la déclaration pass et ajoutez le code de sorte qu'il ressemble à ceci : | ||
+ | |||
+ | def btnClicAller(p1) : | ||
+ | |||
+ | #pass | ||
+ | |||
+ | ConstruireExts() | ||
+ | |||
+ | chemin = CheminFichier.get() | ||
+ | |||
+ | e1 = tuple(exts) | ||
+ | |||
+ | Parcourir(chemin, | ||
+ | |||
+ | ChargerDonnees() | ||
+ | |||
+ | **This is the routine that will be called when the user clicks the “GO!” button. We call a routine called “BuildExts” which creates the list of the extensions that the user has selected. Then we get the path that the user has selected from the AskDirectory dialog and assign that to the fp variable. We then create a tuple from the extension list, which is needed when we check for files. We then call a routine called “Walkit”, | ||
Finally we call a routine called “LoadDataGrid”. | Finally we call a routine called “LoadDataGrid”. | ||
Ligne 198: | Ligne 385: | ||
path = tkFileDialog.askdirectory() # | path = tkFileDialog.askdirectory() # | ||
- | | + | |
- | The init routine is next. Again, make the code look like this... | + | C'est la routine qui est appelée lorsque l' |
+ | |||
+ | Enfin, nous appelons une routine nommée « ChargerDonnees ». | ||
+ | |||
+ | Ensuite, nous devons étoffer la routine « btnClicCheminRecherche ». Commentez la déclaration pass et modifiez le code pour qu'il ressemble à ceci : | ||
+ | |||
+ | def btnClicCheminRecherche(p1) : | ||
+ | |||
+ | # | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | **The init routine is next. Again, make the code look like this... | ||
def init(): | def init(): | ||
Ligne 214: | Ligne 415: | ||
| | ||
- | | + | |
- | Here we create a global called “treeview”. We then call a routine that will clear the gray checks from the check boxes, assign the “treeview” variable to point to the Scrolled treeview in our form and call “SetupTreeview” to set the headers for the columns. | + | Puis vient la routine init. À nouveau, le code doit ressembler à ceci : |
+ | |||
+ | def init(): | ||
+ | |||
+ | # | ||
+ | |||
+ | # se lance apres la creation des fenetres et des widgets... | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | **Here we create a global called “treeview”. We then call a routine that will clear the gray checks from the check boxes, assign the “treeview” variable to point to the Scrolled treeview in our form and call “SetupTreeview” to set the headers for the columns. | ||
Here's the code for the BlankChecks routine which needs to be next. | Here's the code for the BlankChecks routine which needs to be next. | ||
def BlankChecks(): | def BlankChecks(): | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | Ici, nous créons une variable globale appelée VueArborescente. Nous appelons ensuite une routine qui efface les contrôles gris dans les cases à cocher, affectons la variable VueArborescente pour pointer vers l' | ||
+ | Voici le code de la routine InitialiserCases qui doit être la suivante : | ||
+ | |||
+ | def InitialiserCases(): | ||
| | ||
Ligne 231: | Ligne 463: | ||
| | ||
- | Here, all we are doing is setting the variables (which automatically sets the check state in our check boxes) to “0”. If you remember, whenever the check box is clicked, this variable is automatically updated. If the variable is changed by our code, the check box responds as well. Now (above right) we'll deal with the routine that builds the list of extensions from what the user has clicked. | + | **Here, all we are doing is setting the variables (which automatically sets the check state in our check boxes) to “0”. If you remember, whenever the check box is clicked, this variable is automatically updated. If the variable is changed by our code, the check box responds as well. Now (above right) we'll deal with the routine that builds the list of extensions from what the user has clicked. |
Cast your memory back to my ninth article in FCM#35. We wrote some code to create a catalog of MP3 files. We'll use a shortened version of that routine (middle right). Refer back to FCM#35 if you have questions about this routine. | Cast your memory back to my ninth article in FCM#35. We wrote some code to create a catalog of MP3 files. We'll use a shortened version of that routine (middle right). Refer back to FCM#35 if you have questions about this routine. | ||
- | Next (bottom right) we call the SetupTreeview routine. It's fairly straightforward. We define a variable “ColHeads” with the headings we want in each column of the treeview. We do this as a list. We then set the heading attribute for each column. We also set the column width to the size of this header. | + | Next (bottom right) we call the SetupTreeview routine. It's fairly straightforward. We define a variable “ColHeads” with the headings we want in each column of the treeview. We do this as a list. We then set the heading attribute for each column. We also set the column width to the size of this header.** |
- | Finally we have to create the “LoadDataGrid” routine (next page, top right) which is where we load our data into the treeview. Each row of the treeview is one entry in the FileList list variable. We also adjust the width of each column (again) to match the size of the column data. | + | Ici, tout ce que nous faisons, c'est de définir les variables (ce qui définit automatiquement l' |
+ | |||
+ | Essayez de vous rappeler mon neuvième article dans le FCM n° 35. Nous avions écrit du code pour créer un catalogue de fichiers MP3. Nous allons utiliser une version abrégée de cette routine (au milieu à droite). Reportez-vous au FCM n°35 si vous avez des questions au sujet de cette routine. | ||
+ | |||
+ | Ensuite (en bas à droite) nous appelons la routine InitialiserVueArborescente. C'est assez simple. Nous définissons une variable « TitresColonnes » avec les rubriques que nous voulons dans chaque colonne de l' | ||
+ | |||
+ | **Finally we have to create the “LoadDataGrid” routine (next page, top right) which is where we load our data into the treeview. Each row of the treeview is one entry in the FileList list variable. We also adjust the width of each column (again) to match the size of the column data. | ||
That's it for the first blush of the application. Give it a run and see how we did. Notice that if you have a large number of files to go through, the program looks like it's not responding. This is something that needs to be fixed. We'll create routines to change our cursor from the default to a “watch” style cursor and back so when we do something that takes a long time, the user will notice. | That's it for the first blush of the application. Give it a run and see how we did. Notice that if you have a large number of files to go through, the program looks like it's not responding. This is something that needs to be fixed. We'll create routines to change our cursor from the default to a “watch” style cursor and back so when we do something that takes a long time, the user will notice. | ||
Ligne 249: | Ligne 487: | ||
preBusyCursors = None | preBusyCursors = None | ||
- | busyWidgets = (root, ) | + | busyWidgets = (root, )** |
- | What we do here is set up global variables, assign them and then we set the widget(s) (in busyWidgets) we wish to respond to the cursor change. In this case we set it to root which is our full window. Notice that this is a tuple. | + | Enfin, nous devons créer la routine « ChargerDonnees » (page suivante, en haut à droite) qui est l' |
+ | |||
+ | C'est tout pour la première vue de l' | ||
+ | |||
+ | Dans la routine « initialise_var_Tk », ajoutez le code suivant à la fin. | ||
+ | |||
+ | global CurseurOccupe, | ||
+ | |||
+ | CurseurOccupe = ' | ||
+ | |||
+ | CurseursPresqueOccupes = None | ||
+ | |||
+ | WidgetsOccupes = (racine, ) | ||
+ | |||
+ | **What we do here is set up global variables, assign them and then we set the widget(s) (in busyWidgets) we wish to respond to the cursor change. In this case we set it to root which is our full window. Notice that this is a tuple. | ||
Next we create two routines to set and unset the cursor. First the set routine, which we will call “busyStart”. After our “LoadDataGrid” routine, insert the code shown middle right. | Next we create two routines to set and unset the cursor. First the set routine, which we will call “busyStart”. After our “LoadDataGrid” routine, insert the code shown middle right. | ||
Ligne 259: | Ligne 511: | ||
Now put the code shown bottom right below it. | Now put the code shown bottom right below it. | ||
- | In this routine, we basically reset the cursor for the widgets in our busyWidget tuple back to our default cursor. | + | In this routine, we basically reset the cursor for the widgets in our busyWidget tuple back to our default cursor.** |
- | Save and run your program. You should find that the cursor changes whenever you have a long list of files to go through. | + | Ici, nous mettons en place des variables globales, nous les initialisons, |
+ | |||
+ | Ensuite, nous créons deux routines pour modifier et remettre le curseur. D' | ||
+ | |||
+ | Nous vérifions d' | ||
+ | |||
+ | Maintenant, mettez le code que vous voyez en bas juste en dessous. | ||
+ | |||
+ | Dans cette routine, nous réinitialisons simplement le curseur pour les widgets dans notre tuple WidgetsOccupes à notre curseur par défaut. | ||
+ | |||
+ | **Save and run your program. You should find that the cursor changes whenever you have a long list of files to go through. | ||
While this application doesn' | While this application doesn' | ||
Ligne 267: | Ligne 529: | ||
The tcl file is saved in pastebin at http:// | The tcl file is saved in pastebin at http:// | ||
- | See you next time. | + | See you next time.** |
+ | |||
+ | Enregistrez et exécutez votre programme. Vous devrez voir que le curseur change chaque fois que vous avez une longue liste de fichiers à parcourir. | ||
+ | |||
+ | Cette application ne fait pas vraiment grand chose, mais elle vous a montré comment utiliser Page pour développer très rapidement. Avec l' | ||
+ | |||
+ | Le fichier tcl est enregistré sur pastebin : http:// | ||
+ | |||
+ | Rendez-vous la prochaine fois. |
59/tuto_python.1334046982.txt.gz · Dernière modification : 2012/04/10 10:36 de auntiee