]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxStatusBar.py
1 # 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
9 #---------------------------------------------------------------------------
11 class CustomStatusBar(wx
.StatusBar
):
12 def __init__(self
, parent
, log
):
13 wx
.StatusBar
.__init
__(self
, parent
, -1)
15 # This status bar has three fields
16 self
.SetFieldsCount(3)
18 self
.sizeChanged
= False
19 self
.Bind(wx
.EVT_SIZE
, self
.OnSize
)
20 self
.Bind(wx
.EVT_IDLE
, self
.OnIdle
)
22 # Field 0 ... just text
23 self
.SetStatusText("A Custom StatusBar...", 0)
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)
30 # set the initial position of the checkbox
33 # We're going to use a timer to drive a 'clock' in the last
35 self
.timer
= wx
.PyTimer(self
.Notify
)
36 self
.timer
.Start(1000)
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).
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")
49 # the checkbox was clicked
50 def OnToggleClock(self
, event
):
51 if self
.cb
.GetValue():
52 self
.timer
.Start(1000)
58 def OnSize(self
, evt
):
59 self
.Reposition() # for normal size events
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
67 def OnIdle(self
, evt
):
72 # reposition the checkbox
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
81 class TestCustomStatusBar(wx
.Frame
):
82 def __init__(self
, parent
, log
):
83 wx
.Frame
.__init
__(self
, parent
, -1, 'Test Custom StatusBar')
85 self
.sb
= CustomStatusBar(self
, log
)
86 self
.SetStatusBar(self
.sb
)
87 tc
= wx
.TextCtrl(self
, -1, "", style
=wx
.TE_READONLY|wx
.TE_MULTILINE
)
89 self
.SetSize((500, 300))
90 self
.Bind(wx
.EVT_CLOSE
, self
.OnCloseWindow
)
92 def OnCloseWindow(self
, event
):
97 #---------------------------------------------------------------------------
99 def runTest(frame
, nb
, log
):
100 win
= TestCustomStatusBar(frame
, log
)
104 #---------------------------------------------------------------------------
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.
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.
121 if __name__
== '__main__':
124 run
.main(['', os
.path
.basename(sys
.argv
[0])])