Skip to content

vtf txb _buffercomponents trimmer

srccircumflex edited this page Apr 24, 2023 · 4 revisions

↑ vtf-txb-_buffercomponents

trimmer

class trimmer._Trimmer

Optional Buffer Component for limiting the number of _Row's in the TextBuffer.

General parameters:
  • __buffer__
    The TextBuffer for which the _Trimmer is created.
  • rows_max
    The maximum number of rows in a current buffer.
Morphe:

The morph of the _Trimmer and its actions can be defined analogously via the parameters during initialization.

SWAP

This morph of the _Trimmer correlates with _Swap for data chunk management. When rows are cut from the buffer, they are passed as DumpData to _Swap to be stored in a database. This allows the dynamic swapping of data to handle larger amounts of data.

The side from which rows are cut from the TextBuffer is based on the current cursor position: If the trimming is executed, it is first queried whether the number of rows in the buffer has reached the upper limit, which is composed of the defined maximum value and one chunk size. Is this the case, rows of one chunk size are removed from the beginning of the buffer until the row of the current cursor position is in a range of two chunk sizes starting from the beginning of the buffer. Following this, the chunking of rows at the end of the buffer continues until the number of rows no longer exceeds the upper limit.

Feeding chunks back from swap to the current buffer is done by interfaces in the _Trimmer to _Swap methods and is done automatically by main methods in the TextBuffer.

Keyword parameters:
  • swap__chunk_size
    The size of a chunk. The final upper limit of rows in the buffer is composed of this value and the general parametrization.
  • swap__keep_top_row_size
    Define the top row in the currently loaded buffer as the top row and apply the top row parametrization in case of a trimming. If the parameter is False, the top parametrization is applied only to the real top row of the data (default).
DROP

A variation of the behavior of _Trimmer as if a swap were installed for chunk data management.

As reaction to cut rows of the buffer, a function must be passed which receives the rows in a DumpData item as parameter. The function is then called synchronously during trimming.

The management of chunks to be reloaded into the buffer is realized in the _Trimmer morph SWAP by interfaces to _Swap methods. For the DROP morph, these interfaces can be assigned differently, but they must adhere to the signature of the return values, since these are passed to the ChunkLoad item. The "poll"-action is executed when the processing of the TextBuffer data or cursor movement suggests that loading chunks into the buffer is necessary. The "demand"-action is the interface to the _Swap's auto_fill method in the SWAP morph, and is executed when extensive processing of the buffer data or cursor movement occurs.

This morph of trimmer is NOT compatible with the _LocalHistory component, but takes care of adjustment and removal of markings and cursor anchors (component _Marker and _GlobCursor). This morph is intended for use of the TextBuffer as a simple screen-scroller and is not intended for dynamic editing of data.

Keyword parameters:
  • drop__chunk_size
    The size of a chunk. The final upper limit of rows in the buffer is composed of this value and the general parametrization.
  • drop__keep_top_row_size
    Define the top row in the currently loaded buffer as the top row and apply the top row parametrization in case of a trimming. If the parameter is False, the top parametrization is applied only to the real top row of the data (default).
  • drop__poll
    The "poll"-function.
  • drop__demand
    The "demand"-function.
RESTRICTIVE

This design of the _Trimmer removes rows when the maximum value is reached from the end of the buffer and does not provide for any treatment of the removed data. Although the functionality of the _LocalHistory component is extended:

If the _LocalHistory component is installed, "restrictively" cut data is registered chronologically and when an action in the buffer is receded, it is appended to the buffer again. This morph also takes care of markings (component _Marker), thus allowing full compatibility with _LocalHistory.

Keyword parameters:
  • restrictive
    Must be explicitly set to True for the morph.
  • restrictive__last_row_maxsize
    An optional deviation of the size of the final row in the buffer.

morph: Literal["swp", "res", "drp"]

__call__() -> tuple[list[list[_Row]], list[list[_Row]]] | None

Automation. Execute the trim.

Returns: (
  • <_Rowchunk's cut from top> | None,
  • <_Rowchunk's cut from bottom> | None

) | None

overload __init__(__buffer__, rows_max, *, drop__dump, drop__chunk_size, drop__keep_top_row_size=False, drop__poll=lambda: (None, None, None, None), drop__demand=lambda: (None, None, None, None))

overload __init__(__buffer__, rows_max, *, restrictive, restrictive__last_row_maxsize=None)

overload __init__(__buffer__, rows_max, *, swap__chunk_size, swap__keep_top_row_size=False)

__init__(__buffer__, rows_max, *, drop__dump=None, drop__chunk_size=None, drop__keep_top_row_size=False, drop__poll=lambda: (None, None, None, None), drop__demand=lambda: (None, None, None, None), restrictive=None, restrictive__last_row_maxsize=None, swap__chunk_size=None, swap__keep_top_row_size=None)

action__demand__() -> tuple[list[list[_Row]] | None, list[list[_Row]] | None, int | None, int | None]

Should return: (
  • <_Rowchunk's cut from top> | None,
  • <_Rowchunk's cut from bottom> | None,
  • <n loaded chunks from top> | None,
  • <n loaded chunks from bottom> | None

)

action__poll__() -> tuple[list[list[_Row]] | None, list[list[_Row]] | None, int | None, int | None]

Should return: (
  • <_Rowchunk's cut from top> | None,
  • <_Rowchunk's cut from bottom> | None,
  • <n loaded chunks from top> | None,
  • <n loaded chunks from bottom> | None

)

sizing(*, adjust_buffer=True) -> bool

Perform the sizing for the special rows in the current buffer according to the parametrization.

[+] __marker__.adjust [+] __glob_cursor__.adjust

Return True if the sizing is executed.

suit(all_=True, *, _trim=True, _call=True, _fill=True, leave_active=False) -> _Suit[_Trimmer]

Create a context manager to selectively disable trimmer interfaces within the suit (by default all are active).

If a suit is active and leave_active is True, __exit__ of the active suit is executed and a new one is created, otherwise a dummy is returned.


Date: 20 Dec 2022
Version: 0.1
Author: Adrian Hoefflin [srccircumflex]
Doc-Generator: "pyiStructure-RSTGenerator" <prototype>

Clone this wiki locally