Skip to content

Commit

Permalink
Merge pull request #373 from qipe-nlab/select-plot-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
wpfff committed Feb 19, 2023
2 parents 02122a0 + 1e77449 commit c2e6120
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
16 changes: 12 additions & 4 deletions plottr/apps/autoplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from ..node.node import Node
from ..node.histogram import Histogrammer
from ..plot import PlotNode, makeFlowchartWithPlot, PlotWidget
from ..plot.mpl.autoplot import AutoPlot as MPLAutoPlot
from ..plot.pyqtgraph.autoplot import AutoPlot as PGAutoPlot
from ..utils.misc import unwrap_optional

Expand Down Expand Up @@ -335,7 +336,9 @@ def autoplotQcodesDataset(log: bool = False,
return fc, win


def autoplotDDH5(filepath: str = '', groupname: str = 'data') \
def autoplotDDH5(filepath: str = '',
groupname: str = 'data',
plotWidgetClass: Optional[Type[PlotWidget]] = None) \
-> Tuple[Flowchart, AutoPlotMainWindow]:

fc = linearFlowchart(
Expand All @@ -359,7 +362,8 @@ def autoplotDDH5(filepath: str = '', groupname: str = 'data') \
win = AutoPlotMainWindow(fc, loaderName='Data loader',
widgetOptions=widgetOptions,
monitor=True,
monitorInterval=0.0)
monitorInterval=0.0,
plotWidgetClass=plotWidgetClass)
win.show()

fc.nodes()['Data loader'].filepath = filepath
Expand All @@ -372,8 +376,12 @@ def autoplotDDH5(filepath: str = '', groupname: str = 'data') \
def autoplotDDH5App(*args: Any) -> Tuple[Flowchart, AutoPlotMainWindow]:
filepath = args[0][0]
groupname = args[0][1]

return autoplotDDH5(filepath, groupname)
if len(args[0]) > 2 and args[0][2] == "matplotlib":
return autoplotDDH5(filepath, groupname, MPLAutoPlot)
elif len(args[0]) > 2 and args[0][2] == "pyqtgraph":
return autoplotDDH5(filepath, groupname, PGAutoPlot)
else:
return autoplotDDH5(filepath, groupname) # use default backend


def main(f: str, g: str) -> int:
Expand Down
20 changes: 19 additions & 1 deletion plottr/apps/monitr.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

from .. import log as plottrlog
from .. import QtCore, QtWidgets, Signal, Slot, QtGui, plottrPath
from .. import config_entry as getcfg
from ..plot.mpl.autoplot import AutoPlot as MPLAutoPlot
from ..plot.pyqtgraph.autoplot import AutoPlot as PGAutoPlot
from ..data.datadict_storage import all_datadicts_from_hdf5, datadict_from_hdf5
from ..data.datadict import DataDict
from ..utils.misc import unwrap_optional
Expand Down Expand Up @@ -2777,6 +2780,17 @@ def __init__(self, monitorPath: str = '.',
self.main_partition_splitter = QtWidgets.QSplitter()
self.setCentralWidget(self.main_partition_splitter)

# Create menu bar
menu_bar = self.menuBar()
menu = menu_bar.addMenu("Backend")
self.backend_group = QtWidgets.QActionGroup(menu)
for backend, plotWidgetClass in [("matplotlib", MPLAutoPlot), ("pyqtgraph", PGAutoPlot)]:
action = QtWidgets.QAction(backend)
action.setCheckable(True)
action.setChecked(getcfg('main', 'default-plotwidget') == plotWidgetClass)
self.backend_group.addAction(action)
menu.addAction(action)

# Set left side layout
self.left_side_layout = QtWidgets.QVBoxLayout()
self.left_side_dummy_widget = QtWidgets.QWidget()
Expand Down Expand Up @@ -3128,7 +3142,11 @@ def on_plot_data(self, path: Path) -> None:
:param path: The path of the ddh5 file that should be displayed.
:return:
"""
self.app_manager.launchApp(self.current_app_id, AUTOPLOTMODULE, AUTOPLOTFUNC, str(path), 'data')
if self.backend_group.checkedAction() is None:
backend = "default"
else:
backend = self.backend_group.checkedAction().text()
self.app_manager.launchApp(self.current_app_id, AUTOPLOTMODULE, AUTOPLOTFUNC, str(path), 'data', backend)
self.current_app_id += 1

def add_text_input(self, path: Path) -> None:
Expand Down

0 comments on commit c2e6120

Please sign in to comment.