|| [[http://wiki.wxpython.org/index.cgi/WxGladeEventsButtons|Prev]] || [[http://wiki.wxpython.org/index.cgi/WxGladeTutorial|Up]] || [[http://wiki.wxpython.org/index.cgi/WxGladeWxMenu|Next]] || = wxGlade tutorial - Status bar = (Contributed by Chris Lale, chrislale AT users DOT berlios DOT de) '''Table of Contents:''' <> == Create the application in wxglade == Run wxglade. Open the events and buttons project event-glade.wxg that you created in "Events and buttons" (WxGladeEventsButtons). The project consists of a frame containing one button. Set the title to "statusbar-glade" and save it as statusbar-glade.py. In the main (toolbox) window * Properties - -> Widget -> Title: statusbar-glade * File -> Save -> /path/to/your/project/statusbar-glade.wxg The Tree shows that the application contains one frame, a sizer and a button. * `Application` * `frame_1 (MyFrame)` * `sizer_1` * `button_1` == About the wx.StatusBar class == 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. The constructor is `__init__(self, parent, id, pos, size, style, name)`, but you only need to specify the first two: parent, and id. Look for wx.!StatusBar's methods in * wxWidgets manual -> Alphabetical class reference -> wx!StatusBar -> Members and * wxPython API -> Classes -> !StatusBar -> Methods summary == Add a status bar to the frame == * Tree -> Frame_1(!MyFrame) * Properties -> Widget -> Has !StatusBar (ticked) This creates frame_1_statusbar. In frame_1_statusbar's Properties window, accept the defaults: * Properties * Name: frame_1_statusBar * Class: wx!StatusBar * Text: frame_1_statusBar * Size: -1 The status bar instance method is added to `MyFrame`'s `__init()__` method: {{{ #!python self.frame_1_statusbar = self.CreateStatusBar(1, 0) }}} The status bar size (width) and text are set in the `__set_properties()` method {{{ #!python self.frame_1_statusbar.SetStatusWidths([-1]) # statusbar fields frame_1_statusbar_fields = ["frame_1_statusbar"] for i in range(len(frame_1_statusbar_fields)): self.frame_1_statusbar.SetStatusText(frame_1_statusbar_fields[i], i) # end wxGlade }}} Check the result: * Properties - -> Common -> Preview == Create an event handler to modify the status bar == Set Output path to `/path/to/your/project/staturbar-glade.py`, generate the code and edit `statusbar-glade.py`. Modify the existing event handler for button_1. Change {{{ #!python def OnBtn1(self, event): # wxGlade: MyFrame. self.button_1.SetLabel("Ouch!") event.Skip() }}} to {{{ #!python def OnBtn1(self, event): # wxGlade: MyFrame. self.frame_1_statusbar.SetStatusText("Ouch!") event.Skip() }}} Save `statusbar-glade.py` and run it. = Appendix: The complete code = {{{ #!python #!/usr/bin/env python # -*- coding: ISO-8859-1 -*- # generated by wxGlade 0.4.1 on Thu Mar 30 13:53:04 2006 import wx class MyFrame(wx.Frame): def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self.button_1 = wx.Button(self, wx.ID_OK, "") self.frame_1_statusbar = self.CreateStatusBar(1, 0) self.__set_properties() self.__do_layout() self.Bind(wx.EVT_BUTTON, self.OnBtn1, id=wx.ID_OK) # end wxGlade def __set_properties(self): # begin wxGlade: MyFrame.__set_properties self.SetTitle("statusbar-glade") self.SetSize((350, 250)) self.frame_1_statusbar.SetStatusWidths([-1]) # statusbar fields frame_1_statusbar_fields = ["frame_1_statusbar"] for i in range(len(frame_1_statusbar_fields)): self.frame_1_statusbar.SetStatusText(frame_1_statusbar_fields[i], i) # end wxGlade def __do_layout(self): # begin wxGlade: MyFrame.__do_layout sizer_1 = wx.BoxSizer(wx.VERTICAL) sizer_1.Add(self.button_1, 0, wx.ADJUST_MINSIZE, 0) self.SetAutoLayout(True) self.SetSizer(sizer_1) self.Layout() # end wxGlade def OnBtn1(self, event): # wxGlade: MyFrame. self.frame_1_statusbar.SetStatusText("Ouch!") event.Skip() # end of class MyFrame class MyApp(wx.App): def OnInit(self): wx.InitAllImageHandlers() frame_1 = MyFrame(None, -1, "") self.SetTopWindow(frame_1) frame_1.Show() return 1 # end of class MyApp if __name__ == "__main__": app = MyApp(0) app.MainLoop() }}}