]> git.saurik.com Git - wxWidgets.git/blame - wxPython/samples/wxPIA_book/Chapter-18/timer.py
fix building/running of tex2rtf
[wxWidgets.git] / wxPython / samples / wxPIA_book / Chapter-18 / timer.py
CommitLineData
be05b434
RD
1import wx
2import time
3
4class 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
30class MyFrame(wx.Frame):
31 def __init__(self):
32 wx.Frame.__init__(self, None, title="wx.Timer")
33 ClockWindow(self)
34
35
36app = wx.PySimpleApp()
37frm = MyFrame()
38frm.Show()
39app.MainLoop()