0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 11:41:49 +02:00

feat(waveform_widget): autorange button

This commit is contained in:
2024-07-17 22:29:53 +02:00
parent 7089cf356a
commit 8df6b003e5
3 changed files with 44 additions and 7 deletions

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" height="48px" viewBox="0 -960 960 960" width="48px" fill="#FFFFFF">
<path d="M571.91-279.09h191v-194h-60v134h-131v60ZM198.09-486.91h60v-134h131v-60h-191v194Zm-53 341.04q-32.51 0-55.87-23.35-23.35-23.36-23.35-55.87v-509.82q0-32.74 23.35-56.26 23.36-23.53 55.87-23.53h669.82q32.74 0 56.26 23.53 23.53 23.52 23.53 56.26v509.82q0 32.51-23.53 55.87-23.52 23.35-56.26 23.35H145.09Zm0-79.22h669.82v-509.82H145.09v509.82Zm0 0v-509.82 509.82Z"/>
</svg>

After

Width:  |  Height:  |  Size: 487 B

View File

@ -30,6 +30,17 @@ class MatplotlibAction(ToolBarAction):
toolbar.addAction(self.action)
class AutoRangeAction(ToolBarAction):
def add_to_toolbar(self, toolbar, target):
icon = QIcon()
icon.addFile(
os.path.join(MODULE_PATH, "assets", "toolbar_icons", "auto_range.svg"),
size=QSize(20, 20),
)
self.action = QAction(icon, "Autorange Plot", target)
toolbar.addAction(self.action)
class CurveAction(ToolBarAction):
def add_to_toolbar(self, toolbar, target):
icon = QIcon()

View File

@ -75,10 +75,12 @@ class BECWaveformWidget(BECConnector, QWidget):
"save": SaveAction(),
"matplotlib": MatplotlibAction(),
"separator_1": SeparatorAction(),
"auto_range": AutoRangeAction(),
"separator_2": SeparatorAction(),
"curves": CurveAction(),
"fit_params": FitParamsAction(),
"axis_settings": SettingsAction(),
# "separator_2": SeparatorAction(),
# "separator_3": SeparatorAction(),
# "import": ImportAction(),
# "export": ExportAction(),
},
@ -105,15 +107,16 @@ class BECWaveformWidget(BECConnector, QWidget):
def _hook_actions(self):
self.toolbar.widgets["save"].action.triggered.connect(self.export)
self.toolbar.widgets["matplotlib"].action.triggered.connect(self.export_to_matplotlib)
self.toolbar.widgets["auto_range"].action.triggered.connect(self._auto_range_from_toolbar)
self.toolbar.widgets["curves"].action.triggered.connect(self.show_curve_settings)
self.toolbar.widgets["fit_params"].action.triggered.connect(self.show_fit_summary_dialog)
self.toolbar.widgets["axis_settings"].action.triggered.connect(self.show_axis_settings)
self.toolbar.widgets["import"].action.triggered.connect(
lambda: self.load_config(path=None, gui=True)
)
self.toolbar.widgets["export"].action.triggered.connect(
lambda: self.save_config(path=None, gui=True)
)
# self.toolbar.widgets["import"].action.triggered.connect(
# lambda: self.load_config(path=None, gui=True)
# )
# self.toolbar.widgets["export"].action.triggered.connect(
# lambda: self.save_config(path=None, gui=True)
# )
def show_axis_settings(self):
dialog = SettingsDialog(
@ -466,6 +469,26 @@ class BECWaveformWidget(BECConnector, QWidget):
"""
self.waveform.set_legend_label_size(legend_label_size)
def set_auto_range(self, enabled: bool, axis: str = "xy"):
"""
Set the auto range of the plot widget.
Args:
enabled(bool): If True, enable the auto range.
axis(str, optional): The axis to enable the auto range.
- "xy": Enable auto range for both x and y axis.
- "x": Enable auto range for x axis.
- "y": Enable auto range for y axis.
"""
self.waveform.set_auto_range(enabled, axis)
@SafeSlot()
def _auto_range_from_toolbar(self):
"""
Set the auto range of the plot widget from the toolbar.
"""
self.waveform.set_auto_range(True, "xy")
def set_grid(self, x_grid: bool, y_grid: bool):
"""
Set the grid visibility of the plot widget.