On Sat, 28 Jun 2008 11:36:07 +0200
Timo <[EMAIL PROTECTED]> 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.
_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to