FoldableTreeNode#

class penzai.treescope.foldable_representation.part_interface.FoldableTreeNode[source]#

Bases: RenderableTreePart

Abstract base class for a node that can be expanded or collapsed.

Foldable tree nodes can either be expanded or collapsed interactively for display. They are responsible for maintaining their own expand/collapse state, and for reporting metrics about themselves.

FoldableTreeNodes are always RenderableTreeParts, but they report normal metrics for themselves in their collapsed state, and support additional methods for computing their expanded state. This is so that their parents can freely call newlines_in_expanded_parent and foldables_in_this_part without checking the types of their children.

Note: Currently there is only one concrete subclass of FoldableTreeNode, called FoldableTreeNodeImpl. This is kept separate so that the abstract definition of RenderableTreePart doesn’t have to depend on implementation details of FoldableTreeNodeImpl.

Inherited Attributes

collapsed_width

The length of this rendering if collapsed in one line, in characters.

newlines_in_expanded_parent

The number of newlines in this rendering if in an expanded parent.

tags_in_this_part

Returns a set of "tag" objects contained in this part.

Methods

as_expanded_part()

Returns a part that is equivalent to this node but always expanded.

foldables_in_this_part()

Returns this node itself, since it is a foldable node.

get_expand_state()

Returns True if this node is currently set to be expand_state.

set_expand_state(expand_state)

Sets whether this node should start expand_state.

Attributes

collapsed_width

The length of this rendering if collapsed in one line, in characters.

newlines_in_expanded_parent

The number of newlines in this rendering if in an expanded parent.

tags_in_this_part

Returns a set of "tag" objects contained in this part.

Inherited Methods

(expand to view inherited methods)

__init__()

html_setup_parts(context, /)

Returns a set of setup strings for this part.

render_to_html(stream, *[, at_beginning_of_line])

Renders this tree part to an HTML source string.

render_to_text(stream, *, expanded_parent, ...)

Renders this tree part to a plain-text string.

abstract as_expanded_part() RenderableTreePart[source]#

Returns a part that is equivalent to this node but always expanded.

This should be used to extract the height of this foldable when expanded and also to identify its child foldables.

foldables_in_this_part() Sequence[FoldableTreeNode][source]#

Returns this node itself, since it is a foldable node.

abstract get_expand_state() ExpandState[source]#

Returns True if this node is currently set to be expand_state.

abstract set_expand_state(expand_state: ExpandState)[source]#

Sets whether this node should start expand_state.