Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EntryCompletion::set_match_func #137

Open
d47081 opened this issue Jul 24, 2024 · 0 comments
Open

EntryCompletion::set_match_func #137

d47081 opened this issue Jul 24, 2024 · 0 comments

Comments

@d47081
Copy link
Contributor

d47081 commented Jul 24, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants