summaryrefslogtreecommitdiff
path: root/examples/pygtk-demo/demos/entrycompletion.py
blob: 3148aad8a0698c760a0d48978444a199359d085b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Entry Completion

	gtk.EntryCompletion Test
	(c) Fernando San Martín Woerner 2004
	snmartin@galilea.cl
	
	A simple test for gtk.EntryCompletion widget
"""
description = 'Entry Completion'


import pygtk; pygtk.require("2.0")
import gobject
import gtk

def on_match_selected(completion, model, iter):
	month = model.get_value(iter,0)
	print "You have selected " + month

def main():
	# The window...
	window = gtk.Window()
	window.set_title("EntryCompletion Test")
	window.connect('delete-event', gtk.main_quit)
	
	# The entry to fill with autocompletion
	entry = gtk.Entry()
	
	# The EntryCompletion Widget
	compl = gtk.EntryCompletion()
	
	# Connected to on_match_selected
	compl.connect("match-selected", on_match_selected)
	
	# The model with autocompletion
	model = gtk.ListStore(str)
	
	# A model and a text column
	compl.set_model(model)
	compl.set_text_column(0)
	
	# Adding rows
	model.append(["JANUARY"])
	model.append(["FEBRUARY"])
	model.append(["MARCH"])
	model.append(["APRIL"])
	model.append(["MAY"])
	model.append(["JUN"])
	model.append(["JULY"])
	model.append(["AUGUST"])
	model.append(["SEPTEMBER"])
	model.append(["OCTOBER"])
	model.append(["NOVEMBER"])
	model.append(["DECEMBER"])
	
	# Setting the widgets together 
	entry.set_completion(compl)
	
	vbox = gtk.VBox()
	window.add(vbox)
	vbox.pack_start(gtk.Label("Type a month:"))
	vbox.pack_start(entry)
	window.show_all()
	# Running
	gtk.main()

    
if __name__ == '__main__':
	main()