forked from lmotta/mapswipetool_plugin
/
__init__.py
79 lines (63 loc) · 2.65 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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Name : MapSwipe tool
Description : Plugin for swipe active layer
Date : October, 2015
copyright : (C) 2015 by Hirofumi Hayashi and Luiz Motta
email : hayashi@apptec.co.jp and motta.luiz@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. *
* *
***************************************************************************/
"""
__author__ = 'Luiz Motta'
__date__ = '2015-10-14'
__copyright__ = '(C) 2018, Luiz Motta'
__revision__ = '$Format:%H$'
from qgis.PyQt.QtCore import QObject, pyqtSlot
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction
from .mapswipetool import MapSwipeTool
import os
def classFactory(iface):
return MapSwipePlugin( iface )
class MapSwipePlugin(QObject):
def __init__(self, iface):
super().__init__()
self.iface = iface
self.canvas = iface.mapCanvas()
self.action = None # Define by initGui
self.tool = MapSwipeTool( self.iface )
self.prevTool = None # Define by run
def initGui(self):
title = "Map swipe tool"
icon = QIcon( os.path.join( os.path.dirname(__file__), 'mapswipetool.png' ) )
self.action = QAction( icon, title, self.iface.mainWindow() )
self.action.setObjectName( "MapSwipeTool" )
self.action.setWhatsThis( title )
self.action.setStatusTip( title )
self.action.triggered.connect( self.run )
self.menu = "&Map swipe tool"
# Maptool
self.action.setCheckable( True )
self.tool.setAction( self.action )
self.iface.addToolBarIcon( self.action )
self.iface.addPluginToMenu( self.menu, self.action )
def unload(self):
self.canvas.unsetMapTool( self.tool )
self.iface.removeToolBarIcon( self.action )
self.iface.removePluginMenu( self.menu, self.action )
del self.action
@pyqtSlot(bool)
def run(self, checked):
if self.canvas.mapTool() != self.tool:
self.prevTool = self.canvas.mapTool()
self.canvas.setMapTool( self.tool )
else:
self.canvas.setMapTool( self.prevTool )