process.py 2.92 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2016-2017 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/

__authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "06/07/2019"


from silx.gui import qt


class ProcessRunnable(qt.QRunnable):
    """
    qt Runnable for standard process.
    process function should take as input(spectrum, configuration, overwrite)

    :param function pointer fct: process function
    :param :class:`.Spectrum`: spectrum to process
    :param dict configuration: configuration of the process
    :param function pointer callback: optional callback to execute at the end of
                                      the run. Should take no parameter
    """

    def __init__(self, fct, spectrum, configuration, callback=None):
        qt.QRunnable.__init__(self)
        self._spectrum = spectrum
        self._configuration = configuration
        self._callback = callback
        self._function = fct

    def run(self):
        self._configuration, self._spectrum = self._function(
            spectrum=self._spectrum,
            configuration=self._configuration,
            overwrite=True)
        if self._callback:
            self._callback()


class ProcessQThread(qt.QThread):
    """
    Thread dedicated to process execution.
    """

    def __init__(self, parent=None):
        qt.QThread.__init__(self, parent)

    def init(self, xas_obj, process_obj):
        """
        Initialize the thread for processing xas_obj from proces_obj

        :param :class:`.XASObject` xas_obj: object to process 
        :param :class:`.Process` process_obj: object to process xas_obj
        """
        self._xas_obj = xas_obj
        self._process_obj = process_obj

    def run(self):
        self._xas_obj = self._process_obj.process(self._xas_obj)