mbdlyb_ui.helpers
Copyright (c) 2023 - 2026 TNO-ESI All rights reserved.
Classes
Track an editable graph relation and its original endpoints. |
Functions
|
Create nested NiceGUI tree data for a network class or parent subnet. |
|
Export a Bayesian network in Netica or BIF XML format. |
|
Download a conditional probability table as an Excel workbook. |
|
Download a network graph as GraphML for yEd. |
|
Fetch a model object, displaying a message when none is found. |
|
Find a graph relationship and display a message when missing. |
|
Resolve an element or serialized menu-tree ID to its registered URL. |
|
Navigate to a URL or the registered URL of a model element. |
|
Save a new element in a network and optionally redirect. |
|
Save an existing model element, update its FQN, and optionally redirect. |
Module Contents
- class mbdlyb_ui.helpers.Relation(start_node: mbdlyb.gdb.GMBDElement | None = None, end_node: mbdlyb.gdb.GMBDElement | None = None, start_node_type: type[mbdlyb.gdb.GMBDElement] | None = None, end_node_type: type[mbdlyb.gdb.GMBDElement] | None = None)
Track an editable graph relation and its original endpoints.
- end_node_changed() bool
Check whether an existing relation’s target UID changed.
- Returns:
True when the original and selected target UIDs differ.
- get_end_node() mbdlyb.gdb.GMBDElement
Look up the currently selected target element by UID.
- Returns:
The target element, or None when no target UID is selected.
- get_original_end_node() mbdlyb.gdb.GMBDElement
Look up the target element before any edits.
- Returns:
The original target, or None for a new relation.
- get_original_start_node() mbdlyb.gdb.GMBDElement
Look up the source element before any edits.
- Returns:
The original source, or None for a new relation.
- get_props() dict
Provide relationship properties for the edge being saved.
- Returns:
An empty mapping by default; subclasses can supply edge properties.
- get_start_node() mbdlyb.gdb.GMBDElement
Look up the currently selected source element by UID.
- Returns:
The source element, or None when no source UID is selected.
- save(redirect: str | mbdlyb.gdb.GMBDElement | None = None)
Replace the old graph edge with the currently selected relation.
- Parameters:
redirect – Optional URL or element to navigate to after saving.
- start_node_changed() bool
Check whether an existing relation’s source UID changed.
- Returns:
True when the original and selected source UIDs differ.
- end_uid: str | None = None
- start_uid: str | None = None
Create nested NiceGUI tree data for a network class or parent subnet.
- Parameters:
clazz – Network class from which to load root nodes.
parent – Network whose subnets should form this level.
- Returns:
Tree nodes with IDs, labels, and nested child lists.
- mbdlyb_ui.helpers.download_bayesnet(gdb_net: mbdlyb.gdb.GMBDNet, suffix: str = '.dne', colormap: mbdlyb.colormap.ColorMap | None = None)
Export a Bayesian network in Netica or BIF XML format.
- Parameters:
gdb_net – Database-backed network to export.
suffix – Export format, either
.dneor.bifxml.colormap – Optional colors for Netica output.
- mbdlyb_ui.helpers.download_cpt(cpt: mbdlyb.cpt.CPT, name: str)
Download a conditional probability table as an Excel workbook.
- Parameters:
cpt – Probability table to serialize.
name – Base name of the downloaded workbook.
- mbdlyb_ui.helpers.download_graph(gdb_net: mbdlyb.gdb.GMBDNet, colormap: mbdlyb.colormap.ColorMap | None = None)
Download a network graph as GraphML for yEd.
- Parameters:
gdb_net – Database-backed network to export.
colormap – Optional node color mapping used for rendering.
- mbdlyb_ui.helpers.get_object_or_404[T](klass: type[T], **kwargs) T
Fetch a model object, displaying a message when none is found.
- Parameters:
klass – Model class to query.
**kwargs – Properties used to filter the lookup.
- Returns:
The matching object, or None when the lookup finds nothing.
- mbdlyb_ui.helpers.get_relation_or_404(start_node: mbdlyb.gdb.GMBDElement, end_node: mbdlyb.gdb.GMBDElement, attr: str)
Find a graph relationship and display a message when missing.
- Parameters:
start_node – Element whose relationship manager is queried.
end_node – Related element being looked up.
attr – Relationship manager attribute on the source.
- Returns:
The relationship record, or None when no edge exists.
- mbdlyb_ui.helpers.get_url(element: str | mbdlyb.gdb.GMBDIdentifiable) str | None
Resolve an element or serialized menu-tree ID to its registered URL.
- Parameters:
element – Model object, UID, or
ClassName__uidtree ID.- Returns:
A formatted URL, or None if no resolver matches.
- mbdlyb_ui.helpers.goto(url: str | mbdlyb.gdb.GMBDElement)
Navigate to a URL or the registered URL of a model element.
- Parameters:
url – Destination URL or resolvable model element.
- Returns:
The result of NiceGUI’s navigation call.
- mbdlyb_ui.helpers.save_new_object(obj: mbdlyb.gdb.GMBDElement, net: mbdlyb.gdb.GMBDNet, success_url: str | mbdlyb.gdb.GMBDElement | Callable | None = None)
Save a new element in a network and optionally redirect.
- Parameters:
obj – New element to persist.
net – Containing network to associate with the element.
success_url – Destination URL, element, or callable receiving
obj.
- mbdlyb_ui.helpers.save_object(obj: mbdlyb.gdb.GMBDElement, success_url: str | mbdlyb.gdb.GMBDElement | Callable | None = None)
Save an existing model element, update its FQN, and optionally redirect.
- Parameters:
obj – Element to persist.
success_url – Destination URL, element, or callable receiving
obj.