Modifications

Sauter à la navigation Sauter à la recherche
369 octets ajoutés ,  3 mars 2015 à 07:38
Ligne 43 : Ligne 43 :  
{{traduction}}
 
{{traduction}}
   −
To disable the switch callback, pass None to the callback function:
+
Pour désactiver le ''callback'' du bouton, il suffit de passer {{fname|None}} comme fonction ''callback'':
    
  <nowiki>>>> sw.callback(None)</nowiki>
 
  <nowiki>>>> sw.callback(None)</nowiki>
   −
You can pass any function (that takes zero arguments) to the switch callback. Above we used the {{fname|lambda}} feature of Python to create an anonymous function on the fly. But we could equally do:
+
Vous pouvez passer n'importe quelle fonction (qui prend 0 arguments) en tant que fonction callback pour le switch. Ci-dessus, nous utilisons la fonctionnalité {{fname|lambda}} (expression lambda) de Python, cela permet de créer une fonction anonyme (sans nom) à la volée. Mais vous pourriez également faire ceci:
    
  <nowiki>>>> def f():
 
  <nowiki>>>> def f():
Ligne 54 : Ligne 54 :  
>>> sw.callback(f)</nowiki>
 
>>> sw.callback(f)</nowiki>
   −
This creates a function called {{fname|f}} and assigns it to the switch callback. You can do things this way when your function is more complicated than a {{fname|lambda}} will allow.
+
Ce bout de code crée une fonction appelée {{fname|f}} et l'utilise somme fonction callback pour le switch. Vous pouvez utiliser cette methode lorsque le code de la fonction de rappel est plus compliqué que ce que autorise les expressions {{fname|lambda}}.
   −
Note that your callback functions must not allocate any memory (for example they cannot create a tuple or list). Callback functions should be relatively simple. If you need to make a list, make it beforehand and store it in a global variable (or make it local and close over it). If you need to do a long, complicated calculation, then use the callback to set a flag which some other code then responds to.
+
{{ambox|text=Les fonctions callback ne peuvent pas allouer de la mémoire!}}
 +
 
 +
Une fonction callback ne peut pas allouer de la mémoire ***** that your callback functions must not allocate any memory (for example they cannot create a tuple or list). Callback functions should be relatively simple. If you need to make a list, make it beforehand and store it in a global variable (or make it local and close over it). If you need to do a long, complicated calculation, then use the callback to set a flag which some other code then responds to.
 
}}
 
}}
  
29 836

modifications

Menu de navigation