Skip to content

Commit 068b3a7

Browse files
committed
Fixes bugs for cloned slicer plots
1 parent 707ae00 commit 068b3a7

3 files changed

Lines changed: 37 additions & 35 deletions

File tree

src/sas/qtgui/MainWindow/DataExplorer.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import sys
77
import time
8+
from contextlib import suppress
89
from pathlib import Path
910

1011
from PySide6 import QtCore, QtGui, QtWidgets
@@ -845,8 +846,8 @@ def onDataReplaced(self):
845846

846847
def freezeFromName(self, search_name: str = None):
847848
"""
848-
Convert target_plot-data into a separate dataset (CustomNavigation-Button: "sendToDataExplorer").
849-
It searches the target_plot-data in the model and creates a new dataset in the Explorer.
849+
Convert target_plot-data into a separate dataset (CustomNavigation-Button: "freezeDatasets").
850+
It searches the target_plot-data in the model and creates a new dataset in the Data Explorer.
850851
851852
:param search_name: <class 'str'>
852853
"""
@@ -931,7 +932,7 @@ def freezeCheckedData(self):
931932
Convert checked results (fitted model, residuals) into separate dataset.
932933
"""
933934
outer_index = -1
934-
theories_copied = 0
935+
items_copied = 0
935936
orig_model_size = self.model.rowCount()
936937
while outer_index < orig_model_size:
937938
outer_index += 1
@@ -952,20 +953,20 @@ def freezeCheckedData(self):
952953
if inner_item.checkState() != QtCore.Qt.Checked:
953954
continue
954955
self.model.beginResetModel()
955-
theories_copied += 1
956+
items_copied += 1
956957
new_item = self.cloneTheory(inner_item)
957958
self.model.appendRow(new_item)
958959
self.model.endResetModel()
959960

960961
freeze_msg = ""
961-
if theories_copied == 0:
962+
if items_copied == 0:
962963
return
963-
elif theories_copied == 1:
964-
freeze_msg = "1 theory copied to a separate data set"
965-
elif theories_copied > 1:
966-
freeze_msg = "%i theories copied to separate data sets" % theories_copied
964+
elif items_copied == 1:
965+
freeze_msg = "1 item copied to a separate data set"
966+
elif items_copied > 1:
967+
freeze_msg = f"{items_copied} items copied to separate data sets"
967968
else:
968-
freeze_msg = "Unexpected number of theories copied: %i" % theories_copied
969+
freeze_msg = f"Unexpected number of items copied: {items_copied}"
969970
raise AttributeError(freeze_msg)
970971
self.communicator.statusBarUpdateSignal.emit(freeze_msg)
971972

@@ -998,9 +999,9 @@ def freezeTheory(self, event):
998999
elif theories_copied == 1:
9991000
freeze_msg = "1 theory copied from the Theory tab as a data set"
10001001
elif theories_copied > 1:
1001-
freeze_msg = "%i theories copied from the Theory tab as data sets" % theories_copied
1002+
freeze_msg = f"{theories_copied} theories copied from the Theory tab as data sets"
10021003
else:
1003-
freeze_msg = "Unexpected number of theories copied: %i" % theories_copied
1004+
freeze_msg = f"Unexpected number of theories copied: {theories_copied}"
10041005
raise AttributeError(freeze_msg)
10051006
self.communicator.statusBarUpdateSignal.emit(freeze_msg)
10061007
# Actively switch tabs
@@ -1025,13 +1026,18 @@ def cloneTheory(self, item_from):
10251026
new_name = new_item.text() + '_@' + time_bit
10261027
new_item.setText(new_name)
10271028
# Change the underlying data so it is no longer a theory
1028-
try:
1029+
with suppress(AttributeError):
10291030
new_item.child(0).data().is_data = True
10301031
new_item.child(0).data().symbol = 'Circle'
10311032
new_item.child(0).data().id = new_name
1032-
except AttributeError:
1033-
# no data here, pass
1034-
pass
1033+
new_item.child(0).data().name = f"Frozen{orig_data.name}"
1034+
new_item.child(0).data().title = f"Frozen{orig_data.title}"
1035+
# Ensure data from slicer plots will not be identified as
1036+
# a slicer plot when replotted
1037+
with suppress(AttributeError):
1038+
delattr(new_item.child(0).data(), "type_id")
1039+
delattr(new_item.child(0).data(), "custom_color")
1040+
10351041
return new_item
10361042

10371043
def recursivelyCloneItem(self, item):
@@ -1411,8 +1417,9 @@ def updatePlot(self, data):
14111417
assert type(data).__name__ in ['Data1D', 'Data2D']
14121418

14131419
ids_keys = list(self.active_plots.keys())
1414-
#ids_vals = [val.data.name for val in self.active_plots.values()]
14151420

1421+
# We test for whether the data_id starts with any of the plot_ids
1422+
# to account for additional slicers with an "_#" label
14161423
data_id = data.name
14171424
if data_id in ids_keys:
14181425
# We have data, let's replace data that needs replacing
@@ -1421,11 +1428,6 @@ def updatePlot(self, data):
14211428
# restore minimized window, if applicable
14221429
self.active_plots[data_id].showNormal()
14231430
return True
1424-
#elif data_id in ids_vals:
1425-
# if data.plot_role != DataRole.ROLE_DATA:
1426-
# list(self.active_plots.values())[ids_vals.index(data_id)].replacePlot(data_id, data)
1427-
# self.active_plots[data_id].showNormal()
1428-
# return True
14291431
return False
14301432

14311433
def chooseFiles(self):

src/sas/qtgui/MainWindow/media/graph_help.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,12 @@ displayed in the status bar at the very bottom-left of the SasView window.
200200
Sending data to Explorer
201201
^^^^^^^^^^^^^^^^^^^^^^^^
202202

203-
Clicking the button sends the current plot data to the Data Explorer.
204-
This feature is primarily useful for generated 1D plots during slicing, as
205-
data must be selected in the Explorer before it can be sent to the Fitting tool.
203+
Clicking the "Freeze Datasets" button sends the current plot data to the Data Explorer.
204+
This can also be done by right clicking on a child dataset in the Data Explorer and
205+
selecting "Freeze Results", or by selecting the dataset(s) of interest in the Data Explorer
206+
and selecting "Edit>Freeze Fit Results". This feature is primarily useful for generated
207+
1D plots during slicing, as data must be selected in the Data Explorer before it can be
208+
sent to the Fitting tool.
206209

207210
.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
208211

src/sas/qtgui/Plotting/PlotterBase.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CustomToolbar(NavigationToolbar):
2222
Adding custom Actions to the NavigationToolbar, which are visible in 1D/2D plots.
2323
2424
Currently added actions:
25-
- "Send to Data Explorer":
25+
- "Freeze Datasets":
2626
:param canvas: Matplotlib canvas
2727
:param parent: Parent Qt widget
2828
:emit: <class 'str'> name of 1D/2D plot
@@ -31,18 +31,15 @@ class CustomToolbar(NavigationToolbar):
3131
def __init__(self, canvas, parent=None):
3232
super().__init__(canvas, parent)
3333
self.parent = parent
34-
self.addAction_SendToExplorer()
35-
36-
def addAction_SendToExplorer(self):
3734
custom_icon = QtGui.QIcon() # You can load an icon here if you want e.g., QtGui.QIcon("path/to/icon.png")
38-
custom_action = QtGui.QAction(custom_icon, "Send to Data Explorer", self)
39-
custom_action.setToolTip("Send all data to the Data Explorer")
40-
custom_action.triggered.connect(self.sendToDataExplorer)
35+
custom_action = QtGui.QAction(custom_icon, "Freeze Datasets", self)
36+
custom_action.setToolTip("Send all datasets to the Data Explorer")
37+
custom_action.triggered.connect(self.freezeDatasets)
4138
self.insertAction(self.actions()[-1], custom_action)
4239

43-
def sendToDataExplorer(self):
44-
for item in self.parent.data:
45-
GuiUtils.communicator.freezeDataNameSignal.emit(item.name)
40+
def freezeDatasets(self):
41+
for dataset in self.parent.data:
42+
GuiUtils.communicator.freezeDataNameSignal.emit(dataset.name)
4643

4744
class PlotterBase(QtWidgets.QWidget):
4845
#TODO: Describe what this class is

0 commit comments

Comments
 (0)