#!/usr/bin/python

"""
This example shows row-activated not being emitted on GTK+ trunk.

To reproduce:

 * Click a selected row lots of times with a speed that should
   activate it each time.
 * Or quickly double click one row after another.

It sometimes works, most times doesn't. The numbers in each row will
increment on activate..

"""

from gi.repository import Gtk, GLib, Gdk

win = Gtk.Window()
win.set_default_size(200, 200)
liststore = Gtk.ListStore(object)
for i in range(100):
    liststore.append(row=[0])

treeview = Gtk.TreeView(model=liststore)

render = Gtk.CellRendererText()
column = Gtk.TreeViewColumn("foo", render)

def cell_data(column, cell, model, iter_, data):
    cell.set_property('text', str(model.get_value(iter_, 0)))

column.set_cell_data_func(render, cell_data)
treeview.append_column(column)

def button_event(widget, event, name):
    print event.type.value_name
    return Gdk.EVENT_PROPAGATE

treeview.connect("button-release-event", button_event, "button-release-event")
treeview.connect("button-press-event", button_event, "button-press-event")

def row_activated(widget, path, column):
    row = liststore[path]
    row[0] += 1
    liststore.row_changed(row.path, row.iter)
    print("-> ROW-ACTIVATED")

treeview.connect("row-activated", row_activated)

sw = Gtk.ScrolledWindow()
sw.add(treeview)
win.add(sw)

win.connect("delete-event", Gtk.main_quit)
win.show_all()
GLib.unix_signal_add(0, 2, Gtk.main_quit)
Gtk.main()
