Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 March 20, 2008 00:05:50

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

problem with callback


Hello again

I am making a window that has a menu, two drawing_area
and a GtkEntry

I added the following events (GDK_BUTTON1_MOTION_MASK,
GDK_BUTTON2_MOTION_MASK, GDK_BUTTON_PRESS_MASK,
GDK_VISIBILITY_NOTIFY_MASK) to the two drawing_area,
and the respective callback, but the problem is that
when I press a any key, the Gtkentry and the two
drawing_are receive the signal, then call the function
callback of the two drawing_area and writes the
character in the Gtkentry.

My question:

how can I do for that when I press a key, The signal
will be received only by ddd selected?





____________________________________________________________________________________
¡Capacidad ilimitada de almacenamiento en tu correo!
No te preocupes más por el espacio de tu cuenta con Correo Yahoo!:http://correo.yahoo.com.mx/_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#2 March 20, 2008 00:11:43

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

problem with callback


Hello again

I am making a window that has a menu, two drawing_area
and a GtkEntry

I added the following events (GDK_BUTTON1_MOTION_MASK,
GDK_BUTTON2_MOTION_MASK, GDK_BUTTON_PRESS_MASK,
GDK_VISIBILITY_NOTIFY_MASK) to the two drawing_area,
and the respective callback, but the problem is that
when I press a any key, the Gtkentry and the two
drawing_are receive the signal, then call the function
callback of the two drawing_area and writes the
character in the Gtkentry.

My question:

how can I do for that when I press a key, The signal
will be received only by selected widget, a
drawing_area or the gtkEntry?



____________________________________________________________________________________
¡Capacidad ilimitada de almacenamiento en tu correo!
No te preocupes más por el espacio de tu cuenta con Correo Yahoo!:http://correo.yahoo.com.mx/_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#3 March 21, 2008 11:35:12

Ustun E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

problem with callback


did you try this?http://library.gnome.org/devel/gtk/stable/GtkWidget.html#gtk-widget-grab-focus2008/3/20, Moises <>:
> Hello again
>
> I am making a window that has a menu, two drawing_area
> and a GtkEntry
>
> I added the following events (GDK_BUTTON1_MOTION_MASK,
> GDK_BUTTON2_MOTION_MASK, GDK_BUTTON_PRESS_MASK,
> GDK_VISIBILITY_NOTIFY_MASK) to the two drawing_area,
> and the respective callback, but the problem is that
> when I press a any key, the Gtkentry and the two
> drawing_are receive the signal, then call the function
> callback of the two drawing_area and writes the
> character in the Gtkentry.
>
> My question:
>
> how can I do for that when I press a key, The signal
> will be received only by selected widget, a
> drawing_area or the gtkEntry?
>
>
>
> ____________________________________________________________________________________
> ¡Capacidad ilimitada de almacenamiento en tu correo!
> No te preocupes más por el espacio de tu cuenta con Correo Yahoo!:
>http://correo.yahoo.com.mx/> _______________________________________________
> gtk-list mailing list
> gtk-l***@*nome.org
>http://mail.gnome.org/mailman/listinfo/gtk-list>
_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#4 March 21, 2008 23:20:48

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

problem with callback


Hello again

I still have the same problem

>Hello again

>I am making a window that has a menu, two
drawing_area
> and a GtkEntry
>
> I added the following events
(GDK_BUTTON1_MOTION_MASK,
> GDK_BUTTON2_MOTION_MASK, GDK_BUTTON_PRESS_MASK,
> GDK_VISIBILITY_NOTIFY_MASK) to the two drawing_area,
> and the respective callback, but the problem is that
> when I press a any key, the Gtkentry and the two
> drawing_are receive the signal, then call the
function
> callback of the two drawing_area and writes the
> character in the Gtkentry.
>
> My question:
>
> how can I do for that when I press a key, The signal
> will be received only by selected widget, a
> drawing_area or the gtkEntry?



I used the function gtk_widget_grab_focus () but does
not work, because it function only put focus in the
widget selected, but the others widget also receive
the signal.

But I already solve part of problem, I use the event
"button_press_event" of each drawing_area for disable
the GtkEntry with gtk_entry_set_editable() when I
select one of the drawing_area, But even the two
drawing_area receive the signal "key_press_event".

Then I try to block the callback of "key_press_event"
of each drawing_area with
g_signal_handlers_block_by_func(), but does not work,
and with the function g_signal_handler_block I had
problem because I don't know as obtain the handler_id.

now I have 3 question.

how can I obtain the handler_id for the function
g_signal_handler_block?

Is there other way to prevent that the drawing_area
receive the signal key_press_event?

The problem when I use the function
gtk_entry_set_editable() for disable the GtkEntry is
that for enable the GtkEntry I have to enable the
gtkEntry when I select the widget, then I connect the
signal "button_press_event" with GtkEntry and in this
callback enable the GtkEntry, but now I can't select
text of GtkEntry because I connect the event
"key_press_event" with the GtkEntry, how can I enable
the opcion of select copy and paste of GtkEntry after
of connect this signal?



____________________________________________________________________________________
¡Capacidad ilimitada de almacenamiento en tu correo!
No te preocupes más por el espacio de tu cuenta con Correo Yahoo!:http://correo.yahoo.com.mx/_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#5 March 21, 2008 23:41:35

Richard B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

problem with callback


you have gotten your panties into a serious twist.

start over:

when wanting to receive key press events in a drawing area, you must do
all of the following:

1. set up the drawing area to receive key press and/or release events.
2. set up the drawing area to receive enter and leave notify events.
3. when receiving an enter notify event, you must grab focus of the
drawing area and hold it until you receive the leave notify event, and
then let it go!

so, at creation of the drawing area:

// connect the signals, at least:
g_signal_connect (da, "key_press_event", G_CALLBACK (keyEvent), NULL);
g_signal_connect (da, "key_release_event", G_CALLBACK (keyEvent), NULL);
g_signal_connect (da, "enter_notify_event", G_CALLBACK (grabFocus), NULL);
g_signal_connect (da, "leave_notify_event", G_CALLBACK (grabFocus), NULL);

// set up the events to be received by the drawing area, at least:
gtk_widget_set_events (da, gtk_widget_get_events (da)
| GDK_LEAVE_NOTIFY_MASK
| GDK_ENTER_NOTIFY_MASK
| GDK_KEY_PRESS_MASK
| GDK_KEY_RELEASE_MASK);

// define you grabFocus() callback
gboolean grabFocus(GtkWidget *widget, GdkEvent *event, gpointer nil)
{ // we must grab the focus when mouse enters to receive key events
switch(event->type)
{
case GDK_ENTER_NOTIFY:
gtk_grab_add(GTK_WIDGET (widget));
break;
case GDK_LEAVE_NOTIFY:
gtk_grab_remove(GTK_WIDGET (widget));
break;
default:
break;
}
return TRUE;
}

do it like this and when the mouse is inside the drawing are, the drawing
are will receive all keyboard events. when the mouse is outside the
drawing area, the entry area assigned the current focus will receive the
keyboard events. clicking inside an entry area will always assign focus
to that entry area.

to answer your other question, g_signal_connect() returns the signal
handler id you are looking for. save it when creating the signal callback
and blocking and unblocking is easily done.

richard

_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#6 March 22, 2008 02:25:01

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

problem with callback


Thanks for advice Richard Boaz

But only I have a problem with your solution, the user
must have the mouse all time inside of the drawing
area if he want interact with the drawing area, and if
he want interact with the menu he need to move the
mouse or use the keyboard for interact with the menu.

But I need that the user can interact with the drawing
area only with selected the drawing area
Without the mouse are inside of drawing area, Bucause
at same time that he may interact with the window that
contains the drawing area.

And if I use the function for block the signal have
the problem of that I can't select, copy, paste the
text.







--- Richard Boaz <> escribió:

> you have gotten your panties into a serious twist.
>
> start over:
>
> when wanting to receive key press events in a
> drawing area, you must do
> all of the following:
>
> 1. set up the drawing area to receive key press
> and/or release events.
> 2. set up the drawing area to receive enter and
> leave notify events.
> 3. when receiving an enter notify event, you must
> grab focus of the
> drawing area and hold it until you receive the leave
> notify event, and
> then let it go!
>
> so, at creation of the drawing area:
>
> // connect the signals, at least:
> g_signal_connect (da, "key_press_event", G_CALLBACK
> (keyEvent), NULL);
> g_signal_connect (da, "key_release_event",
> G_CALLBACK (keyEvent), NULL);
> g_signal_connect (da, "enter_notify_event",
> G_CALLBACK (grabFocus), NULL);
> g_signal_connect (da, "leave_notify_event",
> G_CALLBACK (grabFocus), NULL);
>
> // set up the events to be received by the drawing
> area, at least:
> gtk_widget_set_events (da, gtk_widget_get_events
> (da)
> | GDK_LEAVE_NOTIFY_MASK
> | GDK_ENTER_NOTIFY_MASK
> | GDK_KEY_PRESS_MASK
> | GDK_KEY_RELEASE_MASK);
>
> // define you grabFocus() callback
> gboolean grabFocus(GtkWidget *widget, GdkEvent
> *event, gpointer nil)
> { // we must grab the focus when mouse enters to
> receive key events
> switch(event->type)
> {
> case GDK_ENTER_NOTIFY:
> gtk_grab_add(GTK_WIDGET (widget));
> break;
> case GDK_LEAVE_NOTIFY:
> gtk_grab_remove(GTK_WIDGET (widget));
> break;
> default:
> break;
> }
> return TRUE;
> }
>
> do it like this and when the mouse is inside the
> drawing are, the drawing
> are will receive all keyboard events. when the
> mouse is outside the
> drawing area, the entry area assigned the current
> focus will receive the
> keyboard events. clicking inside an entry area will
> always assign focus
> to that entry area.
>
> to answer your other question, g_signal_connect()
> returns the signal
> handler id you are looking for. save it when
> creating the signal callback
> and blocking and unblocking is easily done.
>
> richard
>
>




____________________________________________________________________________________
¡Capacidad ilimitada de almacenamiento en tu correo!
No te preocupes más por el espacio de tu cuenta con Correo Yahoo!:http://correo.yahoo.com.mx/_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

Board footer

Moderator control

Enjoy the 11th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support