mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 19:21:50 +02:00
refactor(motor_map_widget): moved to top level
This commit is contained in:
@ -18,6 +18,7 @@ class Widgets(str, enum.Enum):
|
||||
BECDock = "BECDock"
|
||||
BECDockArea = "BECDockArea"
|
||||
BECFigure = "BECFigure"
|
||||
BECMotorMapWidget = "BECMotorMapWidget"
|
||||
RingProgressBar = "RingProgressBar"
|
||||
ScanControl = "ScanControl"
|
||||
TextBox = "TextBox"
|
||||
@ -1192,6 +1193,7 @@ class BECMotorMap(RPCBase):
|
||||
def get_data(self) -> "dict":
|
||||
"""
|
||||
Get the data of the motor map.
|
||||
|
||||
Returns:
|
||||
dict: Data of the motor map.
|
||||
"""
|
||||
@ -1213,12 +1215,12 @@ class BECMotorMapWidget(RPCBase):
|
||||
@rpc_call
|
||||
def change_motors(
|
||||
self,
|
||||
motor_x: str,
|
||||
motor_y: str,
|
||||
motor_x_entry: str = None,
|
||||
motor_y_entry: str = None,
|
||||
validate_bec: bool = True,
|
||||
) -> None:
|
||||
motor_x: "str",
|
||||
motor_y: "str",
|
||||
motor_x_entry: "str" = None,
|
||||
motor_y_entry: "str" = None,
|
||||
validate_bec: "bool" = True,
|
||||
) -> "None":
|
||||
"""
|
||||
Change the active motors for the plot.
|
||||
|
||||
@ -1230,6 +1232,66 @@ class BECMotorMapWidget(RPCBase):
|
||||
validate_bec(bool, optional): If True, validate the signal with BEC. Defaults to True.
|
||||
"""
|
||||
|
||||
@rpc_call
|
||||
def set_max_points(self, max_points: "int") -> "None":
|
||||
"""
|
||||
Set the maximum number of points to display on the motor map.
|
||||
|
||||
Args:
|
||||
max_points(int): Maximum number of points to display.
|
||||
"""
|
||||
|
||||
@rpc_call
|
||||
def set_precision(self, precision: "int") -> "None":
|
||||
"""
|
||||
Set the precision of the motor map.
|
||||
|
||||
Args:
|
||||
precision(int): Precision to set.
|
||||
"""
|
||||
|
||||
@rpc_call
|
||||
def set_num_dim_points(self, num_dim_points: "int") -> "None":
|
||||
"""
|
||||
Set the number of points to display on the motor map.
|
||||
|
||||
Args:
|
||||
num_dim_points(int): Number of points to display.
|
||||
"""
|
||||
|
||||
@rpc_call
|
||||
def set_background_value(self, background_value: "int") -> "None":
|
||||
"""
|
||||
Set the background value of the motor map.
|
||||
|
||||
Args:
|
||||
background_value(int): Background value of the motor map.
|
||||
"""
|
||||
|
||||
@rpc_call
|
||||
def set_scatter_size(self, scatter_size: "int") -> "None":
|
||||
"""
|
||||
Set the scatter size of the motor map.
|
||||
|
||||
Args:
|
||||
scatter_size(int): Scatter size of the motor map.
|
||||
"""
|
||||
|
||||
@rpc_call
|
||||
def get_data(self) -> "dict":
|
||||
"""
|
||||
Get the data of the motor map.
|
||||
|
||||
Returns:
|
||||
dict: Data of the motor map.
|
||||
"""
|
||||
|
||||
@rpc_call
|
||||
def reset_history(self) -> "None":
|
||||
"""
|
||||
Reset the history of the motor map.
|
||||
"""
|
||||
|
||||
|
||||
class BECPlotBase(RPCBase):
|
||||
@property
|
||||
|
@ -10,7 +10,7 @@ from pydantic import Field, ValidationError, field_validator
|
||||
from pydantic_core import PydanticCustomError
|
||||
from qtpy import QtCore, QtGui
|
||||
from qtpy.QtCore import Signal as pyqtSignal
|
||||
from qtpy.QtCore import Slot as pyqtSlot
|
||||
from qtpy.QtCore import Slot
|
||||
from qtpy.QtWidgets import QWidget
|
||||
|
||||
from bec_widgets.utils import Colors, EntryValidator
|
||||
@ -121,7 +121,7 @@ class BECMotorMap(BECPlotBase):
|
||||
motor_y_entry=self.config.signals.y.entry,
|
||||
)
|
||||
|
||||
@pyqtSlot(str, str, str, str, bool)
|
||||
@Slot(str, str, str, str, bool)
|
||||
def change_motors(
|
||||
self,
|
||||
motor_x: str,
|
||||
@ -165,6 +165,7 @@ class BECMotorMap(BECPlotBase):
|
||||
def get_data(self) -> dict:
|
||||
"""
|
||||
Get the data of the motor map.
|
||||
|
||||
Returns:
|
||||
dict: Data of the motor map.
|
||||
"""
|
||||
@ -179,7 +180,7 @@ class BECMotorMap(BECPlotBase):
|
||||
self.database_buffer["y"] = [self.database_buffer["y"][-1]]
|
||||
self.update_signal.emit()
|
||||
|
||||
def set_color(self, color: [str | tuple]):
|
||||
def set_color(self, color: str | tuple):
|
||||
"""
|
||||
Set color of the motor trace.
|
||||
|
||||
@ -437,6 +438,7 @@ class BECMotorMap(BECPlotBase):
|
||||
print(f"The device '{motor}' does not have defined limits.")
|
||||
return None
|
||||
|
||||
@Slot()
|
||||
def _update_plot(self):
|
||||
"""Update the motor map plot."""
|
||||
# If the number of points exceeds max_points, delete the oldest points
|
||||
@ -486,7 +488,7 @@ class BECMotorMap(BECPlotBase):
|
||||
f"Motor position: ({round(float(current_x),precision)}, {round(float(current_y),precision)})"
|
||||
)
|
||||
|
||||
@pyqtSlot(dict)
|
||||
@Slot(dict)
|
||||
def on_device_readback(self, msg: dict) -> None:
|
||||
"""
|
||||
Update the motor map plot with the new motor position.
|
||||
|
0
bec_widgets/widgets/motor_map/__init__.py
Normal file
0
bec_widgets/widgets/motor_map/__init__.py
Normal file
Before Width: | Height: | Size: 313 B After Width: | Height: | Size: 313 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
43
bec_widgets/widgets/motor_map/motor_map_toolbar.py
Normal file
43
bec_widgets/widgets/motor_map/motor_map_toolbar.py
Normal file
@ -0,0 +1,43 @@
|
||||
import os
|
||||
|
||||
from qtpy.QtCore import QSize
|
||||
from qtpy.QtGui import QAction, QIcon
|
||||
from qtpy.QtWidgets import QHBoxLayout, QLabel, QWidget
|
||||
|
||||
from bec_widgets.widgets.device_inputs import DeviceComboBox
|
||||
from bec_widgets.widgets.toolbar.toolbar import ToolBarAction
|
||||
|
||||
|
||||
class SettingsAction(ToolBarAction):
|
||||
def add_to_toolbar(self, toolbar, target):
|
||||
current_path = os.path.dirname(__file__)
|
||||
icon = QIcon()
|
||||
icon.addFile(os.path.join(current_path, "assets", "settings.svg"), size=QSize(20, 20))
|
||||
action = QAction(icon, "Config", target)
|
||||
action.triggered.connect(lambda: print(target.config_dict))
|
||||
toolbar.addAction(action)
|
||||
|
||||
|
||||
class DeviceSelectionAction(ToolBarAction):
|
||||
def __init__(self, label: str):
|
||||
self.label = label
|
||||
self.device_combobox = DeviceComboBox(device_filter="Positioner")
|
||||
|
||||
def add_to_toolbar(self, toolbar, target):
|
||||
widget = QWidget()
|
||||
layout = QHBoxLayout(widget)
|
||||
|
||||
label = QLabel(f"{self.label}")
|
||||
|
||||
layout.addWidget(label)
|
||||
layout.addWidget(self.device_combobox)
|
||||
toolbar.addWidget(widget)
|
||||
|
||||
|
||||
class ConnectAction(ToolBarAction):
|
||||
def add_to_toolbar(self, toolbar, target):
|
||||
current_path = os.path.dirname(__file__)
|
||||
icon = QIcon()
|
||||
icon.addFile(os.path.join(current_path, "assets", "connection.svg"), size=QSize(20, 20))
|
||||
self.action = QAction(icon, "Connect Motors", target)
|
||||
toolbar.addAction(self.action)
|
@ -1,54 +1,29 @@
|
||||
import os
|
||||
from __future__ import annotations
|
||||
|
||||
from qtpy.QtCore import QSize, Slot
|
||||
from qtpy.QtGui import QAction, QIcon
|
||||
from qtpy.QtWidgets import QHBoxLayout, QLabel, QVBoxLayout, QWidget
|
||||
from qtpy.QtWidgets import QVBoxLayout, QWidget
|
||||
|
||||
from bec_widgets.utils import BECConnector
|
||||
from bec_widgets.widgets.device_inputs import DeviceComboBox
|
||||
from bec_widgets.widgets.figure import BECFigure
|
||||
from bec_widgets.widgets.figure.plots.motor_map.motor_map import MotorMapConfig
|
||||
from bec_widgets.widgets.motor_map.motor_map_toolbar import (
|
||||
ConnectAction,
|
||||
DeviceSelectionAction,
|
||||
SettingsAction,
|
||||
)
|
||||
from bec_widgets.widgets.toolbar import ModularToolBar
|
||||
from bec_widgets.widgets.toolbar.toolbar import ToolBarAction
|
||||
|
||||
|
||||
class SettingsAction(ToolBarAction):
|
||||
def add_to_toolbar(self, toolbar, target):
|
||||
current_path = os.path.dirname(__file__)
|
||||
icon = QIcon()
|
||||
icon.addFile(os.path.join(current_path, "assets", "settings.svg"), size=QSize(20, 20))
|
||||
action = QAction(icon, "Config", target)
|
||||
action.triggered.connect(lambda: print(target.config_dict))
|
||||
toolbar.addAction(action)
|
||||
|
||||
|
||||
class DeviceSelectionAction(ToolBarAction):
|
||||
def __init__(self, label: str):
|
||||
self.label = label
|
||||
self.device_combobox = DeviceComboBox(device_filter="Positioner")
|
||||
|
||||
def add_to_toolbar(self, toolbar, target):
|
||||
widget = QWidget()
|
||||
layout = QHBoxLayout(widget)
|
||||
|
||||
label = QLabel(f"{self.label}")
|
||||
|
||||
layout.addWidget(label)
|
||||
layout.addWidget(self.device_combobox)
|
||||
toolbar.addWidget(widget)
|
||||
|
||||
|
||||
class ConnectAction(ToolBarAction):
|
||||
def add_to_toolbar(self, toolbar, target):
|
||||
current_path = os.path.dirname(__file__)
|
||||
icon = QIcon()
|
||||
icon.addFile(os.path.join(current_path, "assets", "connection.svg"), size=QSize(20, 20))
|
||||
self.action = QAction(icon, "Connect Motors", target)
|
||||
toolbar.addAction(self.action)
|
||||
|
||||
|
||||
class BECMotorMapWidget(BECConnector, QWidget):
|
||||
USER_ACCESS = ["change_motors"]
|
||||
USER_ACCESS = [
|
||||
"change_motors",
|
||||
"set_max_points",
|
||||
"set_precision",
|
||||
"set_num_dim_points",
|
||||
"set_background_value",
|
||||
"set_scatter_size",
|
||||
"get_data",
|
||||
"reset_history",
|
||||
]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -98,6 +73,10 @@ class BECMotorMapWidget(BECConnector, QWidget):
|
||||
motor_y = self.toolbar.widgets["motor_y"].device_combobox.currentText()
|
||||
self.change_motors(motor_x, motor_y, None, None, True)
|
||||
|
||||
###################################
|
||||
# User Access Methods from MotorMap
|
||||
###################################
|
||||
|
||||
def change_motors(
|
||||
self,
|
||||
motor_x: str,
|
||||
@ -118,8 +97,74 @@ class BECMotorMapWidget(BECConnector, QWidget):
|
||||
"""
|
||||
self.map.change_motors(motor_x, motor_y, motor_x_entry, motor_y_entry, validate_bec)
|
||||
|
||||
def set(self, **kwargs):
|
||||
self.map.set(**kwargs)
|
||||
def get_data(self) -> dict:
|
||||
"""
|
||||
Get the data of the motor map.
|
||||
|
||||
Returns:
|
||||
dict: Data of the motor map.
|
||||
"""
|
||||
return self.map.get_data()
|
||||
|
||||
def reset_history(self) -> None:
|
||||
"""
|
||||
Reset the history of the motor map.
|
||||
"""
|
||||
self.map.reset_history()
|
||||
|
||||
def set_color(self, color: str | tuple):
|
||||
"""
|
||||
Set the color of the motor map.
|
||||
|
||||
Args:
|
||||
color(str, tuple): Color to set.
|
||||
"""
|
||||
self.map.set_color(color)
|
||||
|
||||
def set_max_points(self, max_points: int) -> None:
|
||||
"""
|
||||
Set the maximum number of points to display on the motor map.
|
||||
|
||||
Args:
|
||||
max_points(int): Maximum number of points to display.
|
||||
"""
|
||||
self.map.set_max_points(max_points)
|
||||
|
||||
def set_precision(self, precision: int) -> None:
|
||||
"""
|
||||
Set the precision of the motor map.
|
||||
|
||||
Args:
|
||||
precision(int): Precision to set.
|
||||
"""
|
||||
self.map.set_precision(precision)
|
||||
|
||||
def set_num_dim_points(self, num_dim_points: int) -> None:
|
||||
"""
|
||||
Set the number of points to display on the motor map.
|
||||
|
||||
Args:
|
||||
num_dim_points(int): Number of points to display.
|
||||
"""
|
||||
self.map.set_num_dim_points(num_dim_points)
|
||||
|
||||
def set_background_value(self, background_value: int) -> None:
|
||||
"""
|
||||
Set the background value of the motor map.
|
||||
|
||||
Args:
|
||||
background_value(int): Background value of the motor map.
|
||||
"""
|
||||
self.map.set_background_value(background_value)
|
||||
|
||||
def set_scatter_size(self, scatter_size: int) -> None:
|
||||
"""
|
||||
Set the scatter size of the motor map.
|
||||
|
||||
Args:
|
||||
scatter_size(int): Scatter size of the motor map.
|
||||
"""
|
||||
self.map.set_scatter_size(scatter_size)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
Reference in New Issue
Block a user