Changeset 811bec1 in sasview for src/sas/qtgui/Perspectives/Fitting
- Timestamp:
- Mar 17, 2017 4:22:23 AM (8 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 4d457df
- Parents:
- cd31251
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingPerspective.py
rcbcdd2c r811bec1 13 13 """ 14 14 name = "Fitting" # For displaying in the combo box in DataExplorer 15 def __init__(self, manager=None,parent=None, data=None):15 def __init__(self, parent=None, data=None): 16 16 super(FittingWindow, self).__init__() 17 17 18 self.manager = manager19 18 self.parent = parent 20 19 self._data = data … … 35 34 self.setTabsClosable(True) 36 35 36 self.communicate = self.parent.communicator() 37 37 38 # Initialize the first tab 38 39 self.addFit(None) … … 43 44 self.setWindowTitle('Fit panel - Active Fitting Optimizer: %s' % self.optimizer) 44 45 45 #self.communicate = GuiUtils.Communicate()46 self.communicate = self.parent.communicator()47 48 46 def addFit(self, data): 49 47 """ 50 48 Add a new tab for passed data 51 49 """ 52 tab = FittingWidget( manager=self.manager,parent=self.parent, data=data, id=self.maxIndex+1)50 tab = FittingWidget(parent=self.parent, data=data, id=self.maxIndex+1) 53 51 self.tabs.append(tab) 54 52 self.maxIndex += 1 -
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
rcd31251 r811bec1 38 38 Main widget for selecting form and structure factor models 39 39 """ 40 def __init__(self, manager=None, parent=None, data=None, id=1): 41 """ 42 43 :param manager: 44 :param parent: 45 :return: 46 """ 40 def __init__(self, parent=None, data=None, id=1): 41 47 42 super(FittingWidget, self).__init__() 48 43 … … 69 64 self.tab_id = id 70 65 71 # Parameters66 # Range parameters 72 67 self.q_range_min = QMIN_DEFAULT 73 68 self.q_range_max = QMAX_DEFAULT 74 69 self.npts = NPTS_DEFAULT 70 75 71 # Main Data[12]D holder 76 72 self._data = None … … 88 84 self._magnet_model = QtGui.QStandardItemModel() 89 85 90 # Set the proxy models for display91 # Main display92 self._model_proxy = QtGui.QSortFilterProxyModel()93 self._model_proxy.setSourceModel(self._model_model)94 #self._model_proxy.setFilterRegExp(r"[^()]")95 96 # Proxy display97 self._poly_proxy = QtGui.QSortFilterProxyModel()98 self._poly_proxy.setSourceModel(self._poly_model)99 self._poly_proxy.setFilterRegExp(r"[^()]")100 101 # Magnetism display102 self._magnet_proxy = QtGui.QSortFilterProxyModel()103 self._magnet_proxy.setSourceModel(self._magnet_model)104 #self._magnet_proxy.setFilterRegExp(r"[^()]")105 106 86 # Param model displayed in param list 107 87 self.lstParams.setModel(self._model_model) 108 #self.lstParams.setModel(self._model_proxy)109 88 self.readCategoryInfo() 110 89 self.model_parameters = None … … 112 91 113 92 # Poly model displayed in poly list 114 self.lstPoly.setModel(self._poly_ proxy)93 self.lstPoly.setModel(self._poly_model) 115 94 self.setPolyModel() 116 95 self.setTableProperties(self.lstPoly) … … 251 230 structure_factors = ["None"] 252 231 self.cbStructureFactor.clear() 253 for (structure_factor, _) in structure_factor_list: 254 structure_factors.append(structure_factor) 232 structure_factors = [factor[0] for factor in structure_factor_list] 255 233 self.cbStructureFactor.addItems(sorted(structure_factors)) 256 234 … … 365 343 If so, returns the name of the counter parameter and the number of shells 366 344 """ 367 iter_param = ""368 iter_length = 0369 370 345 iter_params = self.getIterParams(model) 371 # pull out the iterator parameter name and length 372 if iter_params: 373 iter_length = iter_params[0].length 374 iter_param = iter_params[0].length_control 375 return (iter_param, iter_length) 346 # return the iterator parameter name and length 347 return (iter_params[0].length_control if iter_params else "", 348 iter_params[0].length if iter_params else 0) 376 349 377 350 def addBackgroundToModel(self, model): … … 392 365 393 366 def addCheckedListToModel(self, model, param_list): 367 """ 368 Add a QItem to model. Makes the QItem checkable 369 """ 394 370 assert isinstance(model, QtGui.QStandardItemModel) 395 371 item_list = [QtGui.QStandardItem(item) for item in param_list] -
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingPerspectiveTest.py
- Property mode changed from 100644 to 100755
r6ee82dd r811bec1 1 1 import sys 2 2 import unittest 3 import webbrowser 3 4 4 5 from PyQt4 import QtGui … … 7 8 from mock import MagicMock 8 9 10 # set up import paths 11 import sas.qtgui.path_prepare 12 9 13 # Local 10 from FittingPerspective import FittingWindow 14 import sas.qtgui.GuiUtils as GuiUtils 15 from sas.sasgui.guiframe.dataFitting import Data1D 16 17 from sas.qtgui.Perspectives.Fitting.FittingPerspective import FittingWindow 11 18 12 19 app = QtGui.QApplication(sys.argv) 13 20 14 21 class FittingPerspectiveTest(unittest.TestCase): 15 """Test the Main Window GUI"""22 '''Test the Fitting Perspective''' 16 23 def setUp(self): 17 """Create the GUI""" 24 class dummy_manager(object): 25 def communicator(self): 26 return GuiUtils.Communicate() 27 def communicate(self): 28 return GuiUtils.Communicate() 18 29 19 self.widget = FittingWindow(None) 30 '''Create the perspective''' 31 self.widget = FittingWindow(dummy_manager()) 20 32 21 33 def tearDown(self): 22 """Destroy the GUI"""34 '''Destroy the perspective''' 23 35 self.widget.close() 24 36 self.widget = None 25 37 26 38 def testDefaults(self): 27 """Test the GUI in its default state"""39 '''Test the GUI in its default state''' 28 40 self.assertIsInstance(self.widget, QtGui.QWidget) 29 self.assertEqual(self.widget.windowTitle(), "Fitting") 30 self.assertEqual(self.widget.sizePolicy().Policy(), QtGui.QSizePolicy.Fixed) 41 self.assertIn("Fit panel", self.widget.windowTitle()) 42 self.assertEqual(self.widget.optimizer, "DREAM") 43 self.assertEqual(len(self.widget.tabs), 1) 44 self.assertEqual(self.widget.maxIndex, 1) 45 self.assertEqual(self.widget.tabName(), "FitPage1") 31 46 32 def testSelectCategory(self): 33 """ 34 Test if categories have been load properly 35 :return: 36 """ 37 fittingWindow = FittingWindow(None) 47 def testAddTab(self): 48 '''Add a tab and test it''' 38 49 39 #Test loading from json categories 40 category_list = fittingWindow.master_category_dict.keys() 41 self.assertTrue("Cylinder" in category_list) 42 self.assertTrue("Ellipsoid" in category_list) 43 self.assertTrue("Lamellae" in category_list) 44 self.assertTrue("Paracrystal" in category_list) 45 self.assertTrue("Parallelepiped" in category_list) 46 self.assertTrue("Shape Independent" in category_list) 47 self.assertTrue("Sphere" in category_list) 50 # Add an empty tab 51 self.widget.addFit(None) 52 self.assertEqual(len(self.widget.tabs), 2) 53 self.assertEqual(self.widget.tabName(), "FitPage2") 54 self.assertEqual(self.widget.maxIndex, 2) 48 55 49 #Test for existence in combobox 50 self.assertNotEqual(fittingWindow.cbCategory.findText("Cylinder"),-1) 51 self.assertNotEqual(fittingWindow.cbCategory.findText("Ellipsoid"),-1) 52 self.assertNotEqual(fittingWindow.cbCategory.findText("Lamellae"),-1) 53 self.assertNotEqual(fittingWindow.cbCategory.findText("Paracrystal"),-1) 54 self.assertNotEqual(fittingWindow.cbCategory.findText("Parallelepiped"),-1) 55 self.assertNotEqual(fittingWindow.cbCategory.findText("Shape Independent"),-1) 56 self.assertNotEqual(fittingWindow.cbCategory.findText("Sphere"),-1) 56 def testCloseTab(self): 57 '''Delete a tab and test''' 58 # Add an empty tab 59 self.widget.addFit(None) 57 60 58 #Test what is current text in the combobox 59 self.assertTrue(fittingWindow.cbCategory.currentText(), "Cylinder") 61 # Remove the original tab 62 self.widget.tabCloses(1) 63 self.assertEqual(len(self.widget.tabs), 1) 64 self.assertEqual(self.widget.maxIndex, 2) 65 self.assertEqual(self.widget.tabName(), "FitPage2") 60 66 61 def testSelectModel(self):62 """63 Test if models have been loaded properly64 :return:65 """66 fittingWindow = FittingWindow(None)67 # Attemtp to remove the last tab 68 self.widget.tabCloses(1) 69 # The tab should still be there 70 self.assertEqual(len(self.widget.tabs), 1) 71 self.assertEqual(self.widget.maxIndex, 2) 72 self.assertEqual(self.widget.tabName(), "FitPage2") 67 73 68 #Test loading from json categories 69 model_list = fittingWindow.master_category_dict["Cylinder"] 70 self.assertTrue(['cylinder', True] in model_list) 71 self.assertTrue(['core_shell_cylinder', True] in model_list) 72 self.assertTrue(['barbell', True] in model_list) 73 self.assertTrue(['core_shell_bicelle', True] in model_list) 74 self.assertTrue(['flexible_cylinder', True] in model_list) 75 self.assertTrue(['flexible_cylinder_elliptical', True] in model_list) 76 self.assertTrue(['pearl_necklace', True] in model_list) 77 self.assertTrue(['capped_cylinder', True] in model_list) 78 self.assertTrue(['elliptical_cylinder', True] in model_list) 79 self.assertTrue(['pringle', True] in model_list) 80 self.assertTrue(['hollow_cylinder', True] in model_list) 81 self.assertTrue(['core_shell_bicelle_elliptical', True] in model_list) 82 self.assertTrue(['stacked_disks', True] in model_list) 74 def testAllowBatch(self): 75 '''Assure the perspective allows multiple datasets''' 76 self.assertTrue(self.widget.allowBatch()) 83 77 84 #Test for existence in combobox 85 self.assertNotEqual(fittingWindow.cbModel.findText("cylinder"),-1) 86 self.assertNotEqual(fittingWindow.cbModel.findText("core_shell_cylinder"),-1) 87 self.assertNotEqual(fittingWindow.cbModel.findText("barbell"),-1) 88 self.assertNotEqual(fittingWindow.cbModel.findText("core_shell_bicelle"),-1) 89 self.assertNotEqual(fittingWindow.cbModel.findText("flexible_cylinder"),-1) 90 self.assertNotEqual(fittingWindow.cbModel.findText("flexible_cylinder_elliptical"),-1) 91 self.assertNotEqual(fittingWindow.cbModel.findText("pearl_necklace"),-1) 92 self.assertNotEqual(fittingWindow.cbModel.findText("capped_cylinder"),-1) 93 self.assertNotEqual(fittingWindow.cbModel.findText("elliptical_cylinder"),-1) 94 self.assertNotEqual(fittingWindow.cbModel.findText("pringle"),-1) 95 self.assertNotEqual(fittingWindow.cbModel.findText("hollow_cylinder"),-1) 96 self.assertNotEqual(fittingWindow.cbModel.findText("core_shell_bicelle_elliptical"),-1) 97 self.assertNotEqual(fittingWindow.cbModel.findText("stacked_disks"),-1) 78 def testSetData(self): 79 ''' Assure that setting data is correct''' 80 with self.assertRaises(AssertionError): 81 self.widget.setData(None) 98 82 83 with self.assertRaises(AttributeError): 84 self.widget.setData("BOOP") 99 85 100 def testSelectPolydispersity(self): 101 """ 102 Test if models have been loaded properly 103 :return: 104 """ 105 fittingWindow = FittingWindow(None) 86 # Mock the datafromitem() call from FittingWidget 87 data = Data1D(x=[1,2], y=[1,2]) 88 GuiUtils.dataFromItem = MagicMock(return_value=data) 106 89 107 #Test loading from json categories 108 fittingWindow.setModelModel("cylinder") 109 pd_index = fittingWindow.tableView_2.model().index(0,0) 110 self.assertEqual(str(pd_index.data().toString()), "Distribution of radius") 111 pd_index = fittingWindow.tableView_2.model().index(1,0) 112 self.assertEqual(str(pd_index.data().toString()), "Distribution of length") 90 item = QtGui.QStandardItem("test") 91 self.widget.setData([item]) 113 92 114 def testSelectStructureFactor(self): 115 """ 116 Test if structure factors have been loaded properly 117 :return: 118 """ 119 fittingWindow = FittingWindow(None) 93 # Look at the data in tab 94 self.assertEqual(self.widget._model_item, item) 120 95 121 #Test for existence in combobox 122 self.assertNotEqual(fittingWindow.cbStructureFactor.findText("stickyhardsphere"),-1) 123 self.assertNotEqual(fittingWindow.cbStructureFactor.findText("hayter_msa"),-1) 124 self.assertNotEqual(fittingWindow.cbStructureFactor.findText("squarewell"),-1) 125 self.assertNotEqual(fittingWindow.cbStructureFactor.findText("hardsphere"),-1) 96 # First tab should accept data 97 self.assertEqual(len(self.widget.tabs), 1) 126 98 127 #Test what is current text in the combobox 128 self.assertTrue(fittingWindow.cbCategory.currentText(), "None") 99 # Add another set of data 100 self.widget.setData([item]) 101 102 # Now we should have two tabs 103 self.assertEqual(len(self.widget.tabs), 2) 104 129 105 130 106 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.