From 65bfccce8fce158150652fead769721de805d99e Mon Sep 17 00:00:00 2001
From: wyzula-jan <133381102+wyzula-jan@users.noreply.github.com>
Date: Wed, 30 Aug 2023 15:22:32 +0200
Subject: [PATCH] feat: number of columns can be dynamically changed
---
bec_widgets/examples/extreme/config.yaml | 5 +-
bec_widgets/examples/extreme/extreme.py | 37 +++++++++---
bec_widgets/examples/extreme/extreme.ui | 71 ++++++++++++++++++------
3 files changed, 88 insertions(+), 25 deletions(-)
diff --git a/bec_widgets/examples/extreme/config.yaml b/bec_widgets/examples/extreme/config.yaml
index f59651f8..e5274faa 100644
--- a/bec_widgets/examples/extreme/config.yaml
+++ b/bec_widgets/examples/extreme/config.yaml
@@ -1,3 +1,6 @@
+xy_pairs_1: [["samx", ["gauss_bpm", "gauss_adc1"]]]
xy_pairs: [["samx", ["gauss_bpm", "gauss_adc1"]],
["samx", ["gauss_adc1", "gauss_adc2"]],
- ["samx", ["gauss_adc2"]]]
+ ["samx", ["gauss_adc2"]],
+ ["samx", ["gauss_bpm", "gauss_adc2"]],
+ ["samx", ["gauss_bpm"]]]
diff --git a/bec_widgets/examples/extreme/extreme.py b/bec_widgets/examples/extreme/extreme.py
index 747fdd4e..d09dd506 100644
--- a/bec_widgets/examples/extreme/extreme.py
+++ b/bec_widgets/examples/extreme/extreme.py
@@ -52,35 +52,56 @@ class PlotApp(QWidget):
self.scanID = None
# Initialize the UI
- self.init_ui()
- self.init_curves()
+ self.init_ui(self.spinBox_N_columns.value())
+ self.splitter.setSizes([400, 100])
# Connect the update signal to the update plot method
self.proxy_update_plot = pg.SignalProxy(
self.update_signal, rateLimit=25, slot=self.update_plot
)
+ self.spinBox_N_columns.valueChanged.connect(lambda x: self.init_ui(x))
- def init_ui(self) -> None:
+ def init_ui(self, num_columns=3) -> None:
"""
Initialize the UI components, create plots and store their grid positions.
+ Args:
+ num_columns (int): Number of columns to wrap the layout.
+
This method initializes a dictionary `self.plots` to store the plot objects
- along with their corresponding x and y signal names. It also keeps track of
- the row and column grid positions for each plot in `self.grid_coordinates`.
+ along with their corresponding x and y signal names. It dynamically arranges
+ the plots in a grid layout with a given number of columns and stretches the
+ last plots to fit the remaining space.
"""
+
+ self.glw.clear()
self.plots = {}
self.grid_coordinates = [] # List to keep track of grid positions for each plot
+ num_plots = len(self.xy_pairs)
+ num_rows = num_plots // num_columns # Calculate the number of full rows
+ last_row_cols = num_plots % num_columns # Number of plots in the last row
+
for i, (x, ys) in enumerate(self.xy_pairs):
- row, col = i // 2, i % 2 # Change these numbers based on your grid layout
- plot = self.glw.addPlot(row=row, col=col)
+ row, col = i // num_columns, i % num_columns # Calculate grid position
+
+ colspan = 1 # Default colspan
+
+ # Check if we are in the last row
+ if row == num_rows:
+ if last_row_cols == 1:
+ colspan = num_columns # Stretch across all columns
+ elif last_row_cols == 2 and col == 1: # Special case for 5 plots
+ colspan = num_columns - 1 # Stretch to fill remaining space
+
+ plot = self.glw.addPlot(row=row, col=col, colspan=colspan)
plot.setLabel("bottom", x)
plot.setLabel("left", ", ".join(ys))
plot.addLegend()
self.plots[(x, tuple(ys))] = plot
self.grid_coordinates.append((row, col)) # Store the grid position
- self.splitter.setSizes([200, 100])
+ self.init_curves()
def init_curves(self) -> None:
"""
diff --git a/bec_widgets/examples/extreme/extreme.ui b/bec_widgets/examples/extreme/extreme.ui
index 2b7fb644..51f6ab8a 100644
--- a/bec_widgets/examples/extreme/extreme.ui
+++ b/bec_widgets/examples/extreme/extreme.ui
@@ -20,23 +20,62 @@
Qt::Horizontal
-
-
- Cursor
-
-
+
+
+ -
+
+
+ Number of Columns:
+
+
+
+ -
+
+
+ 1
+
+
+ 10
+
+
+ 3
+
+
+
-
-
-
-
- Moved
-
-
-
-
- Clicked
-
-
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Cursor
+
+
+
-
+
+
+
+ Moved
+
+
+
+
+ Clicked
+
+
+
+
+