paidiverpy.frontend.json_dump#

This module provides functions to extract values from a Panel layout and convert them into a structured JSON-like dictionary.

Functions#

find_deep_layout(→ list[panel.widgets.Widget])

Recursively find all widgets and layouts in a Panel layout.

check_valid_inputs(→ bool)

Check if a widget is valid for extraction.

parse_name(→ list[Any])

Parse a widget name into a list of keys.

insert_nested(→ None)

Insert a value into a nested dictionary structure based on keys.

extract_values(→ dict[str, Any])

Extract values from a list of widgets and return them as a structured dictionary.

extract_json(→ dict[str, Any])

Extract JSON-like dictionary from a Panel layout or widget.

Module Contents#

paidiverpy.frontend.json_dump.find_deep_layout(layout: panel.widgets.Widget, founds: list[panel.widgets.Widget]) list[panel.widgets.Widget][source]#

Recursively find all widgets and layouts in a Panel layout.

Parameters:
  • layout (pn.widgets.Widget) – The Panel layout or widget to search.

  • founds (list[pn.widgets.Widget]) – A list to collect found widgets and layouts.

Returns:

A list of found widgets and layouts.

Return type:

list[pn.widgets.Widget]

paidiverpy.frontend.json_dump.check_valid_inputs(widget: panel.widgets.Widget, step: bool = False) bool[source]#

Check if a widget is valid for extraction.

Parameters:
  • widget (pn.widgets.Widget) – The widget to check.

  • step (bool) – If True, additional checks for step widgets are applied.

Returns:

True if the widget is valid, False otherwise.

Return type:

bool

paidiverpy.frontend.json_dump.parse_name(name: str) list[Any][source]#

Parse a widget name into a list of keys.

Parameters:

name (str) – The name of the widget, which may contain dots and brackets.

Returns:

A list of keys parsed from the name, converting numeric parts to integers.

Return type:

list

paidiverpy.frontend.json_dump.insert_nested(result: dict[str, Any], keys: list[Any], value: Any) None[source]#

Insert a value into a nested dictionary structure based on keys.

Parameters:
  • result (dict) – The dictionary to insert into.

  • keys (list) – A list of keys indicating the path to insert the value.

  • value (Any) – The value to insert.

paidiverpy.frontend.json_dump.extract_values(widgets: list[panel.widgets.Widget], step: bool = False) dict[str, Any][source]#

Extract values from a list of widgets and return them as a structured dictionary.

Parameters:
  • widgets (list[pn.widgets.Widget]) – A list of Panel widgets to extract values from.

  • step (bool) – If True, the extraction will consider step-specific widgets.

Returns:

A dictionary containing the extracted values, structured by widget names.

Return type:

dict

paidiverpy.frontend.json_dump.extract_json(layout: panel.widgets.Widget, step: bool = False) dict[str, Any][source]#

Extract JSON-like dictionary from a Panel layout or widget.

Parameters:
  • layout (pn.widgets.Widget) – The Panel layout or widget to extract from.

  • step (bool) – If True, the extraction will consider step-specific widgets.

Returns:

A dictionary containing the extracted values, structured by widget names.

Return type:

dict