AppEventBus¶
AppEventBus is a singleton Qt signal hub that decouples UI components without creating direct widget references. All cross-component communication flows through typed signals defined here.
Why an Event Bus?¶
Without an event bus, the main window would need direct references to every view in every module, and every module's view would need a reference back to the main window. With the event bus:
MainWindowconnects once to the bus signals it cares about (e.g.status_message).- Module views emit signals onto the bus; they do not know who is listening.
- New listeners can be added without modifying the emitter.
Signal Reference¶
| Signal | Payload | Description |
|---|---|---|
graph_selected |
str (graph_id) |
User has selected a graph to work on |
node_selected |
str (node_id) |
User has selected a node in a view |
node_added |
str (node_id) |
A new node has been persisted |
node_updated |
str (node_id) |
A node update has been persisted |
node_removed |
str (node_id) |
A node has been removed |
outline_tree_changed |
str (graph_id) |
The outline tree structure has changed |
status_message |
str (message) |
Push a transient message to the status bar |
error_occurred |
str (message) |
Show a recoverable error to the user |
Usage¶
from knowledge_platform.ui.events import AppEventBus
bus = AppEventBus()
# Connect a handler
bus.status_message.connect(lambda msg: print(f"Status: {msg}"))
bus.error_occurred.connect(lambda err: show_error_dialog(err))
# Emit from a view
bus.node_added.emit(str(new_node.id))
bus.status_message.emit("Item added successfully.")
API Reference¶
knowledge_platform.ui.events.AppEventBus ¶
Bases: QObject
Singleton event bus for the application.
Signals are emitted by producers and connected to handlers by the main window or individual views. No business logic lives in this class.
Signals
graph_selected: Emitted when the user selects a graph to work on.
Payload: graph_id string.
node_selected: Emitted when the user selects a node in a view.
Payload: node_id string.
node_added: Emitted after a new node has been persisted.
Payload: node_id string.
node_updated: Emitted after a node update has been persisted.
Payload: node_id string.
node_removed: Emitted after a node has been removed.
Payload: node_id string.
outline_tree_changed: Emitted when the outline tree structure changes.
Payload: graph_id string.
status_message: Emitted to push a transient message to the status bar.
Payload: message string.
error_occurred: Emitted when a recoverable error should be shown to the user.
Payload: error message string.