diff --git a/bec_widgets/examples/extreme/config.yaml b/bec_widgets/examples/extreme/config_example.yaml similarity index 64% rename from bec_widgets/examples/extreme/config.yaml rename to bec_widgets/examples/extreme/config_example.yaml index 4f804a56..845ae99b 100644 --- a/bec_widgets/examples/extreme/config.yaml +++ b/bec_widgets/examples/extreme/config_example.yaml @@ -7,6 +7,35 @@ plot_settings: plot_data: - plot_name: "BPM plot" + x: + label: 'Motor X' + signals: + - name: "samx" +# entry: "samx" + y: + label: 'BPM' + signals: + - name: "gauss_bpm" + entry: "gauss_bpm" + - name: "gauss_adc1" + entry: "gauss_adc1" + - name: "gauss_adc2" + entry: "gauss_adc2" + + - plot_name: "BPM plot 2" + x: + label: 'Motor X' + signals: + - name: "samx" + entry: "samx" + y: + label: 'BPM' + signals: + - name: "gauss_bpm" + entry: "gauss_bpm" + - name: "gauss_adc1" + entry: "gauss_adc1" + - plot_name: "BPM plot 3" x: label: 'Motor X' signals: @@ -19,7 +48,6 @@ plot_data: entry: "gauss_bpm" - name: "gauss_adc1" entry: "gauss_adc1" - - plot_name: "ADC plot" x: label: 'Motor Y' diff --git a/bec_widgets/examples/extreme/extreme.py b/bec_widgets/examples/extreme/extreme.py index 567136ea..a4aa53c9 100644 --- a/bec_widgets/examples/extreme/extreme.py +++ b/bec_widgets/examples/extreme/extreme.py @@ -9,6 +9,8 @@ from pyqtgraph.Qt import QtCore, uic from bec_lib.core import MessageEndpoints from bec_widgets.qt_utils import Crosshair, Colors +from pyqtgraph.Qt import QtWidgets +from pyqtgraph import ColorButton # TODO implement: @@ -72,6 +74,8 @@ class PlotApp(QWidget): self.grid_coordinates = None self.scanID = None + self.user_colors = {} # key: (plot_name, y_name, y_entry), value: color + # Initialize the UI self.init_ui(self.plot_settings["num_columns"]) self.spinBox_N_columns.setValue( @@ -198,8 +202,11 @@ class PlotApp(QWidget): y_entries = [y_entries] for y_entry in y_entries: - pen_curve = mkPen(color=color, width=2, style=QtCore.Qt.DashLine) - brush_curve = mkBrush(color=color) + user_color = self.user_colors.get((plot_name, y_name, y_entry), None) + color_to_use = user_color if user_color else color + + pen_curve = mkPen(color=color_to_use, width=2, style=QtCore.Qt.DashLine) + brush_curve = mkBrush(color=color_to_use) curve_data = pg.PlotDataItem( symbolSize=5, @@ -213,12 +220,57 @@ class PlotApp(QWidget): plot.addItem(curve_data) row_labels.append(f"{y_name} ({y_entry}) - {plot_name}") + # Create a ColorButton and set its color + color_btn = ColorButton() + color_btn.setColor(color_to_use) + color_btn.sigColorChanged.connect( + lambda btn=color_btn, plot=plot_name, yname=y_name, yentry=y_entry, curve=curve_data: self.change_curve_color( + btn, plot, yname, yentry, curve + ) + ) + + # Add the ColorButton as a QWidget to the table + color_widget = QtWidgets.QWidget() + layout = QtWidgets.QHBoxLayout() + layout.addWidget(color_btn) + layout.setContentsMargins(0, 0, 0, 0) + color_widget.setLayout(layout) + + row = len(row_labels) - 1 # The row index in the table + self.tableWidget_crosshair.setCellWidget(row, 2, color_widget) + self.curves_data[plot_name] = curve_list self.tableWidget_crosshair.setRowCount(len(row_labels)) self.tableWidget_crosshair.setVerticalHeaderLabels(row_labels) self.hook_crosshair() + # def change_curve_color(self, btn, curve): + # """Change the color of a curve.""" + # color = btn.color() + # pen_curve = mkPen(color=color, width=2, style=QtCore.Qt.DashLine) + # brush_curve = mkBrush(color=color) + # curve.setPen(pen_curve) + # curve.setSymbolBrush(brush_curve) + + def change_curve_color(self, btn, plot_name, y_name, y_entry, curve): + """ + Change the color of a curve and update the corresponding ColorButton. + + Args: + btn (ColorButton): The ColorButton that was clicked. + plot_name (str): The name of the plot where the curve belongs. + y_name (str): The name of the y signal. + y_entry (str): The entry of the y signal. + curve (PlotDataItem): The curve to be changed. + """ + color = btn.color() + pen_curve = mkPen(color=color, width=2, style=QtCore.Qt.DashLine) + brush_curve = mkBrush(color=color) + curve.setPen(pen_curve) + curve.setSymbolBrush(brush_curve) + self.user_colors[(plot_name, y_name, y_entry)] = color + def hook_crosshair(self): """Attach crosshairs to each plot and connect them to the update_table method.""" self.crosshairs = {} @@ -295,6 +347,7 @@ class PlotApp(QWidget): msg (dict): Message received with scan data. metadata (dict): Metadata of the scan. """ + current_scanID = msg.get("scanID", None) if current_scanID is None: return @@ -425,7 +478,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description="Plotting App") parser.add_argument( - "--config", "-c", help="Path to the .yaml configuration file", default="config.yaml" + "--config", "-c", help="Path to the .yaml configuration file", default="config_example.yaml" ) args = parser.parse_args() diff --git a/bec_widgets/examples/extreme/extreme.ui b/bec_widgets/examples/extreme/extreme.ui index e22291c4..6d0a1fdb 100644 --- a/bec_widgets/examples/extreme/extreme.ui +++ b/bec_widgets/examples/extreme/extreme.ui @@ -53,6 +53,11 @@ Clicked + + + Color + +