[pygtk] Entry dir autocompletion
Mitko Haralanov
mitko at qlogic.com
Tue Jul 1 04:48:15 WST 2008
On Sat, 28 Jun 2008 11:36:07 +0200
Timo <timovwb at 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>
--
Mitko Haralanov
==========================================
This is an unauthorized cybernetic announcement.
More information about the pygtk
mailing list