forked from rldhont/qgis-wps-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qgswps.py
executable file
·140 lines (114 loc) · 5.28 KB
/
qgswps.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
# -*- coding: latin1 -*-
"""
/***************************************************************************
QGIS Web Processing Service Plugin
-------------------------------------------------------------------
Date : 09 November 2009
Copyright : (C) 2009 by Dr. Horst Duester
email : horst dot duester at kappasys dot ch
***************************************************************************
* *
* 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 the PyQt and the QGIS libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from QgsWpsDockWidget import QgsWpsDockWidget
from __init__ import version
from doAbout import DlgAbout
import os
PROCESSING_SUPPORT = False
try:
from processing.core.Processing import Processing
from processingwps.WpsAlgorithmProvider import WpsAlgorithmProvider
PROCESSING_SUPPORT = True
except ImportError:
pass
# initialize Qt resources from file resources.py
import resources_rc
DEBUG = False
# Our main class for the plugin
class QgsWps:
MSG_BOX_TITLE = "WPS Client"
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
self.localePath = ""
#Initialise the translation environment
# TODO with this solution probably we could look only for a path and
# not for userPluginPath and systemPluginPath, in this way it should
# recognize what is the right path
userPluginPath = os.path.dirname(os.path.realpath(__file__))
systemPluginPath = QgsApplication.prefixPath() + "/share/qgis/python/plugins/wps"
myLocaleName = QSettings().value("locale/userLocale")
myLocale = myLocaleName[0:2]
print userPluginPath
if QFileInfo(userPluginPath).exists():
self.pluginPath = userPluginPath
self.localePath = userPluginPath + "/i18n/wps_" + myLocale + ".qm"
elif QFileInfo(systemPluginPath).exists():
self.pluginPath = systemPluginPath
self.localePath = systemPluginPath + "/i18n/wps_" + myLocale + ".qm"
if QFileInfo(self.localePath).exists():
self.translator = QTranslator()
self.translator.load(self.localePath)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
############################################################################
def initGui(self):
# Create action that will start plugin configuration
self.action = QAction(QIcon(":/plugins/wps/images/wps-add.png"),
"WPS-Client", self.iface.mainWindow())
QObject.connect(self.action, SIGNAL("triggered()"), self.run)
self.actionAbout = QAction("About", self.iface.mainWindow())
QObject.connect(self.actionAbout, SIGNAL("triggered()"), self.doAbout)
# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
if hasattr(self.iface, "addPluginToWebMenu"):
self.iface.addPluginToWebMenu("WPS-Client", self.action)
self.iface.addPluginToWebMenu("WPS-Client", self.actionAbout)
else:
self.iface.addPluginToMenu("WPS", self.action)
self.iface.addPluginToWebMenu("WPS", self.action)
self.myDockWidget = QgsWpsDockWidget(self.iface)
self.myDockWidget.setWindowTitle('WPS')
self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.myDockWidget)
self.myDockWidget.show()
if PROCESSING_SUPPORT:
self.provider = WpsAlgorithmProvider(self.myDockWidget)
else:
self.provider = None
if self.provider:
try:
Processing.addProvider(self.provider, True) #Force tree update
except TypeError:
Processing.addProvider(self.provider)
############################################################################
def unload(self):
if hasattr(self.iface, "addPluginToWebMenu"):
self.iface.removePluginWebMenu("WPS-Client", self.action)
self.iface.removePluginWebMenu("WPS-Client", self.actionAbout)
else:
self.iface.removePluginToMenu("WPS", self.action)
self.iface.removePluginToMenu("WPS", self.actionAbout)
self.iface.removeToolBarIcon(self.action)
if self.myDockWidget:
self.myDockWidget.close()
self.myDockWidget = None
if self.provider:
Processing.removeProvider(self.provider)
##############################################################################
def run(self):
if self.myDockWidget.isVisible():
self.myDockWidget.hide()
else:
self.myDockWidget.show()
def doAbout(self):
self.dlgAbout = DlgAbout()
self.dlgAbout.show()