#!/usr/bin/python3

from gi.repository import Gtk

contact_list = (
  ( "Foobar", "foo", "foobar@example.com" ),
  ( "Super Framework", "frame", "frame@work.com" ),
  ( "Gtk Framework", "gtk", "gtk@framework.com" ),
  ( "Non sense", "bla", "nowhere@myplace.net" ),
  ( "GtkEntryCompletion", "completion", "fancybox@mail.com" ),
  ( "Gtk rules", "fantastic", "gtk@gtk.org" ),
  ( "some more words", "fillingTheGap", "another@email.com" ),
  ( "new line", "somemore nick", "again@mail.com"),
)


CONTACT_NAME, CONTACT_NICK, CONTACT_EMAIL = range(3)

def on_match_select(entry, model, itr):
    value = model.get_value(itr, CONTACT_EMAIL)
    print("You have selected {}.".format(value))
    return False

if __name__ == '__main__':
    Gtk.init([])
    window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
    window.set_border_width(20)
    window.set_title('Example test!')
    window.set_default_size(200, 50)

    window.connect('destroy', Gtk.main_quit)

    entry = Gtk.Entry.new()
    completion = Gtk.EntryCompletion.new()
    completion.set_text_column(CONTACT_NAME)
    entry.set_completion(completion)
    completion.connect('match-selected', on_match_select)

    model = Gtk.ListStore.new([str, str, str])
    for contact in contact_list:
        model.append(contact)

    completion.set_model(model)

    window.add(entry)

    window.show_all()

    Gtk.main()
