On Tue, 01 Jul 2008 14:59:57 +0200
Timo <[EMAIL PROTECTED]> wrote:

> Anyone with a working example?

Here you go:

import pygtk
import gtk
import gobject
import os
import dircache

def entry_changed (editable, *user_data):
    comp = user_data[0]
    text = editable.get_text ()
    matches = []
    if text:
        path = os.path.dirname (text)
        start = os.path.basename (text)
        files = dircache.listdir (path)
        for file in files:
            if file.startswith (start):
                if path == "/":
                    matches.append (path+file)
                else:
                    matches.append (path+os.sep+file)
        model = comp.get_model ()
        model.clear ()
        for match in matches:
            model.append ([match])
            
    
win = gtk.Window ()
entry = gtk.Entry ()
completion = gtk.EntryCompletion ()
entry.set_completion (completion)
liststore = gtk.ListStore (gobject.TYPE_STRING)
completion.set_model (liststore)
completion.set_text_column (0)
win.add (entry)
entry.connect ("changed", entry_changed, completion)
win.connect ("delete-event", gtk.main_quit)
win.show_all ()

gtk.main ()


-- 
Mitko Haralanov
==========================================
printk("Penguin %d is stuck in the bottle.\n", i);
        2.0.38 /usr/src/linux/arch/sparc/kernel/smp.c
_______________________________________________
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