]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxStatusBar.py
A little tweak to the usage text
[wxWidgets.git] / wxPython / demo / wxStatusBar.py
1 # 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2 #
3 # o Updated for wx namespace
4 #
5
6 import time
7 import wx
8
9 #---------------------------------------------------------------------------
10
11 class CustomStatusBar(wx.StatusBar):
12 def __init__(self, parent, log):
13 wx.StatusBar.__init__(self, parent, -1)
14
15 # This status bar has three fields
16 self.SetFieldsCount(3)
17 self.log = log
18 self.sizeChanged = False
19 self.Bind(wx.EVT_SIZE, self.OnSize)
20 self.Bind(wx.EVT_IDLE, self.OnIdle)
21
22 # Field 0 ... just text
23 self.SetStatusText("A Custom StatusBar...", 0)
24
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)
28 self.cb.SetValue(True)
29
30 # set the initial position of the checkbox
31 self.Reposition()
32
33 # We're going to use a timer to drive a 'clock' in the last
34 # field.
35 self.timer = wx.PyTimer(self.Notify)
36 self.timer.Start(1000)
37 self.Notify()
38
39
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).
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
48
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
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.
64 self.sizeChanged = True
65
66
67 def OnIdle(self, evt):
68 if self.sizeChanged:
69 self.Reposition()
70
71
72 # reposition the checkbox
73 def Reposition(self):
74 rect = self.GetFieldRect(1)
75 self.cb.SetPosition((rect.x+2, rect.y+2))
76 self.cb.SetSize((rect.width-4, rect.height-4))
77 self.sizeChanged = False
78
79
80
81 class TestCustomStatusBar(wx.Frame):
82 def __init__(self, parent, log):
83 wx.Frame.__init__(self, parent, -1, 'Test Custom StatusBar')
84
85 self.sb = CustomStatusBar(self, log)
86 self.SetStatusBar(self.sb)
87 tc = wx.TextCtrl(self, -1, "", style=wx.TE_READONLY|wx.TE_MULTILINE)
88
89 self.SetSize((500, 300))
90 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
91
92 def OnCloseWindow(self, event):
93 self.sb.timer.Stop()
94 del self.sb.timer
95 self.Destroy()
96
97 #---------------------------------------------------------------------------
98
99 def runTest(frame, nb, log):
100 win = TestCustomStatusBar(frame, log)
101 frame.otherWin = win
102 win.Show(True)
103
104 #---------------------------------------------------------------------------
105
106
107 overview = """\
108 A status bar is a narrow window that can be placed along the bottom of
109 a frame to give small amounts of status information. It can contain
110 one or more fields, one or more of which can be variable length
111 according to the size of the window.
112
113 This example demonstrates how to create a custom status bar with actual
114 gadgets embedded in it. In this case, the first field is just plain text,
115 The second one has a checkbox that enables the timer, and the third
116 field has a clock that shows the current time when it is enabled.
117
118 """
119
120
121 if __name__ == '__main__':
122 import sys,os
123 import run
124 run.main(['', os.path.basename(sys.argv[0])])