pg.views.HtmlTreeView

Accessible via pg.views.HtmlTreeView.

class HtmlTreeView(**kwargs)[source]

Bases: pg.views.HtmlView

HTML Tree View.

Classes:

Extension()

The base class for extensions for HtmlTreeView.

Methods:

complex_value(kv, *, parent, root_path[, ...])

Renders a list of key-value pairs.

content(value, *[, name, parent, root_path, ...])

Renders the main content for the value.

css_class_name(value)

Returns the CSS class name for the value.

get_child_kwargs(call_kwargs, child_config, ...)

Enter the child config for a child key.

get_collapse_level(original_level, ...)

Gets the collapse level for a child node.

get_kwargs(call_kwargs, overriden_kwargs[, ...])

Override render arguments.

get_passthrough_kwargs(*[, enable_summary, ...])

Gets the rendering arguments to pass through to the child nodes.

init_uncollapse(uncollapse)

Initializes the uncollapse argument.

merge_uncollapse(uncollapse, child_uncollapse)

Merge uncollapse paths.

needs_summary(value, *[, name, parent, ...])

Returns True if the object needs a summary.

object_key(root_path, *, value, parent[, ...])

Renders a label-style key for the value.

should_collapse(value, name, root_path, parent)

Returns True if the object should be collapsed.

simple_value(value, *[, name, parent, ...])

Renders a simple value.

summary(value, *[, name, parent, root_path, ...])

Renders the summary for an input value.

tooltip(value, *[, parent, root_path, ...])

Renders a tooltip for the value.

class Extension[source]

Bases: Extension

The base class for extensions for HtmlTreeView.

complex_value(kv, *, parent, root_path, name=None, css_classes=None, enable_summary=None, enable_summary_for_str=True, max_summary_len_for_str=80, enable_summary_tooltip=True, key_style='summary', key_color=None, include_keys=None, exclude_keys=None, enable_key_tooltip=True, collapse_level=1, uncollapse=None, child_config=None, highlight=None, lowlight=None, render_key_fn=None, render_value_fn=None, extra_flags=None, debug=False)[source]

Renders a list of key-value pairs.

Return type:

pg.Html

Parameters:
  • kv – The key-value pairs to render.

  • parent – The parent of the value.

  • root_path – The root path of the value.

  • name – The name of the value.

  • css_classes – CSS classes to add to the HTML element.

  • enable_summary – Whether to enable the summary. If None, the default is to enable the summary for non-string and disable the summary for string.

  • enable_summary_for_str – Whether to enable the summary for string.

  • max_summary_len_for_str – The maximum length of the string to display.

  • enable_summary_tooltip – Whether to enable the summary tooltip.

  • key_style – The style of the key. It can be either ‘label’ or ‘summary’. If it is a function, the function takes (root_path, value, parent) and returns either ‘label’ or ‘summary’.

  • key_color – The color of the key. If it is a tuple, the first element is the text color and the second element is the background color. If it is a function, the function takes (root_path, value, parent) and returns a tuple of (text_color, background_color).

  • include_keys – The keys to include (at the immediate child level). If it is a function, the function takes (root_path, value, parent) and returns an iterable of keys to include.

  • exclude_keys – The keys to exclude (at the immediate child level). If it is a function, the function takes (root_path, value, parent) and returns an iterable of keys to exclude.

  • enable_key_tooltip – Whether to enable the key tooltip.

  • collapse_level – The level to collapse the tree.

  • uncollapse – A key path set (relative to root_path) for the nodes to uncollapse. or a function with signature (path, value, parent) -> bool to filter nodes to uncollapse.

  • child_config – The configuration for rendering the child nodes.

  • highlight – A function with signature (path, value, parent) -> bool to determine whether to highlight.

  • lowlight – A function with signature (path, value, parent) -> bool to determine whether to lowlight.

  • render_key_fn – A custom function to render the label-style key.

  • render_value_fn – A custom function to render the child value.

  • extra_flags – Extra flags to pass to the child render.

  • debug – Whether to enable debug mode.

Returns:

The rendered HTML as the key-value pairs.

content(value, *, name=None, parent=None, root_path=None, css_classes=None, enable_summary=None, enable_summary_for_str=True, max_summary_len_for_str=80, enable_summary_tooltip=True, key_style='summary', key_color=None, include_keys=None, exclude_keys=None, enable_key_tooltip=True, collapse_level=1, uncollapse=None, highlight=None, lowlight=None, child_config=None, extra_flags=None, debug=False)[source]

Renders the main content for the value.

Return type:

pg.Html

Parameters:
  • value – The value to render.

  • name – The name of the value.

  • parent – The parent of the value.

  • root_path – The root path of the value.

  • css_classes – CSS classes to add to the HTML element.

  • enable_summary – Whether to enable the summary.

  • enable_summary_for_str – Whether to enable the summary for string.

  • max_summary_len_for_str – The maximum length of the string to display.

  • enable_summary_tooltip – Whether to enable the summary tooltip.

  • key_style – The style of the key. It can be either ‘label’ or ‘summary’. If it is a function, the function takes (root_path, value, parent) and returns either ‘label’ or ‘summary’.

  • key_color – The color of the key. If it is a tuple, the first element is the text color and the second element is the background color. If it is a function, the function takes (root_path, value, parent) and returns a tuple of (text_color, background_color).

  • include_keys – The keys to include (at the immediate child level). If it is a function, the function takes (root_path, value, parent) and returns an iterable of keys to include.

  • exclude_keys – The keys to exclude (at the immediate child level). If it is a function, the function takes (root_path, value, parent) and returns an iterable of keys to exclude.

  • enable_key_tooltip – Whether to enable the key tooltip.

  • collapse_level – The level to collapse the tree.

  • uncollapse – A key path set (relative to root_path) for the nodes to uncollapse. or a function with signature (path, value, parent) -> bool to filter nodes to uncollapse.

  • highlight – A function with signature (path, value, parent) -> bool to determine whether to highlight.

  • lowlight – A function with signature (path, value, parent) -> bool to determine whether to lowlight.

  • child_config – The configuration for rendering the child nodes.

  • extra_flags – Extra flags to pass to the child render.

  • debug – Whether to enable debug mode.

Returns:

The rendered HTML as the main content of the value.

static css_class_name(value)[source]

Returns the CSS class name for the value.

Return type:

Optional[str]

static get_child_kwargs(call_kwargs, child_config, child_key, root_path)[source]

Enter the child config for a child key.

Return type:

Dict[str, Any]

static get_collapse_level(original_level, overriden_level)[source]

Gets the collapse level for a child node.

Return type:

Optional[int]

static get_kwargs(call_kwargs, overriden_kwargs, root_path=None)[source]

Override render arguments.

Return type:

Dict[str, Any]

static get_passthrough_kwargs(*, enable_summary=MISSING_VALUE, enable_summary_for_str=MISSING_VALUE, max_summary_len_for_str=MISSING_VALUE, enable_summary_tooltip=MISSING_VALUE, key_style=MISSING_VALUE, key_color=MISSING_VALUE, include_keys=MISSING_VALUE, exclude_keys=MISSING_VALUE, enable_key_tooltip=MISSING_VALUE, uncollapse=MISSING_VALUE, extra_flags=MISSING_VALUE, highlight=MISSING_VALUE, lowlight=MISSING_VALUE, debug=MISSING_VALUE, remove=None, **kwargs)[source]

Gets the rendering arguments to pass through to the child nodes.

static init_uncollapse(uncollapse)[source]

Initializes the uncollapse argument.

Return type:

Union[pg.KeyPathSet, Callable[[pg.KeyPath, Any, Any], bool]]

static merge_uncollapse(uncollapse, child_uncollapse, child_path=None)[source]

Merge uncollapse paths.

Return type:

Union[pg.KeyPathSet, Callable[[pg.KeyPath, Any, Any], bool]]

needs_summary(value, *, name=None, parent=None, title=None, enable_summary=None, enable_summary_for_str=True, max_summary_len_for_str=80)[source]

Returns True if the object needs a summary.

Return type:

bool

Parameters:
  • value – The value to render.

  • name – The referred field name of the value.

  • parent – The parent of the value.

  • title – The title of the summary.

  • enable_summary – Whether to enable the summary. If None, summary will be enabled for complex types or when string exceeds max_summary_len_for_str.

  • enable_summary_for_str – Whether to enable the summary for strings.

  • max_summary_len_for_str – The maximum length of the string to display.

Returns:

True if the object needs a summary.

object_key(root_path, *, value, parent, css_classes=None, key_color=None, enable_key_tooltip=True, key_tooltip_fn=None, **kwargs)[source]

Renders a label-style key for the value.

Return type:

pg.Html

Parameters:
  • root_path – The root path of the value.

  • value – The value to render.

  • parent – The parent of the value.

  • css_classes – The CSS classes to add to the HTML element.

  • key_color – The color of the key. If None, the key will be rendered without a color. If a tuple, the first element is the text color and the second element is the background color. If a function, the function takes (root_path, value, parent) and returns a tuple of (text_color, background_color).

  • enable_key_tooltip – Whether to enable the tooltip.

  • key_tooltip_fn – The function to render the key tooltip.

  • **kwargs – Additional arguments passed by the user that will be ignored.

Returns:

The rendered HTML as the key of the value.

should_collapse(value, name, root_path, parent, collapse_level=1, uncollapse=None)[source]

Returns True if the object should be collapsed.

Return type:

bool

Parameters:
  • value – The value to render.

  • name – The referred field name of the value.

  • root_path – The root path of the value.

  • parent – The parent of the value.

  • collapse_level – The level of collapsing. If 0, the object will be collapsed (without showing its sub-nodes). If 1, the immediate sub-nodes will be shown in collapsed form. If None, all sub-tree will be shown.

  • uncollapse – Indivdual nodes to uncollapse. It can be a KeyPathSet or a function that takes (root_path, value, parent) and returns a KeyPathSet.

Returns:

True if the object should be collapsed.

simple_value(value, *, name=None, parent=None, root_path=None, css_classes=None, max_summary_len_for_str=80)[source]

Renders a simple value.

Return type:

pg.Html

Parameters:
  • value – The value to render.

  • name – The name of the value.

  • parent – The parent of the value.

  • root_path – The root path of the value.

  • css_classes – CSS classes to add to the HTML element.

  • max_summary_len_for_str – The maximum length of the string to display.

Returns:

The rendered HTML as the simple value.

summary(value, *, name=None, parent=None, root_path=None, css_classes=None, title=None, enable_summary=None, enable_summary_tooltip=True, summary_color=None, max_summary_len_for_str=80, enable_summary_for_str=True, enable_key_tooltip=True, summary_tooltip_fn=None, key_tooltip_fn=None, extra_flags=None)[source]

Renders the summary for an input value.

Return type:

Optional[pg.Html]

Parameters:
  • value – The value to render.

  • name – The referred field name of the value.

  • parent – The parent of the value.

  • root_path – The root path of the value.

  • css_classes – The CSS classes to add to the HTML element.

  • title – The title of the summary.

  • enable_summary – Whether to enable the summary. If None, summary will be enabled for complex types or when string exceeds max_summary_len_for_str.

  • enable_summary_tooltip – Whether to enable the summary tooltip.

  • summary_color – The color of the summary. If None, the summary will be rendered without a color. If a tuple, the first element is the text color and the second element is the background color. If a function, the function takes (root_path, value, parent) and returns a tuple of (text_color, background_color).

  • max_summary_len_for_str – The maximum length of the string to display.

  • enable_summary_for_str – Whether to enable the summary for strings.

  • enable_key_tooltip – Whether to enable the key tooltip.

  • summary_tooltip_fn – The function to render the summary tooltip.

  • key_tooltip_fn – The function to render the key tooltip.

  • extra_flags – The extra flags to pass to the summary.

Returns:

An optional HTML object representing the summary of the value. If None, the summary will not be rendered.

tooltip(value, *, parent=None, root_path=None, css_classes=None, id=None, content=None, **kwargs)[source]

Renders a tooltip for the value.

Return type:

pg.Html

Parameters:
  • value – The value to render.

  • parent – The parent of the value.

  • root_path – The root path of the value.

  • css_classes – CSS classes to add to the HTML element.

  • id – The ID of the tooltip span element. If None, no ID will be added.

  • content – The content to render. If None, the value will be rendered.

  • **kwargs – Additional keyword arguments passed from the user that will be ignored.

Returns:

The rendered HTML as the tooltip of the value.