Re: How to set focus on a text view when tree selection changed?
- From: David Nečas <yeti physics muni cz>
- To: kenny wang <smartkenny gmail com>
- Cc: "gtk-list gnome org" <gtk-list gnome org>
- Subject: Re: How to set focus on a text view when tree selection changed?
- Date: Mon, 8 Mar 2010 19:19:46 +0100
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]