Skip to content

Commit

Permalink
Replace all(?) references to filename when display name is more appro…
Browse files Browse the repository at this point in the history
…priate.
  • Loading branch information
krzywon committed Aug 6, 2020
1 parent dc9b3e6 commit 2811b07
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 63 deletions.
30 changes: 15 additions & 15 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.name
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.name
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.name
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 @@ -975,20 +975,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 @@ -1005,8 +1005,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
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
16 changes: 8 additions & 8 deletions src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,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 @@ -2147,7 +2147,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 @@ -3575,7 +3575,7 @@ def readFitPage(self, fp):
"""
assert isinstance(fp, FitPage)
# Main tab info
self.logic.data.filename = fp.name
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 @@ -3617,7 +3617,7 @@ def saveToFitPage(self, fp):
assert isinstance(fp, FitPage)

# Main tab info
fp.filename = self.logic.data.name
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 @@ -3853,20 +3853,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.name)
names.append(data.name)
else:
if self.data_is_loaded:
data_ids = [str(self.logic.data.id)]
filenames = [str(self.logic.data.name)]
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
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
2 changes: 1 addition & 1 deletion src/sas/qtgui/Perspectives/Invariant/InvariantUtils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sas.qtgui.Utilities.GuiUtils import enum

WIDGETS = enum( 'W_FILENAME',
WIDGETS = enum( 'W_NAME',
'W_QMIN',
'W_QMAX',
'W_BACKGROUND',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def testLowQToggle(self):

def testSetupModel(self):
""" Test default settings of model"""
self.assertEqual(self.widget.model.item(WIDGETS.W_FILENAME).text(),
self.assertEqual(self.widget.model.item(WIDGETS.W_NAME).text(),
self.widget._path)

self.assertEqual(self.widget.model.item(WIDGETS.W_QMIN).text(), '0.0')
Expand Down
20 changes: 10 additions & 10 deletions src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,13 @@ def enableButtons(self):
self.logic.data_is_loaded and
self._calculator.nfunc != self.nTermsSuggested)

def populateDataComboBox(self, filename, data_ref):
def populateDataComboBox(self, name, data_ref):
"""
Append a new file name to the data combobox
:param filename: data filename
Append a new name to the data combobox
:param name: data name
:param data_ref: QStandardItem reference for data set to be added
"""
self.dataList.addItem(filename, data_ref)
self.dataList.addItem(name, data_ref)

def acceptNoTerms(self):
"""Send estimated no of terms to input"""
Expand Down Expand Up @@ -434,7 +434,7 @@ def openExplorerWindow(self):
def showBatchOutput(self):
"""
Display the batch output in tabular form
:param output_data: Dictionary mapping filename -> P(r) instance
:param output_data: Dictionary mapping name -> P(r) instance
"""
if self.batchResultsWindow is None:
self.batchResultsWindow = BatchInversionOutputPanel(
Expand Down Expand Up @@ -487,7 +487,7 @@ def setData(self, data_item=None, is_batch=False):
if np.size(self.logic.data.dy) == 0 or np.all(self.logic.data.dy) == 0:
self.logic.add_errors()
self.updateDataList(data)
self.populateDataComboBox(self.logic.data.filename, data)
self.populateDataComboBox(self.logic.data.name, data)
self.dataList.setCurrentIndex(len(self.dataList) - 1)
#Checking for 1D again to mitigate the case when 2D data is last on the data list
if isinstance(self.logic.data, Data1D):
Expand All @@ -503,7 +503,7 @@ def updateDataList(self, dataRef):
DICT_KEYS[2]: self.dataPlot
}
# Update batch results window when finished
self.batchResults[self.logic.data.filename] = self._calculator
self.batchResults[self.logic.data.name] = self._calculator
if self.batchResultsWindow is not None:
self.showBatchOutput()

Expand Down Expand Up @@ -689,7 +689,7 @@ def getPage(self):
"""
# Get all parameters from page
param_dict = self.getState()
param_dict['data_name'] = str(self.logic.data.filename)
param_dict['data_name'] = str(self.logic.data.name)
param_dict['data_id'] = str(self.logic.data.id)
return param_dict

Expand Down Expand Up @@ -1004,9 +1004,9 @@ def _calculateUpdate(self, output_tuple):

# Update P(r) and fit plots
self.prPlot = self.logic.newPRPlot(out, self._calculator, cov)
self.prPlot.filename = self.logic.data.filename
self.prPlot.name = self.logic.data.name
self.dataPlot = self.logic.new1DPlot(out, self._calculator)
self.dataPlot.filename = self.logic.data.filename
self.dataPlot.name = self.logic.data.name

# Udpate internals and GUI
self.updateDataList(self._data)
Expand Down
4 changes: 2 additions & 2 deletions src/sas/qtgui/Utilities/GridPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ def onPlot(self):
# look for the 'Data' column and extract the filename
for row in rows:
try:
filename = data['Data'][row]
name = data['Data'][row]
# emit a signal so the plots are being shown
self.communicate.plotFromFilenameSignal.emit(filename)
self.communicate.plotFromNameSignal.emit(name)
except (IndexError, AttributeError):
# data messed up.
return
Expand Down
Loading

0 comments on commit 2811b07

Please sign in to comment.