Re: How to use and process GTK enter or leave signals?



Many thanks for your assistance.

I spotted my mistake immediately after reading your example code, but didn't see it while staring at my code for hours. I had named the signal 'entered-notify-event' instead of 'enter-notify-event'. I suppose I had been conditioned by signals given in past tense like clicked, toggled, changed, selection-changed that I have used before. 

When writing the forum post I was on a different PC and got the signal name right this time (pasted from the manual), but threw in a few syntax and naming errors instead!

The documentation for GtkButton says this for 'enter-notify-event':

"To receive this signal, the GdkWindow associated to the widget needs to enable the GDK_ENTER_NOTIFY_MASK mask."

I am not sure how to enable this mask but tried with or without it using gtk_widget_set_events() and gtk_widget_add_events() with identical results.

Again many thanks.
    
Ken

--- On Fri, 18/12/09, David Nečas <yeti physics muni cz> wrote:

From: David Nečas <yeti physics muni cz>
Subject: Re: How to use and process GTK enter or leave signals?
To: "Ken Resander" <kresander yahoo com>
Cc: gtk-list gnome org
Date: Friday, 18 December, 2009, 11:18 PM

On Fri, Dec 18, 2009 at 05:25:57AM -0800, Ken Resander wrote:
> Just for testing I used a GtkButton and substituted signal enter-notify-event for signal clicked (clicked works).  A warning appears: "enter-notify-event is invalid for instance" after g_signal_connect is executed. The callback handler is not called.
> Simplified:
>
> [code]
> GtkWidget * b = gtk_new_button ();
> ....
> g_signal_connect (b, "enter-notify-event",
>                   G_CALLBACK (enterleave), myuserdata) ;
> ...
> [/code]
>
> with callback handler
>
> [code]
> static gboolean enterleave ( GtkWidget * w,
>                              GdkEventCrossing * event,
>                              char * data )
>    {
>   printf ( "Now in enterleave callback\n" ) ;
>    ....
>    return false;
>    }
> [/code]
>
>
> I also tried:
> [code]
> gtk_widget_set_events ( b, _ENTER_NOTIFY_MASK );
> g_signal_connect (b , "enter-notify-event",
>                    G_CALLBACK (enterleave), myuserdata) ;
> [/code]
>
> and also signal "enter" (deprecated), but result was same.
>
> Cannot see what is wrong, so help would be most appreciated.

Your don't post compilable code.  gtk_new_button() does not exist.
gtk_widget_set_events() will likely break GtkButton, use
gtk_widget_add_events(). _ENTER_NOTIFY_MASK does not exist.  How can we
tell what else is wrong?

The events works for me.

Yeti


===================================================
#include <gtk/gtk.h>

static gboolean
enter(GtkWidget *ebox,
      GdkEventCrossing *event)
{
    g_print("Gotcha!\n");
    return FALSE;
}

static gboolean
leave(GtkWidget *ebox,
      GdkEventCrossing *event)
{
    g_print("Oops!\n");
    return FALSE;
}

int
main(int argc, char *argv[])
{
    GtkWidget *window, *button;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    button = gtk_button_new_with_label("Don't Click Me");
    gtk_container_add(GTK_CONTAINER(window), button);
    g_signal_connect(button, "enter-notify-event", G_CALLBACK(enter), NULL);
    g_signal_connect(button, "leave-notify-event", G_CALLBACK(leave), NULL);

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}



Get your preferred Email name!
Now you can @ymail.com and @rocketmail.com.

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