Re: Signal handler args

If I'm not positive something is an object, instead of:
    if (defined $arg2 and $arg2->isa("Gtk2::Gdk::Event")) {
I use:
    if (UNIVERSAL::isa($arg2, "Gtk2::Gdk::Event")) {
This returns false if $arg2 is undefined or isn't a reference.

The first example fails if $arg2 = 10 (any scalar value) or
if $arg2 = \10 (an unblessed reference).
If I made the object and it was never out of my code (kind of like
luggage never being out of my control), I the first, if the user
(other programmer) handed me the object or had a chance to manipulate
it, I use the latter.

On Tue, Oct 22, 2002 at 09:38:04AM +0200, goran kirra net wrote:

I not too happy about the syntax myself,
but the behavior is consistent with how it is done in C
and probably in old gtk-perl(?)

The reason probably is that these signalhandlers are
most often different kind of beast.
You should be able to test the second arggument with
something like (untested code follows):

if (defined $arg2 and $arg2->isa("Gtk2::Gdk::Event")) 

I am willing to change this in line with your
suggestion if we can reach consensus.


On Tue, Oct 22, 2002 at 04:11:32AM +0100, Dermot Musgrove wrote:
Hi all,

Following a previous thread, I tried to connect a signal handler to
'button_press_event' and was delighted that it worked - however ...

In the event handler, 'print Dumper(\ _)' produces:
(I passed {'data'=>'test data'} to the data arg of signal_connect)
$VAR1 = [
          bless( do{\(my $o = 137040016)}, 'Gtk2::Button' ),
          bless( do{\(my $o = 137239944)}, 'Gtk2::Gdk::Event' ),
            'data' => 'test data'

Please can we have the args to the signal handlers delivered as:

  my ($widgetref, $dataref) = @_;

or for an event handler

  my ($widgetref, $dataref, $eventref) = @_;

At least this way, it is possible to write generic handlers that do
not need to know whether the handler is connected to a signal or an
event in order to work. It also makes it possible to auto-generate
simple signal handlers for programmers to edit (Glade-Perl-Two will 
do this so I have an interest :-)

I don't know if it is simple to translate the Gtk2::Gdk::Event into
an anonymous hash and pass that to the handler as Gtk-Perl does but 
IMO that is any easier thing to use and understand.

Regards, Dermot

gtk-perl-list mailing list
gtk-perl-list gnome org

G?ran Thyni
 Senior Technical Consultant
 Lule?, Sweden

gtk-perl-list mailing list
gtk-perl-list gnome org

   Rudy Albachten
   Advanced Micro Devices
   Athlon Design Team
   Texas Microprocessor Division
   Austin, Texas

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