RunList Class

Inheritance diagram of RunList

class RunList(size, initial)

List of contiguous runs of values.

A RunList is an efficient encoding of a sequence of values. For example, the sequence aaaabbccccc is encoded as (4, a), (2, b), (5, c). The class provides methods for modifying and querying the run list without needing to deal with the tricky cases of splitting and merging the run list entries.

Run lists are used to represent formatted character data in pyglet. A separate run list is maintained for each style attribute, for example, bold, italic, font size, and so on. Unless you are overriding the document interfaces, the only interaction with run lists is via RunIterator.

The length and ranges of a run list always refer to the character positions in the decoded list. For example, in the above sequence, set_run(2, 5, 'x') would change the sequence to aaxxxbccccc.

Constructor:

__init__(size, initial)

Create a run list of the given size and a default value.

Parameters:
  • size (int) – Number of characters to represent initially.
  • initial (object) – The value of all characters in the run list.

Methods:

delete(start, end) Remove characters from the run list.
get_run_iterator() Get an extended iterator over the run list.
insert(pos, length) Insert characters into the run list.
set_run(start, end, value) Set the value of a range of characters.

Methods

RunList.delete(start, end)

Remove characters from the run list.

Parameters:
  • start (int) – Starting index to remove from.
  • end (int) – End index, exclusive.
RunList.get_run_iterator()

Get an extended iterator over the run list.

Return type:RunIterator
RunList.insert(pos, length)

Insert characters into the run list.

The inserted characters will take on the value immediately preceding the insertion point (or the value of the first character, if pos is 0).

Parameters:
  • pos (int) – Insertion index
  • length (int) – Number of characters to insert.
RunList.set_run(start, end, value)

Set the value of a range of characters.

Parameters:
  • start (int) – Start index of range.
  • end (int) – End of range, exclusive.
  • value (object) – Value to set over the range.

Table Of Contents

Previous topic

RunIterator Class

Next topic

ZipRunIterator Class