mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 11:11:49 +02:00
feat: add filter i/o utility class
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 32 KiB |
BIN
docs/assets/widget_screenshots/signal_inputs.png
Normal file
BIN
docs/assets/widget_screenshots/signal_inputs.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 63 KiB |
BIN
docs/user/widgets/device_input/QProperties_DeviceInput.png
Normal file
BIN
docs/user/widgets/device_input/QProperties_DeviceInput.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 63 KiB |
@ -13,9 +13,11 @@ The `DeviceLineEdit` widget provides a line edit interface with autocomplete fun
|
||||
The `DeviceComboBox` widget offers a dropdown interface for device selection, providing a more visual way to browse through available devices.
|
||||
|
||||
## Key Features:
|
||||
- **Device Filtering**: Both widgets allow users to filter devices by their class names, ensuring that only relevant devices are shown.
|
||||
- **Device Filtering**: Both widgets allow users to filter devices by device type and readout priority, ensuring that only relevant devices are shown.
|
||||
- **Default Device Setting**: Users can set a default device to be pre-selected when the widget is initialized.
|
||||
- **Set Device Selection**: Both widgets allow users to set the available devices to be displayed independent of the applied filters.
|
||||
- **Real-Time Autocomplete (LineEdit)**: The `DeviceLineEdit` widget supports real-time autocomplete, helping users find devices faster.
|
||||
- **Real-Time Input Validation (LineEdit)**: User input is validated in real-time with a red border around the `DeviceLineEdit` indicating an invalid input.
|
||||
- **Dropdown Selection (ComboBox)**: The `DeviceComboBox` widget displays devices in a dropdown list, making selection straightforward.
|
||||
- **QtDesigner Integration**: Both widgets can be added as custom widgets in `QtDesigner` or instantiated directly in code.
|
||||
|
||||
@ -28,11 +30,15 @@ Both `DeviceLineEdit` and `DeviceComboBox` can be integrated within a GUI applic
|
||||
|
||||
## Example 1 - Creating a DeviceLineEdit in Code
|
||||
|
||||
In this example, we demonstrate how to create a `DeviceLineEdit` widget in code and customize its behavior.
|
||||
In this example, we demonstrate how to create a `DeviceLineEdit` widget in code and customize its behavior.
|
||||
We filter down to Positioners with readout_priority Baseline.
|
||||
Note, if we do not specify a device_filter or readout_filter, all enabled devices will be included.
|
||||
|
||||
```python
|
||||
from qtpy.QtWidgets import QApplication, QVBoxLayout, QWidget
|
||||
from bec_widgets.widgets.device_line_edit import DeviceLineEdit
|
||||
from bec_widgets.widgets.device_line_edit.device_line_edit import DeviceLineEdit
|
||||
from bec_lib.device import ReadoutPriority
|
||||
from bec_widgets.widgets.base_classes.device_input_base import BECDeviceFilter
|
||||
|
||||
class MyGui(QWidget):
|
||||
def __init__(self):
|
||||
@ -40,7 +46,7 @@ class MyGui(QWidget):
|
||||
self.setLayout(QVBoxLayout(self)) # Initialize the layout for the widget
|
||||
|
||||
# Create and add the DeviceLineEdit to the layout
|
||||
self.device_line_edit = DeviceLineEdit(device_filter="Motor")
|
||||
self.device_line_edit = DeviceLineEdit(device_filter=BECDeviceFilter.POSITIONER, readout_priority_filter=ReadoutPriority.BASELINE)
|
||||
self.layout().addWidget(self.device_line_edit)
|
||||
|
||||
# Example of how this custom GUI might be used:
|
||||
@ -56,7 +62,9 @@ Similarly, here is an example of creating a `DeviceComboBox` widget in code and
|
||||
|
||||
```python
|
||||
from qtpy.QtWidgets import QApplication, QVBoxLayout, QWidget
|
||||
from bec_widgets.widgets.device_combo_box import DeviceComboBox
|
||||
from bec_widgets.widgets.device_combobox.device_combobox import DeviceComboBox
|
||||
from bec_lib.device import ReadoutPriority
|
||||
from bec_widgets.widgets.base_classes.device_input_base import BECDeviceFilter
|
||||
|
||||
class MyGui(QWidget):
|
||||
def __init__(self):
|
||||
@ -64,8 +72,8 @@ class MyGui(QWidget):
|
||||
self.setLayout(QVBoxLayout(self)) # Initialize the layout for the widget
|
||||
|
||||
# Create and add the DeviceComboBox to the layout
|
||||
self.device_combo_box = DeviceComboBox(device_filter="Motor")
|
||||
self.layout().addWidget(self.device_combo_box)
|
||||
self.device_combobox = DeviceComboBox(device_filter=BECDeviceFilter.POSITIONER, readout_priority_filter=ReadoutPriority.BASELINE)
|
||||
self.layout().addWidget(self.device_combobox)
|
||||
|
||||
# Example of how this custom GUI might be used:
|
||||
app = QApplication([])
|
||||
@ -80,11 +88,24 @@ Both `DeviceLineEdit` and `DeviceComboBox` allow you to set a default device tha
|
||||
|
||||
```python
|
||||
# Set default device for DeviceLineEdit
|
||||
self.device_line_edit.set_default_device("motor1")
|
||||
self.device_line_edit.set_device("motor1")
|
||||
|
||||
# Set default device for DeviceComboBox
|
||||
self.device_combo_box.set_default_device("motor2")
|
||||
self.device_combo_box.set_device("motor2")
|
||||
|
||||
# Set the available devices to be displayed independent of the applied filters
|
||||
self.device_combo_box.set_available_devices(["motor1", "motor2", "motor3"])
|
||||
```
|
||||
````
|
||||
````{tab} BEC Designer
|
||||
Both widgets are also available as plugins for the BEC Designer. We have included Qt properties for both widgets, allowing customization of filtering and default device settings directly from the designer. In addition to the common signals and slots for `DeviceLineEdit` and `DeviceComboBox`, the following slots are available:
|
||||
- `set_device(str)` to set the default device
|
||||
- `update_devices()` to refresh the devices list
|
||||
|
||||
The following Qt properties are also included:
|
||||
```{figure} ./QProperties_DeviceInput.png
|
||||
```
|
||||
|
||||
````
|
||||
|
||||
````{tab} API - ComboBox
|
||||
|
114
docs/user/widgets/signal_input/signal_input.md
Normal file
114
docs/user/widgets/signal_input/signal_input.md
Normal file
@ -0,0 +1,114 @@
|
||||
(user.widgets.signal_input)=
|
||||
|
||||
# Signal Input Widgets
|
||||
|
||||
````{tab} Overview
|
||||
The `Signal Input Widgets` consist of two primary widgets: `SignalLineEdit` and `SignalComboBox`. Both widgets are designed to facilitate the selection of the available signals for a selected device within the current BEC session. These widgets allow users to filter, search, and select signals dynamically. The widgets can either be integrated into a GUI through direct code instantiation or by using `QtDesigner`.
|
||||
|
||||
## SignalLineEdit
|
||||
The `SignalLineEdit` widget provides a line edit interface with autocomplete functionality for the available of signals associated with the selected device. This widget is ideal for users who prefer to type in the signal name directly. If no device is selected, the autocomplete will be empty. In addition, the widget will display a red border around the line edit if the input signal is invalid.
|
||||
|
||||
## SignalComboBox
|
||||
The `SignalComboBox` widget offers a dropdown interface for choosing a signal from the available signals of a device. It will further categorise the signals according to its `kind`: `hinted`, `normal` and `config`. For more information about `kind`, please check the [ophyd documentation](https://nsls-ii.github.io/ophyd/signals.html#kind). This widget is ideal for users who prefer to select signals from a list.
|
||||
|
||||
## Key Features:
|
||||
- **Signal Filtering**: Both widgets allow users to filter devices by signal types(`kind`). No selected filter will show all signals.
|
||||
- **Real-Time Autocomplete (LineEdit)**: The `SignalLineEdit` widget supports real-time autocomplete, helping users find devices faster.
|
||||
- **Real-Time Input Validation (LineEdit)**: User input is validated in real-time with a red border around the `SignalLineEdit` indicating an invalid input.
|
||||
- **Dropdown Selection (SignalComboBox)**: The `SignalComboBox` widget displays the sorted signals of the device
|
||||
- **QtDesigner Integration**: Both widgets can be added as custom widgets in `QtDesigner` or instantiated directly in code.
|
||||
|
||||
````
|
||||
|
||||
````{tab} Examples
|
||||
|
||||
Both `SignalLineEdit` and `SignalComboBox` can be integrated within a GUI application through direct code instantiation or by using `QtDesigner`. Below are examples demonstrating how to create and use these widgets.
|
||||
|
||||
|
||||
## Example 1 - Creating a SignalLineEdit in Code
|
||||
|
||||
In this example, we demonstrate how to create a `SignalLineEdit` widget in code and customize its behavior.
|
||||
We will select `samx`, which is a motor in the BEC simulation device config, and filter the signals to `normal` and `hinted`.
|
||||
Note, not specifying signal_filter will include all signals.
|
||||
|
||||
```python
|
||||
from qtpy.QtWidgets import QApplication, QVBoxLayout, QWidget
|
||||
from bec_widgets.widgets.signal_line_edit.signal_line_edit import SignalLineEdit
|
||||
from bec_widgets.widgets.base_classes.device_signal_input_base import BECSignalFilter
|
||||
|
||||
class MyGui(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setLayout(QVBoxLayout(self)) # Initialize the layout for the widget
|
||||
|
||||
# Create and add the DeviceLineEdit to the layout
|
||||
self.signal_line_edit = SignalLineEdit(device="samx", signal_filter=[BECSignalFilter.NORMAL, BECSignalFilter.HINTED])
|
||||
self.layout().addWidget(self.signal_line_edit)
|
||||
|
||||
# Example of how this custom GUI might be used:
|
||||
app = QApplication([])
|
||||
my_gui = MyGui()
|
||||
my_gui.show()
|
||||
app.exec_()
|
||||
```
|
||||
|
||||
## Example 2 - Creating a DeviceComboBox in Code
|
||||
|
||||
Similarly, here is an example of creating a `DeviceComboBox` widget in code and customizing its behavior.
|
||||
|
||||
```python
|
||||
from qtpy.QtWidgets import QApplication, QVBoxLayout, QWidget
|
||||
from bec_widgets.widgets.signal_combobox.signal_combobox import SignalComboBox
|
||||
from bec_widgets.widgets.base_classes.device_signal_input_base import BECSignalFilter
|
||||
|
||||
class MyGui(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setLayout(QVBoxLayout(self)) # Initialize the layout for the widget
|
||||
|
||||
# Create and add the DeviceLineEdit to the layout
|
||||
self.signal_combobox = SignalComboBox(device="samx", signal_filter=[BECSignalFilter.NORMAL, BECSignalFilter.HINTED])
|
||||
self.layout().addWidget(self.signal_combobox)
|
||||
|
||||
# Example of how this custom GUI might be used:
|
||||
app = QApplication([])
|
||||
my_gui = MyGui()
|
||||
my_gui.show()
|
||||
app.exec_()
|
||||
```
|
||||
|
||||
## Example 3 - Setting Default Device
|
||||
|
||||
Both `SignalLineEdit` and `SignalComboBox` allow you to set a default device that will be selected when the widget is initialized.
|
||||
|
||||
```python
|
||||
# Set default device for DeviceLineEdit
|
||||
self.signal_line_edit.set_device("motor1")
|
||||
|
||||
# Set default device for DeviceComboBox
|
||||
self.signal_combobox.set_device("motor2")
|
||||
```
|
||||
````
|
||||
````{tab} BEC Designer
|
||||
Both widgets are also available as plugins for the BEC Designer. We have included Qt properties for both widgets, allowing customization of filtering and default device settings directly from the designer. In addition to the common signals and slots for `SignalLineEdit` and `SignalComboBox`, the following slots are available:
|
||||
- `set_device(str)` to set the default device
|
||||
- `set_signal(str)` to set the default signal
|
||||
- `update_signals_from_filters()` to refresh the devices list based on the current filters
|
||||
|
||||
The following Qt properties are also included:
|
||||
```{figure} ./signal_input_qproperties.png
|
||||
```
|
||||
|
||||
````
|
||||
|
||||
````{tab} API - ComboBox
|
||||
```{eval-rst}
|
||||
.. include:: /api_reference/_autosummary/bec_widgets.cli.client.SignalComboBox.rst
|
||||
```
|
||||
````
|
||||
|
||||
````{tab} API - LineEdit
|
||||
```{eval-rst}
|
||||
.. include:: /api_reference/_autosummary/bec_widgets.cli.client.SignalLineEdit.rst
|
||||
```
|
||||
````
|
BIN
docs/user/widgets/signal_input/signal_input_qproperties.png
Normal file
BIN
docs/user/widgets/signal_input/signal_input_qproperties.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 34 KiB |
@ -159,6 +159,14 @@ Various buttons which manage the control of the BEC Queue.
|
||||
Choose individual device from current session.
|
||||
```
|
||||
|
||||
```{grid-item-card} Signal Input Widgets
|
||||
:link: user.widgets.signal_input
|
||||
:link-type: ref
|
||||
:img-top: /assets/widget_screenshots/signal_inputs.png
|
||||
|
||||
Choose individual signals available for a selected device.
|
||||
```
|
||||
|
||||
```{grid-item-card} Text Box Widget
|
||||
:link: user.widgets.text_box
|
||||
:link-type: ref
|
||||
|
Reference in New Issue
Block a user