55import os
66import sys
77import time
8+ from contextlib import suppress
89from pathlib import Path
910
1011from 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 ):
0 commit comments