Changes in / [fb560d2:dcabba7] in sasview
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py
r70f4458 rb764ae5 124 124 return item 125 125 126 def addSimpleParametersToModel(parameters, is2D , parameters_original=None):126 def addSimpleParametersToModel(parameters, is2D): 127 127 """ 128 128 Update local ModelModel with sasmodel parameters 129 parameters_original: list of parameters before any tagging on their IDs, e.g. for product model130 (so that those are the display names; see below)131 129 """ 132 130 if is2D: … … 134 132 else: 135 133 params = parameters.iq_parameters 136 137 if parameters_original:138 # 'parameters_original' contains the parameters as they are to be DISPLAYED, while 'parameters'139 # contains the parameters as they were renamed; this is for handling name collisions in product model.140 # The 'real name' of the parameter will be stored in the item's user data.141 if is2D:142 params_orig = [p for p in parameters_original.kernel_parameters if p.type != 'magnetic']143 else:144 params_orig = parameters_original.iq_parameters145 else:146 # no difference in names anyway147 params_orig = params148 149 134 item = [] 150 for param , param_orig in zip(params, params_orig):135 for param in params: 151 136 # Create the top level, checkable item 152 item_name = param _orig.name137 item_name = param.name 153 138 item1 = QtGui.QStandardItem(item_name) 154 item1.setData(param.name, QtCore.Qt.UserRole)155 139 item1.setCheckable(True) 156 140 item1.setEditable(False) … … 160 144 item4 = QtGui.QStandardItem(str(param.limits[0])) 161 145 item5 = QtGui.QStandardItem(str(param.limits[1])) 162 item6 = QtGui.QStandardItem( str(param.units))146 item6 = QtGui.QStandardItem(param.units) 163 147 item6.setEditable(False) 164 148 item.append([item1, item2, item4, item5, item6]) … … 198 182 model.appendRow(item_list) 199 183 200 def addHeadingRowToModel(model, name):201 """adds a non-interactive top-level row to the model"""202 header_row = [QtGui.QStandardItem() for i in range(5)]203 header_row[0].setText(name)204 205 font = header_row[0].font()206 font.setBold(True)207 header_row[0].setFont(font)208 209 for item in header_row:210 item.setEditable(False)211 item.setCheckable(False)212 item.setSelectable(False)213 214 model.appendRow(header_row)215 216 184 def addHeadersToModel(model): 217 185 """ … … 259 227 model.header_tooltips = copy.copy(poly_header_error_tooltips) 260 228 261 def addShellsToModel(parameters, model, index, row_num=None): 262 """ 263 Find out multishell parameters and update the model with the requested number of them. 264 Inserts them after the row at row_num, if not None; otherwise, appends to end. 265 Returns a list of lists of QStandardItem objects. 229 def addShellsToModel(parameters, model, index): 230 """ 231 Find out multishell parameters and update the model with the requested number of them 266 232 """ 267 233 multishell_parameters = getIterParams(parameters) 268 234 269 rows = []270 235 for i in range(index): 271 236 for par in multishell_parameters: … … 294 259 item4 = QtGui.QStandardItem(str(par.limits[1])) 295 260 item5 = QtGui.QStandardItem(par.units) 296 row = [item1, item2, item3, item4, item5] 297 rows.append(row) 298 299 if row_num is None: 300 model.appendRow(row) 301 else: 302 model.insertRow(row_num, row) 303 row_num += 1 304 305 return rows 261 model.appendRow([item1, item2, item3, item4, item5]) 306 262 307 263 def calculateChi2(reference_data, current_data): -
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
r0109f2a rdcabba7 219 219 # Utility variable to enable unselectable option in category combobox 220 220 self._previous_category_index = 0 221 # Utility variables for multishell display 222 self._n_shells_row = 0 223 self._num_shell_params = 0 221 # Utility variable for multishell display 222 self._last_model_row = 0 224 223 # Dictionary of {model name: model class} for the current category 225 224 self.models = {} … … 677 676 Return list of all parameters for the current model 678 677 """ 679 return [self._model_model.item(row).text() 680 for row in range(self._model_model.rowCount()) 681 if self.isCheckable(row)] 678 return [self._model_model.item(row).text() for row in range(self._model_model.rowCount())] 682 679 683 680 def modifyViewOnRow(self, row, font=None, brush=None): … … 707 704 assert isinstance(constraint, Constraint) 708 705 assert 0 <= row <= self._model_model.rowCount() 709 assert self.isCheckable(row)710 706 711 707 item = QtGui.QStandardItem() … … 728 724 max_col = self.lstParams.itemDelegate().param_max 729 725 for row in self.selectedParameters(): 730 assert(self.isCheckable(row))731 726 param = self._model_model.item(row, 0).text() 732 727 value = self._model_model.item(row, 1).text() … … 771 766 max_col = self.lstParams.itemDelegate().param_max 772 767 for row in range(self._model_model.rowCount()): 773 if not self.isCheckable(row):774 continue775 768 if not self.rowHasConstraint(row): 776 769 continue … … 801 794 For the given row, return its constraint, if any 802 795 """ 803 if self.isCheckable(row):796 try: 804 797 item = self._model_model.item(row, 1) 805 try: 806 return item.child(0).data() 807 except AttributeError: 808 # return none when no constraints 809 pass 810 return None 798 return item.child(0).data() 799 except AttributeError: 800 # return none when no constraints 801 return None 811 802 812 803 def rowHasConstraint(self, row): … … 814 805 Finds out if row of the main model has a constraint child 815 806 """ 816 if self.isCheckable(row): 817 item = self._model_model.item(row, 1) 818 if item.hasChildren(): 819 c = item.child(0).data() 820 if isinstance(c, Constraint): 821 return True 807 item = self._model_model.item(row, 1) 808 if item.hasChildren(): 809 c = item.child(0).data() 810 if isinstance(c, Constraint): 811 return True 822 812 return False 823 813 … … 826 816 Finds out if row of the main model has an active constraint child 827 817 """ 828 if self.isCheckable(row): 829 item = self._model_model.item(row, 1) 830 if item.hasChildren(): 831 c = item.child(0).data() 832 if isinstance(c, Constraint) and c.active: 833 return True 818 item = self._model_model.item(row, 1) 819 if item.hasChildren(): 820 c = item.child(0).data() 821 if isinstance(c, Constraint) and c.active: 822 return True 834 823 return False 835 824 … … 838 827 Finds out if row of the main model has an active, nontrivial constraint child 839 828 """ 840 if self.isCheckable(row): 841 item = self._model_model.item(row, 1) 842 if item.hasChildren(): 843 c = item.child(0).data() 844 if isinstance(c, Constraint) and c.func and c.active: 845 return True 829 item = self._model_model.item(row, 1) 830 if item.hasChildren(): 831 c = item.child(0).data() 832 if isinstance(c, Constraint) and c.func and c.active: 833 return True 846 834 return False 847 835 … … 1589 1577 # internal so can use closure for param_dict 1590 1578 param_name = str(self._model_model.item(row, 0).text()) 1591 if not self.isCheckable(row) orparam_name not in list(param_dict.keys()):1579 if param_name not in list(param_dict.keys()): 1592 1580 return 1593 1581 # modify the param value … … 1601 1589 # Utility function for updateof polydispersity part of the main model 1602 1590 param_name = str(self._model_model.item(row, 0).text())+'.width' 1603 if not self.isCheckable(row) orparam_name not in list(param_dict.keys()):1591 if param_name not in list(param_dict.keys()): 1604 1592 return 1605 1593 # modify the param value … … 1978 1966 # Crete/overwrite model items 1979 1967 self._model_model.clear() 1980 self._poly_model.clear() 1981 self._magnet_model.clear()1982 1983 if model_name is None:1984 if structure_factor not in (None, "None"): 1985 # S(Q) on its own, treat the same as a form factor1986 self.kernel_module = None1987 self.fromStructureFactorToQModel(structure_factor)1988 else:1989 # No models selected1990 return1968 1969 # First, add parameters from the main model 1970 if model_name is not None: 1971 self.fromModelToQModel(model_name) 1972 1973 # Then, add structure factor derived parameters 1974 if structure_factor is not None and structure_factor != "None": 1975 if model_name is None: 1976 # Instantiate the current sasmodel for SF-only models 1977 self.kernel_module = self.models[structure_factor]() 1978 self.fromStructureFactorToQModel(structure_factor) 1991 1979 else: 1992 self.fromModelToQModel(model_name)1993 self.addExtraShells()1994 1995 1980 # Allow the SF combobox visibility for the given sasmodel 1996 1981 self.enableStructureFactorControl(structure_factor) 1997 1998 # Add S(Q)1999 1982 if self.cbStructureFactor.isEnabled(): 2000 1983 structure_factor = self.cbStructureFactor.currentText() 2001 1984 self.fromStructureFactorToQModel(structure_factor) 2002 1985 2003 # Add polydispersity to the model 2004 self.poly_params = {} 2005 self.setPolyModel() 2006 # Add magnetic parameters to the model 2007 self.magnet_params = {} 2008 self.setMagneticModel() 1986 # Then, add multishells 1987 if model_name is not None: 1988 # Multishell models need additional treatment 1989 self.addExtraShells() 1990 1991 # Add polydispersity to the model 1992 self.poly_params = {} 1993 self.setPolyModel() 1994 # Add magnetic parameters to the model 1995 self.magnet_params = {} 1996 self.setMagneticModel() 2009 1997 2010 1998 # Adjust the table cells width … … 2079 2067 self.shell_names = self.shellNamesList() 2080 2068 2081 # Get new rows forQModel2069 # Update the QModel 2082 2070 new_rows = FittingUtilities.addParametersToModel(self.model_parameters, self.kernel_module, self.is2D) 2083 2071 2084 # Add heading row2085 FittingUtilities.addHeadingRowToModel(self._model_model, model_name)2086 2087 # Update QModel2088 2072 for row in new_rows: 2089 2073 self._model_model.appendRow(row) 2074 # Update the counter used for multishell display 2075 self._last_model_row = self._model_model.rowCount() 2090 2076 2091 2077 def fromStructureFactorToQModel(self, structure_factor): … … 2095 2081 if structure_factor is None or structure_factor=="None": 2096 2082 return 2097 2098 s_kernel = self.models[structure_factor]() 2099 p_kernel = self.kernel_module 2100 2101 if p_kernel is None: 2102 # Not a product model, just S(Q) 2103 self.kernel_module = s_kernel 2104 params = modelinfo.ParameterTable(self.kernel_module._model_info.parameters.kernel_parameters) 2105 new_rows = FittingUtilities.addSimpleParametersToModel(params, self.is2D) 2106 else: 2107 p_pars_len = len(p_kernel._model_info.parameters.kernel_parameters) 2108 s_pars_len = len(s_kernel._model_info.parameters.kernel_parameters) 2109 2110 self.kernel_module = MultiplicationModel(p_kernel, s_kernel) 2111 all_params = self.kernel_module._model_info.parameters.kernel_parameters 2112 all_param_names = [param.name for param in all_params] 2113 2114 # S(Q) params from the product model are not necessarily the same as those from the S(Q) model; any 2115 # conflicting names with P(Q) params will cause a rename; we also lose radius_effective (for now...) 2116 2117 # TODO: merge rest of beta approx implementation in 2118 # This is to ensure compatibility when we merge beta approx support in...! 2119 2120 # radius_effective is always s_params[0] 2121 2122 # if radius_effective_mode is in all_params, then all_params contains radius_effective and we want to 2123 # keep it in the model 2124 2125 # if radius_effective_mode is NOT in all_params, then radius_effective should NOT be kept, because the user 2126 # cannot specify it themselves; but, make sure we only remove it if it's actually there in the first place 2127 # (sasmodels master removes it already) 2128 if "radius_effective_mode" in all_param_names: 2129 # Show all parameters 2130 s_params = modelinfo.ParameterTable(all_params[p_pars_len:p_pars_len+s_pars_len]) 2131 s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters) 2132 else: 2133 # Ensure radius_effective is not displayed 2134 s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters[1:]) 2135 if "radius_effective" in all_param_names: 2136 s_params = modelinfo.ParameterTable(all_params[p_pars_len+1:p_pars_len+s_pars_len]) 2137 else: 2138 s_params = modelinfo.ParameterTable(all_params[p_pars_len:p_pars_len+s_pars_len-1]) 2139 2140 # Get new rows for QModel 2141 # Any renamed parameters are stored as data in the relevant item, for later handling 2142 new_rows = FittingUtilities.addSimpleParametersToModel(s_params, self.is2D, s_params_orig) 2143 2144 # TODO: merge rest of beta approx implementation in 2145 # These parameters are not part of P(Q) nor S(Q), but are added only to the product model (e.g. specifying 2146 # structure factor calculation mode) 2147 # product_params = all_params[p_pars_len+s_pars_len:] 2148 2149 # Add heading row 2150 FittingUtilities.addHeadingRowToModel(self._model_model, structure_factor) 2151 2152 # Update QModel 2083 structure_module = generate.load_kernel_module(structure_factor) 2084 structure_parameters = modelinfo.make_parameter_table(getattr(structure_module, 'parameters', [])) 2085 2086 structure_kernel = self.models[structure_factor]() 2087 form_kernel = self.kernel_module 2088 2089 self.kernel_module = MultiplicationModel(form_kernel, structure_kernel) 2090 2091 new_rows = FittingUtilities.addSimpleParametersToModel(structure_parameters, self.is2D) 2153 2092 for row in new_rows: 2154 2093 self._model_model.appendRow(row) 2155 2094 # disable fitting of parameters not listed in self.kernel_module (probably radius_effective) 2156 # if row[0].text() not in self.kernel_module.params.keys(): 2157 # row_num = self._model_model.rowCount() - 1 2158 # FittingUtilities.markParameterDisabled(self._model_model, row_num) 2095 if row[0].text() not in self.kernel_module.params.keys(): 2096 row_num = self._model_model.rowCount() - 1 2097 FittingUtilities.markParameterDisabled(self._model_model, row_num) 2098 2099 # Update the counter used for multishell display 2100 self._last_model_row = self._model_model.rowCount() 2159 2101 2160 2102 def haveParamsToFit(self): … … 2182 2124 model_row = item.row() 2183 2125 name_index = self._model_model.index(model_row, 0) 2184 name_item = self._model_model.itemFromIndex(name_index)2185 2126 2186 2127 # Extract changed value. … … 2191 2132 return 2192 2133 2193 # if the item has user data, this is the actual parameter name (e.g. to handle duplicate names) 2194 if name_item.data(QtCore.Qt.UserRole): 2195 parameter_name = str(name_item.data(QtCore.Qt.UserRole)) 2196 else: 2197 parameter_name = str(self._model_model.data(name_index)) 2134 parameter_name = str(self._model_model.data(name_index)) # sld, background etc. 2198 2135 2199 2136 # Update the parameter value - note: this supports +/-inf as well … … 2429 2366 new_plots.append(sq_data) 2430 2367 2368 # Update/generate plots 2431 2369 for plot in new_plots: 2432 2370 self.communicate.plotUpdateSignal.emit([plot]) … … 2628 2566 def updateFunctionCaption(row): 2629 2567 # Utility function for update of polydispersity function name in the main model 2630 if not self.isCheckable(row):2631 return2632 2568 self._model_model.blockSignals(True) 2633 2569 param_name = str(self._model_model.item(row, 0).text()) … … 2802 2738 2803 2739 self.lstParams.setIndexWidget(shell_index, func) 2804 self._ n_shells_row = shell_row - 12740 self._last_model_row = self._model_model.rowCount() 2805 2741 2806 2742 # Set the index to the state-kept value … … 2813 2749 """ 2814 2750 # Find row location of the combobox 2815 first_row = self._n_shells_row + 12816 remove_rows = self._ num_shell_params2751 last_row = self._last_model_row 2752 remove_rows = self._model_model.rowCount() - last_row 2817 2753 2818 2754 if remove_rows > 1: 2819 self._model_model.removeRows(first_row, remove_rows) 2820 2821 new_rows = FittingUtilities.addShellsToModel(self.model_parameters, self._model_model, index, first_row) 2822 self._num_shell_params = len(new_rows) 2823 2755 self._model_model.removeRows(last_row, remove_rows) 2756 2757 FittingUtilities.addShellsToModel(self.model_parameters, self._model_model, index) 2824 2758 self.current_shell_displayed = index 2825 2759 -
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py
r3fbd77b r66d4370 256 256 self.widget.cbStructureFactor.setCurrentIndex(structure_index) 257 257 258 # We have 3 more param rows now (radius_effective is removed), and a new heading258 # We have 4 more rows now 259 259 self.assertEqual(self.widget._model_model.rowCount(), rowcount+4) 260 260 … … 276 276 last_index = self.widget.cbStructureFactor.count() 277 277 self.widget.cbStructureFactor.setCurrentIndex(last_index-1) 278 # Do we have all the rows (incl. radius_effective & heading row)?279 self.assertEqual(self.widget._model_model.rowCount(), 5)278 # Do we have all the rows? 279 self.assertEqual(self.widget._model_model.rowCount(), 4) 280 280 281 281 # Are the command buttons properly enabled? … … 509 509 Test opening of the load file dialog for 'array' polydisp. function 510 510 """ 511 512 # open a non-existent file513 511 filename = os.path.join("UnitTesting", "testdata_noexist.txt") 514 with self.assertRaises(OSError, msg="testdata_noexist.txt should be a non-existent file"):515 os.stat(filename)516 512 QtWidgets.QFileDialog.getOpenFileName = MagicMock(return_value=(filename,'')) 517 513 self.widget.show() … … 529 525 530 526 # good file 531 # TODO: this depends on the working directory being src/sas/qtgui,532 # TODO: which isn't convenient if you want to run this test suite533 # TODO: individually534 527 filename = os.path.join("UnitTesting", "testdata.txt") 535 try:536 os.stat(filename)537 except OSError:538 self.assertTrue(False, "testdata.txt does not exist")539 528 QtWidgets.QFileDialog.getOpenFileName = MagicMock(return_value=(filename,'')) 540 529 … … 602 591 603 592 # Assure we have the combobox available 604 cbox_row = self.widget._n_shells_row605 func_index = self.widget._model_model.index( cbox_row, 1)593 last_row = self.widget._last_model_row 594 func_index = self.widget._model_model.index(last_row-1, 1) 606 595 self.assertIsInstance(self.widget.lstParams.indexWidget(func_index), QtWidgets.QComboBox) 607 608 # get number of rows before changing shell count609 last_row = self.widget._model_model.rowCount()610 596 611 597 # Change the combo box index … … 1041 1027 1042 1028 # Check the model 1043 self.assertEqual(self.widget._model_model.rowCount(), 7)1029 self.assertEqual(self.widget._model_model.rowCount(), 6) 1044 1030 self.assertEqual(self.widget._model_model.columnCount(), 5) 1045 1031 … … 1157 1143 # two rows selected 1158 1144 index1 = self.widget.lstParams.model().index(1, 0, QtCore.QModelIndex()) 1159 index2 = self.widget.lstParams.model().index( 3, 0, QtCore.QModelIndex())1145 index2 = self.widget.lstParams.model().index(2, 0, QtCore.QModelIndex()) 1160 1146 selection_model = self.widget.lstParams.selectionModel() 1161 1147 selection_model.select(index1, selection_model.Select | selection_model.Rows) … … 1193 1179 # several random parameters 1194 1180 self.assertEqual(self.widget.getRowFromName('scale'), 0) 1195 self.assertEqual(self.widget.getRowFromName('length'), 6)1181 self.assertEqual(self.widget.getRowFromName('length'), 5) 1196 1182 1197 1183 def testGetParamNames(self): … … 1230 1216 # Create a constraint object 1231 1217 const = Constraint(parent=None, value=7.0) 1232 row = 31218 row = 2 1233 1219 1234 1220 spy = QtSignalSpy(self.widget, self.widget.constraintAddedSignal) … … 1249 1235 # assign complex constraint now 1250 1236 const = Constraint(parent=None, param='radius', func='5*sld') 1251 row = 51237 row = 4 1252 1238 # call the method tested 1253 1239 self.widget.addConstraintToRow(constraint=const, row=row) … … 1308 1294 self.widget.cbModel.setCurrentIndex(model_index) 1309 1295 1296 # select two rows 1310 1297 row1 = 1 1311 row2 = 5 1312 1313 param1 = "background" 1314 param2 = "radius" 1315 1316 #default_value1 = "0.001" 1317 default_value2 = "20" 1318 1319 # select two rows 1298 row2 = 4 1320 1299 index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 1321 1300 index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) … … 1334 1313 1335 1314 # delete one of the constraints 1336 self.widget.deleteConstraintOnParameter(param= param1)1315 self.widget.deleteConstraintOnParameter(param='background') 1337 1316 1338 1317 # see that the other constraint is still present 1339 cons = self.widget.getConstraintForRow( row2)1340 self.assertEqual(cons.param, param2)1341 self.assertEqual(cons.value, default_value2)1318 cons = self.widget.getConstraintForRow(4) # 4 = radius 1319 self.assertEqual(cons.param, "radius") 1320 self.assertEqual(cons.value, "20") 1342 1321 1343 1322 # kill the other constraint … … 1345 1324 1346 1325 # see that the other constraint is still present 1347 self.assertEqual(self.widget.getConstraintsForModel(), [( param2, None)])1326 self.assertEqual(self.widget.getConstraintsForModel(), [('radius', None)]) 1348 1327 1349 1328 def testGetConstraintForRow(self): … … 1365 1344 self.widget.cbModel.setCurrentIndex(model_index) 1366 1345 1346 # select two rows 1367 1347 row1 = 1 1368 row2 = 5 1369 1370 # select two rows 1348 row2 = 4 1371 1349 index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 1372 1350 index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) … … 1378 1356 self.widget.addSimpleConstraint() 1379 1357 1380 con_list = [False, True, False, False, False,True, False]1358 con_list = [False, True, False, False, True, False] 1381 1359 new_list = [] 1382 1360 for row in range(self.widget._model_model.rowCount()): … … 1396 1374 self.widget.cbModel.setCurrentIndex(model_index) 1397 1375 1376 # select two rows 1398 1377 row1 = 1 1399 row2 = 5 1400 1401 # select two rows 1378 row2 = 4 1402 1379 index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 1403 1380 index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) … … 1413 1390 constraint_objects[0].active = False 1414 1391 1415 con_list = [False, False, False, False, False,True, False]1392 con_list = [False, False, False, False, True, False] 1416 1393 new_list = [] 1417 1394 for row in range(self.widget._model_model.rowCount()): … … 1434 1411 self.assertEqual(self.widget.getConstraintsForModel(),[]) 1435 1412 1413 # select two rows 1436 1414 row1 = 1 1437 row2 = 5 1438 1439 param1 = "background" 1440 param2 = "radius" 1441 1442 default_value1 = "0.001" 1443 default_value2 = "20" 1444 1445 # select two rows 1415 row2 = 4 1446 1416 index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 1447 1417 index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) … … 1455 1425 # simple constraints 1456 1426 # self.assertEqual(self.widget.getConstraintsForModel(), [('background', '0.001'), ('radius', '20')]) 1457 cons = self.widget.getConstraintForRow( row1)1458 self.assertEqual(cons.param, param1)1459 self.assertEqual(cons.value, default_value1)1460 cons = self.widget.getConstraintForRow( row2)1461 self.assertEqual(cons.param, param2)1462 self.assertEqual(cons.value, default_value2)1427 cons = self.widget.getConstraintForRow(1) # 1 - background 1428 self.assertEqual(cons.param, "background") 1429 self.assertEqual(cons.value, "0.001") 1430 cons = self.widget.getConstraintForRow(4) # 4 = radius 1431 self.assertEqual(cons.param, "radius") 1432 self.assertEqual(cons.value, "20") 1463 1433 1464 1434 objects = self.widget.getConstraintObjectsForModel() 1465 1435 self.assertEqual(len(objects), 2) 1466 self.assertEqual(objects[1].value, default_value2) 1467 self.assertEqual(objects[0].param, param1) 1468 1436 self.assertEqual(objects[1].value, '20') 1437 self.assertEqual(objects[0].param, 'background') 1438 1439 # add complex constraint 1440 const = Constraint(parent=None, param='scale', func='5*sld') 1469 1441 row = 0 1470 param = "scale"1471 func = "5*sld"1472 1473 # add complex constraint1474 const = Constraint(parent=None, param=param, func=func)1475 1442 self.widget.addConstraintToRow(constraint=const, row=row) 1476 1443 #self.assertEqual(self.widget.getConstraintsForModel(),[('scale', '5*sld'), ('background', '0.001'), ('radius', None)]) 1477 cons = self.widget.getConstraintForRow( row2)1478 self.assertEqual(cons.param, param2)1479 self.assertEqual(cons.value, default_value2)1444 cons = self.widget.getConstraintForRow(4) # 4 = radius 1445 self.assertEqual(cons.param, "radius") 1446 self.assertEqual(cons.value, "20") 1480 1447 1481 1448 objects = self.widget.getConstraintObjectsForModel() 1482 1449 self.assertEqual(len(objects), 3) 1483 self.assertEqual(objects[0].func, func)1450 self.assertEqual(objects[0].func, '5*sld') 1484 1451 1485 1452 def testReplaceConstraintName(self):
Note: See TracChangeset
for help on using the changeset viewer.