forked from planetfederal/qgis-mgrs-tools-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mgrstools.py
61 lines (47 loc) · 2.07 KB
/
mgrstools.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
# -*- coding: utf-8 -*-
import math
import os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from maptool import MGRSMapTool
from coorddialog import MGRSCoordInputDialog
class MGRSTools:
def __init__(self, iface):
self.iface = iface
def initGui(self):
self.mapTool = MGRSMapTool(self.iface.mapCanvas())
mapToolIcon = QIcon(os.path.join(os.path.dirname(__file__), "mgrs.svg"))
self.toolAction = QAction(mapToolIcon, "MGRS map tool",
self.iface.mainWindow())
self.toolAction.triggered.connect(self.setTool)
self.toolAction.setCheckable(True)
self.iface.addToolBarIcon(self.toolAction)
self.iface.addPluginToMenu("MGRS", self.toolAction)
zoomToIcon = QIcon(':/images/themes/default/mActionZoomIn.svg')
self.zoomToAction = QAction(zoomToIcon, "Zoom to MGRS coordinate",
self.iface.mainWindow())
self.zoomToAction.triggered.connect(self.zoomTo)
self.iface.addPluginToMenu("MGRS", self.zoomToAction)
self.iface.mapCanvas().mapToolSet.connect(self.unsetTool)
self.zoomTo = MGRSCoordInputDialog(self.iface.mapCanvas(), self.iface.mainWindow())
self.iface.addDockWidget(Qt.TopDockWidgetArea, self.zoomTo)
self.zoomTo.hide()
def zoomTo(self):
self.zoomTo.show()
def unsetTool(self, tool):
try:
if not isinstance(tool, MGRSMapTool):
self.toolAction.setChecked(False)
except:
pass
#ignore exceptions thrown when unloading plugin, since map tool class might not exist already
def setTool(self):
self.toolAction.setChecked(True)
self.iface.mapCanvas().setMapTool(self.mapTool)
def unload(self):
self.iface.mapCanvas().unsetMapTool(self.mapTool)
self.iface.removeToolBarIcon(self.toolAction)
self.iface.removePluginMenu("MGRS", self.toolAction)
self.iface.removePluginMenu("MGRS", self.zoomToAction)