diff --git a/src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py b/src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py index 7227cf36a0..9f1007cbae 100644 --- a/src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py +++ b/src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py @@ -336,13 +336,13 @@ def setData(self, data_item=None, is_batch=False, tab_index=None): self.addData(data = data, is2D=is_2Ddata, is_batch=is_batch, tab_index=tab_index) else: self.setCurrentIndex(tab_index-1) - self.swapData(data = data, is2D = is_2Ddata) + self.swapData(data = data, is2D = is_2Ddata,tab_index=self.currentIndex()) return #debug Batch mode, gives none Type has no attribute name if not is_batch and np.any(available_tabs): first_good_tab = available_tabs.index(True) self.tabs[first_good_tab].data = data - self.tabs[first_good_tab].updateTab(data = data, is2D = is_2Ddata) + self.tabs[first_good_tab].updateTab(data = data, is2D = is_2Ddata, tab_index=first_good_tab) else: self.addData(data = data, is2D=is_2Ddata, is_batch=is_batch, tab_index = tab_index) @@ -351,7 +351,7 @@ def setData(self, data_item=None, is_batch=False, tab_index=None): - def swapData(self, data = None, is2D = False): + def swapData(self, data = None, is2D = False,tab_index=None): """ Replace the data from the current tab """ @@ -368,7 +368,7 @@ def swapData(self, data = None, is2D = False): raise RuntimeError(msg) self.currentTab.data = data - self.currentTab.updateTab(data = data, is2D = is2D) + self.currentTab.updateTab(data = data, is2D = is2D,tab_index= tab_index) @@ -426,14 +426,14 @@ def addData(self, data=None, is_batch=False, tab_index=None, is2D=False): icon.addPixmap(QtGui.QPixmap("src/sas/qtgui/images/icons/layers.svg")) else: if data is not None: - tab.updateTab(data = data, is2D = is2D) + tab.updateTab(data = data, is2D = is2D, tab_index=tab_index) tab.is_batch = is_batch self.addTab(tab, icon, tab.tab_name) tab.enableButtons() self.tabs.append(tab) - # Show the new tab + # the new tab self.maxIndex = max([tab.tab_id for tab in self.tabs], default=0) + 1 self.setCurrentWidget(tab) diff --git a/src/sas/qtgui/Perspectives/Inversion/InversionWidget.py b/src/sas/qtgui/Perspectives/Inversion/InversionWidget.py index 1d8b741adb..e06e8001b7 100644 --- a/src/sas/qtgui/Perspectives/Inversion/InversionWidget.py +++ b/src/sas/qtgui/Perspectives/Inversion/InversionWidget.py @@ -1,6 +1,6 @@ import logging import numpy as np - +import sys from PySide6 import QtGui, QtCore, QtWidgets @@ -8,6 +8,7 @@ # sas-global import sas.qtgui.Utilities.GuiUtils as GuiUtils +import sas.qtgui.Plotting.PlotHelper as PlotHelper # pr inversion GUI elements from .InversionUtils import WIDGETS @@ -23,6 +24,7 @@ from ...Plotting.Plotter import Plotter from ...Plotting.Plotter2D import Plotter2D, Plotter2DWidget from ...Plotting.Slicers.SectorSlicer import SectorInteractor +import sas.qtgui.Plotting.PlotHelper as PlotHelper TAB_2D = 2 @@ -93,8 +95,8 @@ def __init__(self, parent=None, data=None, tab_id=1): # 2D Data Plot - self.plot_widget = None - + self.plot_widgets = {} + self.active_plots = {} self.plotList = None ######################################## @@ -245,11 +247,6 @@ def setupLinks(self): self.slitWidthInput.textChanged.connect( lambda: self._calculator.set_slit_width(is_float(self.slitWidthInput.text()))) -# if self.is2D: -# self.noOfSlicesInput.textChanged.connect(self.show2DPlot()) -# self.startAngleInput.textChanged.connect(self.show2DPlot()) -# self.noOfQbinsInput.textChanged.connect(self.show2DPlot()) - #self.model.itemChanged.connect(self.model_changed) # disabled because it causes dataList to be set to prevous item. further debuging required. self.estimateNTSignal.connect(self._estimateNTUpdate) @@ -465,15 +462,32 @@ def setQ(self): self._calculator.set_qmin(qmin) self._calculator.set_qmax(qmax) - def updateTab(self, data = None, is2D=False): + def updateTab(self, data = None, is2D=False, tab_index=None): self.is2D = is2D self.logic.data = GuiUtils.dataFromItem(data) self.swapDataComboBox(self.logic.data.name, data) if is2D: - data.isSliced = False - #self.communicate.plotUpdateSignal.emit([data]) - self.show2DPlot() + data.isSliced = False + plots = GuiUtils.plotsFromDisplayName(self.logic.data.name, data.model()) + for item, plot_set in plots.items(): + self.plot2D = Plotter2D(self, quickplot=True) + self.plot2D.item = item + self.plot2D.plot(plot_set) + self.addPlot(self.plot2D) + #self.active_plots[self.plot2D.data[0].name] = self.plot2D + + + #if is2D: + # data.isSliced = False + # plots = GuiUtils.plotsFromDisplayName(self.logic.data.name, data.model()) + # # data has not been shown - show just data + # for item, plot in plots.items(): + + + # #GuiUtils.updateModelItemWithPlot(item, self.plot, new_plot.id) + # self.communicate.plotRequestedSignal.emit([item, self.logic.data], self.tab_id) + else: #1D data self.logic.add_errors() self.setQ() @@ -483,18 +497,34 @@ def updateTab(self, data = None, is2D=False): self.calculateAllButton.setVisible(False) self.showResultsButton.setVisible(False) - def addDataPlot2D(self, plot_set, item): + def addPlot(self, new_plot): """ - Create a new 2D plot and add it to the workspace + Helper method for plot bookkeeping """ - self.plot2D = Plotter2DWidget(self, quickplot=True) - self.plot2D.data = self.logic.data - self.plot2D.plot() - self.plot2D.item = self.tabMain - self.plot2D.onSectorView() + # Update the global plot counter + title = 'Plot2D '+self.logic.data.name + new_plot.setWindowTitle(title) + + # Set the object name to satisfy the Squish object picker + new_plot.setObjectName(title) + + # Add the plot to the workspace + plot_widget = self.parent.workspace().addSubWindow(new_plot) + if sys.platform == 'darwin': + workspace_height = int(float(self.parent.workspace().sizeHint().height()) / 2) + workspace_width = int(float(self.parent.workspace().sizeHint().width()) / 2) + plot_widget.resize(workspace_width, workspace_height) + + # Show the plot + new_plot.show() + new_plot.canvas.draw() + + # Update the plot widgets dict + self.plot_widgets[title] = plot_widget + GuiUtils.updateModelItemWithPlot(self.plot2D.item, self.plot2D, name=title) + #self.communicate.plotRequestedSignal.emit([item, self.logic.data], self.tab_id) + - self.plot2D.show() - self.enableButtons() ###################################################################### # GUI Interaction Events @@ -1300,8 +1330,7 @@ def slice(self): # functool's partial function here is used to -> the slice into the showPlot function for the specified slice in the table # A better solution could be used here to avoid the need to import functools from functools import partial - #self.plot1D.plot(slice) - #self.plot1D.show() + self.sliceList.setItem(row, 0, QtWidgets.QTableWidgetItem(slice.title)) # sets the title self.sliceList.setItem(row, 1, QtWidgets.QTableWidgetItem(str(slice.phi))) # sets the phi self.sliceList.setItem(row, 2, QtWidgets.QTableWidgetItem(str(slice.Qbins))) # set Number of points on plot @@ -1342,19 +1371,7 @@ def sendToInversion(self, items, isBatch): self._parent._current_perspective.setData(data_item=items, is_batch=isBatch) - def show2DPlot(self): - """ - Show 2D plot representing the raw 2D data - """ - self.plot2D = Plotter2D(self, quickplot=True) - self.plot2D.data = self.logic.data - self.plot2D.plot() - self.plot2D.item = self.tabMain - self.plot2D.onSectorView() - - self.plot2D.show() - self.enableButtons() def show1DPlot(self, data): """