Re: Fwd: submenu items activate signals...




BoÅ¡tjan Å petiÄ? said:

i have a problem with creating a submenus, because the signals somehow don't
get connected / nothing happens...

are you sure they're not getting connected?


      while (my ($name, $callback) = each (%columns)) {
              my $menu_item = Gtk2::MenuItem->new($name);
              $menu_item->signal_connect('activate', $callback);

is $callback here actually a CODE reference?  note that you can, indeed, send
a string as the subroutine and it will be interpreted as a sub name, but
that's hard to use and thus not widely publicized, but that's why it won't
complain if you don't pass a code reference.


      my $setup = Gtk2::MenuItem->new('Configure');
              $setup->signal_connect('activate' => \&setup_progs);

does this one work?

there is no error, but no effect either...

couldn't test your code directly, so i built a five-minute scaffold... i don't
see any problems.

-=-=-=-=-=-=-=-
#!/usr/bin/perl -w

use strict;
use Gtk2 -init;

my %items = map { my $foo = $_; ($foo => sub { print "$foo\n"; }) }
                qw(red orange yellow green blue indigo violet);

my $window = Gtk2::Window->new;
$window->signal_connect (destroy => \&Gtk2::main_quit);

my $menu = Gtk2::Menu->new;

my $submenu = Gtk2::Menu->new;
while (my ($label, $callback) = each %items) {
        my $item = Gtk2::MenuItem->new ($label);
        $item->signal_connect (activate => $callback);
        $item->show;
        $submenu->append ($item);
}
my $item = Gtk2::MenuItem->new ("Foo");
$item->set_submenu ($submenu);
$menu->append ($item);

$item = Gtk2::MenuItem->new ("Baz");
$item->signal_connect (activate => sub { print "Baz!\n" });
$menu->append ($item);

$menu->show_all;


my $button = Gtk2::Button->new ("Clicky Clicky Clicky");
# only works when you click, not if you activate the button with the keyboard
$button->signal_connect (button_press_event => sub {
        my (undef, $event) = @_;
        $menu->popup (undef, undef, undef, undef, $event->button, $event->time);
        1;
});

$window->add ($button);

$window->show_all;
Gtk2->main;



-- 
muppet <scott at asofyet dot org>




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]