]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/StatusBar.py
doc tweaks, typo fixed, etc.
[wxWidgets.git] / wxPython / demo / StatusBar.py
CommitLineData
8fa876ca
RD
1# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Updated for wx namespace
4#
cf694132 5
8fa876ca
RD
6import time
7import wx
cf694132
RD
8
9#---------------------------------------------------------------------------
10
8fa876ca 11class CustomStatusBar(wx.StatusBar):
cf694132 12 def __init__(self, parent, log):
8fa876ca
RD
13 wx.StatusBar.__init__(self, parent, -1)
14
15 # This status bar has three fields
cf694132
RD
16 self.SetFieldsCount(3)
17 self.log = log
1e4a197e 18 self.sizeChanged = False
8fa876ca
RD
19 self.Bind(wx.EVT_SIZE, self.OnSize)
20 self.Bind(wx.EVT_IDLE, self.OnIdle)
cf694132 21
8fa876ca 22 # Field 0 ... just text
cf694132
RD
23 self.SetStatusText("A Custom StatusBar...", 0)
24
8fa876ca
RD
25 # This will fall into field 1 (the second field)
26 self.cb = wx.CheckBox(self, 1001, "toggle clock")
27 self.Bind(wx.EVT_CHECKBOX, self.OnToggleClock, self.cb)
1e4a197e 28 self.cb.SetValue(True)
cf694132 29
c368d904
RD
30 # set the initial position of the checkbox
31 self.Reposition()
cf694132 32
8fa876ca
RD
33 # We're going to use a timer to drive a 'clock' in the last
34 # field.
35 self.timer = wx.PyTimer(self.Notify)
cf694132
RD
36 self.timer.Start(1000)
37 self.Notify()
38
39
8fa876ca
RD
40 # Handles events from the timer we started in __init__().
41 # We're using it to drive a 'clock' in field 2 (the third field).
cf694132
RD
42 def Notify(self):
43 t = time.localtime(time.time())
44 st = time.strftime("%d-%b-%Y %I:%M:%S", t)
45 self.SetStatusText(st, 2)
46 self.log.WriteText("tick...\n")
47
c368d904 48
cf694132
RD
49 # the checkbox was clicked
50 def OnToggleClock(self, event):
51 if self.cb.GetValue():
52 self.timer.Start(1000)
53 self.Notify()
54 else:
55 self.timer.Stop()
56
57
c368d904
RD
58 def OnSize(self, evt):
59 self.Reposition() # for normal size events
60
61 # Set a flag so the idle time handler will also do the repositioning.
62 # It is done this way to get around a buglet where GetFieldRect is not
63 # accurate during the EVT_SIZE resulting from a frame maximize.
1e4a197e 64 self.sizeChanged = True
c368d904
RD
65
66
67 def OnIdle(self, evt):
68 if self.sizeChanged:
69 self.Reposition()
70
71
cf694132 72 # reposition the checkbox
c368d904 73 def Reposition(self):
cf694132 74 rect = self.GetFieldRect(1)
8fa876ca
RD
75 self.cb.SetPosition((rect.x+2, rect.y+2))
76 self.cb.SetSize((rect.width-4, rect.height-4))
1e4a197e 77 self.sizeChanged = False
cf694132
RD
78
79
80
8fa876ca 81class TestCustomStatusBar(wx.Frame):
cf694132 82 def __init__(self, parent, log):
8fa876ca 83 wx.Frame.__init__(self, parent, -1, 'Test Custom StatusBar')
cf694132
RD
84
85 self.sb = CustomStatusBar(self, log)
86 self.SetStatusBar(self.sb)
8fa876ca 87 tc = wx.TextCtrl(self, -1, "", style=wx.TE_READONLY|wx.TE_MULTILINE)
eb0f373c
RD
88
89 self.SetSize((500, 300))
8fa876ca 90 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
cf694132
RD
91
92 def OnCloseWindow(self, event):
93 self.sb.timer.Stop()
94 del self.sb.timer
95 self.Destroy()
96
97#---------------------------------------------------------------------------
98
99def runTest(frame, nb, log):
100 win = TestCustomStatusBar(frame, log)
101 frame.otherWin = win
1e4a197e 102 win.Show(True)
cf694132
RD
103
104#---------------------------------------------------------------------------
105
106
cf694132 107overview = """\
1fded56b
RD
108A status bar is a narrow window that can be placed along the bottom of
109a frame to give small amounts of status information. It can contain
110one or more fields, one or more of which can be variable length
8fa876ca 111according to the size of the window.
1fded56b 112
8fa876ca
RD
113This example demonstrates how to create a custom status bar with actual
114gadgets embedded in it. In this case, the first field is just plain text,
115The second one has a checkbox that enables the timer, and the third
116field has a clock that shows the current time when it is enabled.
1fded56b 117
8fa876ca 118"""
1fded56b
RD
119
120
121if __name__ == '__main__':
122 import sys,os
123 import run
124 run.main(['', os.path.basename(sys.argv[0])])