-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtombio.py
222 lines (183 loc) · 9.49 KB
/
tombio.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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
A QGIS plugin
FSC QGIS Plugin for biological recorders
-------------------
begin : 2014-02-17
copyright : (C) 2014 by Rich Burkmar, Field Studies Council
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from qgis.core import *
from qgis.gui import *
from qgis.utils import *
from . import osgrdialog
from . import nbndialog
from . import mapmashupdialog
from . import biorecdialog
from . import envdialog
from .add_grid_ref_provider import AddGridRefProvider
from qgis.core import QgsProcessingAlgorithm, QgsApplication
import os
import sys
import inspect
import processing
cmd_folder = os.path.split(inspect.getfile(inspect.currentframe()))[0]
if cmd_folder not in sys.path:
sys.path.insert(0, cmd_folder)
class custDockWidget(QDockWidget):
closed = pyqtSignal()
def __init__(self, title, parent):
super(custDockWidget, self).__init__(title, parent)
# The QDockWidget class is subclassed so that we can detect when the widget
# is closed by the user.
def closeEvent(self, event):
super(custDockWidget, self).closeEvent(event)
self.closed.emit()
class TomBio:
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
localePath = os.path.join(self.plugin_dir, 'i18n', 'tombio_{}.qm'.format(locale))
if os.path.exists(localePath):
self.translator = QTranslator()
self.translator.load(localePath)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
# Init Add GRs to layers Processing tool
self.provider = AddGridRefProvider(iface)
def initGui(self):
# Toolbar
self.toolbar = self.iface.addToolBar("TomBioToolbar")
# OSGR tool
icon_path = os.path.join(os.path.dirname(__file__),'images/osgrPoly.png')
self.actionOsgr = QAction(QIcon(icon_path), u"OSGR Tool", self.iface.mainWindow())
self.iface.addPluginToMenu(u"&FSC Tools", self.actionOsgr)
self.actionOsgr.triggered.connect(self.showOsgrDialog)
self.toolbar.addAction(self.actionOsgr)
self.dwOsgr = None
# Display Biological Records Tool
icon_path = os.path.join(os.path.dirname(__file__),'images/maptaxa.png')
self.actionBiorec = QAction(QIcon(icon_path), u"Biological Records Tool", self.iface.mainWindow())
self.iface.addPluginToMenu(u"&FSC Tools", self.actionBiorec)
self.actionBiorec.triggered.connect(self.showBiorecDialog)
self.toolbar.addAction(self.actionBiorec)
self.dwBiorec = None
# NBN Tool
icon_path = os.path.join(os.path.dirname(__file__),'images/nbn.png')
self.actionNbn = QAction(QIcon(icon_path), u"NBN Atlas Tool", self.iface.mainWindow())
self.iface.addPluginToMenu(u"&FSC Tools", self.actionNbn)
self.actionNbn.triggered.connect(self.showNbnDialog)
self.toolbar.addAction(self.actionNbn)
self.dwNbn = None
# Map Mashup Tool
icon_path = os.path.join(os.path.dirname(__file__),'images/mashup.png')
self.actionMapMash = QAction(QIcon(icon_path), u"Map Mashup Tool", self.iface.mainWindow())
self.iface.addPluginToMenu(u"&FSC Tools", self.actionMapMash)
self.actionMapMash.triggered.connect(self.showMapmashupDialog)
self.toolbar.addAction(self.actionMapMash)
self.dwMapmashup = None
# GRs to points Processing tool
icon_path = os.path.join(os.path.dirname(__file__),'images/gr2point.png')
self.actionGRs2Points = QAction(QIcon(icon_path), u"Add GRs to layers", self.iface.mainWindow())
self.iface.addPluginToMenu(u"&FSC Tools", self.actionGRs2Points)
self.actionGRs2Points.triggered.connect(self.showGRs2PointsProcessingTools)
self.toolbar.addAction(self.actionGRs2Points)
# Help dialog
icon_path = os.path.join(os.path.dirname(__file__),'images/info.png')
self.actionHelp = QAction(QIcon(icon_path), u"Help and Info on FSC QGIS plugin", self.iface.mainWindow())
self.iface.addPluginToMenu(u"&FSC Tools", self.actionHelp)
self.actionHelp.triggered.connect(self.showHelp)
self.toolbar.addAction(self.actionHelp)
# Environment Options
self.actionEnv = QAction(u"Environment Options", self.iface.mainWindow())
self.iface.addPluginToMenu(u"&FSC Tools", self.actionEnv)
self.actionEnv.triggered.connect(self.showEnvDialog)
self.guiEnv = None
# Add Grid Ref to point layer Processing tool
QgsApplication.processingRegistry().addProvider(self.provider)
def showHelp(self):
#showPluginHelp()
QDesktopServices().openUrl(QUrl("http://www.fscbiodiversity.uk/qgisplugin"))
def showOsgrDialog(self):
if self.dwOsgr is None:
self.dwOsgr = custDockWidget("FSC - OSGR Tool", self.iface.mainWindow())
self.guiOsgr = osgrdialog.OsgrDialog(self.iface, self.dwOsgr)
self.dwOsgr.setWidget(self.guiOsgr)
self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dwOsgr)
self.dwOsgr.closed.connect(self.closeOsgrDialog)
else:
self.dwOsgr.setVisible(True)
def closeOsgrDialog(self):
self.guiOsgr.clearMapGraphics(True, True)
self.guiOsgr.cbGRShowSquare.setChecked(False)
def showNbnDialog(self):
if self.dwNbn is None:
self.dwNbn = custDockWidget("FSC - NBN Atlas Tool", self.iface.mainWindow())
self.guiNbn = nbndialog.NBNDialog(self.iface, self.dwNbn)
self.dwNbn.setWidget(self.guiNbn)
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.dwNbn)
self.guiNbn.displayNBNCSVFile.connect(self.displayNBNCSVFile)
else:
self.dwNbn.setVisible(True)
def displayNBNCSVFile(self, strCSV):
self.dwNbn.setVisible(False)
self.showBiorecDialog()
#self.iface.messageBar().pushMessage("Info", "CSV: " + strCSV, level=Qgis.Info)
self.guiBiorec.setCSV(strCSV)
def showMapmashupDialog(self):
if self.dwMapmashup is None:
self.dwMapmashup = custDockWidget("FSC - Map Mashup Tool", self.iface.mainWindow())
self.guiMapmashup = mapmashupdialog.MapmashupDialog(self.iface, self.dwMapmashup)
self.dwMapmashup.setWidget(self.guiMapmashup)
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.dwMapmashup)
else:
self.dwMapmashup.setVisible(True)
def showGRs2PointsProcessingTools(self):
processing.execAlgorithmDialog('FSC:Add GRs to layers', {})
def showBiorecDialog(self):
if self.dwBiorec is None:
self.dwBiorec = custDockWidget("FSC - Biological Records Tool", self.iface.mainWindow())
self.guiBiorec = biorecdialog.BiorecDialog(self.iface, self.dwBiorec)
self.dwBiorec.setWidget(self.guiBiorec)
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.dwBiorec)
else:
self.dwBiorec.setVisible(True)
#self.dwBiorec.setVisible(False)
#self.dwBiorec = custDockWidget("FSC - Biological Records Tool", self.iface.mainWindow())
#self.guiBiorec = BiorecDialog(self.iface, self.dwBiorec)
#self.dwBiorec.setWidget(self.guiBiorec)
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.dwBiorec)
def showEnvDialog(self):
if self.guiEnv is None:
self.guiEnv = envdialog.EnvDialog(self.iface)
self.guiEnv.setVisible(True)
def unload(self):
# Remove the Grid Ref to points Processing tool
QgsApplication.processingRegistry().removeProvider(self.provider)
# Remove the plugin menu item
self.iface.removePluginMenu(u"&FSC Tools", self.actionOsgr)
self.iface.removePluginMenu(u"&FSC Tools", self.actionBiorec)
self.iface.removePluginMenu(u"&FSC Tools", self.actionNbn)
self.iface.removePluginMenu(u"&FSC Tools", self.actionMapMash)
self.iface.removePluginMenu(u"&FSC Tools", self.actionGRs2Points)
self.iface.removePluginMenu(u"&FSC Tools", self.actionEnv)
self.iface.removePluginMenu(u"&FSC Tools", self.actionHelp)
#Remove the toolbar
del self.toolbar