Skip to content

Commit

Permalink
Merge pull request #1652 from SasView/ESS_GUI_display_name
Browse files Browse the repository at this point in the history
Display sample title instead of filename in DataExplorer window (ESS_GUI)
  • Loading branch information
butlerpd authored Aug 18, 2020
2 parents 5dc774d + 1fcc82b commit c11045a
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 84 deletions.
43 changes: 19 additions & 24 deletions src/sas/qtgui/MainWindow/DataExplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ def flatDataForModel(self, model):
data = GuiUtils.dataFromItem(item)
if data is None: continue
# Now, all plots under this item
filename = data.filename
all_data[filename] = data
other_datas = GuiUtils.plotsFromFilename(filename, model)
name = data.name
all_data[name] = data
other_datas = GuiUtils.plotsFromDisplayName(name, model)
# skip the main plot
other_datas = list(other_datas.values())[1:]
for data in other_datas:
Expand All @@ -391,12 +391,12 @@ def allDataForModel(self, model):
data = GuiUtils.dataFromItem(item)
if data is None: continue
# Now, all plots under this item
filename = data.filename
name = data.name
is_checked = item.checkState()
properties['checked'] = is_checked
other_datas = []
# save underlying theories
other_datas = GuiUtils.plotsFromFilename(filename, model)
other_datas = GuiUtils.plotsFromDisplayName(name, model)
# skip the main plot
other_datas = list(other_datas.values())[1:]
all_data[data.id] = [data, properties, other_datas]
Expand All @@ -413,10 +413,10 @@ def getDataForID(self, id):
if data is None: continue
if data.id != id: continue
# We found the dataset - save it.
filename = data.filename
name = data.name
is_checked = item.checkState()
properties['checked'] = is_checked
other_datas = GuiUtils.plotsFromFilename(filename, model)
other_datas = GuiUtils.plotsFromDisplayName(name, model)
# skip the main plot
other_datas = list(other_datas.values())[1:]
all_data = [data, properties, other_datas]
Expand Down Expand Up @@ -622,15 +622,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 @@ -976,20 +976,20 @@ def updatePerspectiveCombo(self, index):
if not self.parent.perspective().allowSwap():
self.chkSwap.setCheckState(False)

def itemFromFilename(self, filename):
def itemFromDisplayName(self, name):
"""
Retrieves model item corresponding to the given filename
Retrieves model item corresponding to the given display name
"""
item = GuiUtils.itemFromFilename(filename, self.model)
item = GuiUtils.itemFromDisplayName(name, self.model)
return item

def displayFile(self, filename=None, is_data=True, id=None):
def displayData(self, name=None, is_data=True, id=None):
"""
Forces display of charts for the given filename
Forces display of charts for the given name
"""
model = self.model if is_data else self.theory_model
# Now query the model item for available plots
plots = GuiUtils.plotsFromFilename(filename, model)
plots = GuiUtils.plotsFromDisplayName(name, model)
# Each fitpage contains the name based on fit widget number
fitpage_name = "" if id is None else "M"+str(id)
new_plots = []
Expand All @@ -1006,8 +1006,8 @@ def displayFile(self, filename=None, is_data=True, id=None):
# Don't include plots from different fitpages,
# but always include the original data
if (fitpage_name in plot.name
or filename in plot.name
or filename == plot.filename):
or name in plot.name
or name == plot.filename):
# Residuals get their own plot
if plot.plot_role == Data1D.ROLE_RESIDUAL:
plot.yscale='linear'
Expand Down Expand Up @@ -1281,11 +1281,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 @@ -1295,7 +1290,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 @@ -1507,7 +1502,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
6 changes: 3 additions & 3 deletions src/sas/qtgui/MainWindow/GuiManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def addCallbacks(self):
self.communicate.updateTheoryFromPerspectiveSignal.connect(self.updateTheoryFromPerspective)
self.communicate.deleteIntermediateTheoryPlotsSignal.connect(self.deleteIntermediateTheoryPlotsByModelID)
self.communicate.plotRequestedSignal.connect(self.showPlot)
self.communicate.plotFromFilenameSignal.connect(self.showPlotFromFilename)
self.communicate.plotFromNameSignal.connect(self.showPlotFromName)
self.communicate.updateModelFromDataOperationPanelSignal.connect(self.updateModelFromDataOperationPanel)
self.communicate.activeGraphsSignal.connect(self.updatePlotItems)

Expand Down Expand Up @@ -1169,12 +1169,12 @@ def updateModelFromDataOperationPanel(self, new_item, new_datalist_item):
self.filesWidget.model.appendRow(new_item)
self._data_manager.add_data(new_datalist_item)

def showPlotFromFilename(self, filename):
def showPlotFromName(self, name):
"""
Pass the show plot request to the data explorer
"""
if hasattr(self, "filesWidget"):
self.filesWidget.displayFile(filename=filename, is_data=True)
self.filesWidget.displayData(name=name, is_data=True)

def showPlot(self, plot, id):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sas/qtgui/Perspectives/Corfunc/CorfuncPerspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ def setData(self, data_item, is_batch=False):

model_item = data_item[0]
data = GuiUtils.dataFromItem(model_item)
self._path = data.name
self._model_item = model_item
self._calculator.set_data(data)
self.cmdCalculateBg.setEnabled(True)
Expand All @@ -500,7 +501,6 @@ def setData(self, data_item, is_batch=False):
self._canvas.extrap = None
self.model_changed(None)
self.cmdTransform.setEnabled(False)
self._path = data.name
self._realplot.data = None
self._realplot.draw_real_space()

Expand Down
2 changes: 1 addition & 1 deletion src/sas/qtgui/Perspectives/Fitting/FitPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self):

self.page_id = 0
self.data_is_loaded = False
self.filename = ""
self.name = ""
self.data = None
self.parameters_to_fit = []
self.kernel_module = None
Expand Down
2 changes: 1 addition & 1 deletion src/sas/qtgui/Perspectives/Fitting/FittingLogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _create1DPlot(self, tab_id, x, y, model, data, component=None):
new_plot.id = str(tab_id) + " " + ("[" + component + "] " if component else "") + model.id

# use data.filename for data, use model.id for theory
id_str = data.filename if data.filename else model.id
id_str = data.name if data.name else model.id
new_plot.name = model.name + ((" " + component) if component else "") + " [" + id_str + "]"

new_plot.title = new_plot.name
Expand Down
2 changes: 1 addition & 1 deletion src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ def plotResiduals(reference_data, current_data, weights):
return None

theory_name = str(current_data.name.split()[0])
res_name = reference_data.filename if reference_data.filename else reference_data.name
res_name = reference_data.name if reference_data.name else reference_data.filename
residuals.name = "Residuals for " + str(theory_name) + "[" + res_name + "]"
residuals.title = residuals.name
residuals.ytransform = 'y'
Expand Down
32 changes: 16 additions & 16 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 @@ -2156,7 +2156,7 @@ def showTheoryPlot(self):
if self.theory_item is None:
self.recalculatePlotData()
elif self.model_data:
self._requestPlots(self.model_data.filename, self.theory_item.model())
self._requestPlots(self.model_data.name, self.theory_item.model())

def showPlot(self):
"""
Expand All @@ -2166,7 +2166,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 All @@ -2176,7 +2176,7 @@ def _requestPlots(self, item_name, item_model):
Emits plotRequestedSignal for all plots found in the given model under the provided item name.
"""
fitpage_name = self.kernel_module.name
plots = GuiUtils.plotsFromFilename(item_name, item_model)
plots = GuiUtils.plotsFromDisplayName(item_name, item_model)
# Has the fitted data been shown?
data_shown = False
item = None
Expand Down Expand Up @@ -2721,7 +2721,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 @@ -2770,7 +2770,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 @@ -3604,7 +3604,7 @@ def readFitPage(self, fp):
"""
assert isinstance(fp, FitPage)
# Main tab info
self.logic.data.filename = fp.filename
self.logic.data.name = 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 @@ -3646,7 +3646,7 @@ def saveToFitPage(self, fp):
assert isinstance(fp, FitPage)

# Main tab info
fp.filename = self.logic.data.filename
fp.name = 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 @@ -3882,20 +3882,20 @@ def getFitPage(self):

param_list.append(['is_data', str(self.data_is_loaded)])
data_ids = []
filenames = []
names = []
if self.is_batch_fitting:
for item in self.all_data:
# need item->data->data_id
data = GuiUtils.dataFromItem(item)
data_ids.append(data.id)
filenames.append(data.filename)
names.append(data.name)
else:
if self.data_is_loaded:
data_ids = [str(self.logic.data.id)]
filenames = [str(self.logic.data.filename)]
names = [str(self.logic.data.name)]
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])
param_list.append(['data_name', names])
param_list.append(['data_id', data_ids])
param_list.append(['tab_name', self.modelName()])
# option tab
Expand Down
2 changes: 1 addition & 1 deletion src/sas/qtgui/Perspectives/Fitting/ReportPageLogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def reportHeader(self):

def buildPlotsForReport(self, images):
""" Convert Matplotlib figure 'fig' into a <img> tag for HTML use using base64 encoding. """
html = FEET_1 % self.data.filename
html = FEET_1 % self.data.name

for fig in images:
canvas = FigureCanvas(fig)
Expand Down
22 changes: 11 additions & 11 deletions src/sas/qtgui/Perspectives/Invariant/InvariantPerspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ def plotResult(self, model):
self.model = model
self.mapper.toFirst()
self._data = GuiUtils.dataFromItem(self._model_item)
filename = self._data.filename
name = self._data.name
# Send the modified model item to DE for keeping in the model
# Currently -unused
# self.communicate.updateModelFromPerspectiveSignal.emit(self._model_item)

plot_data = GuiUtils.plotsFromFilename(filename, self._manager.filesWidget.model)
plot_data = GuiUtils.plotsFromDisplayName(name, self._manager.filesWidget.model)

# only the Low-Q/High-Q data for plotting
data_to_plot = [(self._model_item, p) for p in plot_data.values() if p.plot_role == p.ROLE_DATA]
Expand Down Expand Up @@ -665,7 +665,7 @@ def setupModel(self):
""" """
# filename
item = QtGui.QStandardItem(self._path)
self.model.setItem(WIDGETS.W_FILENAME, item)
self.model.setItem(WIDGETS.W_NAME, item)

# add Q parameters to the model
qmin = 0.0
Expand Down Expand Up @@ -720,7 +720,7 @@ def setupMapper(self):
self.mapper.setModel(self.model)

# Filename
self.mapper.addMapping(self.txtName, WIDGETS.W_FILENAME)
self.mapper.addMapping(self.txtName, WIDGETS.W_NAME)

# Qmin/Qmax
self.mapper.addMapping(self.txtTotalQMin, WIDGETS.W_QMIN)
Expand Down Expand Up @@ -785,7 +785,7 @@ def setData(self, data_item=None, is_batch=False):

# Extract data on 1st child - this is the Data1D/2D component
data = GuiUtils.dataFromItem(self._model_item)
self.model.item(WIDGETS.W_FILENAME).setData(self._model_item.text())
self.model.item(WIDGETS.W_NAME).setData(self._model_item.text())
# update GUI and model with info from loaded data
self.updateGuiFromFile(data=data)

Expand All @@ -801,23 +801,23 @@ def updateGuiFromFile(self, data=None):
raise ValueError(msg)

try:
filename = data.filename
name = data.name
except:
msg = 'No filename chosen.'
msg = 'No data name chosen.'
raise ValueError(msg)
try:
qmin = min(self._data.x)
qmax = max(self._data.x)
except:
msg = "Unable to find q min/max of \n data named %s" % \
data.filename
data.name
raise ValueError(msg)

# update model with input form files: filename, qmin, qmax
self.model.item(WIDGETS.W_FILENAME).setText(filename)
# update model with input form files: name, qmin, qmax
self.model.item(WIDGETS.W_NAME).setText(name)
self.model.item(WIDGETS.W_QMIN).setText(str(qmin))
self.model.item(WIDGETS.W_QMAX).setText(str(qmax))
self._path = filename
self._path = data.filename

# Calculate and add to GUI: volume fraction, invariant total,
# and specific surface if porod checked
Expand Down
Loading

0 comments on commit c11045a

Please sign in to comment.