forked from sourcepole/qgis-wps-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qgswps.py
141 lines (108 loc) · 4.82 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: utf-8 -*-
"""
/***************************************************************************
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 wps import version
from doAbout import DlgAbout
import apicompat
SEXTANTE_SUPPORT = False
try:
from sextante.core.Sextante import Sextante
from wps.sextantewps.WpsAlgorithmProvider import WpsAlgorithmProvider
SEXTANTE_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
userPluginPath = QFileInfo(QgsApplication.qgisUserDbFilePath()).path()+"/python/plugins/wps"
systemPluginPath = QgsApplication.prefixPath()+"/share/qgis/python/plugins/wps"
myLocale = pystring(QSettings().value("locale/userLocale"))[0:2]
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())
self.action.triggered.connect(self.run)
self.actionAbout = QAction("About", self.iface.mainWindow())
self.actionAbout.triggered.connect(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 SEXTANTE_SUPPORT:
self.provider = WpsAlgorithmProvider(self.myDockWidget)
else:
self.provider = None
if self.provider:
try:
Sextante.addProvider(self.provider, True) #Force tree update
except TypeError:
Sextante.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:
Sextante.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()