From 2c6719cf390e6638cadbc814eb0c085bb45c3c6c Mon Sep 17 00:00:00 2001 From: wyzula-jan <133381102+wyzula-jan@users.noreply.github.com> Date: Fri, 1 Sep 2023 10:39:09 +0200 Subject: [PATCH 1/3] feat: colorbutton next to each curve in the table to be able to set up colors --- bec_widgets/examples/extreme/extreme.py | 25 +++++++++++++++++++++++++ bec_widgets/examples/extreme/extreme.ui | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/bec_widgets/examples/extreme/extreme.py b/bec_widgets/examples/extreme/extreme.py index 567136ea..c991ea7c 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: @@ -213,12 +215,35 @@ 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) + color_btn.sigColorChanged.connect( + lambda btn=color_btn, curve=curve_data: self.change_curve_color(btn, 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) + curve.setPen(pen_curve) + def hook_crosshair(self): """Attach crosshairs to each plot and connect them to the update_table method.""" self.crosshairs = {} 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 + + From 6d2e1c9d08595a45f502287c6490905e8df3db10 Mon Sep 17 00:00:00 2001 From: wyzula-jan <133381102+wyzula-jan@users.noreply.github.com> Date: Fri, 1 Sep 2023 10:40:07 +0200 Subject: [PATCH 2/3] fix: colorbutton change now symbols as well --- bec_widgets/examples/extreme/extreme.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bec_widgets/examples/extreme/extreme.py b/bec_widgets/examples/extreme/extreme.py index c991ea7c..97d4f7df 100644 --- a/bec_widgets/examples/extreme/extreme.py +++ b/bec_widgets/examples/extreme/extreme.py @@ -242,7 +242,9 @@ class PlotApp(QWidget): """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 hook_crosshair(self): """Attach crosshairs to each plot and connect them to the update_table method.""" From 8e7885f36dd2812e3285c4d2d101212055644c7b Mon Sep 17 00:00:00 2001 From: wyzula-jan <133381102+wyzula-jan@users.noreply.github.com> Date: Mon, 4 Sep 2023 10:54:59 +0200 Subject: [PATCH 3/3] fix: user selected colors are preserved with the new scan --- .../{config.yaml => config_example.yaml} | 30 +++++++++++++- bec_widgets/examples/extreme/extreme.py | 40 +++++++++++++++---- 2 files changed, 62 insertions(+), 8 deletions(-) rename bec_widgets/examples/extreme/{config.yaml => config_example.yaml} (64%) 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 97d4f7df..a4aa53c9 100644 --- a/bec_widgets/examples/extreme/extreme.py +++ b/bec_widgets/examples/extreme/extreme.py @@ -74,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( @@ -200,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, @@ -217,9 +222,11 @@ class PlotApp(QWidget): # Create a ColorButton and set its color color_btn = ColorButton() - color_btn.setColor(color) + color_btn.setColor(color_to_use) color_btn.sigColorChanged.connect( - lambda btn=color_btn, curve=curve_data: self.change_curve_color(btn, curve) + 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 @@ -238,13 +245,31 @@ class PlotApp(QWidget): self.tableWidget_crosshair.setVerticalHeaderLabels(row_labels) self.hook_crosshair() - def change_curve_color(self, btn, curve): - """Change the color of a curve.""" + # 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.""" @@ -322,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 @@ -452,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()