-
Notifications
You must be signed in to change notification settings - Fork 1
/
task.py
77 lines (66 loc) · 2.24 KB
/
task.py
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
"""
GEEST Plugin
Author: Your Name
Copyright: 2024, Your Organization
License: GPL-3.0-only
This file is part of the GEEST QGIS Plugin. It is available under the terms of the GNU General Public License v3.0 only.
See the LICENSE file in the project root for more information.
"""
from qgis.core import QgsTask, QgsMessageLog, Qgis
from PyQt5.QtCore import pyqtSignal
import os
class GEESTTask(QgsTask):
"""
Custom task for running GEEST plugin operations as a background job.
"""
finished = pyqtSignal(bool)
error = pyqtSignal()
def __init__(self, description, node):
super().__init__(description)
self.node = node
def run(self):
"""
Executes the task. This is the main work method that performs the background operation.
"""
try:
output_path = self.node["output_path"]
if self.node.get("processed", False) and os.path.exists(output_path):
QgsMessageLog.logMessage(
f"{self.node['name']} already processed",
"Geest",
Qgis.Info,
)
self.finished.emit(True)
return True
# Simulate processing
self.process_node()
self.node["processed"] = True
QgsMessageLog.logMessage(
f"Processed {self.node['name']}", "Geest", Qgis.Info
)
self.finished.emit(True)
return True
except Exception as e:
QgsMessageLog.logMessage(
f"Task failed for {self.node['name']}: {str(e)}",
"Geest",
Qgis.Critical,
)
self.error.emit()
return False
def process_node(self):
"""
Simulates the processing of the node.
"""
output_path = self.node["output_path"]
os.makedirs(os.path.dirname(output_path), exist_ok=True)
with open(output_path, "w") as f:
f.write(f"Processed output for {self.node['name']}")
def cancel(self):
"""
Handles task cancellation.
"""
QgsMessageLog.logMessage(
f"{self.node['name']} task was cancelled", "GEEST", Qgis.Info
)
super().cancel()