-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwps_plugin_dockwidget.py
233 lines (197 loc) · 8.73 KB
/
wps_plugin_dockwidget.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# -*- coding: utf-8 -*-
"""
/***************************************************************************
WPSWidgetDockWidget
A QGIS plugin
WPS PLugin OpenGeoLabs
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2021-06-05
git sha : $Format:%H$
copyright : (C) 2021 by OpenGeoLabs
email : jan.ruzicka.vsb@gmail.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
import os
from qgis.PyQt import uic, QtWidgets
from qgis.utils import iface
from qgis.core import *
from qgis.gui import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtWidgets import *
import json
from .connect import *
from .wps_dialog import WpsDialog
from .check_ows_lib import CheckOwsLib
from owslib.wps import WebProcessingService
from owslib.wps import ComplexDataInput
FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'wps_plugin_dockwidget_base.ui'))
class WPSWidgetDockWidget(QtWidgets.QDockWidget, FORM_CLASS):
closingPlugin = pyqtSignal()
def __init__(self, iface, parent=None):
"""Constructor."""
super(WPSWidgetDockWidget, self).__init__(parent)
# Set up the user interface from Designer.
# After setupUI you can access any designer object by doing
# self.<objectname>, and you can use autoconnect slots - see
# http://doc.qt.io/qt-5/designer-using-a-ui-file.html
# #widgets-and-dialogs-with-auto-connect
self.iface = iface
self.setupUi(self)
self.first_start = True
self.settings = QSettings('QGIS_WPS_Plugin')
tree = self.treeWidgetServices
tree.itemSelectionChanged.connect(self.handleSelected)
tree.itemDoubleClicked.connect(self.handleDoubleClicked)
self.pushButtonLoad.clicked.connect(self.executeProcess)
self.root = QTreeWidgetItem(tree)
self.root.setText(0, 'WPS Services')
self.loadServices(self.root)
self.treeWidgetServices.expandItem(self.root)
self.treeWidgetServices.customContextMenuRequested.connect(self.menuContextTree)
self.root.setExpanded(True)
def appendServiceToTree(self, parent, service_url):
service = QTreeWidgetItem(parent)
service.setText(0, service_url)
service.setData(0, Qt.UserRole, service_url)
service.setExpanded(True)
def loadServices(self, parent):
self.services = self.settings.value("services", [])
if self.services is None:
self.services = []
for service_url in self.services:
self.appendServiceToTree(parent, service_url)
def menuContextTree(self, point):
# Infos about the node selected.
index = self.treeWidgetServices.indexAt(point)
if not index.isValid():
return
item = self.treeWidgetServices.itemAt(point)
name = item.text(0) # The text of the node.
# We build the menu.
menu = QtWidgets.QMenu()
# action = menu.addAction("Souris au-dessus de")
# action = menu.addAction(name)
# menu.addSeparator()
if item.parent() is None:
action_new_connection = menu.addAction(self.tr("New Service"))
action_new_connection.triggered.connect(self.newService)
else:
if item.parent().parent() is None:
action_delete_connection = menu.addAction(self.tr("Remove Service"))
action_delete_connection.triggered.connect(self.removeService)
else:
action_run_process = menu.addAction(self.tr("Execute"))
action_run_process.triggered.connect(self.executeProcess)
menu.exec_(self.treeWidgetServices.mapToGlobal(point))
def saveServices(self):
self.settings.setValue("services", self.services)
def newService(self):
dlg = QInputDialog(self)
dlg.setWindowTitle(self.tr('New Service'))
dlg.setInputMode(QInputDialog.TextInput)
dlg.setLabelText(self.tr('Enter URL of the service'))
dlg.resize(500, 100)
if dlg.exec_():
text = dlg.textValue()
if text in self.services:
QMessageBox.information(
None, self.tr("INFO:"),
self.tr("The service is already registered"))
else:
self.services.append(text)
self.appendServiceToTree(self.root, text)
self.saveServices()
def removeService(self):
reply = QMessageBox.question(
self,
self.tr("Remove service"),
"This will remove the service from the list. Are you sure?",
QMessageBox.Yes,
QMessageBox.No,
)
if reply == QMessageBox.Yes:
service = self.getSelectedItem()
service_data = service.data(0, Qt.UserRole)
parent = service.parent()
parent.removeChild(service)
self.services.remove(service_data)
self.saveServices()
def executeProcess(self):
process = self.getSelectedItem()
process_data = process.data(0, Qt.UserRole)
items = process_data.split('|')
if self.first_start == True:
self.first_start = False
self.dlg = WpsDialog(self.iface)
self.dlg.setServiceUrl(items[0])
self.dlg.setProcessIdentifier(items[2])
self.dlg.loadProcess()
# show the dialog
self.dlg.show()
def handleDoubleClicked(self, item, column):
if item.data(0, Qt.UserRole) is not None:
id = item.data(0, Qt.UserRole)
if '|' in id:
self.executeProcess()
def handleSelected(self):
self.pushButtonLoad.setEnabled(False)
for item in self.treeWidgetServices.selectedItems():
if item.data(0, Qt.UserRole) is not None:
id = item.data(0, Qt.UserRole)
if '|' not in id:
# service
self.loadProcesses(id)
else:
# process
self.pushButtonLoad.setEnabled(True)
self.processSelected(id)
def getSelectedItem(self):
for item in self.treeWidgetServices.selectedItems():
return item
def loadProcesses(self, url):
self.setCursor(Qt.WaitCursor)
self.__load_processes = GetProcesses()
self.__load_processes.setUrl(url)
self.__load_processes.statusChanged.connect(self.onLoadProcessesResponse)
self.__load_processes.start()
def onLoadProcessesResponse(self, response):
if response.status == 200:
self.processes = response.data
service = self.getSelectedItem()
for i in reversed(range(service.childCount())):
service.removeChild(service.child(i))
service_url = service.data(0, Qt.UserRole)
id = 0
for proc in self.processes:
process = QTreeWidgetItem(service)
process.setText(0, '[{}] {}'.format(proc.identifier, proc.title))
process.setData(0, Qt.UserRole, service_url + '|' + str(id) + '|' + str(proc.identifier))
# print(proc.title)
id += 1
else:
QMessageBox.information(None, self.tr("ERROR:"), self.tr("Error loading processes"))
self.setCursor(Qt.ArrowCursor)
def showProcessesDescription(self, index):
desc = "[" + self.processes[index].identifier + "]: "
if self.processes[index].title:
desc += self.processes[index].title
if self.processes[index].abstract:
desc += "\n\n" + self.processes[index].abstract
self.textEditProcessDescription.setText(desc)
def processSelected(self, id):
current_index = int(id.split('|')[1])
self.showProcessesDescription(current_index)
def closeEvent(self, event):
self.closingPlugin.emit()
event.accept()