agent_gui#
AgentGUI: BAF’s interface to besser’s GUIModel, with optional-dependency handling.
- class baf.core.gui.agent_gui.AgentGUI(model, gui_id=None, persist=True, width=None)[source]#
Bases:
objectBAF’s interface to besser’s
GUIModel, with helper methods for common GUI operations.Handles the case where besser is not installed: all methods log a warning and return
None/Falseinstead of raising an error. When besser is installed, attribute access is transparently delegated to the inner model so that existing code that usesgui.modules,gui.name, etc. continues to work unchanged.- Parameters:
model – the
GUIModelinstance to wrap, orNone.gui_id – identifier for the AgentGUI.
persist – whether to store GUI updates in the session or not. Defaults to true
- _model#
the inner
GUIModel, orNonewhen besser is not installed or no model has been set.
- _id#
identifier for the AgentGUI.
- _persist#
whether to store GUI updates in the session or not. Defaults to true
- _collect_matching(elements, field, value, results)[source]#
Recursively collect into results every element where
getattr(el, field) == value.
- add_component(component, parent_id=None, screen_name=None)[source]#
Add a component to the GUI model.
Resolution order:
If parent_id is given, the component is added to the container that has that
component_id(must be a container withview_elements).If screen_name is given, the component is added to the top-level
view_elementsof the named screen.Otherwise the component is added to the main screen (
is_main_page=True), or to the first screen when no main screen exists.
- deep_copy()[source]#
Return a deep copy of this
AgentGUIand its inner model.- Returns:
a new instance wrapping a deep-copied model.
- Return type:
- find_component(field, value)[source]#
Find the first component in the model where
getattr(component, field) == value.Recursively searches through all modules → screens → containers.
- Parameters:
field (str) – the attribute name to match (e.g.
'component_id','name','content').value – the value to look for.
- Returns:
The first matching
ViewElement, orNoneif not found.
- find_components(field, value)[source]#
Find all components in the model where
getattr(component, field) == value.Recursively searches through all modules → screens → containers.
- get_screen(screen_name=None)[source]#
Retrieve a screen by name, or the main screen when no name is given.
Falls back to the first screen when there is no screen marked as main.
- Parameters:
screen_name (str | None) – the screen name to look for, or
Noneto get the main/first screen.- Returns:
The
Screen, orNoneif not found.
- property id#
Unique identifier for this GUI reply message.
- property model#
The underlying GUIModel instance, or None.
- property persist#
If True, input values from GUI events for this component are persisted in the session’s gui_inputs.
- Type: