php-gtk3 icon indicating copy to clipboard operation
php-gtk3 copied to clipboard

EntryCompletion::set_match_func

Open d47081 opened this issue 1 year ago • 0 comments

Not implemented exception.

GTK documentation https://docs.gtk.org/gtk3/method.EntryCompletion.set_match_func.html

Usage example simple example in python, because my php app uses massive object dependencies

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

# Custom match function to filter completion results
def custom_match_func(completion, key, iter, user_data):
    model = completion.get_model()
    text = model.get_value(iter, 0)
    key = key.lower()
    
    if key in text.lower():
        return True
    
    return False

# Create a GtkEntry
entry = Gtk.Entry()

# Create a GtkEntryCompletion
completion = Gtk.EntryCompletion()
entry.set_completion(completion)

# Create a GtkListStore to hold the completion data
store = Gtk.ListStore(str)
completion.set_model(store)

# Add some completion data
store.append(['Apple'])
store.append(['Banana'])
store.append(['Cherry'])

# Connect the completion to the entry
completion.set_text_column(0)

# Set the custom match function
completion.set_match_func(custom_match_func, None)

# Show the completion
completion.set_popup_completion(True)

# Show the entry
window = Gtk.Window()
window.add(entry)
window.connect("delete-event", Gtk.main_quit)
window.show_all()

Gtk.main()

Additional context Seems that only one way to make search by mask %ppl% because currently GtkListStore returns only substrings started with prefix appl%,

so this feature is wanted but not sure I know how to make callable implementation in cpp

d47081 avatar Jul 24 '24 20:07 d47081