-
Notifications
You must be signed in to change notification settings - Fork 4
/
__init__.py
133 lines (111 loc) · 4.06 KB
/
__init__.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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Name : Catalog Planet Labs
Description : Create catalog from Planet Labs
Date : April, 2015
copyright : (C) 2015 by Luiz Motta
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. *
* *
***************************************************************************/
"""
import os
from PyQt4 import QtCore, QtGui
from qgis import core as QgsCore, gui as QgsGui
from catalogpl import CatalogPL
from apiqtpl import API_PlanetLabs
def classFactory(iface):
return CatalogPLPlugin( iface )
class CatalogPLPlugin:
icon = QtGui.QIcon( os.path.join( os.path.dirname(__file__), 'catalogpl.svg' ) )
pluginName = "Catalog Planet Labs"
def __init__(self, iface):
self.iface = iface
self.name = u"&Catalog Planet Labs"
self.msgBar = iface.messageBar()
self.action = None
self.ctl = CatalogPL( CatalogPLPlugin.icon )
CatalogPL.copyExpression()
def initGui(self):
dataActions = [
{
'isSepatator': False,
'name': 'Catalog Planet Labs',
'icon': QtGui.QIcon( CatalogPLPlugin.icon ),
'method': self.run
},
{ 'isSepatator': True },
{
'isSepatator': False,
'name': 'Setting...',
'icon': QgsCore.QgsApplication.getThemeIcon('/mActionOptions.svg'),
'method': self.config
},
{ 'isSepatator': True },
{
'isSepatator': False,
'name': 'Clear key',
'icon': QgsCore.QgsApplication.getThemeIcon('/mActionOptions.svg'),
'method': self.clearKey
},
{
'isSepatator': False,
'name': 'Copy key to Clipboard',
'icon': QgsCore.QgsApplication.getThemeIcon('/mActionOptions.svg'),
'method': self.clipboardKey
}
]
mw = self.iface.mainWindow()
popupMenu = QtGui.QMenu( mw )
for d in dataActions:
if d['isSepatator']:
a = QtGui.QAction( mw )
a.setSeparator(True)
else:
a = QtGui.QAction( d['icon'], d['name'], mw )
a.triggered.connect( d['method'] )
self.iface.addPluginToRasterMenu( self.name, a )
popupMenu.addAction( a )
defaultAction = popupMenu.actions()[0]
self.toolButton = QtGui.QToolButton()
self.toolButton.setPopupMode( QtGui.QToolButton.MenuButtonPopup )
self.toolButton.setMenu( popupMenu )
self.toolButton.setDefaultAction( defaultAction )
self.actionPopupMenu = self.iface.addToolBarWidget( self.toolButton )
self.ctl.enableRun.connect( self.actionPopupMenu.setEnabled )
def unload(self):
self.iface.removePluginMenu( self.name, self.action )
self.iface.removeToolBarIcon( self.action )
del self.action
del self.ctl
@QtCore.pyqtSlot()
def run(self):
if self.iface.mapCanvas().layerCount() == 0:
msg = "Need layer(s) in map"
self.iface.messageBar().pushMessage( CatalogPLPlugin.pluginName, msg, QgsGui.QgsMessageBar.WARNING, 2 )
return
if not self.ctl.isHostLive:
self.ctl.hostLive()
if not self.ctl.isHostLive:
return
if not self.ctl.hasRegisterKey:
self.ctl.registerKey()
if not self.ctl.hasRegisterKey:
return
self.ctl.createLayerScenes()
@QtCore.pyqtSlot()
def config(self):
self.ctl.settingImages()
@QtCore.pyqtSlot()
def clearKey(self):
self.ctl.clearKey()
@QtCore.pyqtSlot()
def clipboardKey(self):
self.ctl.clipboardKey()