Re: TextView - access to the popup menu?
- From: "muppet" <scott asofyet org>
- To: gtk-perl-list gnome org
- Subject: Re: TextView - access to the popup menu?
- Date: Wed, 26 Jul 2006 11:11:25 -0400 (EDT)
Matthew Braid wrote:
Hi all,
I've looked through the archives/FAQ and was kind of surprised this hasn't
come up (either this just isn't done or I'm missing something really
simple). I want to alter the right-click menu for a TextView, but I don't
know how to access it.
I looked through the gtk2 source and found references to 'popup_menu', but
calls to $text->popup_menu, $text->get_popup_menu, $text->popupmenu and
$text->menu (amongst others I tried) came back with an unknown method error.
It is the "populate-popup" signal that you seek. Unfortunately, the docs for
it on the web appear to be very, shall we say, rare. I stumbled across it
some time ago while doing something else, entirely. Here's a quick example,
hopefully as entertaining as it is illuminating.
#!/usr/bin/perl -w
use strict;
use Gtk2 -init;
my $textview = Gtk2::TextView->new;
$textview->signal_connect (populate_popup => sub {
my ($textview, $menu) = @_;
print "populate_popup $textview $menu\n";
foreach my $text (reverse 'Party!', 'Get naked!', 'Buy us beer!') {
my $item = Gtk2::MenuItem->new ($text);
$item->show;
$item->signal_connect (activate => sub { print "$text\n" });
$menu->prepend ($item);
}
});
my $window = Gtk2::Window->new;
$window->set_default_size (300, 400);
$window->add ($textview);
$window->signal_connect (destroy => sub {Gtk2->main_quit});
$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]