From beec24412306b581e52bbc97d7c247dfe678c910 Mon Sep 17 00:00:00 2001 From: pfafflab Date: Wed, 7 Dec 2022 15:34:00 -0600 Subject: [PATCH] inspectr now uses the app manager --- plottr/apps/autoplot.py | 21 ++++++++++++++++++++- plottr/apps/inspectr.py | 32 ++++++++++++++++---------------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/plottr/apps/autoplot.py b/plottr/apps/autoplot.py index 35d0bc9a..ef95fa25 100644 --- a/plottr/apps/autoplot.py +++ b/plottr/apps/autoplot.py @@ -299,7 +299,8 @@ def setDefaults(self, data: DataDictBase) -> None: def autoplotQcodesDataset(log: bool = False, - pathAndId: Union[Tuple[str, int], None] = None) \ + pathAndId: Union[Tuple[str, int], None] = None, + monitorInterval: float = 0.0) \ -> Tuple[Flowchart, QCAutoPlotMainWindow]: """ Sets up a simple flowchart consisting of a data selector, @@ -331,10 +332,28 @@ def autoplotQcodesDataset(log: bool = False, monitor=True, loaderName='Data loader') win.show() + win.setMonitorInterval(monitorInterval) return fc, win +def autoplotQcodesDatasetApp(*args: Any) -> Tuple[Flowchart, AutoPlotMainWindow]: + """ + Function used by the apprunner script to convert the arguments + in a console to python objects and run autoplotQcodesDataset. + + returns the flowchart and the window created by the autolpot creation function. + """ + log = bool(args[0][0]) + path = args[0][1] + _id = int(args[0][2]) + refresh = 0.0 + if len(args[0]) == 4: + refresh = float(args[0][3]) + + return autoplotQcodesDataset(log, (path, _id), refresh) + + def autoplotDDH5(filepath: str = '', groupname: str = 'data') \ -> Tuple[Flowchart, AutoPlotMainWindow]: diff --git a/plottr/apps/inspectr.py b/plottr/apps/inspectr.py index 4a710ce4..ae253039 100644 --- a/plottr/apps/inspectr.py +++ b/plottr/apps/inspectr.py @@ -32,11 +32,18 @@ from plottr.gui.widgets import MonitorIntervalInput, FormLayoutWrapper, dictToTreeWidgetItems from .autoplot import autoplotQcodesDataset, QCAutoPlotMainWindow +from .appmanager import AppManager __author__ = 'Wolfgang Pfaff' __license__ = 'MIT' +# Change this variable to change the module of the app that monitr should open. +AUTOPLOTMODULE = 'plottr.apps.autoplot' + +# Function that the app manager should run to open a new app. +AUTOPLOTFUNC = 'autoplotQcodesDatasetApp' + LOGGER = plottrlog.getLogger('plottr.apps.inspectr') @@ -310,8 +317,6 @@ def __init__(self, parent: Optional[QtWidgets.QWidget] = None, """Constructor for :class:`QCodesDBInspector`.""" super().__init__(parent) - self._plotWindows: Dict[int, WindowDict] = {} - self.filepath = dbPath self.dbdf: Optional[pandas.DataFrame] = None self.monitor = QtCore.QTimer() @@ -324,6 +329,9 @@ def __init__(self, parent: Optional[QtWidgets.QWidget] = None, self.setWindowTitle('Plottr | QCoDeS dataset inspectr') + # App manager + self.appManager = AppManager() + ### GUI elements # Main Selection widgets @@ -439,14 +447,13 @@ def closeEvent(self, event: QtGui.QCloseEvent) -> None: """ When closing the inspectr window, do some house keeping: * stop the monitor, if running - * close all plot windows + * closes the app manager. """ if self.monitor.isActive(): self.monitor.stop() - for runId, info in self._plotWindows.items(): - info['window'].close() + self.appManager.close() @Slot() def showDBPath(self) -> None: @@ -505,10 +512,7 @@ def DBLoaded(self, dbdf: pandas.DataFrame) -> None: if self.monitor.isActive() and self.autoLaunchPlots.elements['Auto-plot new'].isChecked(): for idx in newIdxs: - self.plotRun(idx) - self._plotWindows[idx]['window'].setMonitorInterval( - self.monitorInput.spin.value() - ) + self.plotRun(idx, monitorInterval=self.monitorInput.spin.value()) @Slot() def updateDates(self) -> None: @@ -594,14 +598,10 @@ def setRunSelection(self, runId: int) -> None: self._sendInfo.emit(contentInfo) @Slot(int) - def plotRun(self, runId: int) -> None: + def plotRun(self, runId: int, monitorInterval: float = 0.0) -> None: assert self.filepath is not None - fc, win = autoplotQcodesDataset(pathAndId=(self.filepath, runId)) - self._plotWindows[runId] = { - 'flowchart': fc, - 'window': win, - } - win.showTime() + self.appManager.launchApp(runId, AUTOPLOTMODULE, AUTOPLOTFUNC, 'False', str(self.filepath), str(runId), + str(monitorInterval)) def setTag(self, item: QtWidgets.QTreeWidgetItem, tag: str) -> None: # set tag in the database