Hi People,
I have a long running wx.Timer that I call DeviceMonitor 'cos that’s what it does. There are times when it’s busier than other times and so I want to run it in different modes (like ‘Operational’, ‘Startup’, ‘CloseDown’ etc etc. I end up having a whole load of if-statements and global variables, which is not ideal. When I tried to create a new class called DeviceMonitor, it seems to work (ie it doesn’t crash), but I get no events. Here it is (derived from the sample code):
import wx
import time
class TimerTest(wx.Timer):
def __init__(self):
wx.Timer.__init__(self)
def start(self, secs):
self.Start(secs)
def stop(self):
self.Stop()
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Timer Tutorial 1",
size=(500,500))
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY)
self.timer = TimerTest()
self.Bind(wx.EVT_TIMER, self.update, self.timer)
self.toggleBtn = wx.Button(panel, wx.ID_ANY, "Start")
self.toggleBtn.Bind(wx.EVT_BUTTON, self.onToggle)
def onToggle(self, event):
btnLabel = self.toggleBtn.GetLabel()
if btnLabel == "Start":
print ("starting timer...")
self.timer.start(1000)
self.toggleBtn.SetLabel("Stop")
else:
print ("timer stopped!")
self.timer.stop()
self.toggleBtn.SetLabel("Start")
def update(self, event):
print ("\nupdated: "),
print (time.ctime())
# Run the program
if __name__ == "__main__":
app = wx.App()
frame = MyForm().Show()
app.MainLoop()
Any ideas welcome.
Kind regards,
Steve.