You will be surprised how easy it is to create detachable toolbars in php-gtk2.
- First create a toolbar as explained in the article How to set up toolbar?
- Create a GtkHandlebox, and stuff the toolbar in the handlebox. That's it!
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 | $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', ' ', 'Cut', 'Copy', 'Paste', ' ', '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==' ') { $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
What's new here:This example make use of the code in How to set up toolbar?.
- Create a new handlebox.
- Stuff the toolbar in the handlebox.
- Set the size of the handlebox.
No comments:
Post a Comment