mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 19:21:50 +02:00
docs: minor updates to the widget tutorial
This commit is contained in:
@ -5,10 +5,7 @@
|
||||
## Overview
|
||||
|
||||
The [`BECDispatcher`](https://bec.readthedocs.io/projects/bec-widgets/en/latest/api_reference/_autosummary/bec_widgets.utils.bec_dispatcher.BECDispatcher.html#bec_widgets.utils.bec_dispatcher.BECDispatcher)
|
||||
is a powerful tool that
|
||||
simplifies the process of connecting Qt slots to message updates from the BEC server. It enables real-time communication
|
||||
between your widget and the BEC server by listening to specific message channels and triggering callbacks when new data
|
||||
is received.
|
||||
is a powerful tool that simplifies the process of connecting [Qt slots](https://doc.qt.io/qt-6/signalsandslots.html) to message updates from the BEC server. It enables real-time communication between your widget and the BEC server by listening to specific message channels and triggering callbacks when new data is received.
|
||||
|
||||
This tool is especially useful for creating widgets that need to respond to dynamic data, such as device readbacks or
|
||||
scan updates. By
|
||||
@ -31,7 +28,7 @@ etc.).
|
||||
### Step-by-Step Guide
|
||||
|
||||
1. **Create a Callback Function**: Define a function within your widget that will handle the data received from the BEC
|
||||
server. This function should usually accept two parameters: `msg_content` (the message content) and `metadata` (
|
||||
server. This function must accept two parameters: `msg_content` (the message content) and `metadata` (
|
||||
additional
|
||||
information about the message).
|
||||
|
||||
@ -40,7 +37,7 @@ etc.).
|
||||
from qtpy.QtCore import Slot
|
||||
|
||||
@Slot(dict, dict)
|
||||
def on_device_readback(self, msg_content, metadata):
|
||||
def on_device_readback(self, msg_content:dict, metadata:dict):
|
||||
# Process the incoming data
|
||||
new_value = msg_content["signals"]['motor_x']["value"]
|
||||
# Update the widget's display or perform another action
|
||||
@ -132,8 +129,7 @@ widget:
|
||||
## Conclusion
|
||||
|
||||
The [`BECDispatcher`](https://bec.readthedocs.io/projects/bec-widgets/en/latest/api_reference/_autosummary/bec_widgets.utils.bec_dispatcher.BECDispatcher.html#bec_widgets.utils.bec_dispatcher.BECDispatcher)
|
||||
is a key tool for developing interactive and responsive widgets within the BEC framework. By
|
||||
leveraging this tool, you can create widgets that automatically respond to real-time data updates from the BEC server,
|
||||
is a key tool for developing interactive and responsive widgets within the BEC framework. By leveraging this tool, you can create widgets that automatically respond to real-time data updates from the BEC server,
|
||||
enhancing the interactivity and functionality of your user interface.
|
||||
|
||||
In next tutorials we will cover how to create a custom widget using the BECDispatcher and BECWidget base class.
|
||||
|
@ -15,10 +15,8 @@ The [`BECWidget`](https://bec.readthedocs.io/projects/bec-widgets/en/latest/api_
|
||||
base class is designed to serve as the foundation for all BEC-connected widgets. It ensures that your widget is properly
|
||||
integrated with the BEC system by providing:
|
||||
|
||||
1. **Connection to BEC Services
|
||||
**: [`BECWidget`](https://bec.readthedocs.io/projects/bec-widgets/en/latest/api_reference/_autosummary/bec_widgets.utils.bec_widget.BECWidget.html#bec_widgets.utils.bec_widget.BECWidget)
|
||||
includes
|
||||
the [`BECConnector`](https://bec.readthedocs.io/projects/bec-widgets/en/latest/api_reference/_autosummary/bec_widgets.utils.bec_connector.BECConnector.html#bec_widgets.utils.bec_connector.BECConnector)
|
||||
1. **Connection to BEC Services**:
|
||||
[`BECWidget`](https://bec.readthedocs.io/projects/bec-widgets/en/latest/api_reference/_autosummary/bec_widgets.utils.bec_widget.BECWidget.html#bec_widgets.utils.bec_widget.BECWidget) includes the [`BECConnector`](https://bec.readthedocs.io/projects/bec-widgets/en/latest/api_reference/_autosummary/bec_widgets.utils.bec_connector.BECConnector.html#bec_widgets.utils.bec_connector.BECConnector)
|
||||
mixin, which handles all the necessary connections to BEC services such as the BEC server, device manager, scan
|
||||
control, and more.
|
||||
|
||||
|
@ -1,7 +1,49 @@
|
||||
(developer.widget_development)=
|
||||
|
||||
# Widget Development
|
||||
This section provides an introduction to the building blocks of BEC Widgets: widgets. Widgets are the basic components of the graphical user interface (GUI) and are used to create larger applications. We will cover key topics such as how to develop new widgets or how to customise existing widgets. For details on the already available widgets and their usage, please refer to user section about [widgets](#user.widgets)
|
||||
This section provides an introduction to the building blocks of BEC Widgets: widgets. Widgets are the basic components of the graphical user interface (GUI) and are used to create larger applications. We will cover key topics such as how to develop new widgets or how to customise existing widgets. For details on the already available widgets and their usage, please refer to user section about [widgets](#user.widgets).
|
||||
|
||||
To facilitate the development of new widgets, integrated into the BEC framework, we provide two main base classes: `BECWidget` and its parent class `BECDispatcher`. The `BECDispatcher` class is responsible for managing the communication between widgets and the BEC framework. The `BECWidget` class is the base class for all widgets and provides the basic functionality for creating and managing widgets. Leveraging these classes, you can rapidly develop new widgets that are responsive and interactive.
|
||||
|
||||
A very simple "Hello World" example of a widget can be seen below:
|
||||
|
||||
````{dropdown} View code: Hello World Widget
|
||||
:icon: code-square
|
||||
:animate: fade-in-slide-down
|
||||
|
||||
```python
|
||||
from qtpy.QtWidgets import QLabel, QWidget
|
||||
|
||||
from bec_widgets.utils.bec_widget import BECWidget
|
||||
|
||||
|
||||
class HelloWorldWidget(BECWidget, QWidget):
|
||||
def __init__(
|
||||
self, parent: QWidget | None = None, client=None, gui_id: str | None = None
|
||||
) -> None:
|
||||
# Initialize the BECWidget and QWidget
|
||||
super().__init__(client=client, gui_id=gui_id)
|
||||
QWidget.__init__(self, parent)
|
||||
|
||||
# Create a label with the text "Hello World"
|
||||
self.label = QLabel(self)
|
||||
self.label.setText("Hello World")
|
||||
|
||||
|
||||
# Run the widget as a standalone application
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
from qtpy.QtWidgets import QApplication
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
w = HelloWorldWidget()
|
||||
w.show()
|
||||
sys.exit(app.exec_())
|
||||
```
|
||||
````
|
||||
|
||||
The following sections will provide more details on how to develop new widgets and how to leverage the `BECDispatcher` and `BECWidget` classes to create interactive and responsive widgets.
|
||||
|
||||
```{toctree}
|
||||
---
|
||||
|
Reference in New Issue
Block a user