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



Hmm I haven't written Gtk+ code for a while and I seem to be forgetting things. I had the impression that "changed" was a signal with a bool return value, but it turns out that's not the case.

OK anyway, here's what you've got to do: Connect to the _TreeView's_ "button-press-event" (http://library.gnome.org/devel/pygtk/stable/class-gtkwidget.html#signal-gtkwidget--button-press-event) and check for the button being the right mouse button in the event passed into (see here http://library.gnome.org/devel/pygtk/stable/class-gdkevent.html under "gtk.gdk.BUTTON_PRESS", I can not link directly). The numerical value for the right mouse button is 3.

And this time:

* Make sure this time you do NOT connect_after, but just connect

and:

* Return "True" from your handler, so that the TreeView itself doesn't process the button press and changes the selection

HTH :)
Milosz

On Mon, Mar 8, 2010 at 2:57 AM, smartkenny <smartkenny gmail com> wrote:
Hello, Milosz

Thank you for answer my question. But it doesn't work. Here's my program:


#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk


def wrap(widget):
  sw = gtk.ScrolledWindow()
  sw.add(widget)
  sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
  sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
  sw.set_border_width(1)
  return sw



def on_selection_changed(selection):
  selection.get_tree_view().grab_focus()


if __name__ == "__main__":
  paned = gtk.HPaned()
    treestore = gtk.TreeStore(str)
  new_iter = treestore.append(None)
  treestore.set(new_iter, 0, '00000')
  new_iter = treestore.append(None)
  treestore.set(new_iter, 0, '11111')
  new_iter = treestore.append(None)
  treestore.set(new_iter, 0, '22222')
  new_iter = treestore.append(None)
  treestore.set(new_iter, 0, '33333')
  new_iter = treestore.append(None)
  treestore.set(new_iter, 0, '44444')
    treeview = gtk.TreeView(treestore)
  treeview.set_enable_search(False)
  treeview.get_selection().connect_after('changed', on_selection_changed)
  column = gtk.TreeViewColumn();
  renderer = gtk.CellRendererText()
  column.pack_start(renderer, False)
  column.add_attribute(renderer, 'text', 0)
  treeview.append_column(column)
  paned.add1(wrap(treeview))
    textview = gtk.TextView()
  paned.add2(wrap(textview))
  paned.set_position(250)
    window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  window.set_default_size(800, 600)
  window.add(paned)
  window.show_all()
    gtk.main()


Thank you!

Kenny



Milosz Derezynski wrote:
You need to get the TreeSelection from the TreeView and connect to that's "changed" signal, and make sure you connect_after.

Sent from my iPod

On 07.03.2010, at 19:25, smartkenny <smartkenny gmail com> wrote:

Hi, all

Searched for a long time but didn't find any hints on this. Here's my layout:

-------------------------
|           |           |
| tree view | text view |
|           |           |
-------------------------

When clicked on a tree view row, I am going to change text in text view accordingly AND let text view grab focus, so that whenever I press keys it put characters into the text view.

I tried to connect "changed" on tree view and grab focus on text view, but it didn't work, the focus is still on tree view. So when I press keys it doesn't put into the text view.

Can any body please give me a clue how to do this? Thank you very much.

Kenny

_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list





--
Please note that according to the German law on data retention,
information on every electronic information exchange with me is
retained for a period of six months.
[Bitte beachten Sie, dass dem Gesetz zur Vorratsdatenspeicherung zufolge
jeder elektronische Kontakt mit mir sechs Monate lang gespeichert wird.]


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