mbdlyb_ui.helpers

Copyright (c) 2023 - 2026 TNO-ESI All rights reserved.

Classes

Relation

Track an editable graph relation and its original endpoints.

Functions

build_menu_tree(clazz[, parent])

Create nested NiceGUI tree data for a network class or parent subnet.

download_bayesnet(gdb_net[, suffix, colormap])

Export a Bayesian network in Netica or BIF XML format.

download_cpt(cpt, name)

Download a conditional probability table as an Excel workbook.

download_graph(gdb_net[, colormap])

Download a network graph as GraphML for yEd.

get_object_or_404(→ T)

Fetch a model object, displaying a message when none is found.

get_relation_or_404(start_node, end_node, attr)

Find a graph relationship and display a message when missing.

get_url(→ Optional[str])

Resolve an element or serialized menu-tree ID to its registered URL.

goto(url)

Navigate to a URL or the registered URL of a model element.

save_new_object(obj, net[, success_url])

Save a new element in a network and optionally redirect.

save_object(obj[, success_url])

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
mbdlyb_ui.helpers.build_menu_tree(clazz: Type[mbdlyb.gdb.GMBDNet], parent: mbdlyb.gdb.GMBDNet | 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 .dne or .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__uid tree 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.