Re: widget valid signals and properties




On Jul 25, 2006, at 4:59 PM, Dirk Koopman wrote:

1. How do I get a list of valid properties and signals for a widget?

Glib::Type::list_signals() and Glib::Object::list_properties(). See the Glib::Type and Glib::Object manpages.

You may be interested in my Gtk2-Perl object_browser, which knows how to list signals and properties as well as POD: http://asofyet.org/muppet/software/gtk2-perl/object_browser- methodscraper


and related:

2. Is it possible to hook oneself onto all signals? Is there some
"master" signal one could hook into?

Not really -- not from perl, at least. And, honestly, doing so would absolutely drown you in callbacks.

There are other ways, but it depends on what you're doing. If you want to see events, then the "event" and "event-after" signals on Gtk2::Widget will be helpful. However, not all signals are events. If you just want to watch the events fire so you can get a feel for what your program is doing, a signal emission hook is helpful. (You need at least Glib 1.080 for this.) Glib::Object::signal_add_emission_hook() invokes your callback on all invocations of a particular signal, for all instances of that class. There is no blanket "all signals", but combined with Glib::Type::list_signals() and Glib::Type::list_ancestors() you can drown in all the data you want. ;-)

Here's a quick example, using only the handful of signals defined by Gtk2::Button:



#!/usr/bin/perl -w

use strict;
use Gtk2 -init;
use Glib ':constants';

#
# Let's set up an emission hook to announce the emission of all
# Gtk2::Button signals on any button instance.  Note that this is
# only the signals created by Gtk2::Button, not the inherited
# signals.  Installing emission hooks on Gtk2::Widget can be
# informative, but usually results in a deluge of information,
# requiring your hook functions to be much smarter than what i've
# created here.
#
foreach my $siginfo (Glib::Type->list_signals ('Gtk2::Button')) {
        # We'll use a real sub instead of creating a brand new closure for
        # every hook.
        print "installing hook for $siginfo->{itype}"
            . "::$siginfo->{signal_name}\n";
        Gtk2::Button->signal_add_emission_hook
                        ($siginfo->{signal_name} => \&hook);
}

sub hook {
        my ($ihint, $param_list) = @_;
        print "$ihint->{signal_name} (".join (", ", @$param_list).")\n";
}


#
# Now, a window with a button in it, so we can trigger these signals.
#
my $dialog = Gtk2::MessageDialog->new (undef, [], 'info', 'ok-cancel',
                                       "Here's a silly message; do stuff to "
                                       ."the window and watch stdout for "
                                       ."signal emissions.  Ok will close, "
                                       ."cancel will not.");
$dialog->set_resizable (TRUE);

#
# Go!
#

print "running again\n" while 'ok' ne $dialog->run;

$dialog->destroy;



--
Walk softly, and carry a BFG-9000.
  -- unknown




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