Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display sample title instead of filename in DataExplorer window (ESS_GUI) #1652

Merged
merged 3 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/sas/qtgui/MainWindow/DataExplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def flatDataForModel(self, model):
data = GuiUtils.dataFromItem(item)
if data is None: continue
# Now, all plots under this item
filename = data.filename
filename = data.name
all_data[filename] = data
other_datas = GuiUtils.plotsFromFilename(filename, model)
# skip the main plot
Expand All @@ -391,7 +391,7 @@ def allDataForModel(self, model):
data = GuiUtils.dataFromItem(item)
if data is None: continue
# Now, all plots under this item
filename = data.filename
filename = data.name
is_checked = item.checkState()
properties['checked'] = is_checked
other_datas = []
Expand All @@ -413,7 +413,7 @@ def getDataForID(self, id):
if data is None: continue
if data.id != id: continue
# We found the dataset - save it.
filename = data.filename
filename = data.name
is_checked = item.checkState()
properties['checked'] = is_checked
other_datas = GuiUtils.plotsFromFilename(filename, model)
Expand Down Expand Up @@ -621,15 +621,15 @@ def updateModelFromData(self, data):
from sas.sascalc.dataloader.data_info import Data1D as old_data1d
from sas.sascalc.dataloader.data_info import Data2D as old_data2d
if isinstance(new_data, (old_data1d, old_data2d)):
new_data = self.manager.create_gui_data(value[0], new_data.filename)
new_data = self.manager.create_gui_data(value[0], new_data.name)
if hasattr(value[0], 'id'):
new_data.id = value[0].id
new_data.group_id = value[0].group_id
assert isinstance(new_data, (Data1D, Data2D))
# make sure the ID is retained
properties = value[1]
is_checked = properties['checked']
new_item = GuiUtils.createModelItemWithPlot(new_data, new_data.filename)
new_item = GuiUtils.createModelItemWithPlot(new_data, new_data.name)
new_item.setCheckState(is_checked)
items.append(new_item)
model = self.theory_model
Expand Down Expand Up @@ -1280,11 +1280,6 @@ def readData(self, path):

output_objects = self.loader.load(p_file)

# Some loaders return a list and some just a single Data1D object.
# Standardize.
if not isinstance(output_objects, list):
output_objects = [output_objects]

for item in output_objects:
# cast sascalc.dataloader.data_info.Data1D into
# sasgui.guiframe.dataFitting.Data1D
Expand All @@ -1294,7 +1289,7 @@ def readData(self, path):

# Model update should be protected
self.mutex.lock()
self.updateModel(new_data, p_file)
self.updateModel(new_data, new_data.name)
#self.model.reset()
QtWidgets.QApplication.processEvents()
self.mutex.unlock()
Expand Down Expand Up @@ -1506,7 +1501,7 @@ def showDataInfo(self):
self.txt_widget.setReadOnly(True)
self.txt_widget.setWindowFlags(QtCore.Qt.Window)
self.txt_widget.setWindowIcon(QtGui.QIcon(":/res/ball.ico"))
self.txt_widget.setWindowTitle("Data Info: %s" % data.filename)
self.txt_widget.setWindowTitle("Data Info: %s" % data.name)
self.txt_widget.clear()
self.txt_widget.insertPlainText(text_to_show)

Expand Down
4 changes: 3 additions & 1 deletion src/sas/qtgui/MainWindow/DataManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def create_gui_data(self, data, path=None):
#creating a name for data
title = ""
file_name = os.path.basename(path) if path is not None else os.path.basename(data.filename)
if file_name:
if data.title:
name = data.title
elif file_name:
name = file_name
elif data.run:
name = data.run[0]
Expand Down
24 changes: 12 additions & 12 deletions src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ def setEnablementOnDataLoad(self):
"""
# Tag along functionality
self.label.setText("Data loaded from: ")
if self.logic.data.filename:
self.lblFilename.setText(self.logic.data.filename)
else:
if self.logic.data.name:
self.lblFilename.setText(self.logic.data.name)
else:
self.lblFilename.setText(self.logic.data.filename)
self.updateQRange()
# Switch off Data2D control
self.chk2DView.setEnabled(False)
Expand All @@ -463,8 +463,8 @@ def setEnablementOnDataLoad(self):
if self.is_batch_fitting:
self.lblFilename.setVisible(False)
for dataitem in self.all_data:
filename = GuiUtils.dataFromItem(dataitem).filename
self.cbFileNames.addItem(filename)
name = GuiUtils.dataFromItem(dataitem).name
self.cbFileNames.addItem(name)
self.cbFileNames.setVisible(True)
self.chkChainFit.setEnabled(True)
self.chkChainFit.setVisible(True)
Expand Down Expand Up @@ -2137,7 +2137,7 @@ def showPlot(self):
data_to_show = self.data
# Any models for this page
current_index = self.all_data[self.data_index]
item = self._requestPlots(self.data.filename, current_index.model())
item = self._requestPlots(self.data.name, current_index.model())
if item:
# fit+data has not been shown - show just data
self.communicate.plotRequestedSignal.emit([item, data_to_show], self.tab_id)
Expand Down Expand Up @@ -2692,7 +2692,7 @@ def createNewIndex(self, fitted_data):
"""
if self.data_is_loaded:
if not fitted_data.name:
name = self.nameForFittedData(self.data.filename)
name = self.nameForFittedData(self.data.name)
fitted_data.title = name
fitted_data.name = name
fitted_data.filename = name
Expand Down Expand Up @@ -2741,7 +2741,7 @@ def nameFromData(self, fitted_data):
Return name for the dataset. Terribly impure function.
"""
if fitted_data.name is None:
name = self.nameForFittedData(self.logic.data.filename)
name = self.nameForFittedData(self.logic.data.name)
fitted_data.title = name
fitted_data.name = name
fitted_data.filename = name
Expand Down Expand Up @@ -3575,7 +3575,7 @@ def readFitPage(self, fp):
"""
assert isinstance(fp, FitPage)
# Main tab info
self.logic.data.filename = fp.filename
self.logic.data.filename = fp.name
self.data_is_loaded = fp.data_is_loaded
self.chkPolydispersity.setCheckState(fp.is_polydisperse)
self.chkMagnetism.setCheckState(fp.is_magnetic)
Expand Down Expand Up @@ -3617,7 +3617,7 @@ def saveToFitPage(self, fp):
assert isinstance(fp, FitPage)

# Main tab info
fp.filename = self.logic.data.filename
fp.filename = self.logic.data.name
fp.data_is_loaded = self.data_is_loaded
fp.is_polydisperse = self.chkPolydispersity.isChecked()
fp.is_magnetic = self.chkMagnetism.isChecked()
Expand Down Expand Up @@ -3859,11 +3859,11 @@ def getFitPage(self):
# need item->data->data_id
data = GuiUtils.dataFromItem(item)
data_ids.append(data.id)
filenames.append(data.filename)
filenames.append(data.name)
else:
if self.data_is_loaded:
data_ids = [str(self.logic.data.id)]
filenames = [str(self.logic.data.filename)]
filenames = [str(self.logic.data.name)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for data.name to be something other than a string? If it is None, do you want the filename list to be ["None"]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If self.data_is_loaded is True, the name cannot be None, but it could some form of numeral.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems awkward. Can you convert the numeral to a string when you assign it to data.name so you don't have to worry about it elsewhere in the code? That is, how many of your other uses of data.name are implicitly assuming that it is a string, but just haven't been tested yet in the GUI? Are there any bits of the code that use it as a numeral if it is one?

param_list.append(['tab_index', str(self.tab_id)])
param_list.append(['is_batch_fitting', str(self.is_batch_fitting)])
param_list.append(['data_name', filenames])
Expand Down