Added the sample code from wxPython In Action to the samples dir
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42925 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
39
wxPython/samples/wxPIA_book/Chapter-18/timer.py
Normal file
39
wxPython/samples/wxPIA_book/Chapter-18/timer.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import wx
|
||||
import time
|
||||
|
||||
class ClockWindow(wx.Window):
|
||||
def __init__(self, parent):
|
||||
wx.Window.__init__(self, parent)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
|
||||
self.timer.Start(1000)
|
||||
|
||||
def Draw(self, dc):
|
||||
t = time.localtime(time.time())
|
||||
st = time.strftime("%I:%M:%S", t)
|
||||
w, h = self.GetClientSize()
|
||||
dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
|
||||
dc.Clear()
|
||||
dc.SetFont(wx.Font(30, wx.SWISS, wx.NORMAL, wx.NORMAL))
|
||||
tw, th = dc.GetTextExtent(st)
|
||||
dc.DrawText(st, (w-tw)/2, (h)/2 - th/2)
|
||||
|
||||
def OnTimer(self, evt):
|
||||
dc = wx.BufferedDC(wx.ClientDC(self))
|
||||
self.Draw(dc)
|
||||
|
||||
def OnPaint(self, evt):
|
||||
dc = wx.BufferedPaintDC(self)
|
||||
self.Draw(dc)
|
||||
|
||||
class MyFrame(wx.Frame):
|
||||
def __init__(self):
|
||||
wx.Frame.__init__(self, None, title="wx.Timer")
|
||||
ClockWindow(self)
|
||||
|
||||
|
||||
app = wx.PySimpleApp()
|
||||
frm = MyFrame()
|
||||
frm.Show()
|
||||
app.MainLoop()
|
Reference in New Issue
Block a user