-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin.py
More file actions
71 lines (55 loc) · 2.35 KB
/
plugin.py
File metadata and controls
71 lines (55 loc) · 2.35 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
import os
from processing import execAlgorithmDialog
from qgis.core import QgsApplication
from qgis.gui import QgisInterface
from qgis.PyQt.QtCore import QCoreApplication, QSettings, QTranslator
from qgis.PyQt.QtWidgets import QAction, QToolButton
from .processing_provider.quick_dem_for_jp_provider import QuickDEMforJPProvider
class QuickDEMforJP:
def __init__(self, iface: QgisInterface):
self.iface = iface
self.translator = None
self.initTranslator()
def initTranslator(self):
locale = QSettings().value("locale/userLocale")
if locale:
locale = locale[0:2]
else:
locale = "en"
locale_path = os.path.join(
os.path.dirname(__file__), "i18n", f"QuickDEMforJP_{locale}.qm"
)
print(locale_path)
if os.path.exists(locale_path):
self.translator = QTranslator()
if self.translator.load(locale_path):
QCoreApplication.installTranslator(self.translator)
def initProcessing(self):
self.provider = QuickDEMforJPProvider()
QgsApplication.processingRegistry().addProvider(self.provider)
def initGui(self):
self.initProcessing()
self.setup_algorithms_tool_button()
def unload(self):
if hasattr(self, "toolButtonAction"):
self.teardown_algorithms_tool_button()
if hasattr(self, "provider"):
QgsApplication.processingRegistry().removeProvider(self.provider)
del self.provider
def setup_algorithms_tool_button(self):
if hasattr(self, "toolButtonAction"):
return # すでに追加済みなら何もしない
tool_button = QToolButton()
icon = self.provider.icon()
default_action = QAction(icon, "Quick DEM for JP", self.iface.mainWindow())
default_action.triggered.connect(
lambda: execAlgorithmDialog("quickdemforjp:quickdemforjp", {})
)
tool_button.setDefaultAction(default_action)
self.toolButtonAction = self.iface.addToolBarWidget(tool_button)
def teardown_algorithms_tool_button(self):
if hasattr(self, "toolButtonAction"):
self.iface.removeToolBarIcon(self.toolButtonAction)
del self.toolButtonAction
def tr(self, string):
return QgsApplication.translate("QuickDEMforJPProcessingAlgorithm", string)