Sample Code 128: How to create detachable toolbar? |
|
Written by kksou
|
|
Tuesday, 26 December 2006 |
|
Problem You want to create detachable toolbars as shown below:

Solution You will be surprised how easy it is to create detachable toolbars in php-gtk2.
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
| <?php $window = new GtkWindow(); $window->set_size_request(400, 150); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
// define toolbar definition
$toolbar_definition = array('New', 'Open', 'Save', '<hr>', 'Cut', 'Copy', 'Paste', '<hr>', 'Undo','Redo'); setup_toolbar($vbox, $toolbar_definition);
// display title
$title = new GtkLabel("Create Detachable Toolbars"); $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) { $toolbar = new GtkToolBar(); $handlebox = new GtkHandleBox(); // note 1
$handlebox->add($toolbar); // note 2
$toolbar->set_size_request(360,-1); // note 3
$vbox->pack_start($handlebox, 0, 0); foreach($toolbar_definition as $item) { if ($item=='<hr>') { $toolbar->insert(new GtkSeparatorToolItem(), -1); } else { $stock_image_name = 'Gtk::STOCK_'.strtoupper($item); 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 This example make use of the code in How to set up toolbar?.
What's new here:
- Create a new handlebox.
- Stuff the toolbar in the handlebox.
- Set the size of the handlebox.
Related Links
User reviews Average user ratings: 4.0 (from 3 users) Note: You have to be a registered member to leave a comment. Free registration here. |
June 08, 2008 3:38pm
Is it possible to make the GtkHandleBox attach in a different place?
June 08, 2008 4:53pm
Sorry, I meant in lets say a different place altogether. For example if I have 2 handleboxes, and would like the user to be able to swap them - drag one out, and another one in. Is this possible? I kept looking at the API but didn't find anything.
PS. Please make the ratings optional!
June 08, 2008 8:06pm
Please refer to: Sample Code 506: How to create vertical detachable toolbar with handle bar on top - Part 2 - multiple toolbars
Regards,
/kksou