[Python-es] Tiempo

Mariano Reingart reingart en gmail.com
Lun Ene 28 16:37:19 CET 2013


También existe CallLater, una forma simple de llamar a una función en un
período de tiempo determinado (una única vez):

wx.CallLater(5000, self.ImprimeDiaSemana)

Para más info ver:

http://wxpython.org/docs/api/wx.CallLater-class.html

Incluso, si el período de tiempo no es necesario, podés usar wx.CallAfter,
que llama a la función después de terminar de procesar el evento:

http://wxpython.org/docs/api/wx-module.html#CallAfter

Sds

Mariano Reingart
http://www.sistemasagiles.com.ar
http://reingart.blogspot.com


On Mon, Jan 28, 2013 at 12:27 PM, Txema Vicente <txema en nabla.net> wrote:

>  Buenas
>
> En tu clase Ventana(wx.Frame), un método disparado por el evento
> EVT_ENTER_WINDOW que haga algo como:
>
> def EntraEnCuadro(self):
>     self.timer = wx.Timer(self)
>     self.timer.Start(500)
>     self.Bind(wx.EVT_TIMER, self.ImprimeDiaSemana)
>
>
> El 28/01/2013 16:00, Gonzalo Mouriÿfffffffffff1o Pardo escribió:
>
>  Buenas tardes,
> Tengo una duda, alguien sabe como podría hacer que se ejecute una función
> un tiempo x después de entrar en un cuadro?
> Exactamente lo que quiero es que me imprima el dia de la semana cuando
> lleve 5 segundos dentro del cuadro.
>
>  #!/usr/bin/env python
> # -*- coding: cp1252 -*-
>
>  import os
> import wx
> import time
>
>  class Aplicacion(wx.App):
>
>      def OnInit(self):
>         self.frame = Ventana(None, -1, title = "Post It")
>         self.SetTopWindow(self.frame)
>         self.frame.Show()
>         return True
>
>  """Main Frame"""
> class Ventana(wx.Frame):
>
>     """Constructor"""
>     def __init__(self, parent, id, title):
>         wx.Frame.__init__(self, parent, id, title, size = (900, 275))
>         self.panel = Panel(self)
>
>  class Panel(wx.Panel):
>     def __init__(self, parent):
>         wx.Panel.__init__(self, parent)
>         font = wx.Font(15, family = wx.FONTFAMILY_DEFAULT, style =
>                         wx.FONTSTYLE_NORMAL, weight = wx.FONTWEIGHT_BOLD,
>                         encoding = wx.FONTENCODING_CP1252)
>         self.sizer = wx.BoxSizer(wx.HORIZONTAL)
>         self.gbsizer = wx.GridBagSizer(2, 2)
>         self.sizer.Add(self.gbsizer, 1, wx.ALL | wx.EXPAND, border = 6)
>         self.SetSizer(self.sizer)
>         self.casa =  False
>         sem = {0 : ("Lunes", 169), 1 : ("Martes", 266), 2 : ("Miercoles" ,
> 359),
>                3 : ("Jueves",  478), 4 : ("Viernes", 578), 5: ("Sabado",
> 686),
>                6 : ("Domingo", 783)}
>         for num in range(0,7):
>             self.cont = sem[num]
>             self.dia = self.cont[0]
>             y = num + 1
>             self.collab = wx.StaticText(self, -1, label = self.dia,  size
> = wx.Size
>                                         (103, 23), style = wx.ALIGN_CENTER)
>
>              self.collab.SetFont(font)
>             if y < 6:
>                 self.collab.SetBackgroundColour(wx.Colour(255, 255, 255))
>             else:
>                 self.collab.SetBackgroundColour(wx.Colour(255, 0, 0))
>
>              self.gbsizer.Add(self.collab, pos = wx.GBPosition(0, y),
> flag =
>                         wx.ALIGN_CENTER_VERTICAL, border = 6)
>             self.collab.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter)
>             self.collab.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
>         self.Bind(wx.EVT_PAINT,self.OnPaint)
>
>     def OnEnter(self, event):
>         #Time0 = int(time.clock())
>         #Time2 = 0
>         #while Time2 < 5:
>             #Time1 = int(time.clock())
>             #Time2 = Time1 - Time0
>         #if Time2 = 5:
>             #print(self.dia)
>
>      def OnLeave(self, event):
>         Time3 = int(time.clock())
>
>      def OnPaint(self, event):
>         self.dc = wx.PaintDC(self)
>         for colu in range (7):
>             rect_x = 122 + (105 * (colu-1))
>             width = 105
>             self.dc.DrawRectangle(rect_x, 5, width, 25)
>         event.Skip()
>
>  if __name__ == "__main__":
>     app = Aplicacion(False)
>     app.MainLoop()
>
>
> _______________________________________________
> Python-es mailing listPython-es en python.orghttp://mail.python.org/mailman/listinfo/python-es
> FAQ: http://python-es-faq.wikidot.com/
>
>
>  [image: nabla.net]
>
> _______________________________________________
> Python-es mailing list
> Python-es en python.org
> http://mail.python.org/mailman/listinfo/python-es
> FAQ: http://python-es-faq.wikidot.com/
>
>
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://mail.python.org/pipermail/python-es/attachments/20130128/274c5bd0/attachment.html>
------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: nabla.gif
Type: image/gif
Size: 55563 bytes
Desc: no disponible
URL: <http://mail.python.org/pipermail/python-es/attachments/20130128/274c5bd0/attachment.gif>


Más información sobre la lista de distribución Python-es