-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasemaps.py
65 lines (50 loc) · 2.2 KB
/
basemaps.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
# Copyright (C) 2024 Chengyan (Fancy) Fan
# 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 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
from pathlib import Path
from qgis.PyQt.QtCore import QCoreApplication, QSettings, QTranslator
from qgis.PyQt.QtWidgets import QAction
from .basemaps_dialog import BasemapsDialog
from .ui import IconBasemaps
class BasemapsPlugin:
def __init__(self, iface):
self.iface = iface
self.plugin_dir = Path(__file__).parent
self.actions = []
# Initialize translator
locale = QSettings().value("locale/userLocale")[0:2]
locale_path = self.plugin_dir / "i18n" / f"Basemaps_{locale}.qm"
self.translator = None
if locale_path.exists():
self.translator = QTranslator()
if self.translator.load(str(locale_path)):
QCoreApplication.installTranslator(self.translator)
self.menu = self.tr("Basemap Management")
self.dialog = None
def tr(self, message):
"""Get the translation for a string using Qt translation API."""
return QCoreApplication.translate("BasemapsPlugin", message)
def initGui(self):
action = QAction(
IconBasemaps, self.tr("Load Basemaps"), self.iface.mainWindow()
)
action.triggered.connect(self.run)
self.iface.addToolBarIcon(action)
self.iface.addPluginToMenu(self.menu, action)
self.actions.append(action)
def unload(self):
for action in self.actions:
self.iface.removePluginMenu(self.menu, action)
self.iface.removeToolBarIcon(action)
if self.translator:
QCoreApplication.removeTranslator(self.translator)
def run(self):
if not self.dialog:
self.dialog = BasemapsDialog(self.iface)
self.dialog.show()