source: sasview/guiframe/local_perspectives/data_loader/load_thread.py @ 75df58b

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 75df58b was b70caa1, checked in by Gervaise Alina <gervyh@…>, 13 years ago

fix loading file

  • Property mode set to 100644
File size: 2.0 KB
Line 
1
2import time
3import sys
4
5from data_util.calcthread import CalcThread
6
7       
8
9class DataReader(CalcThread):
10    """
11    Load a data given a filename
12    """
13    def __init__(self, path, loader,
14                 completefn=None,
15                 updatefn   = None,
16                 yieldtime  = 0.01,
17                 worktime   = 0.01
18                 ):
19        CalcThread.__init__(self, completefn,
20                 updatefn,
21                 yieldtime,
22                 worktime)
23        self.list_path = path
24        #Instantiate a loader
25        self.loader = loader
26        self.message = ""
27        self.starttime = 0 
28        self.updatefn = updatefn
29       
30    def isquit(self):
31        """
32        :raise KeyboardInterrupt: when the thread is interrupted
33        """
34        try:
35            CalcThread.isquit(self)
36        except KeyboardInterrupt:
37            raise KeyboardInterrupt   
38       
39       
40    def compute(self):
41        """
42        read some data
43        """
44        self.starttime = time.time()
45        output = []
46        error_message = ""
47        for path in self.list_path:
48            try:
49                temp =  self.loader.load(path)
50                elapsed = time.time() - self.starttime
51                if temp.__class__.__name__ == "list":
52                    output += temp
53                else:
54                    output.append(temp)
55                message = "Loading ..." + str(path) + "\n"
56                if self.updatefn is not None:
57                    self.updatefn(output=output, message=message)
58            except:
59                error_message = "Error while loading: %s\n" % str(path)
60                error_message += str(sys.exc_value) + "\n"
61                self.updatefn(output=output, message=error_message)
62               
63        message = "Loading Complete!"
64        self.complete(output=output, error_message=error_message,
65                       message=message, path=self.list_path)
66           
67   
68     
Note: See TracBrowser for help on using the repository browser.