From ff34a0ff8772ef1d3f236ecbe6afd5578b34e5f5 Mon Sep 17 00:00:00 2001
From: Anthony Lim <anthony.lim@stfc.ac.uk>
Date: Tue, 10 Oct 2017 11:34:28 +0100
Subject: [PATCH] refs #20655 cleaned up FDA code

---
 scripts/Muon/fft_presenter.py                 |  8 +------
 scripts/Muon/load_utils.py                    | 24 ++++++++++++++++++-
 scripts/Muon/maxent_presenter.py              | 22 +++++++----------
 scripts/Muon/maxent_view.py                   | 13 ++++++----
 scripts/Muon/model_constructor.py             |  7 +++---
 scripts/Muon/table_utils.py                   |  7 +++---
 scripts/Muon/thread_model.py                  |  8 +++++--
 scripts/Muon/transform_presenter.py           | 13 +++++++---
 scripts/Muon/transform_selection_presenter.py |  5 +++-
 scripts/Muon/transform_selection_view.py      |  5 ++++
 scripts/Muon/transform_view.py                |  9 ++++++-
 scripts/Muon/view_constructor.py              |  1 +
 12 files changed, 83 insertions(+), 39 deletions(-)

diff --git a/scripts/Muon/fft_presenter.py b/scripts/Muon/fft_presenter.py
index f02e75ea60c..944567a4e8d 100644
--- a/scripts/Muon/fft_presenter.py
+++ b/scripts/Muon/fft_presenter.py
@@ -31,14 +31,8 @@ class FFTPresenter(object):
     def deactivate(self):
         self.view.deactivateButton()
 
-    # only get ws that are groups or pairs
-    # ignore raw
     def getWorkspaceNames(self):
-        runName,options = self.load.getCurrentWS()
-        final_options = []
-        for pick in options:
-            if ";" in pick and "Raw" not in pick and runName in pick:
-                final_options.append(pick)
+        final_options=self.load.getWorkspaceNames()
         self.view.addItems(final_options)
 
     #functions
diff --git a/scripts/Muon/load_utils.py b/scripts/Muon/load_utils.py
index 34dfd9b561b..03a7d9a7788 100644
--- a/scripts/Muon/load_utils.py
+++ b/scripts/Muon/load_utils.py
@@ -3,7 +3,11 @@ import mantid.simpleapi as mantid
 
 
 class LoadUtils(object):
-
+    """ 
+    A simple class for identifing the current run
+    and it can return the name, run and instrument.
+    The current run is the same as the one in MonAnalysis
+    """
     def __init__(self, parent=None):
         if self.MuonAnalysisExists():
             # get everything from the ADS
@@ -16,6 +20,7 @@ class LoadUtils(object):
         else:
             mantid.logger.error("Muon Analysis workspace does not exist - no data loaded")
 
+    # get methods
     def getCurrentWS(self):
         return self.runName, self.options
 
@@ -25,8 +30,25 @@ class LoadUtils(object):
     def getInstrument(self):
         return self.instrument
 
+    # check if muon analysis exists
     def MuonAnalysisExists(self):
+        # if period data look for the first period
         if mantid.AnalysisDataService.doesExist("MuonAnalysis_1"):
             return True
         else:
+            # if its not period data
             return mantid.AnalysisDataService.doesExist("MuonAnalysis")
+
+    # Get the groups/pairs for active WS
+    # ignore raw files
+    def getWorkspaceNames(self):
+        # gets all WS in the ADS
+        runName,options = self.getCurrentWS()
+        final_options=[]
+        # only keep the relevant WS (same run as Muon Analysis)
+        for pick in options:
+            if ";" in pick and "Raw" not in pick and runName in pick:
+                final_options.append(pick)
+        return final_options
+
+
diff --git a/scripts/Muon/maxent_presenter.py b/scripts/Muon/maxent_presenter.py
index f846f5dd798..6ab8d1409c7 100644
--- a/scripts/Muon/maxent_presenter.py
+++ b/scripts/Muon/maxent_presenter.py
@@ -4,7 +4,11 @@ from Muon import thread_model
 
 
 class MaxEntPresenter(object):
-
+    """
+    This is the presenter for the maximum entropy widget.
+    It connects the view and model together and deals with
+    logic. 
+    """
     def __init__(self,view,alg,load):
         self.view=view
         self.alg=alg
@@ -14,20 +18,11 @@ class MaxEntPresenter(object):
         #connect
         self.view.maxEntButtonSignal.connect(self.handleMaxEntButton)
 
-    # only get ws that are groups or pairs
-    # ignore raw
-    # move the generating of the list to a helper?
+    #functions
     def getWorkspaceNames(self):
-        # gets all WS in the ADS
-        runName,options = self.load.getCurrentWS()
-        final_options=[]
-        # only keep the relevant WS (same run as Muon Analysis)
-        for pick in options:
-            if ";" in pick and "Raw" not in pick and runName in pick:
-                final_options.append(pick)
+        final_options=self.load.getWorkspaceNames()
         self.view.addItems(final_options)
 
-    #functions
     def createThread(self):
         return thread_model.ThreadModel(self.alg)
 
@@ -42,8 +37,9 @@ class MaxEntPresenter(object):
         self.thread.start()
 
     def handleFinished(self):
-        self.thread.deleteLater
         self.activate()
+        self.thread.deleteLater
+        self.thread=None
 
     def activate(self):
         self.view.activateButton()
diff --git a/scripts/Muon/maxent_view.py b/scripts/Muon/maxent_view.py
index a91c3a38188..7046c7d1cdd 100644
--- a/scripts/Muon/maxent_view.py
+++ b/scripts/Muon/maxent_view.py
@@ -6,6 +6,10 @@ from Muon import table_utils
 
 
 class MaxEntView(QtGui.QWidget):
+    """
+    The view for the MaxEnt widget. This
+    creates the look of the widget
+    """
     # signals
     maxEntButtonSignal = QtCore.pyqtSignal()
 
@@ -14,7 +18,6 @@ class MaxEntView(QtGui.QWidget):
         self.grid = QtGui.QGridLayout(self)
 
         #make table
-
         self.table = QtGui.QTableWidget(self)
         self.table.resize(800, 800)
 
@@ -25,11 +28,9 @@ class MaxEntView(QtGui.QWidget):
         self.table.verticalHeader().setVisible(False)
         self.table.horizontalHeader().setStretchLastSection(True)
         self.table.setHorizontalHeaderLabels(("MaxEnt Property;Value").split(";"))
-
         table_utils.setTableHeaders(self.table)
 
         # populate table
-
         table_utils.setRowName(self.table,0,"Complex Data")
         self.complex_data_box= table_utils.addCheckBoxToTable(self.table,False,0)
         self.complex_data_box.setFlags(QtCore.Qt.ItemIsEnabled)
@@ -97,7 +98,6 @@ class MaxEntView(QtGui.QWidget):
 
         #layout
         # this is if complex data is unhidden
-        #self.table.setMinimumSize(40,228)
         self.table.setMinimumSize(40,203)
         self.tableA.setMinimumSize(40,207)
         self.horizontalSpacer1 = QtGui.QSpacerItem(20, 30, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
@@ -105,7 +105,7 @@ class MaxEntView(QtGui.QWidget):
         #make button
         self.button = QtGui.QPushButton('Calculate MaxEnt', self)
         self.button.setStyleSheet("background-color:lightgrey")
-#        #connects
+#       #connects
         self.button.clicked.connect(self.MaxEntButtonClick)
         # add to layout
         self.grid.addWidget(self.table)
@@ -120,9 +120,11 @@ class MaxEntView(QtGui.QWidget):
         self.ws.clear()
         self.ws.addItems(options)
 
+    # send signal
     def MaxEntButtonClick(self):
         self.maxEntButtonSignal.emit()
 
+    # get some inputs for model
     def initMaxEntInput(self):
         inputs={}
 
@@ -159,6 +161,7 @@ class MaxEntView(QtGui.QWidget):
     def isRaw(self):
         return self.raw_box.checkState() == QtCore.Qt.Checked
 
+    # turn button on and off
     def activateButton(self):
         self.button.setEnabled(True)
 
diff --git a/scripts/Muon/model_constructor.py b/scripts/Muon/model_constructor.py
index 85f2891e9cb..5146eaf29a0 100644
--- a/scripts/Muon/model_constructor.py
+++ b/scripts/Muon/model_constructor.py
@@ -12,17 +12,18 @@ class ModelConstructor(object):
      Only need to pass a single object to all
      presenters
     """
-
     def __init__(self,includeTransform):
         # construct transformation memebers
         if includeTransform:
             self.transformModels={}
-
+            # generate the models
             MaxEnt =maxent_model.MaxEntModel()
-            self.transformModels["MaxEnt"]=MaxEnt
             FFT =fft_model.FFTModel()
             FFTWrapper=fft_model.FFTWrapper(FFT)
+            # adds the models to the transformation tab
+            self.transformModels["MaxEnt"]=MaxEnt
             self.transformModels[FFT.getName()]=FFTWrapper
 
+    # gets the model
     def getModel(self,name):
         return self.transformModels[name]
diff --git a/scripts/Muon/table_utils.py b/scripts/Muon/table_utils.py
index 822c0b7ea45..32729501cc1 100644
--- a/scripts/Muon/table_utils.py
+++ b/scripts/Muon/table_utils.py
@@ -7,8 +7,6 @@ import os
 This module contains the methods for
 adding information to tables.
 """
-
-
 def setRowName(table,row,name):
     text = QtGui.QTableWidgetItem((name))
     text.setFlags(QtCore.Qt.ItemIsEnabled)
@@ -48,8 +46,11 @@ def addSpinBoxToTable(table,default,row):
     table.setCellWidget(row,1,box)
     return box
 
-
+# This is a work around a Windows 10
+# bug that stops tables having underlines for
+# the headers. 
 def setTableHeaders(table):
+        # is it not windows
         if os.name != "nt":
             return
         version=QtCore.QSysInfo.WindowsVersion
diff --git a/scripts/Muon/thread_model.py b/scripts/Muon/thread_model.py
index af23eaad707..601c2bb9d02 100644
--- a/scripts/Muon/thread_model.py
+++ b/scripts/Muon/thread_model.py
@@ -4,9 +4,11 @@ from PyQt4.QtCore import QThread
 
 
 class ThreadModel(QThread):
-    # a wrapper to allow threading with
-    # the MaxEnt algorithm.
 
+    """
+    A wrapper to allow threading with
+    the MaxEnt models.
+    """
     def __init__(self,model):
         QThread.__init__(self)
         self.model=model
@@ -19,8 +21,10 @@ class ThreadModel(QThread):
         self.model.output()
         return
 
+    # if there is one set of inputs (1 alg)
     def setInputs(self,inputs,runName):
         self.model.setInputs(inputs,runName)
 
+    # if there are multiple inputs (alg>1)
     def loadData(self,inputs):
         self.model.loadData(inputs)
diff --git a/scripts/Muon/transform_presenter.py b/scripts/Muon/transform_presenter.py
index 8f426b3974f..2a9375de76a 100644
--- a/scripts/Muon/transform_presenter.py
+++ b/scripts/Muon/transform_presenter.py
@@ -7,22 +7,29 @@ from Muon import transform_selection_presenter
 
 
 class TransformPresenter(object):
-
+    """
+    The widget for controlling which method to display
+    in the transformation tab
+    """
     def __init__(self,view,model):
         self.view=view
         self.load=load_utils.LoadUtils()
         if self.load.MuonAnalysisExists() == False:
             return
 
+        # create presenters for the views
         self.FFTPresenter=fft_presenter.FFTPresenter(self.view.getView("FFT"),model.getModel("FFT"),self.load)
-
         self.MaxEntPresenter=maxent_presenter.MaxEntPresenter(self.view.getView("MaxEnt"),model.getModel("MaxEnt"),self.load)
+        # get the transform selection view
         self.selectionPresenter=transform_selection_presenter.TransformSelectionPresenter(self.view.selection)
+        # gets a list of the views/methods
         self.methodsList=self.view.getMethods()
+        # sets the transform selection view to have the correct options
         self.selectionPresenter.setMethodsCombo(self.methodsList)
-
+        # connect
         self.view.selection.changeMethodSignal.connect(self.updateDisplay)
 
+    #switch the view
     def updateDisplay(self,index):
         self.view.hideAll()
         self.view.show(self.methodsList[index])
diff --git a/scripts/Muon/transform_selection_presenter.py b/scripts/Muon/transform_selection_presenter.py
index 815f1274ea9..ad932cd9102 100644
--- a/scripts/Muon/transform_selection_presenter.py
+++ b/scripts/Muon/transform_selection_presenter.py
@@ -2,7 +2,10 @@ from __future__ import (absolute_import, division, print_function)
 
 
 class TransformSelectionPresenter(object):
-
+    """
+    The widget for selecting the widget 
+    shown in the transformation tab
+    """
     def __init__(self,view):
         self.view=view
 
diff --git a/scripts/Muon/transform_selection_view.py b/scripts/Muon/transform_selection_view.py
index 9e3c0143547..5aa08de1ce1 100644
--- a/scripts/Muon/transform_selection_view.py
+++ b/scripts/Muon/transform_selection_view.py
@@ -4,6 +4,9 @@ from PyQt4 import QtCore, QtGui
 
 
 class TransformSelectionView(QtGui.QWidget):
+    """
+    Create the transformation selection widget's appearance
+    """
     # signals
     changeMethodSignal = QtCore.pyqtSignal(object)
 
@@ -11,11 +14,13 @@ class TransformSelectionView(QtGui.QWidget):
         super(TransformSelectionView, self).__init__(parent)
         self.grid = QtGui.QGridLayout(self)
         self.methods = QtGui.QComboBox()
+        # default to FFT
         options=["FFT"]
         self.methods.addItems(options)
         self.grid.addWidget(self.methods)
         self.methods.currentIndexChanged.connect(self.sendSignal)
 
+    # sets the methods in the selection widget
     def setMethodsCombo(self,options):
         self.methods.clear()
         self.methods.addItems(options)
diff --git a/scripts/Muon/transform_view.py b/scripts/Muon/transform_view.py
index dfad6c80fb1..035e93920bf 100644
--- a/scripts/Muon/transform_view.py
+++ b/scripts/Muon/transform_view.py
@@ -4,12 +4,19 @@ from PyQt4 import QtGui
 
 
 class TransformView(QtGui.QWidget):
+    """
+    Creates the view for the transformation tab.
+    At the top is the transform selection widget
+    and below it is the selected GUI (FFT or MaxEnt)
+    """
     def __init__(self,groupedViews,parent=None):
         super(TransformView,self).__init__(parent)
-        self.methods = groupedViews.getTransformMethods()
+        # set selector
         self.selection = groupedViews.getTransformSelection()
         self.Layout = QtGui.QGridLayout()
         self.Layout.addWidget(self.selection,1,0)
+        # add the transform widgets to the tab
+        self.methods = groupedViews.getTransformMethods()
         for key in self.methods:
             self.Layout.addWidget(self.methods[key])
         self.setLayout(self.Layout)
diff --git a/scripts/Muon/view_constructor.py b/scripts/Muon/view_constructor.py
index 022a00f1dc5..44970df2b81 100644
--- a/scripts/Muon/view_constructor.py
+++ b/scripts/Muon/view_constructor.py
@@ -19,6 +19,7 @@ class ViewConstructor(object):
             self.transformMethods = {}
             self.transformMethods["FFT"] = fft_view.FFTView(parent)
             self.transformMethods["MaxEnt"] = maxent_view.MaxEntView(parent)
+            # create default transform selection widget
             self.transformSelector = transform_selection_view.TransformSelectionView(parent)
 
     def getTransformMethods(self):
-- 
GitLab