Re: how to get signal from child widget

On Mon, Jan 17, 2011 at 02:49:33AM -0800, wrote:
> I've got a question: I have a parent-vbox, and I add some
> child-widgets such as paned-box, label, entry, text-view in it. Now
> when one(it could be anyone) of the child-widgets get focus in, I
> wanna get the signal to handle something.
> How should I do? Should I connect "focus-in" signal to every
> child-widget, or some better way? I tried to connect "focus-in" signal
> to the parent-vbox, but seems not work.

Only widgets that can receive keyboard focus themselves can emit
"focus-in".  But containers have a "set-focus-child" signal so this
might be what you need:

import gtk

win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.connect('destroy', gtk.main_quit)

hbox = gtk.HBox()

def child_focused(widget, child, i):
    print('A child in vbox #%u got focus.' % i)

for i in range(3):
    vbox = gtk.VBox()
    for j in range(5):
        entry = gtk.Entry()
    vbox.connect('set-focus-child', child_focused, i+1)



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