Changeset 28a84e9 in sasview for src/sas/qtgui/GuiUtils.py
- Timestamp:
- Jul 30, 2016 4:22:07 PM (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:
- 39551a68
- Parents:
- 4b71e91
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/GuiUtils.py
r4b71e91 r28a84e9 1 1 """ 2 2 Global defaults and various utility functions usable by the general GUI 3 3 """ 4 4 … … 28 28 from sas.sasgui.guiframe.dataFitting import Data1D 29 29 from sas.sasgui.guiframe.dataFitting import Data2D 30 from sas.sascalc.dataloader.loader import Loader 30 31 31 32 … … 338 339 representation 339 340 """ 341 if not isinstance(data, Data1D): 342 msg = "Incorrect type passed to retrieveData1d" 343 raise AttributeError, msg 340 344 try: 341 345 xmin = min(data.x) … … 423 427 424 428 return text 429 430 def _onTXTSave(data, path): 431 """ 432 Save file as formatted txt 433 """ 434 with open(path,'w') as out: 435 has_errors = True 436 if data.dy == None or data.dy == []: 437 has_errors = False 438 # Sanity check 439 if has_errors: 440 try: 441 if len(data.y) != len(data.dy): 442 has_errors = False 443 except: 444 has_errors = False 445 if has_errors: 446 if data.dx != None and data.dx != []: 447 out.write("<X> <Y> <dY> <dX>\n") 448 else: 449 out.write("<X> <Y> <dY>\n") 450 else: 451 out.write("<X> <Y>\n") 452 453 for i in range(len(data.x)): 454 if has_errors: 455 if data.dx != None and data.dx != []: 456 if data.dx[i] != None: 457 out.write("%g %g %g %g\n" % (data.x[i], 458 data.y[i], 459 data.dy[i], 460 data.dx[i])) 461 else: 462 out.write("%g %g %g\n" % (data.x[i], 463 data.y[i], 464 data.dy[i])) 465 else: 466 out.write("%g %g %g\n" % (data.x[i], 467 data.y[i], 468 data.dy[i])) 469 else: 470 out.write("%g %g\n" % (data.x[i], 471 data.y[i])) 472 473 def saveData1D(data): 474 """ 475 Save 1D data points 476 """ 477 default_name = os.path.basename(data.filename) 478 default_name, extension = os.path.splitext(default_name) 479 default_name += "_out" + extension 480 481 wildcard = "Text files (*.txt);;"\ 482 "CanSAS 1D files(*.xml)" 483 kwargs = { 484 'caption' : 'Save As', 485 'directory' : default_name, 486 'filter' : wildcard, 487 'parent' : None, 488 } 489 # Query user for filename. 490 filename = QtGui.QFileDialog.getSaveFileName(**kwargs) 491 492 # User cancelled. 493 if not filename: 494 return 495 496 filename = str(filename) 497 498 #Instantiate a loader 499 loader = Loader() 500 if os.path.splitext(filename)[1].lower() == ".txt": 501 _onTXTSave(data, filename) 502 if os.path.splitext(filename)[1].lower() == ".xml": 503 loader.save(filename, data, ".xml") 504 505 def saveData2D(data): 506 """ 507 Save data2d dialog 508 """ 509 default_name = os.path.basename(data.filename) 510 default_name, _ = os.path.splitext(default_name) 511 ext_format = ".dat" 512 default_name += "_out" + ext_format 513 514 wildcard = "IGOR/DAT 2D file in Q_map (*.dat)" 515 kwargs = { 516 'caption' : 'Save As', 517 'directory' : default_name, 518 'filter' : wildcard, 519 'parent' : None, 520 } 521 # Query user for filename. 522 filename = QtGui.QFileDialog.getSaveFileName(**kwargs) 523 524 # User cancelled. 525 if not filename: 526 return 527 filename = str(filename) 528 #Instantiate a loader 529 loader = Loader() 530 531 if os.path.splitext(filename)[1].lower() == ext_format: 532 loader.save(filename, data, ext_format)
Note: See TracChangeset
for help on using the changeset viewer.