-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.py
More file actions
43 lines (36 loc) · 1.5 KB
/
plugin.py
File metadata and controls
43 lines (36 loc) · 1.5 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
import os
from qgis.PyQt.QtCore import Qt # noqa: UP035
from qgis.PyQt.QtGui import QIcon # noqa: UP035
from qgis.PyQt.QtWidgets import QAction # noqa: UP035
from .ui.panel import SecateurPanel
class Plugin:
def __init__(self, iface):
self.iface = iface
self.action = None
self.panel = None
def initGui(self):
icon_path = os.path.join(os.path.dirname(__file__), "resources", "icon.png")
icon = QIcon(icon_path) if os.path.exists(icon_path) else QIcon()
self.action = QAction(icon, "Sécateur", self.iface.mainWindow())
self.action.setCheckable(True)
self.action.triggered.connect(self._toggle_panel)
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu("&Sécateur", self.action)
def unload(self):
if self.action:
self.iface.removeToolBarIcon(self.action)
self.iface.removePluginMenu("Sécateur", self.action)
if self.panel:
self.iface.removeDockWidget(self.panel)
self.panel.deleteLater()
self.panel = None
def _toggle_panel(self, checked):
if self.panel is None:
self.panel = SecateurPanel(self.iface)
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.panel)
if self.action:
self.panel.visibilityChanged.connect(self.action.setChecked)
if checked:
self.panel.show()
else:
self.panel.hide()