Re: how to get signal from child widget



On Mon, Jan 17, 2011 at 02:49:33AM -0800, fengzi.gg 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()
win.add(hbox)

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

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

win.show_all()
gtk.main()
=====================================================================

Yeti



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