Scroll to navigation

PerlPanel::MenuBase(3) User Contributed Perl Documentation PerlPanel::MenuBase(3)

NAME

PerlPanel::MenuBase - a base class for PerlPanel menu applets.

SYNOPSIS

        package PerlPanel::Applet::MyMenu;
        use base 'PerlPanel::MenuBase';
        use strict;
        sub create_menu {
                my $self = shift;
                $self->menu->append($self->menu_item(
                        'Hello World!',
                        $icon,
                        sub { print "Hello World!\n" }
                ));
                return 1;
        }
        1;

DESCRIPTION

"PerlPanel::MenuBase" is a base class that does as much as possible to abstract the nuts-and-bolts details of building a PerlPanel menu applet. If you use "PerlPanel::MenuBase" to write a menu applet, you don't need to worry about menu hierarchies or icons - all that's done for you. Instead to can concentrate on building your menu backend.

USAGE

"PerlPanel::MenuBase" is a base class - that means, you must write a Perl module that inherits from it. The "use base" line in the example above is one way you can do this. Then you simply override the "configure()" and "create_menu()" methods with your own.

STANDARD METHODS

        $self->add_control_items;

This method appends the standard set of PerlPanel control options to the menu. The menu will subsequently look like this:

        |                               |
        | ----------------------------- |
        | Lock Screen                   |
        | Run Program...                |
        | Take Screenshot...            |
        | ----------------------------- |
        | Shut Down...                  |
        | Reboot...                     |
        | ----------------------------- |
        | Configure...                  |
        | Close Panel                   |
        | Add To Panel                > |
        | ----------------------------- |
        | About...                      |
        +-------------------------------+

        my $item = $self->menu_item($label, $icon, $callback);

This returns a ready-prepared Gtk2::ImageMenuItem. This method does a lot of hard work for you - $label is set as the text label for the item, and if defined, $callback is connected to the 'activate' signal.

$icon can be either a file, a "Gtk::Gdk::Pixbuf", or a stock ID. "menu_item" will automagically resize the icon to fit in with the rest of the menu.

        my $icon = $self->get_icon($string, $is_submenu_parent);

This method is deprecated and is no longer available. Use PerlPanel::lookup_icon() instead.

SEE ALSO

  • perlpanel
  • perlpanel-applet-howto
  • Gtk2
2017-06-26 perl v5.24.1