Changeset 253e7170 in sasview


Ignore:
Timestamp:
Dec 13, 2016 7:02:55 AM (7 years ago)
Author:
wojciech
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:
6b9d41d
Parents:
a8ec5b1
Message:

Loading data using simple loader

Location:
src/sas/qtgui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/DataExplorer.py

    rcad617b r253e7170  
    490490        data_error = False 
    491491        error_message = "" 
    492  
    493492        number_of_files = len(path) 
    494493        self.communicator.progressBarUpdateSignal.emit(0.0) 
  • src/sas/qtgui/SlitSizeCalculator.py

    ra8ec5b1 r253e7170  
    22from PyQt4 import QtCore 
    33from UI.SlitSizeCalculator import Ui_SlitSizeCalculator 
    4 from twisted.internet import threads 
    5 import logging 
     4from sas.sascalc.dataloader.loader import Loader 
     5from sas.sasgui.guiframe.dataFitting import Data1D 
     6from sas.sasgui.guiframe.dataFitting import Data2D 
     7from sas.sascalc.calculator.slit_length_calculator import SlitlengthCalculator 
    68 
    7 # sas-global 
    8 from sas.sascalc.calculator.slit_length_calculator import SlitlengthCalculator 
    9 from DataExplorer import DataExplorerWindow 
     9import sys 
    1010 
    1111class SlitSizeCalculator(QtGui.QDialog, Ui_SlitSizeCalculator): 
     
    5050        Execute the computation of thickness 
    5151        """ 
    52         path_str = self.chooseFiles() 
     52        path_str = self.chooseFile() 
    5353        if not path_str: 
    5454            return 
    55         self.loadFromURL(path_str) 
    56         #Path_str is a list - it needs to be changed, so that only one file can be uploaded 
    57         self.deltaq_in.setText(path_str[0]) 
     55        loader = Loader() 
     56        data = loader.load(path_str) 
    5857 
    59     def loadFromURL(self, url): 
    60         """ 
    61         Threaded file load 
    62         """ 
    63         data_explorer = DataExplorerWindow(parent=self._parent, guimanager=self._guimanager) 
    64         load_thread = threads.deferToThread(data_explorer.readData, url) 
    65         load_thread.addCallback(data_explorer.loadComplete) 
    66         #On complete loading 
     58        self.deltaq_in.setText(path_str) 
     59        #We are loading data for one model only therefor index 0 
     60        self.complete_loading(data) 
     61        #Complete loading here 
    6762 
    68     def chooseFiles(self): 
     63    def chooseFile(self): 
    6964        """ 
    7065        Shows the Open file dialog and returns the chosen path(s) 
     
    7368        # Location is automatically saved - no need to keep track of the last dir 
    7469        # But only with Qt built-in dialog (non-platform native) 
    75         paths = QtGui.QFileDialog.getOpenFileNames(self, "Choose a file", "", 
    76                 "SAXSess Data 1D (*.txt *.TXT *.dat *.DAT)", None, 
     70        path = QtGui.QFileDialog.getOpenFileName(self, "Choose a file", "", 
     71                "SAS data 1D (*.txt *.TXT *.dat *.DAT)", None, 
    7772                QtGui.QFileDialog.DontUseNativeDialog) 
    78         if paths is None: 
     73        if path is None: 
    7974            return 
    8075 
    81         if isinstance(paths, QtCore.QStringList): 
    82             paths = [str(f) for f in paths] 
     76        if isinstance(path, QtCore.QString): 
     77            path = str(path) 
    8378 
    84         if not isinstance(paths, list): 
    85             paths = [paths] 
    86  
    87         return paths 
     79        return path 
    8880 
    8981    def onClose(self): 
     
    9789            Complete the loading and compute the slit size 
    9890        """ 
    99         #TODO: Provided we have an access to data then it should be fairly easy 
    100         index = self.treeView.selectedIndexes()[0] 
    101         model_item = self.model.itemFromIndex(self.data_proxy.mapToSource(index)) 
    102         data = GuiUtils.dataFromItem(model_item) 
    10391 
    104         if data is None or isinstance(data, Data2D): 
    105             #I guess this doesn't apply 
    106             if self.parent.parent is None: 
    107                 return 
     92        if data is None: 
     93            msg = "ERROR: Data hasn't been loaded correctly" 
     94            raise RuntimeError, msg 
     95 
     96        if isinstance(data, Data2D): 
    10897            msg = "Slit Length cannot be computed for 2D Data" 
    109             logging.info(msg) 
    110             return 
    111         self.data_name_tcl.SetValue(str(data.filename)) 
     98            raise Exception, msg 
     99 
    112100        #compute the slit size 
    113101        try: 
    114             x = data.x 
    115             y = data.y 
    116             if x == [] or  x is None or y == [] or y is None: 
    117                 msg = "The current data is empty please check x and y" 
    118                 raise ValueError, msg 
    119             slit_length_calculator = SlitlengthCalculator() 
    120             slit_length_calculator.set_data(x=x, y=y) 
    121             slit_length = slit_length_calculator.calculate_slit_length() 
     102             x = data.x 
     103             y = data.y 
     104             if x == [] or  x is None or y == [] or y is None: 
     105                 msg = "The current data is empty please check x and y" 
     106                 raise ValueError, msg 
     107             slit_length_calculator = SlitlengthCalculator() 
     108             slit_length_calculator.set_data(x=x, y=y) 
     109             slit_length = slit_length_calculator.calculate_slit_length() 
    122110        except: 
    123             if self.parent.parent is None: 
    124                 return 
    125             msg = "Slit Size Calculator: %s" % (sys.exc_value) 
    126             logging.info(msg) 
    127             return 
    128         self.slit_size_tcl.SetValue(str(slit_length)) 
     111             msg = "Slit Size Calculator: %s" % (sys.exc_value) 
     112             raise RuntimeError, msg 
     113 
     114        print("Slit lenght", slit_length) 
     115        self.lengthscale_out.setText(str(slit_length)) 
    129116        #Display unit 
    130         self.slit_size_unit_tcl.SetValue('[Unknown]') 
    131         if self.parent.parent is None: 
    132             return 
    133         msg = "Load Complete" 
    134         logging.info(msg) 
     117        self.lineEdit.setText("[UNKNOWN]") 
    135118 
Note: See TracChangeset for help on using the changeset viewer.