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

feat(waveform_widget): switch between drag and rectangle mode

This commit is contained in:
2024-07-17 23:14:24 +02:00
parent 8df6b003e5
commit 2be009c647
5 changed files with 53 additions and 1 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="M480-54 303.43-230.56 361-288.13l79.39 78.83v-231.09H209.3L283.13-366l-57.57 57.57L54-480l172.56-172.57L284.13-595l-74.83 75.39h231.09v-231.65L366-676.87l-57.57-57.57L480-906l171.57 171.56L594-676.87l-74.39-74.39v231.65h231.65L676.87-594l57.57-57.57L906-480 734.44-308.43 676.87-366l74.39-74.39H519.61v231.09L599-288.13l57.57 57.57L480-54Z"/>
</svg>

After

Width:  |  Height:  |  Size: 470 B

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="M444.19-421.3q39.72 0 67.4-27.78 27.67-27.78 27.67-66.91 0-39.14-27.71-66.57Q483.83-610 444.4-610q-39.44 0-66.92 27.28Q350-555.44 350-516.3q0 39.13 27.36 67.06 27.35 27.94 66.83 27.94ZM634.52-274 532.78-375.74q-22.56 12.31-44.41 19.02-21.84 6.72-43.28 6.72-69.57 0-117.7-48.62-48.13-48.62-48.13-117.88 0-67.98 48.29-116.39t117.08-48.41q68.79 0 117.08 48.41Q610-584.48 610-515.75q0 21.72-6.93 44.13-6.94 22.4-20.37 44.97l102.73 102.74L634.52-274ZM185.09-105.87q-32.51 0-55.87-23.35-23.35-23.36-23.35-55.87V-352h79.22v166.91H352v79.22H185.09Zm422.91 0v-79.22h166.91V-352h79.79v166.91q0 32.51-23.53 55.87-23.52 23.35-56.26 23.35H608ZM105.87-608v-166.91q0-32.74 23.35-56.26 23.36-23.53 55.87-23.53H352v79.79H185.09V-608h-79.22Zm669.04 0v-166.91H608v-79.79h166.91q32.74 0 56.26 23.53 23.53 23.52 23.53 56.26V-608h-79.79Z"/>
</svg>

After

Width:  |  Height:  |  Size: 946 B

View File

@ -390,7 +390,6 @@ class BECWaveform(BECPlotBase):
self.async_signal_update.emit() self.async_signal_update.emit()
self.scan_signal_update.emit() self.scan_signal_update.emit()
# self.autorange_timer.start(200)
@pyqtSlot() @pyqtSlot()
def auto_range(self): def auto_range(self):

View File

@ -30,6 +30,30 @@ class MatplotlibAction(ToolBarAction):
toolbar.addAction(self.action) toolbar.addAction(self.action)
class DragModeAction(ToolBarAction):
def add_to_toolbar(self, toolbar, target):
icon = QIcon()
icon.addFile(
os.path.join(MODULE_PATH, "assets", "toolbar_icons", "drag_pan_mode.svg"),
size=QSize(20, 20),
)
self.action = QAction(icon, "Drag Mouse Mode", target)
self.action.setCheckable(True)
toolbar.addAction(self.action)
class RectangeModeAction(ToolBarAction):
def add_to_toolbar(self, toolbar, target):
icon = QIcon()
icon.addFile(
os.path.join(MODULE_PATH, "assets", "toolbar_icons", "rectangle_mode.svg"),
size=QSize(20, 20),
)
self.action = QAction(icon, "Rectangle Zoom Mode", target)
self.action.setCheckable(True)
toolbar.addAction(self.action)
class AutoRangeAction(ToolBarAction): class AutoRangeAction(ToolBarAction):
def add_to_toolbar(self, toolbar, target): def add_to_toolbar(self, toolbar, target):
icon = QIcon() icon = QIcon()

View File

@ -4,6 +4,8 @@ import sys
from typing import Literal from typing import Literal
import numpy as np import numpy as np
import pyqtgraph as pg
from qtpy.QtCore import Slot
from qtpy.QtWidgets import QVBoxLayout, QWidget from qtpy.QtWidgets import QVBoxLayout, QWidget
from bec_widgets.qt_utils.error_popups import SafeSlot, WarningPopupUtility from bec_widgets.qt_utils.error_popups import SafeSlot, WarningPopupUtility
@ -75,6 +77,8 @@ class BECWaveformWidget(BECConnector, QWidget):
"save": SaveAction(), "save": SaveAction(),
"matplotlib": MatplotlibAction(), "matplotlib": MatplotlibAction(),
"separator_1": SeparatorAction(), "separator_1": SeparatorAction(),
"drag_mode": DragModeAction(),
"rectangle_mode": RectangeModeAction(),
"auto_range": AutoRangeAction(), "auto_range": AutoRangeAction(),
"separator_2": SeparatorAction(), "separator_2": SeparatorAction(),
"curves": CurveAction(), "curves": CurveAction(),
@ -107,6 +111,10 @@ class BECWaveformWidget(BECConnector, QWidget):
def _hook_actions(self): def _hook_actions(self):
self.toolbar.widgets["save"].action.triggered.connect(self.export) self.toolbar.widgets["save"].action.triggered.connect(self.export)
self.toolbar.widgets["matplotlib"].action.triggered.connect(self.export_to_matplotlib) self.toolbar.widgets["matplotlib"].action.triggered.connect(self.export_to_matplotlib)
self.toolbar.widgets["drag_mode"].action.triggered.connect(self.enable_mouse_pan_mode)
self.toolbar.widgets["rectangle_mode"].action.triggered.connect(
self.enable_mouse_rectangle_mode
)
self.toolbar.widgets["auto_range"].action.triggered.connect(self._auto_range_from_toolbar) 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["curves"].action.triggered.connect(self.show_curve_settings)
self.toolbar.widgets["fit_params"].action.triggered.connect(self.show_fit_summary_dialog) self.toolbar.widgets["fit_params"].action.triggered.connect(self.show_fit_summary_dialog)
@ -118,6 +126,9 @@ class BECWaveformWidget(BECConnector, QWidget):
# lambda: self.save_config(path=None, gui=True) # lambda: self.save_config(path=None, gui=True)
# ) # )
###################################
# Dialog Windows
###################################
def show_axis_settings(self): def show_axis_settings(self):
dialog = SettingsDialog( dialog = SettingsDialog(
self, self,
@ -508,6 +519,18 @@ class BECWaveformWidget(BECConnector, QWidget):
""" """
self.waveform.lock_aspect_ratio(lock) self.waveform.lock_aspect_ratio(lock)
@Slot()
def enable_mouse_rectangle_mode(self):
self.toolbar.widgets["rectangle_mode"].action.setChecked(True)
self.toolbar.widgets["drag_mode"].action.setChecked(False)
self.waveform.plot_item.getViewBox().setMouseMode(pg.ViewBox.RectMode)
@Slot()
def enable_mouse_pan_mode(self):
self.toolbar.widgets["drag_mode"].action.setChecked(True)
self.toolbar.widgets["rectangle_mode"].action.setChecked(False)
self.waveform.plot_item.getViewBox().setMouseMode(pg.ViewBox.PanMode)
def export(self): def export(self):
""" """
Show the export dialog for the plot widget. Show the export dialog for the plot widget.