X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..dae0faa6be08c5bb5635fd464b695ac8bb8f2b8d:/wxPython/demo/wxStatusBar.py?ds=sidebyside diff --git a/wxPython/demo/wxStatusBar.py b/wxPython/demo/wxStatusBar.py index bdb016a1fa..0d1cd90880 100644 --- a/wxPython/demo/wxStatusBar.py +++ b/wxPython/demo/wxStatusBar.py @@ -1,43 +1,51 @@ +# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o Updated for wx namespace +# -from wxPython.wx import * - -import time +import time +import wx #--------------------------------------------------------------------------- -class CustomStatusBar(wxStatusBar): +class CustomStatusBar(wx.StatusBar): def __init__(self, parent, log): - wxStatusBar.__init__(self, parent, -1) + wx.StatusBar.__init__(self, parent, -1) + + # This status bar has three fields self.SetFieldsCount(3) self.log = log - EVT_SIZE(self, self.OnSize) + self.sizeChanged = False + self.Bind(wx.EVT_SIZE, self.OnSize) + self.Bind(wx.EVT_IDLE, self.OnIdle) + # Field 0 ... just text self.SetStatusText("A Custom StatusBar...", 0) - self.cb = wxCheckBox(self, 1001, "toggle clock") - EVT_CHECKBOX(self, 1001, self.OnToggleClock) - self.cb.SetValue(true) + # This will fall into field 1 (the second field) + self.cb = wx.CheckBox(self, 1001, "toggle clock") + self.Bind(wx.EVT_CHECKBOX, self.OnToggleClock, self.cb) + self.cb.SetValue(True) - # figure out how tall to make it. - dc = wxClientDC(self) - dc.SetFont(self.GetFont()) - (w,h) = dc.GetTextExtent('X') - h = int(h * 1.8) - self.SetSize(wxSize(100, h)) + # set the initial position of the checkbox + self.Reposition() - # start our timer - self.timer = wxPyTimer(self.Notify) + # We're going to use a timer to drive a 'clock' in the last + # field. + self.timer = wx.PyTimer(self.Notify) self.timer.Start(1000) self.Notify() - # Time-out handler + # Handles events from the timer we started in __init__(). + # We're using it to drive a 'clock' in field 2 (the third field). def Notify(self): t = time.localtime(time.time()) st = time.strftime("%d-%b-%Y %I:%M:%S", t) self.SetStatusText(st, 2) self.log.WriteText("tick...\n") + # the checkbox was clicked def OnToggleClock(self, event): if self.cb.GetValue(): @@ -47,23 +55,39 @@ class CustomStatusBar(wxStatusBar): self.timer.Stop() + def OnSize(self, evt): + self.Reposition() # for normal size events + + # Set a flag so the idle time handler will also do the repositioning. + # It is done this way to get around a buglet where GetFieldRect is not + # accurate during the EVT_SIZE resulting from a frame maximize. + self.sizeChanged = True + + + def OnIdle(self, evt): + if self.sizeChanged: + self.Reposition() + + # reposition the checkbox - def OnSize(self, event): + def Reposition(self): rect = self.GetFieldRect(1) - self.cb.SetPosition(wxPoint(rect.x+2, rect.y+2)) - self.cb.SetSize(wxSize(rect.width-4, rect.height-4)) + self.cb.SetPosition((rect.x+2, rect.y+2)) + self.cb.SetSize((rect.width-4, rect.height-4)) + self.sizeChanged = False -class TestCustomStatusBar(wxFrame): +class TestCustomStatusBar(wx.Frame): def __init__(self, parent, log): - wxFrame.__init__(self, parent, -1, 'Test Custom StatusBar', - wxPoint(0,0), wxSize(500, 300)) - wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE")) + wx.Frame.__init__(self, parent, -1, 'Test Custom StatusBar') self.sb = CustomStatusBar(self, log) self.SetStatusBar(self.sb) - EVT_CLOSE(self, self.OnCloseWindow) + tc = wx.TextCtrl(self, -1, "", style=wx.TE_READONLY|wx.TE_MULTILINE) + + self.SetSize((500, 300)) + self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) def OnCloseWindow(self, event): self.sb.timer.Stop() @@ -75,42 +99,26 @@ class TestCustomStatusBar(wxFrame): def runTest(frame, nb, log): win = TestCustomStatusBar(frame, log) frame.otherWin = win - win.Show(true) + win.Show(True) #--------------------------------------------------------------------------- - - - - - - - overview = """\ -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. - -wxStatusBar() ----------------------------- - -Default constructor. - -wxStatusBar(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = "statusBar") +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. -Constructor, creating the window. +This example demonstrates how to create a custom status bar with actual +gadgets embedded in it. In this case, the first field is just plain text, +The second one has a checkbox that enables the timer, and the third +field has a clock that shows the current time when it is enabled. -Parameters -------------------- - -parent = The window parent, usually a frame. - -id = The window identifier. It may take a value of -1 to indicate a default value. - -pos = The window position. A value of (-1, -1) indicates a default position, chosen by either the windowing system or wxWindows, depending on platform. - -size = The window size. A value of (-1, -1) indicates a default size, chosen by either the windowing system or wxWindows, depending on platform. +""" -style = The window style. See wxStatusBar. -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. -""" +if __name__ == '__main__': + import sys,os + import run + run.main(['', os.path.basename(sys.argv[0])])