PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 505: How to create vertical detachable toolbar with handle bar on top - Part 1?
Written by kksou   
Sunday, 08 June 2008
Problem

This example is similar to that of How to create detachable toolbar?

The only difference is that in this example, the detachable toolbar is a vertical one with the handle bar on top as shown below:

How to create vertical detachable toolbar with handle bar on top - Part 1?


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   
33   
34   
35   
36   
37   
38   
39   
40   
41   
<?php
$window = new GtkWindow();
$window->set_title($argv[0]);
$window->set_size_request(400, 360);
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->add($vbox = new GtkVBox());
$vbox->pack_start($hbox = new GtkHBox(), 0);

// define menu definition
$toolbar_definition = array('New', 'Open', 'Save',
    'Cut', 'Copy', 'Paste',
    'Undo','Redo');
setup_toolbar($hbox, $toolbar_definition);

// display title
$title = new GtkLabel("Create vertical detachable toolbar\n".
"         with handle bar on top");
$title->modify_font(new PangoFontDescription("Times New Roman Italic 10"));
$title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff"));
$hbox->pack_start($vbox2 = new GtkVBox());
$vbox2->pack_start($title);
$vbox2->pack_start(new GtkLabel(''));

$window->show_all();
Gtk::main();

// setup toolbar
function setup_toolbar($hbox, $toolbar_definition) {
    $toolbar = new GtkToolBar();
    $toolbar->set_orientation(Gtk::ORIENTATION_VERTICAL); // note 1
    $handlebox = new GtkHandleBox();
    $handlebox->add($toolbar);
    $handlebox->set_handle_position(Gtk::POS_TOP); // note 2
    $toolbar->set_size_request(34, 340);
    $toolbar->set_property('icon-size', Gtk::ICON_SIZE_MENU);

    $hbox->pack_start($handlebox, 0);
    foreach($toolbar_definition as $item) {
        if ($item=='<hr>') {
            $toolbar->insert(new GtkSeparatorToolItem(), -1);
        } else {
  • 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

This example make use of the code in How to create detachable toolbar?.

What's new here:

  1. Display the toolbar vertically.
  2. Place the handle bar on top.

Related Links
 

Add comment


Security code
Refresh

< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Links - Classes - Social Business - BPM - Web - General
Copyright © 2006-2013. kksou.com. All Rights Reserved