Gtk2::SimpleMenu(3)
β¨ Gtk2::SimpleMenu π
okay bestie, gather round, because today we're talking about Gtk2::SimpleMenu β yes, the whole manual page, from the Perl docs, and it's lowkey iconic. This is the module that lets you build application menus without wanting to scream. It's a simple interface to Gtk2's ItemFactory for creating application menus. π
πΈ SYNOPSIS πΈ
like, here's the vibe, fr fr:
use Gtk2 '-init';
use Gtk2::SimpleMenu;
my $menu_tree = [
_File => {
item_type => '<Branch>',
children => [
_New => {
callback => \&new_cb,
callback_action => 0,
accelerator => '<ctrl>N',
},
_Save => {
callback_action => 1,
callback_data => 'per entry cbdata',
accelerator => '<ctrl>S',
},
_Exec => {
item_type => '<StockItem>',
callback_action => 2,
extra_data => 'gtk-execute',
},
_Quit => {
callback => sub { Gtk2->main_quit; },
callback_action => 3,
accelerator => '<ctrl>Q',
},
],
},
_Mode => {
_First => {
item_type => '<RadioItem>',
callback => \&mode_callback,
callback_action => 4,
groupid => 1,
},
_Second => {
item_type => '<RadioItem>',
callback => \&mode_callback,
callback_action => 5,
groupid => 1,
},
_Third => {
item_type => '<RadioItem>',
callback => \&mode_callback,
callback_action => 6,
groupid => 1,
},
}
_Help => {
children => [
_Tearoff => {
item_type => '<Tearoff>',
},
_CheckItem => {
item_type => '<CheckItem>',
callback_action => 7,
},
Separator => {
item_type => '<Separator>',
},
_Contents => {
callback_action => 8,
},
_About => {
callback_action => 9,
},
]
}
];
my $menu = Gtk2::SimpleMenu->new (
menu_tree => $menu_tree,
default_callback => \&default_callback,
user_data => 'user_data',
);
# an example of how to get to the menuitems.
$menu->get_widget('/File/Save')->activate;
$container->add ($menu->{widget});
π¦ ABSTRACT π¦
so basically, SimpleMenu is an interface for creating application menubars in as simple a manner as possible. its main benefit? the menu is specified as a tree, which is, like, the natural representation of such a menu. no cap. π³
π DESCRIPTION π
SimpleMenu aims to simplify the design and management of a complex application menu bar by allowing the structure to be specified as a multi-rooted tree. Much the same functionality is provided by Gtk2::ItemFactory, but the data provided as input is a 1-D array and the hierarchy of the menu is controlled entirely by the path components. that's... not ideal when languages such as Perl provide for simple nested data structures. like, why would you π
Another advantage of the SimpleMenu widget is that it simplifies the creation and use of accelerators. keyboard shortcuts, slay. β¨
SimpleMenu is a child of Gtk2::ItemFactory, so that it may be treated as such. Any method that can be called on a ItemFactory can be called on a SimpleMenu. it's giving inheritance, and we love that for us. π
π OBJECT HIERARCHY π
Glib::Object
+--- Gtk2::Object
+--- Gtk2::ItemFactory
+--- Gtk2::SimpleMenu
look at the family tree bestie, it's gorgeous π«Ά
β FUNCTIONS β
$menu = Gtk2::SimpleMenu->new (menu_tree => $menu_tree, ...)β Creates a new Gtk2::SimpleMenu object with the specified tree. Optionally key value paris providing adefault_callbackanduser_datacan be provided as well. After creating the menu object all of the subsequent widgets will have been created and are ready for use. like, everything's already built for you, go off π
π MEMBER VARIABLES π
$menu->{widget}β TheGtk2::MenuBarroot of the SimpleMenu. This is what should be added to the widget which will contain the SimpleMenu.
$container->add ($menu->{widget});
$menu->{accel_group}β TheGtk2::AccellGroupcreated by the menu tree. Normallyaccell_groupwould be added to the main window of an application, but this is only necessary if accelerators are being used in the menu tree's items.
$win->add_accel_group ($menu->{accel_group});
π SEE ALSO π
Perl(1), Glib(3pm), Gtk2(3pm), examples/simple_menu.pl.
okay so important heads up bestie: Gtk2::SimpleMenu is deprecated in favor of Gtk2::Ex::Simple::Menu, part of the Gtk2-Perl-Ex project at <http://gtk2-perl-ex.sf.net/>. it's giving "we've moved on", and honestly? valid. but now you know. π
π AUTHORS π
Ross McFarland <rwmcfa1 at neces dot com>
π COPYRIGHT AND LICENSE π
Copyright 2003 by the Gtk2-Perl team.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
okay that's the whole page, and honestly, you ate that. π§ anyway, this little beauty is from perl v5.42.0, dated 2025-07-25, and it's filed under the manual page for Gtk2::SimpleMenu(3). periodt. π
π¦ where this page comes from
- fedora 43: perl-Gtk2 1.24993-23.fc43 Β· LicenseRef-Callaway-LGPLv2+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms