Sample Code 122: How to have a status area using GtkStatusbar?
Written by kksou   
Monday, 18 December 2006
Problem

You want to have a status bar at the bottom of your GtkWindow as shown below:

How to have a status area using GtkStatusbar?


Solution
  • Create a GtkStatusbar.
  • Create a GtkVBox if necessary, and stuff the status bar as the last widget in the vbox (so that it's at the bottom).
  • If you need the status bar to have a different background color or respond to events, stuff the status bar inside an GtkEventBox and then pack the eventbox into the vbox.
  • To display a message, we need to first get a message id with GtkStatusbar::get_context_id(), then display the message with GtkStatusbar::push().

Sample Code
1   
2   
3   
4   
5   
6   
7   
8   
9   
10   
11   
12   
13   
14   
15   
16   
17   
18   
19   
20   
21   
<?php
$window = new GtkWindow();
$window->set_size_request(400, 200);
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->add($vbox = new GtkVBox());

// display title
$title = new GtkLabel("Window with status area");
$title->modify_font(new PangoFontDescription("Times New Roman Italic 10"));
$title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff"));
$title->set_size_request(-1, 40);
$vbox->pack_start($title, 0, 0);

$vbox->pack_start(new GtkLabel('your body contents'));

// setup status area
$status = new GtkStatusbar(); // note 1
$eventbox = new GtkEventBox();
$eventbox->add($status);
$vbox->pack_start($eventbox, 0, 0); // note 2
$eventbox->modify_bg(Gtk::STATE_NORMAL, GdkColor::parse('#ffff00')); // note 3
  • Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
  • Registration is free and immediate.
  • Have some doubt about the registration? Please read this forum article.
Explanation
  1. Create a statu bar, stuff it inside an eventbox, and pack the eventbox into the vbox.
  2. Don't forget to set expand and fill to false when packing so that the status bar stays at the bottom.
  3. Here we set the background color of the status bar to yellow.
  4. Display a sample message.

Related Links

User reviews   Average user ratings:    4.0   (from 4 users)
  1. Tanes Sriviroolchai
    April 13, 2008 5:26am

    I think line #20 should be pack_end instead of pack_start.

  2. kksou
    April 14, 2008 2:50am

    Hi Tanes,

    You're right! You can definitely use pack_end() for line #20.

    In this example, the status bar is packed using pack_start() as the last item. So the effect will be the same as using pack_end().

    Thanks and Regards,
    /kksou

  3. M Drake
    July 22, 2008 5:25pm

    You can also use the pop function to clear the statusbar when you're done, for moving on to another field, button, etc. As in:

    $status->pop($context_id);

    In our app, I connect two signals to each field; one for enter_notify_event, and one for leave_notify_event, so that the statusbar always reflects the help note for wherever the user is pointing.

  4. The following NEW packages will be installed:
    August 17, 2008 9:03am

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev   Next >

Copyright © 2006-2008. kksou.com. All Rights Reserved