]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/StatusBar.py
   5 #--------------------------------------------------------------------------- 
   7 class CustomStatusBar(wx
.StatusBar
): 
   8     def __init__(self
, parent
, log
): 
   9         wx
.StatusBar
.__init
__(self
, parent
, -1) 
  11         # This status bar has three fields 
  12         self
.SetFieldsCount(3) 
  13         # Sets the three fields to be relative widths to each other. 
  14         self
.SetStatusWidths([-2, -1, -2]) 
  16         self
.sizeChanged 
= False 
  17         self
.Bind(wx
.EVT_SIZE
, self
.OnSize
) 
  18         self
.Bind(wx
.EVT_IDLE
, self
.OnIdle
) 
  20         # Field 0 ... just text 
  21         self
.SetStatusText("A Custom StatusBar...", 0) 
  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
) 
  26         self
.cb
.SetValue(True) 
  28         # set the initial position of the checkbox 
  31         # We're going to use a timer to drive a 'clock' in the last 
  33         self
.timer 
= wx
.PyTimer(self
.Notify
) 
  34         self
.timer
.Start(1000) 
  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). 
  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") 
  47     # the checkbox was clicked 
  48     def OnToggleClock(self
, event
): 
  49         if self
.cb
.GetValue(): 
  50             self
.timer
.Start(1000) 
  56     def OnSize(self
, evt
): 
  57         self
.Reposition()  # for normal size events 
  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. 
  62         self
.sizeChanged 
= True 
  65     def OnIdle(self
, evt
): 
  70     # reposition the checkbox 
  72         rect 
= self
.GetFieldRect(1) 
  73         self
.cb
.SetPosition((rect
.x
+2, rect
.y
+2)) 
  74         self
.cb
.SetSize((rect
.width
-4, rect
.height
-4)) 
  75         self
.sizeChanged 
= False 
  79 class TestCustomStatusBar(wx
.Frame
): 
  80     def __init__(self
, parent
, log
): 
  81         wx
.Frame
.__init
__(self
, parent
, -1, 'Test Custom StatusBar') 
  83         self
.sb 
= CustomStatusBar(self
, log
) 
  84         self
.SetStatusBar(self
.sb
) 
  85         tc 
= wx
.TextCtrl(self
, -1, "", style
=wx
.TE_READONLY|wx
.TE_MULTILINE
) 
  87         self
.SetSize((500, 300)) 
  88         self
.Bind(wx
.EVT_CLOSE
, self
.OnCloseWindow
) 
  90     def OnCloseWindow(self
, event
): 
  95 #--------------------------------------------------------------------------- 
  97 def runTest(frame
, nb
, log
): 
  98     win 
= TestCustomStatusBar(frame
, log
) 
 102 #--------------------------------------------------------------------------- 
 106 A status bar is a narrow window that can be placed along the bottom of 
 107 a frame to give small amounts of status information. It can contain 
 108 one or more fields, one or more of which can be variable length 
 109 according to the size of the window.   
 111 This example demonstrates how to create a custom status bar with actual 
 112 gadgets embedded in it. In this case, the first field is just plain text, 
 113 The second one has a checkbox that enables the timer, and the third 
 114 field has a clock that shows the current time when it is enabled. 
 119 if __name__ 
== '__main__': 
 122     run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])