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