Re: Controlling a widget from an other



David Nečas (Yeti <yeti <at> physics.muni.cz> writes:
> 
> So if you still want this
> 
>     g_signal_connect(entry, "key-press-event",
>                      G_CALLBACK(key_pressed), treeview);
> 
> static gboolean
> key_pressed(GtkWidget *entry, GdkEventKey *event, GtkWidget *treeview)
> {
>     if (event->keyval == etc.) {
>         GdkEvent *sevent;
> 
>         sevent = gdk_event_new(GDK_KEY_PRESS);
>         sevent->key.window = g_object_ref(treeview->window);
>         sevent->key.send_event = TRUE;
>         sevent->key.time = GDK_CURRENT_TIME;  /* not good */
>         sevent->key.state = event->state;
>         sevent->key.keyval = event->keyval;
>         sevent->key.length = event->length;
>         sevent->key.string = g_strdup(event->string);
>         sevent->key.hardware_keycode = event->hardware_keycode;
>         sevent->key.group = event->group;
>         sevent->key.is_modifier = event->is_modifier;
>         gtk_widget_grab_focus(treeview);
>         gtk_widget_event(treeview, sevent);
>         gdk_event_free(sevent);
>         gtk_widget_grab_focus(entry);
>         return TRUE;
>     }
> 
>     return FALSE;
> }
> 

This is working as advertised. Cool! :) I omitted copying the event, but it 
seems to work with pygtk:


def text_keypress(widget, event):
    if event.keyval in (Page_Up, Page_Down):
        list.grab_focus();
        list.event(event)
        text.grab_focus()


Thanks again for helping.





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