-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy path__init__.py
More file actions
112 lines (86 loc) · 3.68 KB
/
__init__.py
File metadata and controls
112 lines (86 loc) · 3.68 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
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
# -*- 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$'
import os
from qgis.PyQt.QtCore import (
QObject,
QDir,
pyqtSlot
)
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction
from qgis.gui import QgisInterface, QgsMapTool
from .tool.maptool import MapSwipeTool
from .tool.translate import setTranslation
def classFactory(iface:QgisInterface):
return MapSwipe( iface )
class MapSwipe(QObject):
def __init__(self, iface:QgisInterface):
super().__init__()
self.iface = iface
self.canvas = iface.mapCanvas()
setTranslation( type(self).__name__, os.path.dirname(__file__) )
self.plugin_name = 'MapSwipe'
self.action_name = 'MapSwipe'
self.action = None
self.maptool = None
self.previus_maptool = None # Define by run
def initGui(self):
path = QDir( os.path.dirname(__file__) )
icon = QIcon( path.filePath('resources/mapswipe.png'))
self.action = QAction( icon, self.action_name, self.iface.mainWindow() )
self.action.setToolTip( self.action_name )
self.action.setCheckable(True)
self.action.triggered.connect(self.on_Clicked)
self.canvas.mapToolSet.connect( self.on_MapToolSet )
self.maptool = MapSwipeTool( self.plugin_name, self.iface )
self.previus_maptool = self.canvas.mapTool()
self.menu_name = f"&{self.action_name}"
self.iface.addPluginToMenu( self.menu_name, self.action )
self.iface.addToolBarIcon( self.action )
def unload(self)->None:
self.iface.removePluginMenu( self.menu_name, self.action )
self.iface.removeToolBarIcon( self.action )
self.iface.unregisterMainWindowAction( self.action )
if self.maptool:
self.canvas.unsetMapTool( self.maptool )
# Disconnect
try:
self.action.triggered.disconnect( self.on_Clicked )
except Exception:
pass
self.action.deleteLater()
del self.maptool
@pyqtSlot(bool)
def on_Clicked(self, enabled:bool)->None:
if enabled:
if not self.maptool.canExecute():
self.action.setChecked(False)
return
self.previus_maptool = self.canvas.mapTool()
self.canvas.setMapTool( self.maptool )
return
self.canvas.setMapTool( self.previus_maptool )
@pyqtSlot(QgsMapTool, QgsMapTool)
def on_MapToolSet(self, newTool:QgsMapTool, oldTool:QgsMapTool)->None:
if oldTool == self.maptool:
self.action.setChecked(False)