Ticket #4133: events.py

File events.py, 1.3 KB (added by erikos, 10 years ago)

test script that has a treeview and a button

Line 
1from gi.repository import Gtk
2from gi.repository import Gdk
3
4def _destroy_cb(widget, data=None):
5    Gtk.main_quit()
6
7def __leave_notify_event_cb(widget, event):
8    print 'leave: ', widget, event.mode
9
10def __button_release_event_cb(widget, event):
11    print 'button release: ', widget, event.button
12
13window = Gtk.Window()
14window.connect("destroy", _destroy_cb)
15window.show()
16
17box = Gtk.VBox()
18window.add(box)
19box.show()
20
21model = Gtk.ListStore(str)
22for icon in ['one', 'two', 'three']:
23    model.append([icon])
24
25treeview = Gtk.TreeView()
26treeview.set_model(model)
27box.add(treeview)
28treeview.show()
29treeview.connect('leave-notify-event',
30                 __leave_notify_event_cb)
31treeview.connect('button-release-event',
32                 __button_release_event_cb)
33#treeview.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
34#                    Gdk.EventMask.TOUCH_MASK |
35#                    Gdk.EventMask.BUTTON_RELEASE_MASK)
36
37col = Gtk.TreeViewColumn()
38treeview.append_column(col)
39
40cell_text = Gtk.CellRendererText()
41col.pack_start(cell_text, expand=True)
42col.add_attribute(cell_text, 'text', 0)
43
44button = Gtk.Button(label='Click me!')
45box.add(button)
46button.show()
47button.connect('leave-notify-event',
48               __leave_notify_event_cb)
49button.connect('button-release-event',
50               __button_release_event_cb)
51
52
53Gtk.main()