Gtk2-Ex-WidgetBits

 view release on metacpan or  search on metacpan

examples/action-tooltips.pl  view on Meta::CPAN


my $actiongroup = Gtk2::ActionGroup->new ('my-action-group');
Gtk2::Ex::ActionTooltips::group_tooltips_to_menuitems ($actiongroup);

$actiongroup->add_actions
  ([
    { name  => 'FileMenu',
      label => '_File',
    },

    { name  => 'MyAction',
      label => '_MyAction',
      # tooltip is set in the code below
      callback => sub {
        print "MyAction runs\n";
      },
    },
    { name => 'Quit',
      label => '_Quit',
      tooltip => 'Quit means close the window and exit the program',
      callback => sub {
        $toplevel->destroy;
      },
    },
   ]);

my $my_action = $actiongroup->get_action('MyAction');
Gtk2::Ex::ActionTooltips::action_tooltips_to_menuitems_dynamic ($my_action);

Glib::Timeout->add
  (1000, sub {
     my $tip = strftime ('As of %H:%M:%S, this is the tooltip for my action',
                         localtime (time()));
     $my_action->set (tooltip => $tip);
     return 1; # Glib::SOURCE_CONTINUE
   });

my $ui = Gtk2::UIManager->new;
$ui->insert_action_group ($actiongroup, 0);

$ui->add_ui_from_string (<<'HERE');
<ui>
  <menubar name='MenuBar'>
    <menu action='FileMenu'>
      <menuitem action='MyAction'/>
      <menuitem action='Quit'/>
    </menu>
  </menubar>
  <toolbar  name='ToolBar'>
    <toolitem action='MyAction'/>
    <toolitem action='Quit'/>
  </toolbar>
</ui>
HERE

$vbox->pack_start ($ui->get_widget('/MenuBar'), 0,0,0);
$vbox->pack_start ($ui->get_widget('/ToolBar'), 0,0,0);

my $label = Gtk2::Label->new (<<'HERE');
Move the mouse over the tool items or
the menu items (after you popup the menu)
to see the tooltips.
HERE
$vbox->pack_start ($label, 1,1,0);

$toplevel->show_all;
Gtk2->main;
exit 0;



( run in 1.603 second using v1.01-cache-2.11-cpan-364913b4093 )