[Tutor] wxPython timer

nova812 sentinel805@netscape.net
Sat, 06 Apr 2002 12:53:52 -0500


I have two questions....
1  Whats wrong with my timer here?  the tmrOneSec_expired method isn't 
being called.  
2  How can I add my own methods to the Mainloop  without using a timer?

<pre>
from wxPython.wx import *

class EggTimer(wxFrame):
  def __init__(self):
    wxFrame. __init__(self, NULL, -1, 
'wxPython',wxDefaultPosition,(200,100))
    timeLeft = 3

    btnSetTimer = wxButton(self, 111,'&Set')
    EVT_BUTTON(self, 111, self.btnSetTimer_click)

    tmrOneSec = wxTimer(self,222)
    EVT_TIMER(self,222, self.tmrOneSec_expired)
    tmrOneSec.Start(1000)

  def btnSetTimer_click(self, event):
    dlg = wxMessageDialog(self,'"Set" button clicked','Alert',wxOK)
    dlg.ShowModal()
    dlg.Destroy()

  def tmrOneSec_expired(self):
    self.timeLeft = timeLeft - 1
    if (timeLeft < 1):
      self.alertTimesUp()

  def alertTimesUp(self):
    dlg = wxMessageDialog(self,'Times UP!!!','Alert',wxOK)
    dlg.ShowModal()
    dlg.Destroy()

class App(wxApp):
  def OnInit(self):
    frame = EggTimer()
    frame.Show(true)
    return true

app = App(0)
app.MainLoop()

</pre>