-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.py
More file actions
67 lines (56 loc) · 2.39 KB
/
plugin.py
File metadata and controls
67 lines (56 loc) · 2.39 KB
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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
QRightAngle
A QGIS plugin
The plugin for right angle processing of vector features
-------------------
begin : 2020-04-03
copyright : (C) 2020 by DHui Jiang
email : dhuijiang@163.com
git : https://github.com/dhuijiang/QRightAngle
***************************************************************************/
"""
from qgis.core import QgsVectorLayer, QgsWkbTypes
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction, QMessageBox
from QRightAngle import RESOURCE_PREFIX
from . import resources
from .QRightAngle import QRightAngle
class MainPlugin:
mapTool = None
def __init__(self, iface):
self.iface = iface
def initGui(self):
self.action = QAction('Right Angle')
self.action.triggered.connect(self.onClick)
self.action.setIcon(QIcon(RESOURCE_PREFIX + 'icon.png'))
self.action.setCheckable(True)
tooltip = '<strong>RightAngle of vector features</strong>'
tooltip += '<p>Supported geometry types:<br><strong>'
tooltip += '/'.join([QgsWkbTypes.displayString(x) for x in QRightAngle.CanDoTypes])
tooltip += '</strong></p>'
self.action.setToolTip(tooltip)
self.action.setStatusTip("Select vector features for right angle processing ...")
self.iface.addToolBarIcon(self.action)
self.iface.currentLayerChanged.connect(self.currentLayerChanged)
self.enableTool()
def unload(self):
self.iface.removeToolBarIcon(self.action)
def currentLayerChanged(self):
self.enableTool()
def onClick(self):
if not self.action.isChecked():
self.iface.mapCanvas().unsetMapTool(self.mapTool)
self.mapTool = None
return
self.action.setChecked(True)
self.mapTool = QRightAngle(self.iface.mapCanvas())
self.mapTool.setAction(self.action)
self.iface.mapCanvas().setMapTool(self.mapTool)
def enableTool(self):
self.action.setEnabled(False)
layer = self.iface.activeLayer()
if layer != None and isinstance(layer, QgsVectorLayer):
if layer.wkbType() in QRightAngle.CanDoTypes:
self.action.setEnabled(True)