Gtk.EntryBuffer

g GObject.Object GObject.Object Gtk.EntryBuffer Gtk.EntryBuffer GObject.Object->Gtk.EntryBuffer

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new (initial_chars, n_initial_chars)

delete_text (position, n_chars)

emit_deleted_text (position, n_chars)

emit_inserted_text (position, chars, n_chars)

get_bytes ()

get_length ()

get_max_length ()

get_text ()

insert_text (position, chars, n_chars)

set_max_length (max_length)

set_text (chars, n_chars)

Virtual Methods

Inherited:

GObject.Object (7)

do_delete_text (position, n_chars)

do_deleted_text (position, n_chars)

do_get_length ()

do_get_text (n_bytes)

do_insert_text (position, chars, n_chars)

do_inserted_text (position, chars, n_chars)

Properties

Name

Type

Flags

Short Description

length

int

r

Length of the text currently in the buffer

max-length

int

r/w/en

Maximum number of characters for this entry. Zero if no maximum

text

str

r/w

The contents of the buffer

Signals

Inherited:

GObject.Object (1)

Name

Short Description

deleted-text

This signal is emitted after text is deleted from the buffer.

inserted-text

This signal is emitted after text is inserted into the buffer.

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class Gtk.EntryBuffer(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Gtk.EntryBufferClass

The Gtk.EntryBuffer class contains the actual text displayed in a Gtk.Entry widget.

A single Gtk.EntryBuffer object can be shared by multiple Gtk.Entry 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.

New in version 2.18.

classmethod new(initial_chars, n_initial_chars)[source]
Parameters:
  • initial_chars (str or None) – initial buffer text, or None

  • n_initial_chars (int) – number of characters in initial_chars, or -1

Returns:

A new Gtk.EntryBuffer object.

Return type:

Gtk.EntryBuffer

Create a new Gtk.EntryBuffer object.

Optionally, specify initial text to set in the buffer.

New in version 2.18.

delete_text(position, n_chars)[source]
Parameters:
  • position (int) – position at which to delete text

  • n_chars (int) – number of characters to delete

Returns:

The number of characters deleted.

Return type:

int

Deletes a sequence of characters from the buffer. n_chars characters are deleted starting at position. If n_chars is negative, then all characters until the end of the text are deleted.

If position or n_chars are out of bounds, then they are coerced to sane values.

Note that the positions are specified in characters, not bytes.

New in version 2.18.

emit_deleted_text(position, n_chars)[source]
Parameters:
  • position (int) – position at which text was deleted

  • n_chars (int) – number of characters deleted

Used when subclassing Gtk.EntryBuffer

New in version 2.18.

emit_inserted_text(position, chars, n_chars)[source]
Parameters:
  • position (int) – position at which text was inserted

  • chars (str) – text that was inserted

  • n_chars (int) – number of characters inserted

Used when subclassing Gtk.EntryBuffer

New in version 2.18.

get_bytes()[source]
Returns:

The byte length of the buffer.

Return type:

int

Retrieves the length in bytes of the buffer. See Gtk.EntryBuffer.get_length().

New in version 2.18.

get_length()[source]
Returns:

The number of characters in the buffer.

Return type:

int

Retrieves the length in characters of the buffer.

New in version 2.18.

get_max_length()[source]
Returns:

the maximum allowed number of characters in Gtk.EntryBuffer, or 0 if there is no maximum.

Return type:

int

Retrieves the maximum allowed length of the text in self. See Gtk.EntryBuffer.set_max_length().

New in version 2.18.

get_text()[source]
Returns:

a pointer to the contents of the widget as a string. This string points to internally allocated storage in the buffer and must not be freed, modified or stored.

Return type:

str

Retrieves the contents of the buffer.

The memory pointer returned by this call will not change unless this object emits a signal, or is finalized.

New in version 2.18.

insert_text(position, chars, n_chars)[source]
Parameters:
  • position (int) – the position at which to insert text.

  • chars (str) – the text to insert into the buffer.

  • n_chars (int) – the length of the text in characters, or -1

Returns:

The number of characters actually inserted.

Return type:

int

Inserts n_chars characters of chars into the contents of the buffer, at position position.

If n_chars is negative, then characters from chars will be inserted until a null-terminator is found. If position or n_chars are out of bounds, or the maximum buffer text length is exceeded, then they are coerced to sane values.

Note that the position and length are in characters, not in bytes.

New in version 2.18.

set_max_length(max_length)[source]
Parameters:

max_length (int) – the maximum length of the entry buffer, or 0 for no maximum. (other than the maximum length of entries.) The value passed in will be clamped to the range 0-65536.

Sets the maximum allowed length of the contents of the buffer. If the current contents are longer than the given length, then they will be truncated to fit.

New in version 2.18.

set_text(chars, n_chars)[source]
Parameters:
  • chars (str) – the new text

  • n_chars (int) – the number of characters in text, or -1

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.

New in version 2.18.

do_delete_text(position, n_chars) virtual
Parameters:
  • position (int) – position at which to delete text

  • n_chars (int) – number of characters to delete

Returns:

The number of characters deleted.

Return type:

int

Deletes a sequence of characters from the buffer. n_chars characters are deleted starting at position. If n_chars is negative, then all characters until the end of the text are deleted.

If position or n_chars are out of bounds, then they are coerced to sane values.

Note that the positions are specified in characters, not bytes.

New in version 2.18.

do_deleted_text(position, n_chars) virtual
Parameters:
  • position (int) –

  • n_chars (int) –

do_get_length() virtual
Returns:

The number of characters in the buffer.

Return type:

int

Retrieves the length in characters of the buffer.

New in version 2.18.

do_get_text(n_bytes) virtual
Parameters:

n_bytes (int) –

Return type:

str

do_insert_text(position, chars, n_chars) virtual
Parameters:
  • position (int) – the position at which to insert text.

  • chars (str) – the text to insert into the buffer.

  • n_chars (int) – the length of the text in characters, or -1

Returns:

The number of characters actually inserted.

Return type:

int

Inserts n_chars characters of chars into the contents of the buffer, at position position.

If n_chars is negative, then characters from chars will be inserted until a null-terminator is found. If position or n_chars are out of bounds, or the maximum buffer text length is exceeded, then they are coerced to sane values.

Note that the position and length are in characters, not in bytes.

New in version 2.18.

do_inserted_text(position, chars, n_chars) virtual
Parameters:
  • position (int) –

  • chars (str) –

  • n_chars (int) –

Signal Details

Gtk.EntryBuffer.signals.deleted_text(entry_buffer, position, n_chars)
Signal Name:

deleted-text

Flags:

RUN_FIRST

Parameters:
  • entry_buffer (Gtk.EntryBuffer) – The object which received the signal

  • position (int) – the position the text was deleted at.

  • n_chars (int) – The number of characters that were deleted.

This signal is emitted after text is deleted from the buffer.

New in version 2.18.

Gtk.EntryBuffer.signals.inserted_text(entry_buffer, position, chars, n_chars)
Signal Name:

inserted-text

Flags:

RUN_FIRST

Parameters:
  • entry_buffer (Gtk.EntryBuffer) – The object which received the signal

  • position (int) – the position the text was inserted at.

  • chars (str) – The text that was inserted.

  • n_chars (int) – The number of characters that were inserted.

This signal is emitted after text is inserted into the buffer.

New in version 2.18.

Property Details

Gtk.EntryBuffer.props.length
Name:

length

Type:

int

Default Value:

0

Flags:

READABLE

The length (in characters) of the text in buffer.

New in version 2.18.

Gtk.EntryBuffer.props.max_length
Name:

max-length

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The maximum length (in characters) of the text in the buffer.

New in version 2.18.

Gtk.EntryBuffer.props.text
Name:

text

Type:

str

Default Value:

''

Flags:

READABLE, WRITABLE

The contents of the buffer.

New in version 2.18.