Gtk.EntryBuffer
Gtk.EntryBuffer — Text buffer for Gtk.Entry
Object Hierarchy:
GObject
╰── Gtk.EntryBuffer
Functions:
- new
(initial_chars:str=None, n_initial_chars:int) -> Gtk.EntryBuffer
- get_text
(self) -> str
- set_text
(self, chars:str, n_chars:int)
- get_bytes
(self) -> int
- get_length
(self) -> int
- get_max_length
(self) -> int
- set_max_length
(self, max_length:int)
- insert_text
(self, position:int, chars:str, n_chars:int) -> int
- delete_text
(self, position:int, n_chars:int) -> int
- emit_deleted_text
(self, position:int, n_chars:int)
- emit_inserted_text
(self, position:int, chars:str, n_chars:int)
Signals:
- “deleted-text”
(buffer, position, n_chars, user_data)
- “inserted-text”
(buffer, position, chars, n_chars, user_data)
Description:
The Gtk.EntryBuffer
class contains the actual text displayed in a Gtk.Entry widget.
A single Gtk.EntryBuffer
object can be shared by multiple GtkEntry widgets which will then share the same text content, but not the cursor position, visibility attributes, icon etc.
Gtk.EntryBuffer
may be derived from. Such a derived class might allow text to be stored in an alternate location, such as non-pageable memory, useful in the case of important passwords. Or a derived class could integrate with an application’s concept of undo/redo.
Function Details:
new()
new (initial_chars:str=None, n_initial_chars:int) -> Gtk.EntryBuffer
Create a new Gtk.EntryBuffer
object.
Optionally, specify initial text to set in the buffer.
Returns: A new
Gtk.EntryBuffer
object.Since: 2.18
get_text()
get_text (self) -> str
Retrieves the contents of the buffer. The memory pointer returned by this call will not changeunless this object emits a signal, or is finalized.
Returns: a pointer to the contents of the widget as astring. This string points to internally allocatedstorage in the buffer and must not be freed, modified orstored.
Since: 2.18
set_text()
set_text (self, chars:str, n_chars:int)
Sets the text in the buffer.
This is roughly equivalent to calling Gtk.EntryBuffer:delete_text()
and Gtk.EntryBuffer:insert_text()
.
Note that n_chars
is in characters, not in bytes.
- Since: 2.18
get_bytes()
get_bytes (self) -> int
Retrieves the length in bytes of the buffer.See Gtk.EntryBuffer:get_length()
.
Returns: The byte length of the buffer.
Since: 2.18
get_length()
get_length (self) -> int
Retrieves the length in characters of the buffer.
Returns: The number of characters in the buffer.
Since: 2.18
get_max_length()
get_max_length (self) -> int
Retrieves the maximum allowed length of the text inbuffer
. See Gtk.EntryBuffer:set_max_length()
.
Returns: the maximum allowed number of charactersin
Gtk.EntryBuffer
, or 0 if there is no maximum.Since: 2.18
set_max_length()
set_max_length (self, max_length:int)
Sets the maximum allowed length of the contents of the buffer. Ifthe current contents are longer than the given length, then theywill be truncated to fit.
- Since: 2.18
insert_text()
insert_text (self, position:int, chars:str, n_chars:int) -> int
Inserts n_chars
characters of chars
into the contents of thebuffer, at position position
.
If n_chars
is negative, then characters from chars will be inserteduntil a null-terminator is found. If position
or n_chars
are out ofbounds, or the maximum buffer text length is exceeded, then they arecoerced to sane values.
Note that the position and length are in characters, not in bytes.
Returns: The number of characters actually inserted.
Since: 2.18
delete_text()
delete_text (self, position:int, n_chars:int) -> int
Deletes a sequence of characters from the buffer. n_chars
characters aredeleted starting at position
. If n_chars
is negative, then all charactersuntil the end of the text are deleted.
If position
or n_chars
are out of bounds, then they are coerced to sanevalues.
Note that the positions are specified in characters, not bytes.
Returns: The number of characters deleted.
Since: 2.18
emit_deleted_text()
emit_deleted_text (self, position:int, n_chars:int)
Used when subclassing Gtk.EntryBuffer
- Since: 2.18
emit_inserted_text()
emit_inserted_text (self, position:int, chars:str, n_chars:int)
Used when subclassing Gtk.EntryBuffer
- Since: 2.18
Example:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class EntryBuffer(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("EntryBuffer")
self.connect("destroy", Gtk.main_quit)
box = Gtk.Box()
box.set_orientation(Gtk.Orientation.VERTICAL)
self.add(box)
entrybuffer = Gtk.EntryBuffer()
entrybuffer.set_text("Text in EntryBuffer", -1)
entry = Gtk.Entry()
entry.set_buffer(entrybuffer)
box.pack_start(entry, True, True, 0)
entry = Gtk.Entry()
entry.set_buffer(entrybuffer)
box.pack_start(entry, True, True, 0)
entry = Gtk.Entry()
entry.set_buffer(entrybuffer)
box.pack_start(entry, True, True, 0)
window = EntryBuffer()
window.show_all()
Gtk.main()