Development Team/Almanac/lang-es: Difference between revisions

Fede (talk | contribs)
Fede (talk | contribs)
Line 238: Line 238:
</pre>
</pre>


=== How do I repeatedly call a specific method after N number of seconds? ===
=== ¿Cómo llamar repetidamente a un método específico después de un número N de segundos? ===
The gobject.timeout_add() function allows you to invoke a callback method after a certain amount of time. If you want to repeatedly call a method, simply keep invoking the gobject.timeout_add function in your callback itself. The code below is a simple example, where the callback function is named repeatedly_call. Note that the timing of the callbacks are approximate. To get the process going, you should make an initial call to repeatedly_call() somewhere in your code.  
La función gobject.timeout_add() te permite invocar un método después de un período de tiempo determinado. Si quieres llamar a un método en varias ocasiones, simplemente sigue llamando a la función de gobject.timeout_add desde tu función.
El código de abajo es un ejemplo simple en donde la función que implementa el timeout se llama repeatedly_call. Nota que la sincronización entre las llamadas son aproximadas. Para que esto funcione debes llamar a repeatedly_call() desde alguna parte de tu código.


You can see a more substantive example of this pattern in use when we [[olpc:Pango#How_do_I_dynamically_set_the_text_in_a_pango_layout.3F | regularly update the time displayed on a pango layout object]].  
Puedes ver un mejor ejemplo de este patrón en uso [[olpc:Pango#How_do_I_dynamically_set_the_text_in_a_pango_layout.3F | aquí]].  


<pre>
<pre>


#This method calls itself ROUGHLY every 1 second
#Este método se llama a sí mismo aproximadamente cada 1 segundo
def repeatedly_call(self):
def repeatedly_call(self):
now = datetime.datetime.now()
now = datetime.datetime.now()
gobject.timeout_add(self.repeat_period_msec, self.repeatedly_update_time)
gobject.timeout_add(self.repeat_period_msec, self.repeatedly_update_time)
</pre>
</pre>


=== How do I update the current build version of code that is running on my XO? ===
=== How do I update the current build version of code that is running on my XO? ===