| 1 |
.. currentmodule:: gi.repository |
| 2 |
|
| 3 |
Entries |
| 4 |
======= |
| 5 |
|
| 6 |
Entries allows the user to enter text. |
| 7 |
GTK provides a few entry widgets for different use cases. |
| 8 |
Those are the generic :class:`Gtk.Entry`, :class:`Gtk.PasswordEntry` and |
| 9 |
:class:`Gtk.SearchEntry`. |
| 10 |
Although none of these widgets derive from each other, they implement the |
| 11 |
:class:`Gtk.Editable` :doc:`interface </tutorials/gobject/interfaces>`, so they share some |
| 12 |
properties and methods. |
| 13 |
You can change and get the contents with the :attr:`Gtk.Editable.props.text` |
| 14 |
property. |
| 15 |
You can also limit the number of characters the entry can take with |
| 16 |
:attr:`Gtk.Editable.props.max_width_chars`. |
| 17 |
|
| 18 |
Occasionally you might want to make an Entry widget read-only. This can be done |
| 19 |
by setting :attr:`Gtk.Editable.props.editable` to ``False``. |
| 20 |
|
| 21 |
Generic Entry |
| 22 |
------------- |
| 23 |
|
| 24 |
:class:`Gtk.Entry` is the standard entry. |
| 25 |
|
| 26 |
:class:`Gtk.Entry` can be set to show a invisible character using |
| 27 |
:attr:`Gtk.Entry.props.visibility` and :attr:`Gtk.Entry.props.invisible_char`, |
| 28 |
this is useful to hide the text of the entry when it is used for example to |
| 29 |
retrieve passwords. |
| 30 |
Though :ref:`password-entry` exist for this specific use |
| 31 |
case. |
| 32 |
|
| 33 |
:class:`Gtk.Entry` has the ability to display progress or activity information |
| 34 |
behind the text. This is similar to :class:`Gtk.ProgressBar` widget and is |
| 35 |
commonly found in web browsers to indicate how much of a page download has been |
| 36 |
completed. To make an entry display such information, use |
| 37 |
:attr:`Gtk.Entry.props.progress_fraction`, |
| 38 |
:attr:`Gtk.Entry.props.progress_pulse_step`, or :meth:`Gtk.Entry.progress_pulse`. |
| 39 |
|
| 40 |
Additionally, a :class:`Gtk.Entry` can show icons at either side of the entry. |
| 41 |
These icons can be activatable by clicking, can be set up as drag source and can |
| 42 |
have tooltips. |
| 43 |
To add an icon, use :meth:`Gtk.Entry.set_icon_from_icon_name` or one of the |
| 44 |
various other properties and methods that set an icon from an icon name, |
| 45 |
:class:`Gio.Icon`, or a :class:`Gdk.Paintable`. |
| 46 |
To set a tooltip on an icon, use :meth:`Gtk.Entry.set_icon_tooltip_text` or the |
| 47 |
corresponding function for markup. |
| 48 |
|
| 49 |
Entries can have a placeholder text, |
| 50 |
just use :attr:`Gtk.Entry.props.placeholder_text`. |
| 51 |
|
| 52 |
.. _password-entry: |
| 53 |
|
| 54 |
Password Entry |
| 55 |
-------------- |
| 56 |
|
| 57 |
:class:`Gtk.PasswordEntry` brings some features for password handing. |
| 58 |
It can show a button to toggle the visibility of the text if you set |
| 59 |
:attr:`Gtk.PasswordEntry.props.show_peek_icon` to ``True``. |
| 60 |
|
| 61 |
Search Entry |
| 62 |
------------ |
| 63 |
|
| 64 |
:class:`Gtk.SearchEntry` is an entry specially designed for use as a search |
| 65 |
entry. |
| 66 |
:class:`Gtk.SearchEntry` allows you to implement the popular "type to search" |
| 67 |
feature. |
| 68 |
You can use :meth:`Gtk.SearchEntry.set_key_capture_widget` to set the parent |
| 69 |
widget that will redirect its key events to the entry. |
| 70 |
|
| 71 |
:class:`Gtk.SearchEntry` has the |
| 72 |
:func:`search-changed <Gtk.SearchEntry.signals.search_changed>` signal, it |
| 73 |
differs from :class:`Gtk.Editable`'s :func:`changed <Gtk.Editable.signals.changed>` |
| 74 |
in the sense that it gets emitted after a short delay that you can configure |
| 75 |
with :attr:`Gtk.SearchEntry.props.search_delay`. |
| 76 |
This way you can get reactive searching without over loading your backend. |
| 77 |
|
| 78 |
Example |
| 79 |
------- |
| 80 |
|
| 81 |
.. image:: images/entries.png |
| 82 |
|
| 83 |
.. literalinclude:: examples/entries.py |
| 84 |
:linenos: |