File size: 984 Bytes
128f42e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Worker thread for image processing.
"""

from PyQt5.QtCore import QThread, pyqtSignal
import traceback

try:
    from image_postprocess import process_image
except Exception:
    process_image = None
    IMPORT_ERROR = "Could not import process_image module"
else:
    IMPORT_ERROR = None

class Worker(QThread):
    finished = pyqtSignal(str)
    error = pyqtSignal(str, str)  # error message + traceback

    def __init__(self, inpath, outpath, args):
        super().__init__()
        self.inpath = inpath
        self.outpath = outpath
        self.args = args

    def run(self):
        try:
            if process_image is None:
                raise RuntimeError("Could not import process_image: " + (IMPORT_ERROR or "unknown"))
            process_image(self.inpath, self.outpath, self.args)
            self.finished.emit(self.outpath)
        except Exception as e:
            tb = traceback.format_exc()
            self.error.emit(str(e), tb)