Re: Can't locate object method "motion_notify_event" via package "Gtk2::HRuler".

csld skynet be said:

In the Rulers example of the Gtk+ 2.0 tutorial, the
'motion_notify_event' of a DrawingArea widget is connected to the
'motion_notify_event' handler of an HRuler.

the typical C code you see to do this involves messing directly with the class
structures to find and invoke directly a private method on the rulers.

you can't get to that method from perl because, we'll, you're not really
supposed to be able to do that.

the proper way to do this is to propagate that event to the other object with

the C code tends to avoid this step because it's rather circuitous when you
can just invoke the method directly.  since we can't do that, i think we
should use the more proper route.

(if you look at the gtk-perl tutorial (for gtk+ 1.x), it shows the syntax you
were trying to use; gtk-perl implemented just that one method specifically for
getting rulers to work.  i do not want to bring that hack to gtk2-perl when
the more correct solution is available.)

$area->signal_connect(motion_notify_event =>
                       sub { $hrule->motion_notify_event($_[1]); });

this should really be

                         sub { $hrule->event ($_[1]) });

but (and there's always a "but"), that won't work in Gtk2-1.00 because
gtk_widget_event() is not bound to perl.

the solution:

either start using gtk2-perl out of CVS (where that method will be implemented
in just a few minutes), wait for the next stable release in a few days, or
patch your copy of Gtk2 like this:

Index: xs/GtkWidget.xs
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Gtk2/xs/GtkWidget.xs,v
retrieving revision 1.35
diff -u -r1.35 GtkWidget.xs
--- xs/GtkWidget.xs     10 Nov 2003 06:49:51 -0000      1.35
+++ xs/GtkWidget.xs     10 Nov 2003 19:47:20 -0000
@@ -401,8 +401,16 @@
        gboolean    group_cycling

  # gtk docs say rarely used, suggest other ways
- #gboolean   gtk_widget_event            (GtkWidget           *widget,
- #                                        GdkEvent            *event);
+=for apidoc
+This rarely-used function emits an event signal on I<$widget>.  Don't use
+this to synthesize events; use C<< Gtk2->main_do_event >> instead.  Don't
+synthesize expose events; use C<< $gdkwindow->invalidate_rect >> instead.
+Basically, the main use for this in gtk2-perl will be to pass motion
+notify events to rulers from other widgets.
+gboolean gtk_widget_event (GtkWidget * widget, GdkEvent        *event);
+ # gtk docs say rarely used, suggest other ways
  #gint       gtk_widget_send_expose         (GtkWidget           *widget,
  #                                        GdkEvent            *event);

muppet <scott at asofyet dot org>

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