Hi,
I am trying to create a toasterbox that has an LEDCtrl in it to create a sort
of timer. I want the tosterbox to close a few seconds after the timer stops or
if the close button is clicked on. The problem is that the tosterbox only pops
up for a few milliseconds even when I set pause time to a high value. Also,
when I try to stop the timer using Stop() some time after calling Start()
, the time shown is stuck at "00:00" meaning no wx.EVT_TIMER events are being
fired. What am I doing wrong?
The class for the toasterbox is shown below:
class MyTimer(TB.ToasterBox):
def __init__(self, parent):
TB.ToasterBox.__init__(self, parent, tbstyle=TB.TB_COMPLEX,
windowstyle=TB.TB_CAPTION, closingstyle=TB.TB_ONTIME)
self.SetPopupSize((200,150))
screen = wx.GetDisplaySize()
pos = wx.Point(screen.GetWidth()-200, screen.GetHeight()-185)
self.SetPopupPosition(pos)
self.SetTitle("Timer")
self.SetPopupPauseTime(10000)
self.SetPopupScrollSpeed(8)
tbpanel = self.GetToasterBoxWindow()
self.panel = wx.Panel(tbpanel, -1, style=wx.DOUBLE_BORDER)
sizer = wx.BoxSizer(wx.VERTICAL)
self.txt = wx.StaticText(self.panel, -1, "Solving the problem ...")
self.led = led.LEDCtrl(self.panel, -1, size=wx.Size(150,40),
style=wx.SIMPLE_BORDER,digits=10, value="00:00",
ledstyle=led.LED_AGG|led.LED_ALIGN_CENTER|
led.LED_ALLOW_COLONS)
sizer.AddF(self.txt, wx.SizerFlags(0).Expand().Top().Border(wx.ALL, 10))
sizer.AddF(self.led, wx.SizerFlags(1).Expand().Bottom().Border(wx.ALL,
10))
self.panel.SetSizer(sizer)
sizer.Fit(self.panel)
self.tc = -1
self.AddPanel(self.panel)
self.stop = False
self.Play()
self.StartTimer()
def StartTimer(self):
self.start = time.clock()
self.timer = wx.Timer(self.panel)
self.panel.Bind(wx.EVT_TIMER, self.OnTimer)
self.timer.Start(1000)
def GetTime(self):
return self.t
def OnTimer(self, evt):
if self.stop:
#self.timer.Stop()
pass
self.SetPopupPauseTime(10000)
self.tc = -self.tc
self.t = time.localtime(time.clock()-self.start)
if self.tc > 0:
st = time.strftime("%M:%S", self.t)
else:
st = time.strftime("%M%S", self.t)
self.led.SetValue(st)