Re: How to set focus on a text view when tree selection changed?



On Mon, Mar 08, 2010 at 09:55:02AM -0800, kenny wang wrote:
> Hope for better solutions.

If you can stand (or, better, handle) a slight race condition:

import gtk, gobject, glib, glob

def grab_focus(self, widget):
    def grab_this(widget):
        widget.grab_focus()
        return False
    glib.idle_add(grab_this, widget)

window = gtk.Window()
window.set_default_size(0, 400)

hbox = gtk.HBox(False, 2)
window.add(hbox)

scwin = gtk.ScrolledWindow()
scwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
hbox.pack_start(scwin)

treemodel = gtk.ListStore(gobject.TYPE_STRING)
for x in glob.glob('*'):
    treemodel.append((x, ))

tree = gtk.TreeView(treemodel)
scwin.add(tree)

column = gtk.TreeViewColumn('Name', gtk.CellRendererText(), text=0)
tree.append_column(column)

textmodel = gtk.TextBuffer()
textmodel.set_text('Some text goes here.')

text = gtk.TextView(textmodel)
hbox.pack_start(text)

window.connect('destroy', gtk.main_quit)
selection = tree.get_selection()
selection.connect_after('changed', grab_focus, text)

window.show_all()
gtk.main()


Yeti



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