-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWorkflowProviderBase.py
152 lines (127 loc) · 5.85 KB
/
WorkflowProviderBase.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
"""
***************************************************************************
WorkflowProvider.py
-------------------------------------
Copyright (C) 2014 TIGER-NET (www.tiger-net.org)
***************************************************************************
* This plugin is part of the Water Observation Information System (WOIS) *
* developed under the TIGER-NET project funded by the European Space *
* Agency as part of the long-term TIGER initiative aiming at promoting *
* the use of Earth Observation (EO) for improved Integrated Water *
* Resources Management (IWRM) in Africa. *
* *
* WOIS is a free software i.e. you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published *
* by the Free Software Foundation, either version 3 of the License, *
* or (at your option) any later version. *
* *
* WOIS is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
* for more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************
"""
from builtins import str
from qgis.PyQt.QtWidgets import QAction
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QCoreApplication
from qgis.utils import iface
from qgis.core import QgsProcessingProvider, QgsMessageLog, Qgis
from processing.core.ProcessingConfig import ProcessingConfig, settingsWatcher
from processing_workflow.EditWorkflowAction import EditWorkflowAction
from processing_workflow.DeleteWorkflowAction import DeleteWorkflowAction
from processing_workflow.Workflow import Workflow
from processing_workflow.WorkflowListDialog import WorkflowListDialog
from processing_workflow.WrongWorkflowException import WrongWorkflowException
class WorkflowProviderBase(QgsProcessingProvider):
def __init__(self, activate=False):
QgsProcessingProvider.__init__(self)
self.activate = activate
self.algs = []
self.actions = []
self.descriptionFile = ""
self.baseDir = ""
self.description = ""
self._name = ""
self.iconPath = ""
self.aboutHTML = ""
self.css = ""
# Right click button actions
self.contextMenuActions = [EditWorkflowAction(), DeleteWorkflowAction()]
settingsWatcher.settingsChanged.connect(self.addRemoveTaskbarButton)
def unload(self):
QgsProcessingProvider.unload(self)
def _addToolbarIcon(self):
# Create action that will display workflow list dialog when toolbar button is clicked
self.action = QAction(self.icon(), self.longName(), iface.mainWindow())
self.action.triggered.connect(self.displayWorkflowListDialog)
# Load all the workflows saved in the workflow folder
def createAlgsList(self):
return []
def loadWorkflow(self, workflowFilePath):
try:
workflow = Workflow()
workflow.openWorkflow(workflowFilePath)
if workflow.name().strip() != "":
self.preloadedAlgs.append(workflow)
else:
QgsMessageLog.logMessage(
self.tr("Could not open Workflow algorithm: " + workflowFilePath),
self.tr("Processing"),
Qgis.Critical)
except WrongWorkflowException as e:
QgsMessageLog.logMessage(
self.tr("Could not open Workflow algorithm "+workflowFilePath+". "+e.msg),
self.tr("Processing"),
Qgis.Critical)
except Exception as e:
QgsMessageLog.logMessage(
self.tr("Could not open Workflow algorithm: " + workflowFilePath +
". Unknown exception: "+str(e)+"\n"),
self.tr("Processing"),
Qgis.Critical)
def longName(self):
return self.description
def name(self):
return self._name
def id(self):
return "processing_workflow"
def helpId(self):
return "processing_workflow"
def icon(self):
return QIcon(self.iconPath)
def getActivateSetting(self):
return 'ACTIVATE_' + self.name().upper().replace(' ', '_')
def getTaskbarButtonSetting(self):
return 'TASKBAR_BUTTON_' + self.name().upper().replace(' ', '_')
def addRemoveTaskbarButton(self):
name = self.getActivateSetting()
taskbar = self.getTaskbarButtonSetting()
if self.isActive() and ProcessingConfig.getSetting(taskbar):
# Add toolbar button
iface.addToolBarIcon(self.action)
else:
# Remove toolbar button
iface.removeToolBarIcon(self.action)
def load(self):
QgsProcessingProvider.load(self)
ProcessingConfig.readSettings()
self.addRemoveTaskbarButton()
self.loadAlgorithms()
return True
def loadAlgorithms(self):
algs = self.createAlgsList()
for a in algs:
self.addAlgorithm(a)
# display a dialog listing all the workflows
def displayWorkflowListDialog(self):
dlg = WorkflowListDialog(self)
dlg.show()
dlg.exec_()
def tr(self, string, context=''):
if context == '':
context = 'WorkflowProvider'
return QCoreApplication.translate(context, string)