Commit 64288df2 authored by Valentin Valls's avatar Valentin Valls
Browse files

Insert scan at right place when it is loaded from history

parent 9ab47bf7
...@@ -394,6 +394,10 @@ class Scan(qt.QObject, _Sealable): ...@@ -394,6 +394,10 @@ class Scan(qt.QObject, _Sealable):
raise KeyError("Version do not match") raise KeyError("Version do not match")
return result[1] return result[1]
def startTime(self):
scanInfo = self.scanInfo()
return scanInfo.get("start_time", None)
class ScanGroup(Scan): class ScanGroup(Scan):
"""Scan group object. """Scan group object.
...@@ -555,6 +555,18 @@ class CurvePlotWidget(plot_helper.PlotWidget): ...@@ -555,6 +555,18 @@ class CurvePlotWidget(plot_helper.PlotWidget):
self.scanListUpdated.emit(self.__scans) self.scanListUpdated.emit(self.__scans)
self.__redrawAllScans() self.__redrawAllScans()
def insertScan(self, scan):
if scan is None:
if scan is self.__scan:
_logger.warning("Removing the current scan is not available")
self.__scans = list(reversed(sorted(self.__scans, key=lambda s: s.startTime())))
def setMaxStoredScans(self, maxScans: int): def setMaxStoredScans(self, maxScans: int):
# FIXME: Must emit event # FIXME: Must emit event
self.__maxStoredScans = maxScans self.__maxStoredScans = maxScans
...@@ -890,27 +890,32 @@ class CurvePlotPropertyWidget(qt.QWidget): ...@@ -890,27 +890,32 @@ class CurvePlotPropertyWidget(qt.QWidget):
scan = scan_history.create_scan(nodeName) scan = scan_history.create_scan(nodeName)
widget = self.__focusWidget widget = self.__focusWidget
if widget is not None: if widget is not None:
plots = scan_info_helper.create_plot_model(scan.scanInfo(), scan) if widget.isPreviousScanStored():
plots = [p for p in plots if isinstance(p, plot_item_model.CurvePlot)] widget.insertScan(scan)
if len(plots) == 0: else:
_logger.warning("No curve plot to display") plots = scan_info_helper.create_plot_model(scan.scanInfo(), scan)
qt.QMessageBox.warning( plots = [p for p in plots if isinstance(p, plot_item_model.CurvePlot)]
None, "Warning", "There was no curve plot in the selected scan" if len(plots) == 0:
) _logger.warning("No curve plot to display")
return qt.QMessageBox.warning(
plotModel = plots[0] None, "Warning", "There was no curve plot in the selected scan"
previousWidgetPlot = self.__plotModel )
# Reuse only available values plotModel = plots[0]
if isinstance(previousWidgetPlot, plot_item_model.CurvePlot): previousWidgetPlot = self.__plotModel
previousWidgetPlot, plotModel, scan # Reuse only available values
) if isinstance(previousWidgetPlot, plot_item_model.CurvePlot):
widget.setScan(scan) model_helper.removeNotAvailableChannels(
if previousWidgetPlot is None or previousWidgetPlot.isEmpty(): previousWidgetPlot, plotModel, scan
if plotModel.styleStrategy() is None: )
plotModel.setStyleStrategy(DefaultStyleStrategy(self.__flintModel)) widget.setScan(scan)
widget.setPlotModel(plotModel) if previousWidgetPlot is None or previousWidgetPlot.isEmpty():
if plotModel.styleStrategy() is None:
def __findItemFromPlotItem( def __findItemFromPlotItem(
self, requestedItem: plot_model.Item self, requestedItem: plot_model.Item
...@@ -378,8 +378,7 @@ class ScanStartTimeDelegate(qt.QStyledItemDelegate): ...@@ -378,8 +378,7 @@ class ScanStartTimeDelegate(qt.QStyledItemDelegate):
return editor return editor
def __toStartTimeText(self, scan: scan_model.Scan) -> str: def __toStartTimeText(self, scan: scan_model.Scan) -> str:
scanInfo = scan.scanInfo() value = scan.startTime()
value = scanInfo.get("start_time", None)
if value is None: if value is None:
return "" return ""
return value.strftime("%H:%M") return value.strftime("%H:%M")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment