mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
feat(waveform): export to matplotlib window of current scene
This commit is contained in:
3
bec_widgets/assets/toolbar_icons/photo_library.svg
Normal file
3
bec_widgets/assets/toolbar_icons/photo_library.svg
Normal 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="M354.61-386.61h391l-127-171-103 135-68-87-93 123ZM274.7-195.48q-32.51 0-55.87-23.35-23.35-23.36-23.35-55.87v-549.82q0-32.74 23.35-56.26 23.36-23.53 55.87-23.53h549.82q32.74 0 56.26 23.53 23.53 23.52 23.53 56.26v549.82q0 32.51-23.53 55.87-23.52 23.35-56.26 23.35H274.7Zm0-79.22h549.82v-549.82H274.7v549.82ZM135.48-55.69q-32.74 0-56.26-23.53-23.53-23.52-23.53-56.26v-629.04h79.79v629.04h629.04v79.79H135.48ZM274.7-824.52v549.82-549.82Z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 564 B |
@ -2010,6 +2010,12 @@ class BECWaveformWidget(RPCBase):
|
||||
Show the export dialog for the plot widget.
|
||||
"""
|
||||
|
||||
@rpc_call
|
||||
def export_to_matplotlib(self):
|
||||
"""
|
||||
Export the plot widget to Matplotlib.
|
||||
"""
|
||||
|
||||
|
||||
class DeviceBox(RPCBase):
|
||||
@property
|
||||
|
@ -4,7 +4,6 @@ from typing import Literal, Optional
|
||||
|
||||
import pyqtgraph as pg
|
||||
from pydantic import BaseModel, Field
|
||||
from pyqtgraph.GraphicsScene.exportDialog import ExportDialog
|
||||
from qtpy.QtWidgets import QWidget
|
||||
|
||||
from bec_widgets.utils import BECConnector, ConnectionConfig
|
||||
|
@ -9,6 +9,7 @@ from bec_lib import messages
|
||||
from bec_lib.device import ReadoutPriority
|
||||
from bec_lib.endpoints import MessageEndpoints
|
||||
from pydantic import Field, ValidationError, field_validator
|
||||
from pyqtgraph.exporters import MatplotlibExporter
|
||||
from qtpy.QtCore import Signal as pyqtSignal
|
||||
from qtpy.QtCore import Slot as pyqtSlot
|
||||
from qtpy.QtWidgets import QWidget
|
||||
@ -1324,6 +1325,13 @@ class BECWaveform(BECPlotBase):
|
||||
return combined_data
|
||||
return data
|
||||
|
||||
def export_to_matplotlib(self):
|
||||
"""
|
||||
Export current waveform to matplotlib gui. Available only if matplotlib is installed in the enviroment.
|
||||
|
||||
"""
|
||||
MatplotlibExporter(self.plot_item).export()
|
||||
|
||||
def clear_all(self):
|
||||
curves_data = self._curves_data
|
||||
sources = list(curves_data.keys())
|
||||
|
@ -19,6 +19,17 @@ class SaveAction(ToolBarAction):
|
||||
toolbar.addAction(self.action)
|
||||
|
||||
|
||||
class MatplotlibAction(ToolBarAction):
|
||||
def add_to_toolbar(self, toolbar, target):
|
||||
icon = QIcon()
|
||||
icon.addFile(
|
||||
os.path.join(MODULE_PATH, "assets", "toolbar_icons", "photo_library.svg"),
|
||||
size=QSize(20, 20),
|
||||
)
|
||||
self.action = QAction(icon, "Open Matplotlib Plot", target)
|
||||
toolbar.addAction(self.action)
|
||||
|
||||
|
||||
class CurveAction(ToolBarAction):
|
||||
def add_to_toolbar(self, toolbar, target):
|
||||
icon = QIcon()
|
||||
|
@ -6,7 +6,7 @@ from typing import Literal
|
||||
import numpy as np
|
||||
from qtpy.QtWidgets import QVBoxLayout, QWidget
|
||||
|
||||
from bec_widgets.qt_utils.error_popups import error_managed
|
||||
from bec_widgets.qt_utils.error_popups import WarningPopupUtility, error_managed
|
||||
from bec_widgets.qt_utils.settings_dialog import SettingsDialog
|
||||
from bec_widgets.qt_utils.toolbar import ModularToolBar, SeparatorAction
|
||||
from bec_widgets.utils import BECConnector
|
||||
@ -44,6 +44,7 @@ class BECWaveformWidget(BECConnector, QWidget):
|
||||
"set_grid",
|
||||
"lock_aspect_ratio",
|
||||
"export",
|
||||
"export_to_matplotlib",
|
||||
]
|
||||
|
||||
def __init__(
|
||||
@ -69,6 +70,7 @@ class BECWaveformWidget(BECConnector, QWidget):
|
||||
self.toolbar = ModularToolBar(
|
||||
actions={
|
||||
"save": SaveAction(),
|
||||
"matplotlib": MatplotlibAction(),
|
||||
"separator_1": SeparatorAction(),
|
||||
"curves": CurveAction(),
|
||||
"axis_settings": SettingsAction(),
|
||||
@ -82,6 +84,8 @@ class BECWaveformWidget(BECConnector, QWidget):
|
||||
self.layout.addWidget(self.toolbar)
|
||||
self.layout.addWidget(self.fig)
|
||||
|
||||
self.warning_util = WarningPopupUtility(self)
|
||||
|
||||
self.waveform = self.fig.plot()
|
||||
self.waveform.apply_config(config)
|
||||
|
||||
@ -96,6 +100,7 @@ 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["curves"].action.triggered.connect(self.show_curve_settings)
|
||||
self.toolbar.widgets["axis_settings"].action.triggered.connect(self.show_axis_settings)
|
||||
self.toolbar.widgets["import"].action.triggered.connect(
|
||||
@ -467,6 +472,21 @@ class BECWaveformWidget(BECConnector, QWidget):
|
||||
"""
|
||||
self.waveform.export()
|
||||
|
||||
def export_to_matplotlib(self):
|
||||
"""
|
||||
Export the plot widget to Matplotlib.
|
||||
"""
|
||||
try:
|
||||
import matplotlib as mpl
|
||||
except ImportError:
|
||||
self.warning_util.show_warning(
|
||||
title="Matplotlib not installed",
|
||||
message="Matplotlib is required for this feature.",
|
||||
detailed_text="Please install matplotlib in your Python environment by using 'pip install matplotlib'.",
|
||||
)
|
||||
return
|
||||
self.waveform.export_to_matplotlib()
|
||||
|
||||
#######################################
|
||||
# User Access Methods from BECConnector
|
||||
######################################
|
||||
|
Reference in New Issue
Block a user