[pygtk] Entry dir autocompletion
Timo
timovwb at gmail.com
Tue Jul 1 20:59:57 WST 2008
Mitko Haralanov schreef:
> On Sat, 28 Jun 2008 11:36:07 +0200
> Timo <timovwb op gmail.com> wrote:
>
>
>> Hello, I want autocompletion in my gtk.entry. I found a lot of info, but
>> all for autocompletion of an existing list and stuff.
>> What I want is that it completes the path that I'm typing. So if I type
>> "/ho" it should complete with "/home/", and so on.
>> How can this be done?
>>
>
> What I would do is connect a callback to the "changed" signal of the
> gtk.Entry. This way the callback gets called on every character change.
>
> In the callback construct the completion list based on the current
> content of the Entry:
>
> def entry_cb (editable, *user_data):
> text = editable.get_text ()
> path = os.path.dirname (text)
> start = os.path.basename (text)
> files = dircache.listdir (path)
> matches = []
> for file in files:
> if file.startswith (start):
> matches.append (path+os.sep+file)
> <use 'matches' as completion list>
>
>
Thanks, that works! But I can't seem to apply it to my program. Well, I
added it to my code and I can print it to the terminal, so I know it
does something (and it does correctly), but after reading lots of
examples I can't seem to fix it with my entry-box. It just doesn't complete.
Anyone with a working example?
Timo
More information about the pygtk
mailing list