Changeset b1b71ad in sasview
- Timestamp:
- Oct 27, 2018 9:21:44 AM (6 years ago)
- Branches:
- ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 186d678
- Parents:
- d00475d
- Location:
- src/sas
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/MainWindow/DataExplorer.py
rd00475d rb1b71ad 225 225 Called when the "Open Project" menu item chosen. 226 226 """ 227 # check if any items loaded and warn about data deletion 228 if self.model.rowCount() > 0: 229 msg = "This operation will set remove all data, plots and analyses from" 230 msg += " SasView before loading the project. Do you wish to continue?" 231 msgbox = QtWidgets.QMessageBox(self) 232 msgbox.setIcon(QtWidgets.QMessageBox.Warning) 233 msgbox.setText(msg) 234 msgbox.setWindowTitle("Project Load") 235 # custom buttons 236 button_yes = QtWidgets.QPushButton("Yes") 237 msgbox.addButton(button_yes, QtWidgets.QMessageBox.YesRole) 238 button_no = QtWidgets.QPushButton("No") 239 msgbox.addButton(button_no, QtWidgets.QMessageBox.RejectRole) 240 retval = msgbox.exec_() 241 if retval == QtWidgets.QMessageBox.RejectRole: 242 # cancel fit 243 return 244 227 245 kwargs = { 228 246 'parent' : self, 229 247 'caption' : 'Open Project', 230 'filter' : 'Project (*.json);;All files (*.*)',248 'filter' : 'Project Files (*.json);;Old Project Files (*.svs);;All files (*.*)', 231 249 'options' : QtWidgets.QFileDialog.DontUseNativeDialog 232 250 } 233 251 filename = QtWidgets.QFileDialog.getOpenFileName(**kwargs)[0] 234 252 if filename: 253 self.deleteAllItems() 235 254 self.readProject(filename) 236 255 … … 374 393 Read out datasets and fitpages from file 375 394 """ 376 with open(filename, 'r') as infile: 377 all_data = GuiUtils.readDataFromFile(infile) 395 # Find out the filetype based on extension 396 ext = os.path.splitext(filename)[1] 397 all_data = {} 398 if 'svs' in ext.lower(): 399 # backward compatibility mode. 400 datasets = GuiUtils.readProjectFromSVS(filename) 401 #[[item_1, state_1], [item_2, state_2],...] 402 403 # Convert fitpage properties and update the dict 404 all_data = GuiUtils.convertFromSVS(datasets) 405 else: 406 with open(filename, 'r') as infile: 407 all_data = GuiUtils.readDataFromFile(infile) 378 408 379 409 for key, value in all_data.items(): … … 420 450 if not value: continue 421 451 new_data = value[0] 452 from sas.sascalc.dataloader.data_info import Data1D as old_data1d 453 from sas.sascalc.dataloader.data_info import Data2D as old_data2d 454 if isinstance(new_data, (old_data1d, old_data2d)): 455 new_data = self.manager.create_gui_data(value[0], new_data.filename) 422 456 assert isinstance(new_data, (Data1D, Data2D)) 423 457 properties = value[1] … … 1202 1236 self.actionQuick3DPlot.triggered.connect(self.quickData3DPlot) 1203 1237 self.actionEditMask.triggered.connect(self.showEditDataMask) 1204 self.actionDelete.triggered.connect(self.delete Item)1238 self.actionDelete.triggered.connect(self.deleteSelectedItem) 1205 1239 self.actionFreezeResults.triggered.connect(self.freezeSelectedItems) 1206 1240 … … 1415 1449 self.freezeItem(item_to_copy) 1416 1450 1417 def deleteItem(self): 1451 def deleteAllItems(self): 1452 """ 1453 Deletes all datasets from both model and theory_model 1454 """ 1455 deleted_items = [self.model.item(row) for row in range(self.model.rowCount()) 1456 if self.model.item(row).isCheckable()] 1457 deleted_names = [item.text() for item in deleted_items] 1458 # Let others know we deleted data 1459 self.communicator.dataDeletedSignal.emit(deleted_items) 1460 # update stored_data 1461 self.manager.update_stored_data(deleted_names) 1462 1463 # Clear the model 1464 self.model.clear() 1465 1466 def deleteSelectedItem(self): 1418 1467 """ 1419 1468 Delete the current item … … 1432 1481 return 1433 1482 1483 indices = self.current_view.selectedIndexes() 1484 self.deleteIndices(indices) 1485 1486 def deleteIndices(self, indices): 1487 """ 1488 Delete model idices from the current view 1489 """ 1490 proxy = self.current_view.model() 1491 model = proxy.sourceModel() 1492 1493 deleted_items = [] 1494 deleted_names = [] 1495 1434 1496 # Every time a row is removed, the indices change, so we'll just remove 1435 1497 # rows and keep calling selectedIndexes until it returns an empty list. 1436 indices = self.current_view.selectedIndexes()1437 1438 proxy = self.current_view.model()1439 model = proxy.sourceModel()1440 1441 deleted_items = []1442 deleted_names = []1443 1444 1498 while len(indices) > 0: 1445 1499 index = indices[0] 1446 row_index = proxy.mapToSource(index) 1447 item_to_delete = model.itemFromIndex(row_index) 1500 #row_index = proxy.mapToSource(index) 1501 #item_to_delete = model.itemFromIndex(row_index) 1502 item_to_delete = model.itemFromIndex(index) 1448 1503 if item_to_delete and item_to_delete.isCheckable(): 1449 row = row_index.row() 1504 #row = row_index.row() 1505 row = index.row() 1450 1506 1451 1507 # store the deleted item details so we can pass them on later -
src/sas/qtgui/MainWindow/GuiManager.py
rd00475d rb1b71ad 464 464 self._workspace.actionOpen_Project.triggered.connect(self.actionOpen_Project) 465 465 self._workspace.actionOpen_Analysis.triggered.connect(self.actionOpen_Analysis) 466 self._workspace.actionSave.triggered.connect(self.actionSave )466 self._workspace.actionSave.triggered.connect(self.actionSave_Project) 467 467 self._workspace.actionSave_Analysis.triggered.connect(self.actionSave_Analysis) 468 468 self._workspace.actionQuit.triggered.connect(self.actionQuit) … … 557 557 pass 558 558 559 def actionSave (self):559 def actionSave_Project(self): 560 560 """ 561 561 Menu Save Project -
src/sas/qtgui/MainWindow/UnitTesting/DataExplorerTest.py
ra24eacf rb1b71ad 854 854 855 855 # Attempt at deleting 856 self.form.delete Item()856 self.form.deleteSelectedItem() 857 857 858 858 # Test the warning dialog called once … … 868 868 self.form.current_view.selectionModel().select(select_index, QtCore.QItemSelectionModel.Rows) 869 869 # delete it. now for good 870 self.form.delete Item()870 self.form.deleteSelectedItem() 871 871 872 872 # Test the warning dialog called once -
src/sas/qtgui/Utilities/GuiUtils.py
rd00475d rb1b71ad 295 295 resultPlotUpdateSignal = QtCore.pyqtSignal(list) 296 296 297 def updateModelItemWithPlot(item, update_data, name="", checkbox_state=None): 297 298 """ 298 299 Adds a checkboxed row named "name" to QStandardItem … … 1287 1288 return new_stored_data 1288 1289 1290 def readProjectFromSVS(filepath): 1291 """ 1292 Read old SVS file and convert to the project dictionary 1293 """ 1294 from sas.sascalc.dataloader.readers.cansas_reader import Reader as CansasReader 1295 from sas.sascalc.fit.pagestate import Reader 1296 1297 loader = Loader() 1298 loader.associate_file_reader('.svs', Reader) 1299 temp = loader.load(filepath) 1300 state_reader = Reader() 1301 data_svs, state_svs = state_reader.read(filepath) 1302 1303 output = [] 1304 if isinstance(temp, list) and isinstance(state_svs, list): 1305 for item, state in zip(temp, state_svs): 1306 output.append([item, state]) 1307 else: 1308 output[temp, state_svs] 1309 return output 1310 1311 def convertFromSVS(datasets): 1312 """ 1313 Read in properties from SVS and convert into a simple dict 1314 """ 1315 content = {} 1316 for dataset in datasets: 1317 # we already have data - interested only in properties 1318 #[[item_1, state_1], [item_2, state_2],...] 1319 data = dataset[0] 1320 params = dataset[1] 1321 content[params.data_id] = {} 1322 content[params.data_id]['fit_data'] = [data, {'checked': 2}, []] 1323 param_dict = {} 1324 param_dict['fitpage_category'] = [params.categorycombobox] 1325 param_dict['fitpage_model'] = [params.formfactorcombobox] 1326 param_dict['fitpage_structure'] = [params.structurecombobox] 1327 param_dict['2D_params'] = [str(params.is_2D)] 1328 param_dict['chainfit_params'] = ["False"] 1329 param_dict['data_id'] = [params.data_id] 1330 param_dict['data_name'] = [params.data_name] 1331 param_dict['is_data'] = [str(params.is_data)] 1332 param_dict['magnetic_params'] = [str(params.magnetic_on)] 1333 param_dict['model_name'] = [params.formfactorcombobox] 1334 param_dict['polydisperse_params'] = [str(params.enable_disp)] 1335 param_dict['q_range_max'] = [str(params.qmax)] 1336 param_dict['q_range_min'] = [str(params.qmin)] 1337 # Smearing is a bit trickier. 4.x has multiple keywords, 1338 # one for each combobox option 1339 if params.enable_smearer: 1340 if params.slit_smearer: 1341 w = 1 1342 elif params.pinhole_smearer: 1343 w = 2 1344 else: 1345 w = 0 1346 param_dict['smearing'] = [str(w)] 1347 # weighting is a bit trickier. 4.x has multiple keywords, 1348 # one for each radio box. 1349 if params.dI_noweight: 1350 w = 2 1351 elif params.dI_didata: 1352 w = 3 1353 elif params.dI_sqrdata: 1354 w = 4 1355 elif params.dI_idata: 1356 w = 5 1357 else: 1358 w = 2 1359 param_dict['weighting'] = [str(w)] 1360 1361 # 4.x multi_factor is really the multiplicity 1362 if params.multi_factor is not None: 1363 param_dict['multiplicity'] = [str(int(params.multi_factor))] 1364 1365 # playing with titles 1366 data.filename = params.file 1367 data.title = params.data_name 1368 data.name = params.data_name 1369 1370 # main parameters 1371 for p in params.parameters: 1372 p_name = p[1] 1373 param_dict[p_name] = [str(p[0]), str(p[2]), None, str(p[5][1]), str(p[6][1])] 1374 # orientation parameters 1375 if params.is_2D: 1376 for p in params.orientation_params: 1377 p_name = p[1] 1378 param_dict[p_name] = [str(p[0]), str(p[2]), None, str(p[5][1]), str(p[6][1])] 1379 1380 # disperse parameters 1381 if params.enable_disp: 1382 for p in params.fittable_param: 1383 p_name = p[1] 1384 param_dict[p_name] = [str(p[0]), str(p[2]), None, str(35), str(3)] 1385 1386 # magnetic parameters 1387 1388 content[params.data_id]['fit_params'] = param_dict 1389 return content 1289 1390 1290 1391 def enum(*sequential, **named): -
src/sas/sascalc/dataloader/readers/cansas_reader.py
rb8080e1 rb1b71ad 184 184 if CANSAS_NS.get(self.cansas_version).get("ns") == value.rsplit(" ")[0]: 185 185 return True 186 if ext == " svs":186 if ext == ".svs": 187 187 return True # Why is this required? 188 188 # If we get to this point then file isn't valid CanSAS -
src/sas/sascalc/fit/pagestate.py
rb8080e1 rb1b71ad 1249 1249 1250 1250 else: 1251 self.call_back(format=ext)1251 #self.call_back(format=ext) 1252 1252 raise RuntimeError("%s is not a file" % path) 1253 1253 1254 1254 # Return output consistent with the loader's api 1255 1255 if len(output) == 0: 1256 self.call_back(state=None, datainfo=None, format=ext)1256 #self.call_back(state=None, datainfo=None, format=ext) 1257 1257 return None 1258 1258 else: 1259 states=[] 1259 1260 for data in output: 1260 1261 # Call back to post the new state … … 1281 1282 if isinstance(data.run_name, dict): 1282 1283 # Note: key order in dict is not guaranteed, so sort 1283 name = data.run_name.keys()[0]1284 name = list(data.run_name.keys())[0] 1284 1285 else: 1285 1286 name = data.run_name … … 1289 1290 state.version = fitstate.version 1290 1291 # store state in fitting 1291 self.call_back(state=state, datainfo=data, format=ext)1292 #self.call_back(state=state, datainfo=data, format=ext) 1292 1293 self.state = state 1294 states.append(state) 1293 1295 simfitstate = self._parse_simfit_state(entry) 1294 1296 if simfitstate is not None: 1295 self.call_back(state=simfitstate)1296 1297 return output1297 #self.call_back(state=simfitstate) 1298 states.append(simfitstate) 1299 return (output, states) 1298 1300 except: 1299 self.call_back(format=ext)1301 #self.call_back(format=ext) 1300 1302 raise 1301 1303
Note: See TracChangeset
for help on using the changeset viewer.