Modifications

Sauter à la navigation Sauter à la recherche
aucun résumé de modification
Ligne 1 : Ligne 1 :  
{{RASP-PYGAME-GUI-NAV}}
 
{{RASP-PYGAME-GUI-NAV}}
  −
{{traduction}}
      
== Installation ==
 
== Installation ==
Ligne 42 : Ligne 40 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
{{traduction}}
+
Dans cet exemple, nous allons contrôler les GPIO #17 et #4 comme avant mais en utilisant un nouveau Framework.
 
  −
This example controls GPIO #17 and #4 as before but now we're using the new framework.
      
{{ADFImage|RASP-PYGAME-GUI-PygameUI-GPIO-00.jpg}}
 
{{ADFImage|RASP-PYGAME-GUI-PygameUI-GPIO-00.jpg}}
   −
The widget rendering and touchscreen events are handled by PygameUI. The PiTft class defines the buttons to draw on screen and the click event to be fired when a button is pressed.
+
Le rendu des widgets et gestion des événements écrans seront pris en charge par PygameUI. La classe {{fname|PiTft}} définit les boutons à dessiner sur l'écran et l'événement click (''clic'') à exécuter lorsque le bouton est pressé.
    
{{ADFImage|RASP-PYGAME-GUI-PygameUI-GPIO-01.png}}
 
{{ADFImage|RASP-PYGAME-GUI-PygameUI-GPIO-01.png}}
    
== Démarrer ==
 
== Démarrer ==
At the top here we've now imported the pygameui library. We use it quite a bit later on so {{fname|ui}} is a nice short alias for it.
+
Au début du script, nous importons la bibliothèque {{fname|pygameui}}. Comme nous l'utiliserons régulièrement dans le code, nous lui associons l'alias {{fname|ui}} (plus sympa et plus court à taper).
   −
The other key addition here is {{https://docs.python.org/2/library/logging.html logging}}. When using more libraries and frameworks it's very useful to set up logging so you can see the output in a file or, in this case, on the console. We're also able to configure the logger into {{fname|DEBUG}} mode so we can really see what's going on underneath our code and troubleshoot if needs be.
+
L'autre ajout important ici est [https://docs.python.org/2/library/logging.html logging]. Il est utile de mettre une trace (''logging'') en place Lorsque l'on utilise plusieurs bibliothèques et frameworks pour façon à voir les sorties dans un fichier (ou dans ce cas, sur une console). Il est également possible de définir le logger en mode {{fname|DEBUG}} de manière à voir ce qui se passe sous votre code et effectuer des corrections si nécessaire.
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Ligne 64 : Ligne 60 :  
import RPi.GPIO as GPIO
 
import RPi.GPIO as GPIO
 
   
 
   
#Setup the GPIOs as outputs - only 4 and 17 are available
+
# Configurer les GPIOs comme sortie (OUTPUT) - Seuls 4 et 17 sont disponibles
 
GPIO.setmode(GPIO.BCM)
 
GPIO.setmode(GPIO.BCM)
 
GPIO.setup(4, GPIO.OUT)
 
GPIO.setup(4, GPIO.OUT)
 
GPIO.setup(17, GPIO.OUT)
 
GPIO.setup(17, GPIO.OUT)
 
   
 
   
 +
# Format de trace
 +
# Definition d'un flux pour le logger (flux associé à la console)
 
log_format = '%(asctime)-6s: %(name)s - %(levelname)s - %(message)s'
 
log_format = '%(asctime)-6s: %(name)s - %(levelname)s - %(message)s'
 
console_handler = logging.StreamHandler()
 
console_handler = logging.StreamHandler()
 
console_handler.setFormatter(logging.Formatter(log_format))
 
console_handler.setFormatter(logging.Formatter(log_format))
 +
# Definir la trace
 
logger = logging.getLogger()
 
logger = logging.getLogger()
 
logger.setLevel(logging.DEBUG)
 
logger.setLevel(logging.DEBUG)
logger.addHandler(console_handler)
+
logger.addHandler(console_handler) # Sortie trace sur console
 
   
 
   
 
os.putenv('SDL_FBDEV', '/dev/fb1')
 
os.putenv('SDL_FBDEV', '/dev/fb1')
Ligne 82 : Ligne 81 :     
== Définition de l'interface utilisateur ==
 
== Définition de l'interface utilisateur ==
For some hints on how to use widgets within the framework take a look at the [https://github.com/fictorial/pygameui/blob/master/bin/pygameui-kitchensink.py kitchen sink (pygameui-kitchensink.py)] script.
+
Pour quelques astuces sur l'utilisation des widgets avec le framework vous pouvez consulter le script [https://github.com/fictorial/pygameui/blob/master/bin/pygameui-kitchensink.py kitchen sink (pygameui-kitchensink.py)] .
   −
The basic principle is that you define a class that inherits from {{fname|ui.Scene}} and in the {{fname|__init__}} method you define all the widgets. A Scene is the full window, in our case the entire display (320,240).
+
Le principe de base c'est qu'il faut définir une classe qui hérite de {{fname|ui.Scene}} et dans la méthode {{fname|__init__}} vous définissez tous les widgets. Une ''Scene'' est une fenêtre compllète, dans notre cas c'est l'afficheur en entier (320,240).
   −
Each button's position and size is defined using a {{fname|ui.Rect}} and a text label is also supplied. An {{fname|on_clicked}} handler is then assigned - this handler is called when the button is clicked. In our case this is the {{fname|gpi_button}} method.
+
La poisition et la taille de chaque bouton est défini en utilisant {{fname|ui.Rect}} et un libellé (''text label'') est également disponible. Un gestionnaire d'événement {{fname|on_clicked}} (aussi appelé "''handler''" en anglais) est alors assigné - ce ''handler'' est appelé lorsque l'on clique sur le bouton. Dans notre cas, le ''handler'' est la méthode {{fname|gpi_button}} .
   −
The  {{fname|gpi_button}} method simply looks at the label of the button that's been clicked to determine which GPIO to set on or off.
+
La méthode {{fname|gpi_button}} vérifie simplement le libellé du bouton qui à été clické pour déterminer le GPIO qu'il faut allumer ou éteindre.
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Ligne 131 : Ligne 130 :     
== La boucle principale ==
 
== La boucle principale ==
This is a key point. The main loop of you program is now taken care of by pygameui. The [https://en.wikipedia.org/wiki/Inversion_of_control control has been inverted] - we've supplied pygameui with code to call when certain user actions occur.
+
C'est le point clé du programme. La boucle principale de votre programe est maintenant pris en charge par pygameui. Le [https://en.wikipedia.org/wiki/Inversion_of_control contrôle du programme est ''inversé''] - Nous fournissons à pygameui le code a appeler lorsque certaines actions utilisateurs arrivent.
   −
The pygameui main loop is started with this final line of code:
+
La boucle principale de pygameui est démarré à l'aide de cette dernière ligne de code:
    
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Ligne 139 : Ligne 138 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
As usual, you can run this from the pygamelcd project:
+
Comme d'habitude, vous pouvez exécuter ce programme depuis le projet pygamelcd :
    
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
29 918

modifications

Menu de navigation