PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



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
 
< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2012. kksou.com. All Rights Reserved