Node classes¶
- class pantra.common.UniNode(parent: Self | None = None)[source]¶
Simple tree of nodes
- Parameters:
parent (Optional[Self])
- property parent: Self¶
parent property
- property root¶
return root node of this tree
- select(predicate: Callable[[Self], bool], depth: int = None) Generator[Self][source]¶
select all nodes by predicate condition
- upto(predicate: str | Callable[[Self], bool]) Self | None[source]¶
find the closest ascendant by specified predicate
- class pantra.common.UniqueNode(parent: Self = None)[source]¶
Extension to
UniNodewith unique OID andweakrefsupport- Parameters:
parent (Self)
- oid_gen¶
oid generator
- oid¶
unique object identifier (usually, within session)
- class pantra.components.render.render_node.RenderNode(parent: RenderNode | None, shot: ContextShotLike | None = None, session: Session | None = None, context: Context | None = None)[source]¶
Base class for rendered nodes (extension to
UniqueNode).- Parameters:
parent (Optional[RenderNode])
shot (Optional[ContextShotLike])
session (Optional[Session])
context (Optional[Context])
- shot¶
snapshot manager to update changes
- Type:
ContextShot
- property top_most_scope: ScopeDict¶
get parent scope or this one
- render(template: str | HTMLTemplate, locals: dict = None, build: bool = True)[source]¶
render new child node.
- Parameters:
template (Union[str, HTMLTemplate]) – template to render or code
locals (dict) – locals dict for current context
build (bool) – whether to build the node
- add(tag_name: str, attributes: dict = None, text: str = None) HTMLElement | Context | None[source]¶
add and render component context or HTML element
- Parameters:
- Returns:
added node
- Return type:
HTMLElement | Context | None
- remove(node: RenderNode | None = None)[source]¶
remove this or specified node
- Parameters:
node (Optional[RenderNode])
- update(with_attrs: bool = False)[source]¶
send node changes to the client-side
- Parameters:
with_attrs (bool) – whether to update dynamic attributes
- frozen_clone(new_parent: RenderNode | None = None) HTMLElement | TextNode | None[source]¶
make visual copy of the node and all its children
Visual copy means - all dynamic nodes become static, freezing last states and values
- Parameters:
new_parent (Optional[RenderNode]) – optionally, new parent node
- Returns:
new node
- Return type:
Optional[HTMLElement, TextNode]
- select(predicate: str | Iterable[str] | Callable[[RenderNode], bool], depth: int = None) Generator[RenderNode][source]¶
select all nodes by condition
- Parameters:
predicate (Union[str, Iterable[str], Callable[[RenderNode], bool]]) – lambda function, string representation of list of string representations
depth (int) – depth of selection
- Yields:
selected node
- Return type:
Generator[RenderNode]
- contains(predicate: str | Iterable[str] | Callable[[RenderNode], bool], depth: int = None) bool[source]¶
check if node is contained by predicate
Arguments are similar to
select()
- kill_task(func_name: str | Callable)[source]¶
kill running task by context OID and function name
Read more: session tasks
- Parameters:
func_name (str | Callable)
- class pantra.components.context.Context(template_name: str, parent: RenderNode | None = None, shot: ContextShot | None = None, session: Session | None = None, locals: dict | None = None)[source]¶
Context of the component.
- Parameters:
template_name (str)
parent (Optional[RenderNode])
shot (Optional[ContextShot])
session (Optional[Session])
locals (Optional[dict])
- attributes¶
initial attributes defined with component
- Type:
- refs¶
references to named nodes
- Type:
dict[str, ‘Context’ | HTMLElement]
- template¶
template to build component context
- Type:
HTMLTemplate | CodeType
- code_metrics¶
code metrics of the Python script
- Type:
CodeMetrics
- data_nodes¶
collection of data nodes
- Type:
- div(classes: str = '', src: HTMLElement | None = None, from_x: int = 0, from_y: int = 0, attributes: dict | None | None = None)[source]¶
add positioned <div> container
Usually used to make temporary box to visualize drag-and-drop.
- get_caller(action: str) Callable | Awaitable | None[source]¶
get callable local action by name
- Parameters:
action (str)
- Return type:
Callable | Awaitable | None
- allow_call(method: str)[source]¶
add method name to allowed calls set for JS callback
- Parameters:
method (str)
- class pantra.components.context.HTMLElement(tag_name: str, parent: RenderNode, attributes: dict[str, Any] | None = None, text: str = '', context: Context = None)[source]¶
HTML element node
- Parameters:
- attributes¶
HTML node attributes
- Type:
- classes¶
HTML classes
- Type:
- style¶
CSS style attributes
- Type:
- data¶
custom node data
- Type:
- get_caller(action: str) Callable | Awaitable | None[source]¶
get context caller by name
- Parameters:
action (str)
- Return type:
Callable | Awaitable | None
- classmethod parse(element: str, parent: RenderNode, text: str = '') HTMLElement | None[source]¶
create HTMLElement from string
Example:
div = HTMLElement.parse('input type=text value="Hello"', parent)
- Parameters:
element (str)
parent (RenderNode)
text (str)
- Return type:
Optional[HTMLElement]
- request_measures()[source]¶
get position and size of this element, rendered in user browser
Warning
Take in account getBoundingClientRect() repeated calls side effect.
- property measures: MeasuresData¶
get cached position and size of this element, rendered in user browser
Measures is cached after the first request. To update call
request_measures().
- set_measures(m: MeasuresData | list[int | str], from_x: int = 0, from_y: int = 0, shift_x: int = 0, shift_y: int = 0, grow: int = 0)[source]¶
change this element position and size in user browser
Calling this method sets position: fixed style of element, and then changed metrics
- property value¶
request value of this element <input> from user browser
It cached once requested.
- validate()[source]¶
check validity state of this element
- move_box(delta_x, delta_y)[source]¶
shift element location by delta_x, delta_y
Designed for drag’n’drop
- class pantra.components.context.NSElement(tag_name: str, parent: RenderNode, attributes: dict[str, Any] | None = None, text: str = '', context: Context = None)[source]¶
Extension to
HTMLElementwith namespace support- Parameters:
- ns_type¶
namespace type
- Type:
NSType
- class pantra.components.context.LoopNode(parent: RenderNode, template: HTMLTemplate | None)[source]¶
Node for loops {{#for …}}
- Parameters:
parent (RenderNode)
template (Optional[HTMLTemplate])
- class pantra.components.context.ConditionNode(parent: RenderNode, template: HTMLTemplate | None)[source]¶
Node for conditional {{#if …}}, {{#elif …}}, {{#else}}
- Parameters:
parent (RenderNode)
template (Optional[HTMLTemplate])
- class pantra.components.context.TextNode(parent: RenderNode, text: ValueOrCode)[source]¶
node for raw text content
intended to render sliced text blocks:
<div> Text one <p>...</p> {{get_content()}} <p>...</p> Text three </div>
- Parameters:
parent (RenderNode)
text (ValueOrCode)
- class pantra.components.context.EventNode(parent: RenderNode, selector: str | None = None, events: DynamicDict = None)[source]¶
Event node
- Parameters:
parent (RenderNode)
selector (str | None)
events (DynamicDict)
- class pantra.components.context.SetNode(parent: RenderNode, template: HTMLTemplate | Callable[[...], None] | None)[source]¶
-
- Parameters:
parent (RenderNode)
template (CallableTemplate)
- class pantra.components.context.ReactNode(parent: RenderNode, var_name: str, action: str | Callable[[...], None])[source]¶
:ref`React node <reactive tag>`
- Parameters:
parent (RenderNode)
var_name (str)
action (str | Callable[[...], None])