GLXCurses.EntryBuffer module

class GLXCurses.EntryBuffer.EntryBuffer[source]

Bases: GLXCurses.Object.Object

EntryBuffer — Text buffer for GLXCurses.Entry

Description

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

A single GLXCurses.EntryBuffer object can be shared by multiple GLXCurses.Entry widgets which will then share the same text content, but not the cursor position, visibility attributes, etc.

GLXCurses.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.

max_length
length

The length property

Allowed values: <= 65535

Default value: 0

Returns:The length (in characters) of the text in buffer.
Return type:int
text

The text property

Returns:The contents of the buffer.
Return type:char
new(initial_chars=None, n_initial_chars=-1)[source]

Create a new GLXCurses.EntryBuffer object.

Optionally, specify initial text to set in the buffer.

Parameters:
  • initial_chars – initial buffer text, or None
  • n_initial_chars – number of characters in initial_chars , or -1
Returns:

the new EntryBuffer

Return type:

GLXCurses.EntryBuffer.EntryBuffer

Raises:
  • TypeError – if initial_chars is not printable string or None
  • TypeError – if n_initial_chars is not int or -1
get_text()[source]

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.

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
set_text(chars='', n_chars=-1)[source]

Sets the text in the buffer.

This is roughly equivalent to calling EntryBuffer.delete_text() and EntryBuffer.insert_text().

Note

n_chars is in characters, not in bytes.

Parameters:
  • chars (str) – the new text
  • n_chars (int) – the number of characters in text , or -1
Raises:
  • TypeError – if chars is not str
  • TypeError – if n_chars is not int or -1
get_bytes()[source]

Retrieves the length in bytes of the buffer.

See also

EntryBuffer.get_length().

Returns:The byte length of the buffer.
Return type:int
get_length()[source]

Retrieves the length in characters of the buffer.

Returns:The number of characters in the buffer.
Return type:int
get_max_length()[source]

Retrieves the maximum allowed length of the text in buffer .

See also

EntryBuffer.set_max_length().

Returns:the maximum allowed number of characters in EntryBuffer, or 0 if there is no maximum.
Return type:int
set_max_length(max_length=0)[source]

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.

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.
Raises:TypeError – if max_length is not int
insert_text(position=0, chars='', n_chars=-1)[source]

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

The position and length are in characters, not in bytes.

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

Raises:
  • TypeError – if position is not int
  • TypeError – if chars is not printable str
  • TypeError – if n_chars is not int
delete_text(position=None, n_chars=-1)[source]

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

The positions are specified in characters, not bytes..

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

Raises:
  • TypeError – if position is not int
  • TypeError – if n_chars is not int