-
Notifications
You must be signed in to change notification settings - Fork 2
/
plugin.py
74 lines (58 loc) · 2.82 KB
/
plugin.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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Name : RT QSpider
Description : Convert a table to an event layer or a spider diagram
Date : Nov 14, 2012
copyright : (C) 2012 by Giuseppe Sucameli (Faunalia)
email : brush.tyler@gmail.com
***************************************************************************/
/***************************************************************************
* *
* 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 PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
import resources_rc
class RTQSpiderPlugin:
def __init__(self, iface):
self.iface = iface
def initGui(self):
self.action = QAction(QIcon(":/rt_qspider/icons/logo"), "Table to vector converter", self.iface.mainWindow())
QObject.connect(self.action, SIGNAL("triggered()"), self.run)
self.aboutAction = QAction( QIcon( ":/rt_qspider/icons/about" ), "About", self.iface.mainWindow() )
QObject.connect( self.aboutAction, SIGNAL("triggered()"), self.about )
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu("RT QSpider", self.action)
self.iface.addPluginToMenu("RT QSpider", self.aboutAction)
def unload(self):
self.iface.removeToolBarIcon(self.action)
self.iface.removePluginMenu("RT QSpider", self.action)
self.iface.removePluginMenu("RT QSpider", self.aboutAction)
def about(self):
""" display the about dialog """
from .DlgAbout import DlgAbout
dlg = DlgAbout( self.iface.mainWindow() )
dlg.exec_()
def run(self):
# check for an active vector layer
vl = self.iface.activeLayer()
if not vl or vl.type() != QgsMapLayer.VectorLayer:
QMessageBox.information(None, "RT QSpider", "Select a table or a vector layer to continue...")
return
# open the dialog
from .dialog import RTQSpiderDlg
dlg = RTQSpiderDlg(vl, self.iface.mainWindow())
if not dlg.exec_():
return # cancel pressed
# create the output vector layer and add it to canvas
fn = dlg.getOutputFilename()
if fn is not None:
self.iface.addVectorLayer(fn, vl.name(), "ogr")