3

I was looking at this post: https://stackoverflow.com/a/2262200 and I have a very similar setup in the little thing I'm coding up. My question is, once the entrycompletion finishes, and the entry box has the url, how do I get that url from the completion into a variable? entry.get_text() doesn't seem to work, and everything else I try just seems to give me an object or address. Here is the quote from the above link if you don't feel like clicking.

# simplified example from the tutorial
import gtk

urls = [
    'http://www.google.com',
    'http://www.google.com/android',
    'http://www.greatstuff.com',
    'http://www.facebook.com',
    ]
liststore = gtk.ListStore(str)
for s in urls:
    liststore.append([s])

completion = gtk.EntryCompletion()
completion.set_model(liststore)
completion.set_text_column(0)

entry = gtk.Entry()
entry.set_completion(completion)

# boilerplate
window = gtk.Window()
window.add(entry)

window.connect('destroy', lambda w: gtk.main_quit())
window.show_all()
gtk.main()
Community
  • 1
  • 1

1 Answers1

6

The following variant of your code works for me.

# simplified example from the tutorial
import gtk 

def on_match_selected(completion, treemodel, treeiter):
  print treemodel[treeiter][completion.get_text_column()]

urls = [ 
    'http://www.google.com',
    'http://www.google.com/android',
    'http://www.greatstuff.com',
    'http://www.facebook.com',
    ]   
liststore = gtk.ListStore(str)
for s in urls:
    liststore.append([s])

completion = gtk.EntryCompletion()
completion.set_model(liststore)
completion.set_text_column(0)

completion.connect('match-selected', on_match_selected)

entry = gtk.Entry()
entry.set_completion(completion)

# boilerplate
window = gtk.Window()
window.add(entry)

window.connect('destroy', lambda w: gtk.main_quit())
window.show_all()
gtk.main()
Szilárd Pfeiffer
  • 1,636
  • 1
  • 12
  • 6