gtk.EntryCompletion — completion functionality for gtk.Entry (new in PyGTK 2.4)
class gtk.EntryCompletion(gobject.GObject, gtk.CellLayout): |
|
gobject.GObject Signal Prototypes
"action-activated" | def callback(completion, index, user_param1, ...) |
"insert-prefix" | def callback(completion, prefix, user_param1, ...) |
"match-selected" | def callback(completion, model, iter, user_param1, ...) |
This widget is available in PyGTK 2.4 and above.
gtk.EntryCompletion is an auxiliary object to be used in conjunction with gtk.Entry to provide completion functionality. It implements the gtk.CellLayout interface, to allow the user to add extra cells to the popup display of completions.
To add completion functionality to an entry, use the gtk.Entry.set_completion() method. In addition to regular completion matches, that will be inserted into the entry when they are selected, gtk.EntryCompletion also allows "actions" to be displayed in the popup window below any completions. Their appearance is similar to menuitems, to differentiate them clearly from completion strings. When an action is selected, the "action-activated" signal is emitted.
A gtk.TreeModel (e.g. a gtk.ListStore) containing the completion strings is associated with the gtk.EntryCompletion using the set_model() method. The tree model column containing the completion strings can be set using the convenience method set_text_column() that also creates a gtk.CellRendererText and packs it into the entry completion.
Otherwise, you can create gtk.CellRenderer objects and pack them into the gtk.EntryCompletion using the gtk.CellLayout methods gtk.CellLayout.pack_start() or gtk.CellLayout.pack_start(). However, you will also have to define a match function and set it with the set_match_func() method.
If you wanted to create a completion list with the strings to insert and some additional info e.g. an icon or description you could do something like:
entry = gtk.Entry() completion = gtk.EntryCompletion() entry.set_completion(completion) liststore = gtk.ListStore(gobject.TYPE_STRING, gtk.gdk.Pixbuf) completion.set_model(liststore) pixbufcell = gtk.CellRendererPixbuf() completion.pack_start(pixbufcell) completion.add_attribute(pixbufcell, 'pixbuf', 1) # create a gtk.CellRendererText and pack it in the completion. Also set the # 'text' attribute completion.set_text_column(0) # load up the liststore with string - pixbuf data - assuming pixbuf created liststore.append(['string text', pixbuf]) |
This will create an entry that will display a pixbuf and the text string during completion.
Actions are easily managed using the insert_action_text(), insert_action_markup() and delete_action() methods.
|
Returns : | A newly created gtk.EntryCompletion object. |
This constructor is available in PyGTK 2.4 and above.
Creates a new gtk.EntryCompletion object.
|
Returns : | The gtk.Entry that the completion is attached to. |
This method is available in PyGTK 2.4 and above.
The get_entry() method retrieves the gtk.Entry that the entry completion is attached to.
|
model : | The gtk.TreeModel to use with the entry completion. |
This method is available in PyGTK 2.4 and above.
The set_model() method sets the gtk.TreeModel specified by model to be used with the entry completion. A previously set model will be removed before the new model is set. If model is None or not specified, the old model will be unset.
In PyGTK 2.4.0 the model could not be None and did not default to None.
|
Returns : | The current gtk.TreeModel, or None if not set. |
This method is available in PyGTK 2.4 and above.
The get_model() method returns the gtk.TreeModel that the entry completion is using as data source. Returns None if the model is unset.
|
func : | A function to be used. |
func_data : | The user data for func. |
This method is available in PyGTK 2.4 and above.
The set_match_func() method sets the match function specified by func. The match function is used by the entry completion to determine if a row of the associated tree model should be in the completion list.
The signature of the match function is:
def match_func(completion, key_string, iter, func_data): |
where completion is the gtk.EntryCompletion that the match function is invoked on, key_string is the current contents of the gtk.Entry to be matched, iter is a gtk.TreeIter pointing at a row in the gtk.TreeModel associated with completion and func_data is the data specified when the set_match_func() method was called. The match function should return TRUE if the completion string should be displayed; otherwise, FALSE.
A simple example match function is:
# Assumes that the func_data is set to the number of the text column in the # model. def match_func(completion, key, iter, column): model = completion.get_model() text = model.get_value(iter, column) if text.startswith(key): return True return False |
You must use the set_match_func() method to display completions if you don't use the set_text_column() method.
|
length : | The minimum length of the key string in order to start completing. |
This method is available in PyGTK 2.4 and above.
The set_minimum_key_length() method sets the minimum length of the search key to the value specified by length. This means that the key string (contents of the gtk.Entry) must be at least length characters before a completion list will be displayed. This is useful for long lists, where completing using a small key will take too much time and will likely return too large a dataset.
|
Returns : | The currently used minimum key length. |
This method is available in PyGTK 2.4 and above.
The get_minimum_key_length() method returns the minimum key length set for the entry completion. See the set_minimum_key_length() method for more information.
|
This method is available in PyGTK 2.4 and above.
The complete() method requests a completion operation, i.e. a refiltering of the current list with completions, using the current key. The completion list view will be updated accordingly.
|
index : | The index in the action list where the item should be inserted. |
text : | The text of the item to insert. |
This method is available in PyGTK 2.4 and above.
The insert_action_text() method inserts an action in the action item list of the entry completion at the position specified by index with the text specified by text. If you want the action item to have markup, use the gtk.EntryCompletion.insert_action_markup() method.
|
index : | The index in the action list where the item should be inserted. |
markup : | The Pango markup of the item to insert. |
This method is available in PyGTK 2.4 and above.
The insert_action_markup() method inserts an action item in the action item list of the entry completion at the position specified by index with the Pango markup specified by markup.
|
index : | The index of the item to delete. |
This method is available in PyGTK 2.4 and above.
The delete_action() method deletes the action item at the position in the action item list specified by index.
|
This method is available in PyGTK 2.6 and above.
The insert_prefix() method requests a prefix insertion.
|
column : | The column in the model to get strings from. |
This method is available in PyGTK 2.4 and above.
The set_text_column() method is a convenience method for setting up the most common completion scenario: a completion list with just strings. This method creates and adds a gtk.CellRendererText using the column specified by column as the source for completion strings. If you don't use this method you will have to install a gtk.CellRendererText in the entry completion and set a match function using the set_match_func() method to display the completion strings. In GTK+ 2.6 the "text-column" property is set to the value of column.
|
Returns : | The column containing the text strings. |
This method is available in PyGTK 2.8 and above.
The get_text_column() method returns the value of the "text-column" property. The "text-column" property contains the index of the column in the completion model to get strings from. See the set_text_column() method for more information.
|
inline_completion : | if TRUE do inline completion |
This method is available in PyGTK 2.6 and above.
The set_inline_completion() method sets the "inline-completion" property to the value of inline_completion. If inline_completion is TRUE, the common prefix of the possible completions should be automatically inserted in the entry.
|
Returns : | TRUE if automatic inline completion is enabled. |
This method is available in PyGTK 2.6 and above.
The get_inline_completion() method returns the value of the "inline-completion" property. If the value of the "inline-completion" property is TRUE the common prefix of possible completions is automatically inserted in the entry.
|
popup_completion : | If TRUE do popup completion. |
This method is available in PyGTK 2.6 and above.
The set_popup_completion() method sets the "popup-completion" property to the value of popup_completion. If popup_completion is TRUE the completions should be presented in a popup window.
|
Returns : | TRUE if completions should be displayed in a popup. |
This method is available in PyGTK 2.6 and above.
The get_popup_completion() method returns the value of the "popup-completion" property. If the value of "popup-completion" property is TRUE the completions should be presented in a popup window.
|
popup_set_width : | If TRUE the completions popup window will be resized to the width of the completion. |
This method is available in PyGTK 2.8 and above.
The set_popup_set_width() method sets the "popup-set-width" property to the value of popup_set_width. If popup_set_width is TRUE the completions popup window will be resized to the width of the completion.
|
Returns : | TRUE if the completions popup window will be resized to the width of the completion. |
This method is available in PyGTK 2.8 and above.
The get_popup_set_width() method returns the value of the "popup-set-width" property. If the value of "popup-set-width" property is TRUE the completions popup window will be resized to the width of the completion.
|
popup_single_match : | If TRUE the completions popup window will appear even for a single match. |
This method is available in PyGTK 2.8 and above.
The set_popup_single_match() method sets the "popup-single-match" property to the value of popup_single_match. If popup_single_match is TRUE the completions popup window will appear even for a single match.
|
Returns : | TRUE if the completions popup window should appear even for a single match. |
This method is available in PyGTK 2.8 and above.
The get_popup_single_match() method returns the value of the "popup-single-match" property. If the value of "popup-single-match" property is TRUE the completions popup window should appear even for a single match.
|
completion : | the entry completion that received the signal |
index : | the index of the action item that was activated. |
user_param1 : | the first user parameter (if any) specified with the connect() method |
... : | additional user parameters (if any) |
This signal is available in GTK+ 2.4 and above.
The "action-activated" signal is emitted when an action item is selected from the popup action list.
|
completion : | the entry completion that received the signal |
prefix : | the common prefix of all possible completions |
user_param1 : | the first user parameter (if any) specified with the connect() method |
... : | additional user parameters (if any) |
This signal is available in GTK+ 2.6 and above.
The "insert-prefix" signal is emitted when the inline auto-completion is triggered. The default behavior is to make the entry display the whole prefix and select the newly inserted part.
Applications may connect to this signal in order to insert only a smaller part of the prefix into the entry - e.g. the entry used in the gtk.FileChooser inserts only the part of the prefix up to the next '/'.
|
completion : | the entry completion that received the signal |
model : | the gtk.TreeModel that iter points into. |
iter : | a gtk.TreeIter pointing at the selection completion string row in model. |
user_param1 : | the first user parameter (if any) specified with the connect() method |
... : | additional user parameters (if any) |
This signal is available in GTK+ 2.4 and above.
The "match-selected" signal is emitted when a completion string was selected from the completion list. iter points at the row in model that contains the completion string.