diff --git a/bec_widgets/examples/jupyter_console/jupyter_console_window.py b/bec_widgets/examples/jupyter_console/jupyter_console_window.py index ce27d21a..5ea0ad5c 100644 --- a/bec_widgets/examples/jupyter_console/jupyter_console_window.py +++ b/bec_widgets/examples/jupyter_console/jupyter_console_window.py @@ -2,7 +2,7 @@ import os import numpy as np import pyqtgraph as pg -from pyqtgraph.Qt import QtWidgets, uic +from pyqtgraph.Qt import QtWidgets from qtconsole.inprocess import QtInProcessKernelManager from qtconsole.rich_jupyter_widget import RichJupyterWidget from qtpy.QtCore import QSize @@ -10,7 +10,7 @@ from qtpy.QtGui import QIcon from qtpy.QtWidgets import QApplication, QVBoxLayout, QWidget from bec_widgets.cli.rpc_register import RPCRegister -from bec_widgets.utils import BECDispatcher +from bec_widgets.utils import BECDispatcher, UILoader from bec_widgets.widgets import BECFigure from bec_widgets.widgets.dock.dock_area import BECDockArea from bec_widgets.widgets.spiral_progress_bar.spiral_progress_bar import SpiralProgressBar @@ -40,11 +40,11 @@ class JupyterConsoleWindow(QWidget): # pragma: no cover: super().__init__(parent) current_path = os.path.dirname(__file__) - uic.loadUi(os.path.join(current_path, "jupyter_console_window.ui"), self) + self.ui = UILoader().load_ui(os.path.join(current_path, "jupyter_console_window.ui"), self) self._init_ui() - self.splitter.setSizes([200, 100]) + self.ui.splitter.setSizes([200, 100]) self.safe_close = False # self.figure.clean_signal.connect(self.confirm_close) @@ -75,11 +75,11 @@ class JupyterConsoleWindow(QWidget): # pragma: no cover: def _init_ui(self): # Plotting window - self.glw_1_layout = QVBoxLayout(self.glw) # Create a new QVBoxLayout + self.glw_1_layout = QVBoxLayout(self.ui.glw) # Create a new QVBoxLayout self.figure = BECFigure(parent=self, gui_id="remote") # Create a new BECDeviceMonitor self.glw_1_layout.addWidget(self.figure) # Add BECDeviceMonitor to the layout - self.dock_layout = QVBoxLayout(self.dock_placeholder) + self.dock_layout = QVBoxLayout(self.ui.dock_placeholder) self.dock = BECDockArea(gui_id="remote") self.dock_layout.addWidget(self.dock) @@ -89,7 +89,7 @@ class JupyterConsoleWindow(QWidget): # pragma: no cover: # init dock for testing self._init_dock() - self.console_layout = QVBoxLayout(self.widget_console) + self.console_layout = QVBoxLayout(self.ui.widget_console) self.console = JupyterConsoleWidget() self.console_layout.addWidget(self.console) self.console.set_default_style("linux") diff --git a/bec_widgets/examples/modular_app/___init__.py b/bec_widgets/examples/modular_app/___init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/bec_widgets/examples/modular_app/modular.ui b/bec_widgets/examples/modular_app/modular.ui deleted file mode 100644 index ca4994c1..00000000 --- a/bec_widgets/examples/modular_app/modular.ui +++ /dev/null @@ -1,92 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 1433 - 689 - - - - MainWindow - - - - - - - Plot Config 2 - - - - - - - - - - Setting Plot 2 - - - - - - - - - - Plot Scan Types = True - - - - - - - Setting Plot 1 - - - - - - - Plot Config 1 - - - - - - - Setting Plot 3 - - - - - - - - - - - - 0 - 0 - 1433 - 37 - - - - - - - - BECMonitor - QGraphicsView -
bec_widgets.widgets.h
-
-
- - -
diff --git a/bec_widgets/examples/modular_app/modular_app.py b/bec_widgets/examples/modular_app/modular_app.py deleted file mode 100644 index 42b013b4..00000000 --- a/bec_widgets/examples/modular_app/modular_app.py +++ /dev/null @@ -1,197 +0,0 @@ -import os - -from qtpy import uic -from qtpy.QtWidgets import QApplication, QMainWindow - -from bec_widgets.utils.bec_dispatcher import BECDispatcher -from bec_widgets.widgets import BECMonitor - -# some default configs for demonstration purposes -CONFIG_SIMPLE = { - "plot_settings": { - "background_color": "black", - "num_columns": 2, - "colormap": "plasma", - "scan_types": False, - }, - "plot_data": [ - { - "plot_name": "BPM4i plots vs samx", - "x_label": "Motor X", - "y_label": "bpm4i", - "sources": [ - { - "type": "scan_segment", - "signals": { - "x": [{"name": "samx"}], - "y": [{"name": "bpm4i", "entry": "bpm4i"}], - }, - }, - # { - # "type": "history", - # "signals": { - # "x": [{"name": "samx"}], - # "y": [{"name": "bpm4i", "entry": "bpm4i"}], - # }, - # }, - # { - # "type": "dap", - # 'worker':'some_worker', - # "signals": { - # "x": [{"name": "samx"}], - # "y": [{"name": "bpm4i", "entry": "bpm4i"}], - # }, - # }, - ], - }, - { - "plot_name": "Gauss plots vs samx", - "x_label": "Motor X", - "y_label": "Gauss", - "sources": [ - { - "type": "scan_segment", - "signals": { - "x": [{"name": "samx", "entry": "samx"}], - "y": [{"name": "gauss_bpm"}, {"name": "gauss_adc1"}], - }, - } - ], - }, - ], -} - - -CONFIG_SCAN_MODE = { - "plot_settings": { - "background_color": "white", - "num_columns": 3, - "colormap": "plasma", - "scan_types": True, - }, - "plot_data": { - "grid_scan": [ - { - "plot_name": "Grid plot 1", - "x_label": "Motor X", - "y_label": "BPM", - "sources": [ - { - "type": "scan_segment", - "signals": { - "x": [{"name": "samx", "entry": "samx"}], - "y": [{"name": "gauss_bpm"}], - }, - } - ], - }, - { - "plot_name": "Grid plot 2", - "x_label": "Motor X", - "y_label": "BPM", - "sources": [ - { - "type": "scan_segment", - "signals": { - "x": [{"name": "samx", "entry": "samx"}], - "y": [{"name": "gauss_adc1"}], - }, - } - ], - }, - { - "plot_name": "Grid plot 3", - "x_label": "Motor X", - "y_label": "BPM", - "sources": [ - { - "type": "scan_segment", - "signals": {"x": [{"name": "samy"}], "y": [{"name": "gauss_adc2"}]}, - } - ], - }, - { - "plot_name": "Grid plot 4", - "x_label": "Motor X", - "y_label": "BPM", - "sources": [ - { - "type": "scan_segment", - "signals": { - "x": [{"name": "samy", "entry": "samy"}], - "y": [{"name": "gauss_adc3"}], - }, - } - ], - }, - ], - "line_scan": [ - { - "plot_name": "BPM plots vs samx", - "x_label": "Motor X", - "y_label": "Gauss", - "sources": [ - { - "type": "scan_segment", - "signals": { - "x": [{"name": "samx", "entry": "samx"}], - "y": [{"name": "bpm4i"}], - }, - } - ], - }, - { - "plot_name": "Gauss plots vs samx", - "x_label": "Motor X", - "y_label": "Gauss", - "sources": [ - { - "type": "scan_segment", - "signals": { - "x": [{"name": "samx", "entry": "samx"}], - "y": [{"name": "gauss_bpm"}, {"name": "gauss_adc1"}], - }, - } - ], - }, - ], - }, -} - - -class ModularApp(QMainWindow): - def __init__(self, client=None, parent=None): - super(ModularApp, self).__init__(parent) - - # Client and device manager from BEC - self.client = BECDispatcher().client if client is None else client - - # Loading UI - current_path = os.path.dirname(__file__) - uic.loadUi(os.path.join(current_path, "modular.ui"), self) - - self._init_plots() - - def _init_plots(self): - """Initialize plots and connect the buttons to the config dialogs""" - plots = [self.plot_1, self.plot_2, self.plot_3] - configs = [CONFIG_SIMPLE, CONFIG_SCAN_MODE, CONFIG_SCAN_MODE] - buttons = [self.pushButton_setting_1, self.pushButton_setting_2, self.pushButton_setting_3] - - # hook plots, configs and buttons together - for plot, config, button in zip(plots, configs, buttons): - plot.on_config_update(config) - button.clicked.connect(plot.show_config_dialog) - - -if __name__ == "__main__": - # BECclient global variables - client = BECDispatcher().client - client.start() - - app = QApplication([]) - modularApp = ModularApp(client=client) - - window = modularApp - window.show() - app.exec() diff --git a/bec_widgets/examples/motor_movement/motor_control_compilations.py b/bec_widgets/examples/motor_movement/motor_control_compilations.py index d715e02b..21cb8a94 100644 --- a/bec_widgets/examples/motor_movement/motor_control_compilations.py +++ b/bec_widgets/examples/motor_movement/motor_control_compilations.py @@ -151,7 +151,7 @@ class MotorControlPanel(QWidget): self.selection_widget.selected_motors_signal.connect(self.absolute_widget.change_motors) # Set the window to a fixed size based on its contents - self.layout().setSizeConstraint(layout.SetFixedSize) + # self.layout().setSizeConstraint(layout.SetFixedSize) class MotorControlPanelAbsolute(QWidget): @@ -178,9 +178,6 @@ class MotorControlPanelAbsolute(QWidget): # Connecting signals and slots self.selection_widget.selected_motors_signal.connect(self.absolute_widget.change_motors) - # Set the window to a fixed size based on its contents - self.layout().setSizeConstraint(layout.SetFixedSize) - class MotorControlPanelRelative(QWidget): def __init__(self, parent=None, client=None, config=None): @@ -206,9 +203,6 @@ class MotorControlPanelRelative(QWidget): # Connecting signals and slots self.selection_widget.selected_motors_signal.connect(self.relative_widget.change_motors) - # Set the window to a fixed size based on its contents - self.layout().setSizeConstraint(layout.SetFixedSize) - if __name__ == "__main__": # pragma: no cover import argparse diff --git a/bec_widgets/examples/stream_plot/line_plot.ui b/bec_widgets/examples/stream_plot/line_plot.ui index 8f4c0731..b403f8c0 100644 --- a/bec_widgets/examples/stream_plot/line_plot.ui +++ b/bec_widgets/examples/stream_plot/line_plot.ui @@ -29,10 +29,10 @@ Qt::Vertical - - + + - + @@ -143,13 +143,6 @@ - - - GraphicsLayoutWidget - QGraphicsView -
pyqtgraph.h
-
-
diff --git a/bec_widgets/examples/stream_plot/stream_plot.py b/bec_widgets/examples/stream_plot/stream_plot.py index 4bb79179..145d7a6d 100644 --- a/bec_widgets/examples/stream_plot/stream_plot.py +++ b/bec_widgets/examples/stream_plot/stream_plot.py @@ -9,18 +9,17 @@ from bec_lib import messages from bec_lib.endpoints import MessageEndpoints from bec_lib.redis_connector import RedisConnector from pyqtgraph import mkBrush, mkPen -from pyqtgraph.Qt import QtCore, QtWidgets, uic -from pyqtgraph.Qt.QtCore import pyqtSignal -from qtpy.QtCore import Slot as pyqtSlot -from qtpy.QtWidgets import QTableWidgetItem +from pyqtgraph.Qt import QtCore, QtWidgets +from qtpy.QtCore import Signal, Slot +from qtpy.QtWidgets import QTableWidgetItem, QVBoxLayout -from bec_widgets.utils import Colors, Crosshair +from bec_widgets.utils import Colors, Crosshair, UILoader from bec_widgets.utils.bec_dispatcher import BECDispatcher class StreamPlot(QtWidgets.QWidget): - update_signal = pyqtSignal() - roi_signal = pyqtSignal(tuple) + update_signal = Signal() + roi_signal = Signal(tuple) def __init__(self, name="", y_value_list=["gauss_bpm"], client=None, parent=None) -> None: """ @@ -39,7 +38,7 @@ class StreamPlot(QtWidgets.QWidget): pg.setConfigOption("background", "w") pg.setConfigOption("foreground", "k") current_path = os.path.dirname(__file__) - uic.loadUi(os.path.join(current_path, "line_plot.ui"), self) + self.ui = UILoader().load_ui(os.path.join(current_path, "line_plot.ui"), self) self._idle_time = 100 self.connector = RedisConnector(["localhost:6379"]) @@ -82,6 +81,9 @@ class StreamPlot(QtWidgets.QWidget): # LabelItem for ROI self.label_plot = pg.LabelItem(justify="center") + self.glw_plot_layout = QVBoxLayout(self.ui.glw_plot_placeholder) + self.glw_plot = pg.GraphicsLayoutWidget() + self.glw_plot_layout.addWidget(self.glw_plot) self.glw_plot.addItem(self.label_plot) self.label_plot.setText("ROI region") @@ -112,6 +114,9 @@ class StreamPlot(QtWidgets.QWidget): # Label for coordinates moved self.label_image_moved = pg.LabelItem(justify="center") + self.glw_image_layout = QVBoxLayout(self.ui.glw_image_placeholder) + self.glw_image = pg.GraphicsLayoutWidget() + self.glw_plot_layout.addWidget(self.glw_image) self.glw_image.addItem(self.label_image_moved) self.label_image_moved.setText("Actual coordinates (X, Y)") @@ -221,10 +226,10 @@ class StreamPlot(QtWidgets.QWidget): def init_table(self): # Init number of rows in table according to n of devices - self.cursor_table.setRowCount(len(self.y_value_list)) + self.ui.cursor_table.setRowCount(len(self.y_value_list)) # self.table.setHorizontalHeaderLabels(["(X, Y) - Moved", "(X, Y) - Clicked"]) #TODO can be dynamic - self.cursor_table.setVerticalHeaderLabels(self.y_value_list) - self.cursor_table.resizeColumnsToContents() + self.ui.cursor_table.setVerticalHeaderLabels(self.y_value_list) + self.ui.cursor_table.resizeColumnsToContents() def update_table(self, table_widget, x, y_values): for i, y in enumerate(y_values): @@ -287,13 +292,13 @@ class StreamPlot(QtWidgets.QWidget): self.update_signal.emit() - @pyqtSlot(dict, dict) + @Slot(dict, dict) def on_dap_update(self, data: dict, metadata: dict): flipped_data = self.flip_even_rows(data["data"]["z"]) self.img.setImage(flipped_data) - @pyqtSlot(dict, dict) + @Slot(dict, dict) def new_proj(self, content: dict, _metadata: dict): proj_nr = content["signals"]["proj_nr"] endpoint = f"px_stream/projection_{proj_nr}/metadata"