Sample Code 83: How to set up toolbar? |
|
Written by kksou
|
|
Thursday, 02 November 2006 |
|
Problem You want to set up toolbars as shown below:

Solution
Sample Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| <?php $window = new GtkWindow(); $window->set_size_request(400, 150); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
// define menu definition
$toolbar_definition = array('New', 'Open', 'Save', '<hr>', // note 1
'Cut', 'Copy', 'Paste', '<hr>', 'Undo','Redo'); setup_toolbar($vbox, $toolbar_definition);
// display title
$title = new GtkLabel("Set up Toolbar"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $vbox->pack_start($title); $vbox->pack_start(new GtkLabel(''));
$window->show_all(); Gtk::main();
// setup toolbar
function setup_toolbar($vbox, $toolbar_definition) { // note 1
$toolbar = new GtkToolBar(); // note 2
$vbox->pack_start($toolbar, 0, 0); foreach($toolbar_definition as $item) { if ($item=='<hr>') { $toolbar->insert(new GtkSeparatorToolItem(), -1); } else { $stock_image_name = 'Gtk::STOCK_'.strtoupper($item); // note 3
if (defined($stock_image_name)) {
|
- 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
- To set up a toolbar, simply defines the
$toolbar_definition and call the function setup_toolbar.
- Create a new toolbar.
- Get the stock image name from toolbar definition.
- Create the toolbar item.
- Insert into toolbar.
- Process toolbutton click here.
Note
You may want to compare this with the setting up of GtkMenu - How to set up menu and radio menu - Part 1?. The two are very similar.
Related Links
User reviews Average user ratings: 5.0 (from 3 users) Note: You have to be a registered member to leave a comment. Free registration here. |
July 25, 2007 6:26am
I Have a toolbar like this, but can i add custom text and images?
July 26, 2007 2:33am
Here are three examples to show you how to setup toolbar with custom text and images.
How to set up toolbar with custom text and graphics - Part 1 - labels below graphics?
How to set up toolbar with custom text and graphics - Part 2 - labels on right of graphics?
How to set up toolbar with custom text and graphics - Part 3 - exact positioning of labels?
May 06, 2008 3:36am