source: sasview/src/sas/sasgui/perspectives/calculator/load_thread.py @ cb05bfd

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.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since cb05bfd was d85c194, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago

Remaining modules refactored

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[7343319]1"""
2    Thread handler used to load data
3"""
[378d2eb]4import time
[b699768]5from sas.sascalc.data_util.calcthread import CalcThread
6from sas.sascalc.dataloader.loader import Loader
[49ab5d7]7
[378d2eb]8class DataReader(CalcThread):
9    """
[7343319]10        Load a data given a filename
[378d2eb]11    """
[7dca26e]12    def __init__(self, path, completefn=None,
[49ab5d7]13                 updatefn=None,
14                 yieldtime=0.01,
15                 worktime=0.01
[378d2eb]16                 ):
17        CalcThread.__init__(self, completefn,
18                 updatefn,
19                 yieldtime,
20                 worktime)
21        self.path = path
22        #Instantiate a loader
23        self.loader = Loader()
[49ab5d7]24        self.starttime = 0
25
[378d2eb]26    def isquit(self):
27        """
28             @raise KeyboardInterrupt: when the thread is interrupted
29        """
30        try:
31            CalcThread.isquit(self)
32        except KeyboardInterrupt:
[49ab5d7]33            raise KeyboardInterrupt
34
35
[378d2eb]36    def compute(self):
37        """
38            read some data
39        """
40        self.starttime = time.time()
41        try:
[49ab5d7]42            data = self.loader.load(self.path)
[7dca26e]43            self.complete(data=data)
[378d2eb]44        except KeyboardInterrupt:
45            # Thread was interrupted, just proceed and re-raise.
46            # Real code should not print, but this is an example...
47            raise
[49ab5d7]48
[318b5bbb]49class GenReader(CalcThread):
50    """
51        Load a sld data given a filename
52    """
[49ab5d7]53    def __init__(self, path, loader,
[318b5bbb]54                 completefn=None,
[49ab5d7]55                 updatefn=None,
56                 yieldtime=0.01,
57                 worktime=0.01
[318b5bbb]58                 ):
59        CalcThread.__init__(self, completefn,
60                 updatefn,
61                 yieldtime,
62                 worktime)
63        self.path = path
64        #Instantiate a loader
65        self.loader = loader
[49ab5d7]66        self.starttime = 0
67
[318b5bbb]68    def isquit(self):
69        """
70             @raise KeyboardInterrupt: when the thread is interrupted
71        """
72        try:
73            CalcThread.isquit(self)
74        except KeyboardInterrupt:
[49ab5d7]75            raise KeyboardInterrupt
76
77
[318b5bbb]78    def compute(self):
79        """
80            read some data
81        """
82        self.starttime = time.time()
83        try:
[49ab5d7]84            data = self.loader.read(self.path)
[318b5bbb]85            self.complete(data=data)
86        except:
87            # Thread was interrupted, just proceed and re-raise.
88            # Real code should not print, but this is an example...
89            raise
Note: See TracBrowser for help on using the repository browser.