01 May 2013 - After the site upgrade, all passwords were reset and you will need to ask the site for a login reset on your first connection.
Here is a quick overview of how to build a menu bar using php-gtk2 widgets. Think of it as a cheat sheet on menubar and friends.
The goal of this page is to list the most important objects and
methods needed to build a basic menubar. You can use
this document to write your own function or menubar class builder.
We try to keep this document as simple as possible,
not to show all advanced mechanisms.
Here is a complete widget tree with some useful information
Gtk class related
# widget tree (or relations) :
0 - $window (GtkWindow) -> add()
1 - $menubar (GtkMenubar) -> append() or add()
2 - $item (GtkMenuItem) (File, Edit) -> set_submenu()
3 - $menu (GtkMenu) ($quit_menu, $file_menu) -> append() or add()
4 - $menu_item (GtkMenuItem|GtkSeparatorMenuItem|GtkRadioMenuItem)
and here is the expected widget representation on
your screen
menubar:
File
New
Quit
Edit
Cut
Copy
Paste
---
- Choice 1
* Choice 2 (activated)
- Choice 3
Here is a complete source code example. For this example, code indentation is relative to the object tree hierarchy, not to the code structure as usual. A few points :
null to first widget in a group,
and the first widget in successive widget creations.append() or
add() methods without significant
changes.set_active() method,"activate" signal,"toggled",<?php
$menubar = new GtkMenuBar(); // 1
$menubar->append($file_item = new GtkMenuItem('_File')); // 2
$menubar->append($edit_item = new GtkMenuItem('_Edit')); // 2
$file_item->set_submenu($quit_menu = new GtkMenu()); // 3
$quit_menu->append($file_new_item = new GtkMenuItem('_New')); // 4
$quit_menu->append($file_quit_item = new GtkMenuItem('_Quit')); // 4
$edit_item->set_submenu($edit_menu = new GtkMenu()); // 3
# create 3 buttons : signal : 'activate'
$edit_menu->append($edit_cut_item = new GtkMenuItem('_Cut')); // 4
$edit_menu->append($edit_copy_item = new GtkMenuItem('Co_py')); // 4
$edit_menu->append($edit_paste_item = new GtkMenuItem('_Paste')); // 4
$edit_menu->append(new GtkSeparatorMenuItem()); // 4
# create a group of radio buttons : signal : 'toggled' // note 1
$edit_menu->append($radio1 = new GtkRadioMenuItem(null, 'Choice _1')); // 4
$edit_menu->append($radio2 = new GtkRadioMenuItem($radio1, 'Choice _2')); // 4
$edit_menu->append($radio3 = new GtkRadioMenuItem($radio1, 'Choice _3')); // 4
$radio2->set_active(true); // note 3
# setup some signal callbacks
$file_quit_item->connect_simple('activate', array('Gtk','main_quit')); //note 4
$file_new_item->connect ('activate', 'menu_activate', 'file_new');
$edit_copy_item->connect ('activate', 'menu_activate', 'edit_copy');
$edit_paste_item->connect('activate', 'menu_activate', 'edit_paste');
$edit_cut_item->connect ('activate', 'menu_activate', 'edit_cut');
$radio1->connect('toggled', 'menu_toggle', 'edit_choice1'); // note 5
$radio2->connect('toggled', 'menu_toggle', 'edit_choice2');
$radio3->connect('toggled', 'menu_toggle', 'edit_choice3');
# php-gtk usual application initialization
$window = new GtkWindow(); // 0
$window->set_size_request(150, -1);
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->set_position(Gtk::WIN_POS_CENTER);
$window->add($menubar); // 0
$window->show_all();
Gtk::main();
function menu_activate($button, $userdata) {
echo "button : $userdata\n";
}
function menu_toggle($button, $userdata) {
# if button is active (selected)
if ($button->get_active())
echo "button toggle : $userdata\n";
}
?>Examples
API
| Attachment | Size |
|---|---|
| gtk-menubar-overview.php_.txt | 2.51 KB |
Recent comments
43 weeks 4 days ago
44 weeks 3 days ago
45 weeks 10 hours ago
47 weeks 3 days ago
1 year 15 weeks ago
1 year 19 weeks ago
1 year 23 weeks ago
1 year 23 weeks ago
1 year 23 weeks ago
1 year 40 weeks ago