]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/wxStatusBar.py
Merged the wxPy_newswig branch into the HEAD branch (main trunk)
[wxWidgets.git] / wxPython / demo / wxStatusBar.py
... / ...
CommitLineData
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
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
72class TestCustomStatusBar(wxFrame):
73 def __init__(self, parent, log):
74 wxFrame.__init__(self, parent, -1, 'Test Custom StatusBar')
75 #wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
76
77 self.sb = CustomStatusBar(self, log)
78 self.SetStatusBar(self.sb)
79 tc = wxTextCtrl(self, -1, "", style=wxTE_READONLY|wxTE_MULTILINE)
80
81 self.SetSize((500, 300))
82 EVT_CLOSE(self, self.OnCloseWindow)
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
94 win.Show(True)
95
96#---------------------------------------------------------------------------
97
98
99
100
101
102
103
104
105
106overview = """\
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])])