numero61:python_p._7-9
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
numero61:python_p._7-9 [2012/05/26 15:51] – créée andre_domenech | numero61:python_p._7-9 [2012/07/20 12:34] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | This time, we’ll set up the Android SDK on our Linux desktop. We’ll also create a virtual Android device, install SL4A and python on it, and do a quick test. | + | **This time, we’ll set up the Android SDK on our Linux desktop. We’ll also create a virtual Android device, install SL4A and python on it, and do a quick test. |
Please be aware, this is not something you would want to do for machines that have less than 1 GB of ram. The emulator eats up a huge amount of memory. I’ve tried it on a laptop running Ubuntu with only 512 MB of ram. It WILL work, but it is REALLY slow. | Please be aware, this is not something you would want to do for machines that have less than 1 GB of ram. The emulator eats up a huge amount of memory. I’ve tried it on a laptop running Ubuntu with only 512 MB of ram. It WILL work, but it is REALLY slow. | ||
Ligne 9: | Ligne 9: | ||
• Test AVD, and install SL4A and Python. | • Test AVD, and install SL4A and Python. | ||
- | In reality, we should also install Eclipse and the Android ADT plugin for Eclipse, but, since we won’t be dealing with Eclipse in this set of articles, we can bypass that. If you want to include those steps, head over to http:// | + | In reality, we should also install Eclipse and the Android ADT plugin for Eclipse, but, since we won’t be dealing with Eclipse in this set of articles, we can bypass that. If you want to include those steps, head over to http:// |
- | STEP 1 - Java JDK 6 | + | Ce mois-ci, nous allons mettre en place le SDK Android sur notre bureau Linux. Nous allons aussi créer un périphérique Android virtuel, installer SL4A et Python dessus, et faire un test rapide. |
+ | |||
+ | S'il vous plaît faites attention, ce n'est pas quelque chose qu'il faut faire sur une machine qui a moins de 1 Go de RAM. L' | ||
+ | |||
+ | Voici une liste rapide de ce que nous allons faire. Nous allons y aller étape par étape dans une minute : | ||
+ | • Installer le JDK6 Java. | ||
+ | • Installer le pack de démarrage SDK Android. | ||
+ | • Créer et configurer les AVD. | ||
+ | • Tester AVD et installer SL4A et Python. | ||
+ | |||
+ | En réalité, nous devrions également installer Eclipse et le plugin Android ADT pour Eclipse, mais, puisque nous n' | ||
+ | |||
+ | **STEP 1 - Java JDK 6 | ||
From everything I’ve read and tried, it must be the actual Sun release. OpenJDK is not supposed to work. You can find information on this on the web, but here’s the steps that I did. In a terminal, type the following... | From everything I’ve read and tried, it must be the actual Sun release. OpenJDK is not supposed to work. You can find information on this on the web, but here’s the steps that I did. In a terminal, type the following... | ||
Ligne 25: | Ligne 37: | ||
export JAVA_HOME=”/ | export JAVA_HOME=”/ | ||
- | Save the file and move on to step 2. | + | Save the file and move on to step 2.** |
- | STEP 2 - Android SDK Starter Pack | + | ÉTAPE 1 - Java JDK 6 |
+ | |||
+ | D' | ||
+ | |||
+ | sudo add-apt-repository ppa: | ||
+ | |||
+ | sudo apt-get update | ||
+ | |||
+ | sudo apt-get install sun-java6-jdk | ||
+ | |||
+ | Une fois que tout ceci est fait, vous devrez modifier votre fichier .bashrc pour régler « JAVA_HOME » pour que tout fonctionne correctement. J'ai utilisé gedit pour ajouter la ligne suivante à la fin du fichier : | ||
+ | |||
+ | export JAVA_HOME=”/ | ||
+ | |||
+ | Enregistrez le fichier et passez à l' | ||
+ | |||
+ | **STEP 2 - Android SDK Starter Pack | ||
Now the actual “fun” begins. You’ll want to go to developer.android.com/ | Now the actual “fun” begins. You’ll want to go to developer.android.com/ | ||
- | Now the boring part. Run the android file, and the Android SDK Manager will start. It will go out and update the platforms that are available. I will warn you now that this process will take some time, so don’t bother if you don’t have a lot of time to deal with it. For the sake of brevity, I would suggest you get only one platform to start. A good one to begin with is the Android 2.1 platform, since, for the most part, if you develop for an older platform, there should be no problem running on a newer platform. You also need to get the Tools set as well. Simply check the box next to those two items, then click on the install button. Once you get the platform of your choice, and the tool set, you are almost ready to create your first virtual machine. | + | Now the boring part. Run the android file, and the Android SDK Manager will start. It will go out and update the platforms that are available. I will warn you now that this process will take some time, so don’t bother if you don’t have a lot of time to deal with it. For the sake of brevity, I would suggest you get only one platform to start. A good one to begin with is the Android 2.1 platform, since, for the most part, if you develop for an older platform, there should be no problem running on a newer platform. You also need to get the Tools set as well. Simply check the box next to those two items, then click on the install button. Once you get the platform of your choice, and the tool set, you are almost ready to create your first virtual machine.** |
- | STEP 3 - Create and set up your first AVD | + | ÉTAPE 2 - Pack de démarrage Android SDK |
+ | |||
+ | Maintenant, la partie « marrante » commence. Rendez-vous sur developer.android.com/ | ||
+ | |||
+ | Maintenant, la partie ennuyeuse. Exécutez le fichier android ; le gestionnaire de SDK Android va démarrer. Il va mettre à jour les plateformes qui sont disponibles. Je vous préviens maintenant que ce processus prendra un certain temps, alors ne vous embêtez pas si vous n'avez pas beaucoup de temps pour y faire face. Par souci de concision, je vous conseille de n' | ||
+ | |||
+ | **STEP 3 - Create and set up your first AVD | ||
Back in the Android SDK Manager, select Tools from the main menu, then select Manage AVDs. This will open a new window. Since this is the first time, there won’t be any virtual devices set up. Click on the “New” button. This opens yet another window where we define the properties of the virtual Android device. Here’s the steps that you should use to set up a simple Android emulator device: | Back in the Android SDK Manager, select Tools from the main menu, then select Manage AVDs. This will open a new window. Since this is the first time, there won’t be any virtual devices set up. Click on the “New” button. This opens yet another window where we define the properties of the virtual Android device. Here’s the steps that you should use to set up a simple Android emulator device: | ||
Ligne 42: | Ligne 76: | ||
• Create the device. | • Create the device. | ||
- | So, In the name text box, type “Test1”. Under the target combo-box, select Android 2.1 - API Level 7. In the text box for “SD Card:” enter 512 and make sure the dropdown shows “MiB”. Under “Skin”, set the resolution to 800x600. (You can play with the other built-in sizes on your own.) Finally, click the “Create AVD” button. Soon, you’ll see a message box saying that the AVD was created. | + | So, In the name text box, type “Test1”. Under the target combo-box, select Android 2.1 - API Level 7. In the text box for “SD Card:” enter 512 and make sure the dropdown shows “MiB”. Under “Skin”, set the resolution to 800x600. (You can play with the other built-in sizes on your own.) Finally, click the “Create AVD” button. Soon, you’ll see a message box saying that the AVD was created.** |
- | STEP 4 - Testing the AVD and installing SL4A and Python | + | ÉTAPE 3 - Créer et configurer votre première AVD |
+ | |||
+ | Retournez dans le Gestionnaire de SDK Android, sélectionnez Outils (« Tools ») dans le menu principal, puis sélectionnez « Gérer les AVD ». Cela va ouvrir une nouvelle fenêtre. Puisque c'est la première fois, il n'y aura pas encore de périphérique virtuel configuré. Cliquez sur le bouton « Nouveau ». Cela ouvre une autre fenêtre où nous définissons les propriétés du périphérique virtuel Android. Voici les étapes que vous devrez suivre pour mettre en place un dispositif émulateur Android simple : | ||
+ | • Définissez le nom de l' | ||
+ | • Réglez le niveau de plateforme cible. | ||
+ | • Définissez la taille de la carte SD (voir ci-dessous). | ||
+ | • Réglez la résolution. | ||
+ | • Créez le périphérique. | ||
+ | |||
+ | Par exemple, dans la zone de texte Nom, tapez « Test1 ». Pour la cible, sélectionnez Android 2.1 - API de niveau 7. Dans la boîte pour « Carte SD : », entrez 512 et assurez-vous que la liste affiche « Mio ». Dans « Skin », réglez la résolution à 800x600. (Vous pouvez jouer avec les autres paramètres de tailles.) Enfin, cliquez sur le bouton « Créer AVD ». Vous verrez alors un message disant que l'AVD a été créée. | ||
+ | |||
+ | **STEP 4 - Testing the AVD and installing SL4A and Python | ||
Now, finally, we can have a bit of fun. Highlight the AVD you just created and click on the Start button. In the dialog box that pops up, simply click the “Launch” button. Now, you have to wait a few minutes for the virtual device to be created in memory, and the Android platform to be loaded and started. (We’ll talk about speeding this process up in later runs.) | Now, finally, we can have a bit of fun. Highlight the AVD you just created and click on the Start button. In the dialog box that pops up, simply click the “Launch” button. Now, you have to wait a few minutes for the virtual device to be created in memory, and the Android platform to be loaded and started. (We’ll talk about speeding this process up in later runs.) | ||
Ligne 50: | Ligne 95: | ||
Once the AVD starts up and you have the “home” screen up, you will install SL4A. Using the browser or the google web search box on the home screen, search for “sl4a”. Go to the downloads page, and you’ll eventually find the web page for the downloads at http:// | Once the AVD starts up and you have the “home” screen up, you will install SL4A. Using the browser or the google web search box on the home screen, search for “sl4a”. Go to the downloads page, and you’ll eventually find the web page for the downloads at http:// | ||
- | Scroll down the page until you get to the sl4a_r5 link. Open the link and tap on the “sl4a_r5.apk” link. Notice I said “tap” rather than “click”. Start thinking about using your finger to tap the screen rather than clicking the mouse. It will make your programming transition easier. You’ll see the download start. You may have to pull down the notification bar at the top to get to the downloaded file. Tap on that, then tap the install button. | + | Scroll down the page until you get to the sl4a_r5 link. Open the link and tap on the “sl4a_r5.apk” link. Notice I said “tap” rather than “click”. Start thinking about using your finger to tap the screen rather than clicking the mouse. It will make your programming transition easier. You’ll see the download start. You may have to pull down the notification bar at the top to get to the downloaded file. Tap on that, then tap the install button.** |
+ | |||
+ | ÉTAPE 4 - Test de l'AVD et installation de SL4A et Python | ||
+ | |||
+ | Maintenant, enfin, nous pouvons nous amuser un peu. Mettez en surbrillance l'AVD que vous venez de créer et cliquez sur le bouton Démarrer. Dans la boîte de dialogue qui apparaît, cliquez simplement sur le bouton « Lancer ». Vous devez alors attendre quelques minutes pour que le périphérique virtuel soit créé dans la mémoire et que la plateforme Android soit chargée et démarrée. (Nous reparlerons de l' | ||
+ | |||
+ | Une fois que l'AVD a démarré et que vous avez l' | ||
+ | |||
+ | Faites défiler la page jusqu' | ||
- | Once the file is downloaded, you’ll be presented with the option to open the downloaded app or to tap “Done” to exit the installer. Here we will want to tap “Open”. | + | **Once the file is downloaded, you’ll be presented with the option to open the downloaded app or to tap “Done” to exit the installer. Here we will want to tap “Open”. |
Now SL4A will start. You’ll probably see a dialog asking if you will agree to usage tracking. Either accept or refuse this - it’s up to you. Before we go any farther, you should know some keyboard shortcuts that will help you move around. Since we don’t have a “real” Android device, buttons like Back, Home, and Menu, aren’t available. You’ll need them to navigate around. Here’s a few important shortcuts. | Now SL4A will start. You’ll probably see a dialog asking if you will agree to usage tracking. Either accept or refuse this - it’s up to you. Before we go any farther, you should know some keyboard shortcuts that will help you move around. Since we don’t have a “real” Android device, buttons like Back, Home, and Menu, aren’t available. You’ll need them to navigate around. Here’s a few important shortcuts. | ||
Ligne 58: | Ligne 111: | ||
Back - Escape | Back - Escape | ||
Home - Home | Home - Home | ||
+ | Menu - F2** | ||
+ | |||
+ | Une fois le fichier téléchargé, | ||
+ | |||
+ | Maintenant SL4A va démarrer. Vous verrez probablement une boîte de dialogue vous demandant si vous acceptez un suivi de l' | ||
+ | |||
+ | Retour - Échap | ||
+ | Accueil - Début | ||
Menu - F2 | Menu - F2 | ||
- | Now we will want to download and install python into SL4A. To do this, first tap Menu (press F2). Select “View” from the menu. Now select “Interpreters”. It looks like nothing happened, but tap Menu again (F2), then select “Add” from the popup. Now scroll down and select “Python 2.6.2”. This will download the base package for Python for Android. Install the package, then open it. You will be presented with four options. Install, Import Modules, Browse Modules, and Uninstall Module. Tap on Install. This will start downloading and installing all the pieces of the latest Python for Android. This can take a few minutes. | + | **Now we will want to download and install python into SL4A. To do this, first tap Menu (press F2). Select “View” from the menu. Now select “Interpreters”. It looks like nothing happened, but tap Menu again (F2), then select “Add” from the popup. Now scroll down and select “Python 2.6.2”. This will download the base package for Python for Android. Install the package, then open it. You will be presented with four options. Install, Import Modules, Browse Modules, and Uninstall Module. Tap on Install. This will start downloading and installing all the pieces of the latest Python for Android. This can take a few minutes. |
+ | |||
+ | Once everything is done, tap Back (escape key) until you get to the SL4A Interpreters screen. Now everything is loaded for us to play in Python on Android. Tap Python 2.6.2, and you’ll be in the “standard” Python shell. This is just like the shell on your desktop. Type the following three lines, one at a time, into the shell. Be sure to wait for the “>>> | ||
+ | |||
+ | Maintenant, nous voulons télécharger et installer Python dans SL4A. Pour faire cela, appuyez d' | ||
- | Once everything is done, tap Back (escape key) until you get to the SL4A Interpreters screen. Now everything is loaded for us to play in Python | + | Une fois que tout est terminé, appuyez sur Retour |
- | import android | + | **import android |
droid = android.Android() | droid = android.Android() | ||
Ligne 72: | Ligne 137: | ||
After you type the last line and press Enter, you’ll see a rounded corner box at the center bottom of the shell that says “Hello from Python on Android”. That’s what the “droid.makeToast” command does. | After you type the last line and press Enter, you’ll see a rounded corner box at the center bottom of the shell that says “Hello from Python on Android”. That’s what the “droid.makeToast” command does. | ||
- | You’ve written your first Python script for Android. Neat, huh? | + | You’ve written your first Python script for Android. Neat, huh?** |
- | Now let’s create a shortcut on the Android home screen. Tap the Home key (Home button). If you chose the 2.1 platform, you should see a slider bar on the far right of the screen. If you chose another platform, it might be a square or rectangle consisting of small squares. Either way, this gets you to the Apps screen. Tap that, and find the SL4A icon. Now perform a “long tap” (long click), which will create a shortcut on the Home screen. Move the shortcut wherever you want it. | + | import android |
- | Next, we will create our first saved script. Go back into SL4A. You should be presented with the sample scripts that come with Python 4 Android. Tap the Menu button and select “Add”. Select “Python 2.6.2” from the list. You’ll be presented with the script editor. At the top is the filename box with “.py” already filled out. Below that is the editor window that already has the first two lines of our program entered for us. (I included them below in italics so you can check it. We also used these two lines in our first sample.) | + | droid = android.Android() |
- | import android | + | droid.makeToast(" |
+ | |||
+ | Après avoir tapé la dernière ligne et appuyé sur Entrée, vous verrez une fenêtre aux coins arrondis centrée en bas de la ligne de commande, qui dit : « Bonjour depuis Python pour Android ». C'est ce que fait la commande droid.makeToast. | ||
+ | |||
+ | Vous avez écrit votre premier script Python pour Android. Chouette, hein ? | ||
+ | |||
+ | **Now let’s create a shortcut on the Android home screen. Tap the Home key (Home button). If you chose the 2.1 platform, you should see a slider bar on the far right of the screen. If you chose another platform, it might be a square or rectangle consisting of small squares. Either way, this gets you to the Apps screen. Tap that, and find the SL4A icon. Now perform a “long tap” (long click), which will create a shortcut on the Home screen. Move the shortcut wherever you want it. | ||
+ | |||
+ | Next, we will create our first saved script. Go back into SL4A. You should be presented with the sample scripts that come with Python 4 Android. Tap the Menu button and select “Add”. Select “Python 2.6.2” from the list. You’ll be presented with the script editor. At the top is the filename box with “.py” already filled out. Below that is the editor window that already has the first two lines of our program entered for us. (I included them below in italics so you can check it. We also used these two lines in our first sample.)** | ||
+ | |||
+ | Maintenant, nous allons créer un raccourci sur l' | ||
+ | |||
+ | Ensuite nous allons créer notre premier script sauvegardé. Retournez dans SL4A. Vous devriez voir les exemples de scripts fournis avec Python pour Android. Tapez sur le bouton Menu et sélectionnez « Ajouter ». Sélectionnez « Python 2.6.2 » dans la liste. Vous verrez l' | ||
+ | |||
+ | **import android | ||
droid = android.Android() | droid = android.Android() | ||
Ligne 86: | Ligne 165: | ||
uname = droid.dialogGetInput(“What’s your name?”) | uname = droid.dialogGetInput(“What’s your name?”) | ||
- | droid.makeToast(“Hello %s from Python on Android”) % uname.result | + | droid.makeToast(“Hello %s from Python on Android”) % uname.result** |
- | The first new line will create a dialog box (droid.dialogGetInput()) that asks for the user’s name. The response is returned to our program in uname.result. We’ve already used the droid.makeToast() function. | + | import android |
+ | |||
+ | droid = android.Android() | ||
+ | |||
+ | Maintenant saisissez les deux lignes suivantes dans le script python : | ||
+ | |||
+ | uname = droid.dialogGetInput(" | ||
+ | |||
+ | droid.makeToast(" | ||
+ | |||
+ | **The first new line will create a dialog box (droid.dialogGetInput()) that asks for the user’s name. The response is returned to our program in uname.result. We’ve already used the droid.makeToast() function. | ||
Name the file andtest1.py, | Name the file andtest1.py, | ||
- | That’s all for this time. For now, there’s a TON of documentation about SL4A for free on the web. You can play a bit on your own until next time. I’d suggest that you start by going to http:// | + | That’s all for this time. For now, there’s a TON of documentation about SL4A for free on the web. You can play a bit on your own until next time. I’d suggest that you start by going to http:// |
+ | La première ligne nouvelle crée une boîte de dialogue (droid.dialogGetInput()) qui demande son nom à l' | ||
- | ANNONCE | + | Nommez le fichier andtest1.py, |
+ | |||
+ | C'est tout pour cette fois-ci. Pour l' | ||
+ | |||
+ | **ANNONCE | ||
Santa Clara Convention Center | Santa Clara Convention Center | ||
Ligne 103: | Ligne 197: | ||
Take advantage of this rare opportunity to meet face-to-face with a cadre of industry leaders who are taking web performance and operations to the next level. Velocity packs a wealth of big ideas, know-how, and connections into three concentrated days. You'll be able to apply what you've learned immediately and you'll be well prepared for what lies ahead with four in-depth tracks covering the key aspects of web performance, | Take advantage of this rare opportunity to meet face-to-face with a cadre of industry leaders who are taking web performance and operations to the next level. Velocity packs a wealth of big ideas, know-how, and connections into three concentrated days. You'll be able to apply what you've learned immediately and you'll be well prepared for what lies ahead with four in-depth tracks covering the key aspects of web performance, | ||
- | Velocity has sold out the last two years, so if you want to reserve your spot at Velocity 2012, register now and save an additional 20% with code FULLCIR. | + | Velocity has sold out the last two years, so if you want to reserve your spot at Velocity 2012, register now and save an additional 20% with code FULLCIR.** |
+ | |||
+ | ANNONCE | ||
+ | |||
+ | Centre de conventions de Santa Clara | ||
+ | |||
+ | O' | ||
+ | |||
+ | Profitez de cette occasion rare de rencontrer en face-à-face un groupe de leaders de l' | ||
+ | Les deux dernières années, Vélocity a fait salle comble ; ainsi, si vous souhaitez réserver votre place pour Velocity 2012, inscrivez-vous maintenant et économisez 20% supplémentaires avec le code FULLCIR. |
numero61/python_p._7-9.1338040268.txt.gz · Dernière modification : 2012/05/26 15:51 de andre_domenech