Skip to content

Commit

Permalink
Merge pull request #2210 from SasView/2103-copy-parameters-from-corfu…
Browse files Browse the repository at this point in the history
…nc-gives-wrong-values

2103 copy parameters from corfunc gives wrong values
  • Loading branch information
lucas-wilkins authored Sep 26, 2022
2 parents d7b5341 + fde2e20 commit ee4bd64
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 133 deletions.
39 changes: 24 additions & 15 deletions src/sas/qtgui/MainWindow/GuiManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import webbrowser
import traceback

from typing import Optional
from typing import Optional, Dict

from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
Expand Down Expand Up @@ -102,7 +102,7 @@ def __init__(self, parent=None):

# Currently displayed perspective
self._current_perspective: Optional[Perspective] = None
self.loadedPerspectives = {}
self.loadedPerspectives: Dict[str, Perspective] = {}

# Populate the main window with stuff
self.addWidgets()
Expand Down Expand Up @@ -277,7 +277,6 @@ def plotSelectedSlot(self, plot_name):
PlotHelper.plotById(plot).showNormal()
PlotHelper.plotById(plot).setFocus()
return
pass

def removePlotItemsInWindowsMenu(self, plot):
"""
Expand All @@ -293,7 +292,6 @@ def removePlotItemsInWindowsMenu(self, plot):
action.triggered.disconnect()
self._workspace.menuWindow.removeAction(action)
return
pass

def updateLogContextMenus(self, visible=False):
"""
Expand Down Expand Up @@ -382,7 +380,16 @@ def perspectiveChanged(self, new_perspective_name: str):
# but new_perspective is of type Perspective, thus call to Perspective members are safe
new_perspective = self.loadedPerspectives[new_perspective_name]

# Report options
self._workspace.actionReport.setEnabled(new_perspective.supports_reports)

# Copy paste options
self._workspace.actionCopy.setEnabled(new_perspective.supports_copy)
self._workspace.actionLatex.setEnabled(new_perspective.supports_copy_latex)
self._workspace.actionExcel.setEnabled(new_perspective.supports_copy_excel)
self._workspace.actionPaste.setEnabled(new_perspective.supports_paste)

# Serialisation/saving things
self._workspace.actionOpen_Analysis.setEnabled(False)
self._workspace.actionSave_Analysis.setEnabled(False)

Expand Down Expand Up @@ -417,6 +424,7 @@ def perspectiveChanged(self, new_perspective_name: str):
self.checkAnalysisOption(self._workspace.actionCorfunc)



#
# Set up the window
#
Expand Down Expand Up @@ -818,19 +826,17 @@ def actionRedo(self):

def actionCopy(self):
"""
Send a signal to the fitting perspective so parameters
can be saved to the clipboard
Response to copy menu / button trigger
"""
self.communicate.copyFitParamsSignal.emit("")
#self._workspace.actionPaste.setEnabled(True)
pass
if self._current_perspective is not None:
self._current_perspective.clipboard_copy()

def actionPaste(self):
"""
Send a signal to the fitting perspective so parameters
from the clipboard can be used to modify the fit state
Response to paste menu / button trigger
"""
self.communicate.pasteFitParamsSignal.emit()
if self._current_perspective is not None:
self._current_perspective.clipboard_paste()

def actionReport(self):
"""
Expand Down Expand Up @@ -860,20 +866,23 @@ def actionExcel(self):
Send a signal to the fitting perspective so parameters
can be saved to the clipboard
"""
self.communicate.copyExcelFitParamsSignal.emit("Excel")
if self._current_perspective is not None:
self._current_perspective.excel_clipboard_copy()

def actionLatex(self):
"""
Send a signal to the fitting perspective so parameters
can be saved to the clipboard
"""
self.communicate.copyLatexFitParamsSignal.emit("Latex")
if self._current_perspective is not None:
self._current_perspective.latex_clipboard_copy()

def actionSaveParamsAs(self):
"""
Menu Save Params
"""
self.communicate.SaveFitParamsSignal.emit("Save")
if self._current_perspective is not None:
self._current_perspective.save_parameters()

#============ VIEW =================
def actionShow_Grid_Window(self):
Expand Down
48 changes: 31 additions & 17 deletions src/sas/qtgui/Perspectives/Fitting/FittingPerspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ def __init__(self, parent=None, data=None):
self.fittingStartedSignal.connect(self.onFittingStarted)
self.fittingStoppedSignal.connect(self.onFittingStopped)

self.communicate.copyFitParamsSignal.connect(self.onParamCopy)
self.communicate.pasteFitParamsSignal.connect(self.onParamPaste)
self.communicate.copyExcelFitParamsSignal.connect(self.onExcelCopy)
self.communicate.copyLatexFitParamsSignal.connect(self.onLatexCopy)
self.communicate.SaveFitParamsSignal.connect(self.onParamSave)

# Perspective window not allowed to close by default
self._allow_close = False

Expand Down Expand Up @@ -119,17 +113,25 @@ def setClosable(self, value=True):

self._allow_close = value

def onParamCopy(self):
self.currentTab.onCopyToClipboard("")
def clipboard_copy(self):
if self.currentFittingWidget is not None:
self.currentFittingWidget.clipboard_copy()

def clipboard_paste(self):
if self.currentFittingWidget is not None:
self.currentFittingWidget.clipboard_paste()

def onParamPaste(self):
self.currentTab.onParameterPaste()
def excel_clipboard_copy(self):
if self.currentFittingWidget is not None:
self.currentFittingWidget.clipboard_copy_excel()

def onExcelCopy(self):
self.currentTab.onCopyToClipboard("Excel")
def latex_clipboard_copy(self):
if self.currentFittingWidget is not None:
self.currentFittingWidget.clipboard_copy_latex()

def onLatexCopy(self):
self.currentTab.onCopyToClipboard("Latex")
def save_parameters(self):
if self.currentFittingWidget is not None:
self.currentFittingWidget.save_parameters()

def serializeAll(self):
return self.serializeAllFitpage()
Expand Down Expand Up @@ -219,9 +221,6 @@ def updateFromConstraints(self, constraint_dict):
row=tab.getRowFromName(
constraint_param[1]))

def onParamSave(self):
self.currentTab.onCopyToClipboard("Save")

def closeEvent(self, event):
"""
Overwrite QDialog close method to allow for custom widget close
Expand Down Expand Up @@ -586,3 +585,18 @@ def getReport(self) -> Optional[ReportData]:
def supports_fitting_menu(self) -> bool:
return True

@property
def supports_copy(self) -> bool:
return True

@property
def supports_copy_excel(self) -> bool:
return True

@property
def supports_copy_latex(self) -> bool:
return True

@property
def supports_paste(self) -> bool:
return True
29 changes: 9 additions & 20 deletions src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,31 +854,21 @@ def getOrientationParam(kernel_module=None):

return param

def formatParameters(parameters, Check=True):
def formatParameters(parameters: list, entry_sep=',', line_sep=':'):
"""
Prepare the parameter string in the standard SasView layout
"""
assert parameters is not None
assert isinstance(parameters, list)
output_string = "sasview_parameter_values:"

parameter_strings = ["sasview_parameter_values"]
for parameter in parameters:
# recast tuples into strings
parameter = [str(p) for p in parameter]
output_string += ",".join([p for p in parameter if p is not None])
output_string += ":"

if Check == False:
new_string = output_string.replace(':', '\n')
return new_string
else:
return output_string
parameter_strings.append(entry_sep.join([str(component) for component in parameter]))

def formatParametersExcel(parameters):
return line_sep.join(parameter_strings)

def formatParametersExcel(parameters: list):
"""
Prepare the parameter string in the Excel format (tab delimited)
"""
assert parameters is not None
assert isinstance(parameters, list)
crlf = chr(13) + chr(10)
tab = chr(9)

Expand Down Expand Up @@ -906,12 +896,11 @@ def formatParametersExcel(parameters):
output_string = names + crlf + values + crlf + check
return output_string

def formatParametersLatex(parameters):
def formatParametersLatex(parameters: list):
"""
Prepare the parameter string in latex
"""
assert parameters is not None
assert isinstance(parameters, list)

output_string = r'\begin{table}'
output_string += r'\begin{tabular}[h]'

Expand Down
Loading

0 comments on commit ee4bd64

Please sign in to comment.