Re: Event Handling

James Muir said:
Nice, but this handler will receive all events. Is there a way to
indicate to Gnome that my program is only interested in, say,
"button-press"  events and to call my handler
only for "button-press" events. Or do I have to handle all possible
events in my handler?

Unfortunately, no.  GnomeCanvas does its own event routing, and
GnomeCanvasItem gets a small subset of the events that GtkWidget gets.  You
get to dispatch based on $event->type in your event handler.

Something evil i have done in the past is create a table of these things:

  %foo_event_dispatch = (
      'button-press-event' => \&foo_button_press_event,
      'button-release-event' => \&foo_button_release_event,
  sub foo_event {
     my ($item, $event) = @_;
     my $handler = $foo_event_dispatch{$event->type};
     return $handler
          ? $foo_event_dispatch{$event->type}->($item, $event)
          : FALSE;

But depending on how much code you have in each one, that may be more work
than it's worth.

muppet <scott at asofyet dot org>

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