]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxStatusBar.py
Allowed MSW wxTrextCtrl styling to also set the background colour,
[wxWidgets.git] / wxPython / demo / wxStatusBar.py
1
2 from wxPython.wx import *
3
4 import time
5
6 #---------------------------------------------------------------------------
7
8 class CustomStatusBar(wxStatusBar):
9 def __init__(self, parent, log):
10 wxStatusBar.__init__(self, parent, -1)
11 self.SetFieldsCount(3)
12 self.log = log
13 self.sizeChanged = false
14 EVT_SIZE(self, self.OnSize)
15 EVT_IDLE(self, self.OnIdle)
16
17 self.SetStatusText("A Custom StatusBar...", 0)
18
19 self.cb = wxCheckBox(self, 1001, "toggle clock")
20 EVT_CHECKBOX(self, 1001, self.OnToggleClock)
21 self.cb.SetValue(true)
22
23 # set the initial position of the checkbox
24 self.Reposition()
25
26 # start our timer
27 self.timer = wxPyTimer(self.Notify)
28 self.timer.Start(1000)
29 self.Notify()
30
31
32 # Time-out handler
33 def Notify(self):
34 t = time.localtime(time.time())
35 st = time.strftime("%d-%b-%Y %I:%M:%S", t)
36 self.SetStatusText(st, 2)
37 self.log.WriteText("tick...\n")
38
39
40 # the checkbox was clicked
41 def OnToggleClock(self, event):
42 if self.cb.GetValue():
43 self.timer.Start(1000)
44 self.Notify()
45 else:
46 self.timer.Stop()
47
48
49 def OnSize(self, evt):
50 self.Reposition() # for normal size events
51
52 # Set a flag so the idle time handler will also do the repositioning.
53 # It is done this way to get around a buglet where GetFieldRect is not
54 # accurate during the EVT_SIZE resulting from a frame maximize.
55 self.sizeChanged = true
56
57
58 def OnIdle(self, evt):
59 if self.sizeChanged:
60 self.Reposition()
61
62
63 # reposition the checkbox
64 def Reposition(self):
65 rect = self.GetFieldRect(1)
66 self.cb.SetPosition(wxPoint(rect.x+2, rect.y+2))
67 self.cb.SetSize(wxSize(rect.width-4, rect.height-4))
68 self.sizeChanged = false
69
70
71
72 class TestCustomStatusBar(wxFrame):
73 def __init__(self, parent, log):
74 wxFrame.__init__(self, parent, -1, 'Test Custom StatusBar',
75 wxPoint(0,0), wxSize(500, 300))
76 wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
77
78 self.sb = CustomStatusBar(self, log)
79 self.SetStatusBar(self.sb)
80 EVT_CLOSE(self, self.OnCloseWindow)
81
82 def OnCloseWindow(self, event):
83 self.sb.timer.Stop()
84 del self.sb.timer
85 self.Destroy()
86
87 #---------------------------------------------------------------------------
88
89 def runTest(frame, nb, log):
90 win = TestCustomStatusBar(frame, log)
91 frame.otherWin = win
92 win.Show(true)
93
94 #---------------------------------------------------------------------------
95
96
97
98
99
100
101
102
103
104 overview = """\
105 A status bar is a narrow window that can be placed along the bottom of a frame to give small amounts of status information. It can contain one or more fields, one or more of which can be variable length according to the size of the window.
106 """