python 2.7 - Is it possible to display an Image in an autocompletion-popup list (Gtk3) -
i using entry entrycompletion opbject has liststore model. each record in model, there image display in autocomplete-popup list.
how can done? possible add gtk.cellrendererpixbuf column model?
interesting enough not find examples of yet turns out possible , not insanely complicated. lets start small image of goal uses icons convinces reasons. 
so how there, first create liststore containing column strings match on , icon-name convert pixbuf (this pixbuf directly).
# define entries auto complete entries = [ ('revert', 'document-revert'), ('delete', 'edit-delete'), ('dev help', 'devhelp'), ] # setup list store (note data types should match of entries) list_store = gtk.liststore(str, str) # fill list store entry_pair in entries: list_store.append(entry_pair) next step setting entrycompletion , linking liststore
# create entry completion , link list store completion = gtk.entrycompletion() completion.set_model(list_store) now magic, need create 2 renderers, 1 text, 1 pixbufs. pack these in completion add columns it.
# create renderer's pixbufs , text image_renderer = gtk.cellrendererpixbuf.new() cell_renderer = gtk.cellrenderertext.new() # pack columns in completion, in case first image string completion.pack_start(image_renderer, true) completion.pack_start(cell_renderer, true) in order make sure renderers use the correct column here specify column liststore renderers should read. image_renderer set icon_name attribute give icon names. if feed pixbuf's need pixbuf instead.
# set renderer's such read correct column completion.add_attribute(image_renderer, "icon_name", 1) completion.add_attribute(cell_renderer, "text", 0) as there no multiple column need tell completion column contains string. in our case column 0.
# tell completion column contains strings base completion on completion.props.text_column = 0 # create entry , link completion entry = gtk.entry() entry.set_completion(completion) and that's it!
Comments
Post a Comment