Multiple menu popups with a single Gtk2::SimpleList

View: New views
2 Messages — Rating Filter:   Alert me  

Multiple menu popups with a single Gtk2::SimpleList

by Michael McGinn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hi,


I'm trying to display a popup menu in a Gtk2::SimpleList which can have different menu choices depending on the data in the Gtk2::SimpleList.


The menu popup choices are driven by the value selected from a Gtk2::ComboBox. There is a signal on the combobox that runs the popup sub below when the value changes.


The first time the popup menu is invoked it displays correctly; displaying the appropriate popup menu. The next time I select a different value from the Gtk2::ComboBox and right click it a row in the Gtk2::SimpleList, it continues to show the old popup in addition to the new one.


It's seems the Gtk2::SimpleList won't let go of menus you associate.


Here is a sample code snippet of what's not working.

sub popup {

my $menu;

if ($type eq 'type1') {
$menu = Gtk2::Menu->new();
my $menu_item = Gtk2::MenuItem->('Properties');
$menu_item->signal_connect(activate => sub {
# do something
});

$menu->append($menu_item);

} elsif ($type eq 'type2') {
$menu = Gtk2::Menu->new();
my $menu_item = Gtk2::MenuItem->('View');
$menu_item->signal_connect(activate => sub {
# do something else
});

$menu->append($menu_item);
}

$simple_list =>signal_connect('button-press-event' => sub {
my ($widget, $event) = @_;
return FALSE unless $event->button eq 3;
$menu->popup (
undef,
undef,
undef,
undef,
$event->button,
$event->time);
}

$menu->show_all;

}

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

RE: Multiple menu popups with a single Gtk2::SimpleList

by Jeff Hallock :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

________________________________________

>From: gtk-perl-list-bounces@... [mailto:gtk-perl-list-bounces@...] On Behalf Of MICHAEL MCGINN

>Sent: Monday, October 26, 2009 8:32 PM

>To: gtk-perl-list@...

>Subject: Multiple menu popups with a single Gtk2::SimpleList

> 

>Hi,

> 

>I'm trying to display a popup menu in a Gtk2::SimpleList which can have different menu choices depending on the data in the Gtk2::SimpleList.

> 

>The menu popup choices are driven by the value selected from a Gtk2::ComboBox. There is a signal on the combobox that runs the popup sub below when the value changes.

> 

>The first time the popup menu is invoked it displays correctly; displaying the appropriate popup menu. The next time I select a different value from the Gtk2::ComboBox and right click it a row in the Gtk2::SimpleList, it continues to show the old popup in addition to the new one.

> 

>It's seems the Gtk2::SimpleList won't let go of menus you associate.

> 

>Here is a sample code snippet of what's not working.

>sub popup {

> 

>my $menu;

> 

>if ($type eq 'type1') {

>   $menu = Gtk2::Menu->new();

>   my $menu_item = Gtk2::MenuItem->('Properties');

>   $menu_item->signal_connect(activate => sub {

>       # do something

>   });

>  

>   $menu->append($menu_item);

> 

>} elsif ($type eq 'type2') {

>   $menu = Gtk2::Menu->new();

>   my $menu_item = Gtk2::MenuItem->('View');

>   $menu_item->signal_connect(activate => sub {

>       # do something else

>   });

>  

>   $menu->append($menu_item);

>}

> 

>$simple_list =>signal_connect('button-press-event' => sub {

>   my ($widget, $event) = @_;

>   return FALSE unless $event->button eq 3;

> $menu->popup (

>   undef,

>   undef,

>   undef,

>   undef,

>   $event->button,

>   $event->time);

>}

> 

>$menu->show_all;

> 

>}

 

Correct, every time you call signal_connect, you are adding another callback to be executed when the event happens.

You could try creating two menus, the decide which one to show in the callback.

 

my $menu1 = ...

my $menu2 = ...

 

 

$simple_list =>signal_connect('button-press-event' => sub {

  my ($widget, $event) = @_;

  return FALSE unless $event->button eq 3;

 

  if ( some condition ... ) {

       $menu1->popup (

       undef,

       undef,

       undef,

       undef,

       $event->button,

       $event->time

     );

  }

  else {

       $menu2->popup (

       undef,

       undef,

       undef,

       undef,

       $event->button,

       $event->time

     ); 

  }

 

}

 

 

It's also worth noting you can disconnect signals.

 

my $handler_id = $simple_list =>signal_connect('button-press-event' => sub { ... });

$simple_list->signal_disconnect($handler_id);


_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list