]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxStatusBar.py
First draft of a cygwin script to create wxMSW distributions
[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 EVT_SIZE(self, self.OnSize)
14
15 self.SetStatusText("A Custom StatusBar...", 0)
16
17 self.cb = wxCheckBox(self, 1001, "toggle clock")
18 EVT_CHECKBOX(self, 1001, self.OnToggleClock)
19 self.cb.SetValue(true)
20
21 # figure out how tall to make it.
22 dc = wxClientDC(self)
23 dc.SetFont(self.GetFont())
24 (w,h) = dc.GetTextExtent('X')
25 h = int(h * 1.8)
26 self.SetSize(wxSize(100, h))
27
28 # start our timer
29 self.timer = wxPyTimer(self.Notify)
30 self.timer.Start(1000)
31 self.Notify()
32
33
34 # Time-out handler
35 def Notify(self):
36 t = time.localtime(time.time())
37 st = time.strftime("%d-%b-%Y %I:%M:%S", t)
38 self.SetStatusText(st, 2)
39 self.log.WriteText("tick...\n")
40
41 # the checkbox was clicked
42 def OnToggleClock(self, event):
43 if self.cb.GetValue():
44 self.timer.Start(1000)
45 self.Notify()
46 else:
47 self.timer.Stop()
48
49
50 # reposition the checkbox
51 def OnSize(self, event):
52 rect = self.GetFieldRect(1)
53 self.cb.SetPosition(wxPoint(rect.x+2, rect.y+2))
54 self.cb.SetSize(wxSize(rect.width-4, rect.height-4))
55
56
57
58 class TestCustomStatusBar(wxFrame):
59 def __init__(self, parent, log):
60 wxFrame.__init__(self, parent, -1, 'Test Custom StatusBar',
61 wxPoint(0,0), wxSize(500, 300))
62 wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
63
64 self.sb = CustomStatusBar(self, log)
65 self.SetStatusBar(self.sb)
66 EVT_CLOSE(self, self.OnCloseWindow)
67
68 def OnCloseWindow(self, event):
69 self.sb.timer.Stop()
70 del self.sb.timer
71 self.Destroy()
72
73 #---------------------------------------------------------------------------
74
75 def runTest(frame, nb, log):
76 win = TestCustomStatusBar(frame, log)
77 frame.otherWin = win
78 win.Show(true)
79
80 #---------------------------------------------------------------------------
81
82
83
84
85
86
87
88
89
90 overview = """\
91 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.
92
93 wxStatusBar()
94 ----------------------------
95
96 Default constructor.
97
98 wxStatusBar(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = "statusBar")
99
100 Constructor, creating the window.
101
102 Parameters
103 -------------------
104
105 parent = The window parent, usually a frame.
106
107 id = The window identifier. It may take a value of -1 to indicate a default value.
108
109 pos = The window position. A value of (-1, -1) indicates a default position, chosen by either the windowing system or wxWindows, depending on platform.
110
111 size = The window size. A value of (-1, -1) indicates a default size, chosen by either the windowing system or wxWindows, depending on platform.
112
113 style = The window style. See wxStatusBar.
114
115 name = The name of the window. This parameter is used to associate a name with the item, allowing the application user to set Motif resource values for individual windows.
116 """