Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # DevPlayer @ gmai ..lcom
- # 2011-Oct-2
- # EventHandler
- import sys
- import wx
- import time
- class MyTimer(wx.Timer):
- MS_DEFAULT = 1000
- countTo = 1
- counted = 0
- def __init__(self, owner=None, Id=-1):
- print('MyTimer() initializing')
- me = self
- wx.Timer.__init__(self, owner, Id)
- self.counted = 0
- self.countTo = self.MS_DEFAULT
- self.interval = self.MS_DEFAULT
- # comment next line to see MainLoop() just drop out.
- self.frame = wx.Frame(None) # doesn't work without it
- self.Bind(wx.EVT_TIMER, self.OnTimer)
- #self.frame.Bind(wx.EVT_CLOSE, self.OnClose)
- self.Bind(wx.EVT_CLOSE, self.OnClose)
- print('MyTimer() Initialized')
- def Start(self, ms_length=MS_DEFAULT,
- ms_interval=MS_DEFAULT, oneShot=False):
- print('MyTimer().Start(%d, %d, %s)' % (ms_length, ms_interval, oneShot))
- self.countTo = ms_length
- val = super(MyTimer, self).Start(
- milliseconds=ms_interval, oneShot=oneShot)
- return val
- def OnTimer(self, event):
- if self.counted >= self.countTo:
- print('Times up !')
- if hasattr(self, 'frame') \
- and hasattr(self.frame, 'Close') \
- and isinstance( self.frame.Close, type(self.OnTimer)):
- self.frame.Close()
- #self.frame.Destroy()
- else:
- self.Destroy()
- text = time.strftime('%I:%M:%S %p', time.localtime())
- print('%07d: %s' % (self.counted, text))
- self.counted += self.interval
- event.Skip()
- def OnClose(self, event):
- print('Closing')
- self.Stop()
- event.Skip()
- print('Starting')
- app = wx.App(0)
- timer = MyTimer()
- timer.Start(10000, 1000, False)
- app.MainLoop()
- print('Finished')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement