]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-18/timer.py
don't use strlen() to verify the length of the string as it can contain embedded...
[wxWidgets.git] / wxPython / samples / wxPIA_book / Chapter-18 / timer.py
1 import wx
2 import time
3
4 class ClockWindow(wx.Window):
5 def __init__(self, parent):
6 wx.Window.__init__(self, parent)
7 self.Bind(wx.EVT_PAINT, self.OnPaint)
8 self.timer = wx.Timer(self)
9 self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
10 self.timer.Start(1000)
11
12 def Draw(self, dc):
13 t = time.localtime(time.time())
14 st = time.strftime("%I:%M:%S", t)
15 w, h = self.GetClientSize()
16 dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
17 dc.Clear()
18 dc.SetFont(wx.Font(30, wx.SWISS, wx.NORMAL, wx.NORMAL))
19 tw, th = dc.GetTextExtent(st)
20 dc.DrawText(st, (w-tw)/2, (h)/2 - th/2)
21
22 def OnTimer(self, evt):
23 dc = wx.BufferedDC(wx.ClientDC(self))
24 self.Draw(dc)
25
26 def OnPaint(self, evt):
27 dc = wx.BufferedPaintDC(self)
28 self.Draw(dc)
29
30 class MyFrame(wx.Frame):
31 def __init__(self):
32 wx.Frame.__init__(self, None, title="wx.Timer")
33 ClockWindow(self)
34
35
36 app = wx.PySimpleApp()
37 frm = MyFrame()
38 frm.Show()
39 app.MainLoop()