forked from NationalSecurityAgency/qgis-kmltools-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkmltools.py
83 lines (74 loc) · 3.68 KB
/
kmltools.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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
KMLTools
A QGIS plugin for importing KML into simple points, lines, and polygons.
It ignores KML styling.
-------------------
begin : 2018-03-16
***************************************************************************/
/***************************************************************************
* *
* 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 qgis.PyQt.QtCore import QUrl
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction
from qgis.core import QgsApplication
import processing
import os
from .provider import KmlToolsProvider
class KMLTools(object):
def __init__(self, iface):
self.iface = iface
self.htmlDialog = None
self.provider = KmlToolsProvider()
def initGui(self):
"""Create the menu & tool bar items within QGIS"""
icon = QIcon(os.path.dirname(__file__) + "/icon.png")
self.kmlAction = QAction(icon, "Import KML/KMZ", self.iface.mainWindow())
self.kmlAction.triggered.connect(self.showDialog)
self.kmlAction.setCheckable(False)
self.iface.addToolBarIcon(self.kmlAction)
self.iface.addPluginToVectorMenu("KML Tools", self.kmlAction)
# Expansion of HTML description field
icon = QIcon(os.path.dirname(__file__) + "/html.png")
self.htmlDescAction = QAction(icon, "Expand HTML description field", self.iface.mainWindow())
self.htmlDescAction.triggered.connect(self.htmlDescDialog)
self.htmlDescAction.setCheckable(False)
self.iface.addToolBarIcon(self.htmlDescAction)
self.iface.addPluginToVectorMenu("KML Tools", self.htmlDescAction)
# Help
icon = QIcon(os.path.dirname(__file__) + '/help.png')
self.helpAction = QAction(icon, "Help", self.iface.mainWindow())
self.helpAction.triggered.connect(self.help)
self.iface.addPluginToVectorMenu('KML Tools', self.helpAction)
# Add the processing provider
QgsApplication.processingRegistry().addProvider(self.provider)
def unload(self):
"""Remove the plugin menu item and icon from QGIS GUI."""
self.iface.removePluginVectorMenu("KML Tools", self.kmlAction)
self.iface.removePluginVectorMenu("KML Tools", self.htmlDescAction)
self.iface.removePluginVectorMenu("KML Tools", self.helpAction)
self.iface.removeToolBarIcon(self.kmlAction)
self.iface.removeToolBarIcon(self.htmlDescAction)
QgsApplication.processingRegistry().removeProvider(self.provider)
def showDialog(self):
"""Display the KML Dialog window."""
processing.execAlgorithmDialog('kmltools:importkml', {})
def htmlDescDialog(self):
"""Display the KML Dialog window."""
if not self.htmlDialog:
from .htmlExpansionDialog import HTMLExpansionDialog
self.htmlDialog = HTMLExpansionDialog(self.iface)
self.htmlDialog.show()
def help(self):
'''Display a help page'''
import webbrowser
url = QUrl.fromLocalFile(os.path.dirname(__file__) + "/index.html").toString()
webbrowser.open(url, new=2)