]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxStatusBar.py
adjusting to changes in xti.h
[wxWidgets.git] / wxPython / demo / wxStatusBar.py
CommitLineData
cf694132
RD
1
2from wxPython.wx import *
3
4import time
5
6#---------------------------------------------------------------------------
7
8class CustomStatusBar(wxStatusBar):
9 def __init__(self, parent, log):
10 wxStatusBar.__init__(self, parent, -1)
11 self.SetFieldsCount(3)
12 self.log = log
1e4a197e 13 self.sizeChanged = False
f6bcfd97 14 EVT_SIZE(self, self.OnSize)
c368d904 15 EVT_IDLE(self, self.OnIdle)
cf694132
RD
16
17 self.SetStatusText("A Custom StatusBar...", 0)
18
19 self.cb = wxCheckBox(self, 1001, "toggle clock")
20 EVT_CHECKBOX(self, 1001, self.OnToggleClock)
1e4a197e 21 self.cb.SetValue(True)
cf694132 22
c368d904
RD
23 # set the initial position of the checkbox
24 self.Reposition()
cf694132
RD
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
c368d904 39
cf694132
RD
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
c368d904
RD
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.
1e4a197e 55 self.sizeChanged = True
c368d904
RD
56
57
58 def OnIdle(self, evt):
59 if self.sizeChanged:
60 self.Reposition()
61
62
cf694132 63 # reposition the checkbox
c368d904 64 def Reposition(self):
cf694132
RD
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))
1e4a197e 68 self.sizeChanged = False
cf694132
RD
69
70
71
72class TestCustomStatusBar(wxFrame):
73 def __init__(self, parent, log):
eb0f373c
RD
74 wxFrame.__init__(self, parent, -1, 'Test Custom StatusBar')
75 #wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
cf694132
RD
76
77 self.sb = CustomStatusBar(self, log)
78 self.SetStatusBar(self.sb)
eb0f373c
RD
79 tc = wxTextCtrl(self, -1, "", style=wxTE_READONLY|wxTE_MULTILINE)
80
81 self.SetSize((500, 300))
f6bcfd97 82 EVT_CLOSE(self, self.OnCloseWindow)
cf694132
RD
83
84 def OnCloseWindow(self, event):
85 self.sb.timer.Stop()
86 del self.sb.timer
87 self.Destroy()
88
89#---------------------------------------------------------------------------
90
91def runTest(frame, nb, log):
92 win = TestCustomStatusBar(frame, log)
93 frame.otherWin = win
1e4a197e 94 win.Show(True)
cf694132
RD
95
96#---------------------------------------------------------------------------
97
98
99
100
101
102
103
104
105
106overview = """\
1fded56b
RD
107A status bar is a narrow window that can be placed along the bottom of
108a frame to give small amounts of status information. It can contain
109one or more fields, one or more of which can be variable length
110according to the size of the window. """
111
112
113
114
115
116if __name__ == '__main__':
117 import sys,os
118 import run
119 run.main(['', os.path.basename(sys.argv[0])])