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