-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniversal_map2web.py
More file actions
130 lines (106 loc) · 4.72 KB
/
Copy pathuniversal_map2web.py
File metadata and controls
130 lines (106 loc) · 4.72 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# -*- coding: utf-8 -*-
import os
from qgis.PyQt import QtGui
from qgis.PyQt.QtWidgets import QAction
from qgis.PyQt.QtCore import QCoreApplication, QTranslator, QSettings
from .exporter import Exporter
from .universal_map2web_dialog import UniversalMap2webDialog
class UniversalMap2web:
"""Classe principale de l'extension Universal Map2web"""
def __init__(self, iface):
self.iface = iface
self.plugin_dir = os.path.dirname(__file__)
self.dialog = None
self.action = None
self.exporter = Exporter(iface)
self.translator = None
# Charger la traduction
self.load_translation()
def load_translation(self):
"""Charge la traduction selon la langue de QGIS"""
settings = QSettings()
locale = settings.value("locale/userLocale", "en_US")
# Nettoyer le locale (enlever .UTF-8 etc.)
if locale:
locale = locale.split(".")[0]
# Si la langue est française, on utilise fr_FR, sinon en_US
if locale.startswith("fr"):
locale = "fr_FR"
else:
locale = "en_US"
print(f"Langue chargée: {locale}")
i18n_path = os.path.join(self.plugin_dir, "i18n")
translation_file = os.path.join(i18n_path, f"{locale}.qm")
self.translator = QTranslator()
if os.path.exists(translation_file):
self.translator.load(translation_file)
QCoreApplication.installTranslator(self.translator)
print(f"Traduction chargée: {locale}")
return True
else:
print(f"Fichier de traduction non trouvé: {translation_file}")
# Fallback sur l'anglais
translation_file = os.path.join(i18n_path, "en_US.qm")
if os.path.exists(translation_file):
self.translator.load(translation_file)
QCoreApplication.installTranslator(self.translator)
print("Fallback: en_US chargé")
return True
return False
def tr(self, text):
"""Traduit un texte"""
return QCoreApplication.translate("UniversalMap2web", text)
def initGui(self):
icon_path = os.path.join(self.plugin_dir, "icon.png")
self.action = QAction(
(QtGui.QIcon(icon_path) if os.path.exists(icon_path) else QtGui.QIcon()),
self.tr("Create web map"),
self.iface.mainWindow(),
)
self.action.setWhatsThis(self.tr("Export the layers in interactive HTML map"))
self.action.triggered.connect(self.run)
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu(self.tr("&Universal Map2web"), self.action)
def unload(self):
if self.action:
self.iface.removeToolBarIcon(self.action)
self.iface.removePluginMenu(self.tr("&Universal Map2web"), self.action)
def run(self):
self.dialog = UniversalMap2webDialog(self.iface.mainWindow())
if self.dialog.comboFondPlan.count() == 0:
self.dialog.comboFondPlan.addItems(
[
self.tr("OpenStreetMap"),
self.tr("Google Satellite"),
self.tr("Google Hybrid"),
]
)
for i in range(self.dialog.comboFondPlan.count()):
item = self.dialog.comboFondPlan.itemText(i)
if "OpenStreetMap" in item:
self.dialog.comboFondPlan.setItemText(i, f"🌍 {item}")
elif "Google Satellite" in item:
self.dialog.comboFondPlan.setItemText(i, f"🛰️ {item}")
elif "Google Hybrid" in item:
self.dialog.comboFondPlan.setItemText(i, f"🌐 {item}")
self.dialog.chkFondPlanPersonnalise.toggled.connect(
self.activer_fond_personnalise
)
if hasattr(self.dialog, "btnExporter"):
self.dialog.btnExporter.clicked.connect(self.exporter_courant)
elif hasattr(self.dialog, "buttonBox"):
try:
self.dialog.buttonBox.accepted.disconnect()
except (TypeError, RuntimeError):
pass
self.dialog.buttonBox.accepted.connect(self.exporter_courant)
self.dialog.show()
def activer_fond_personnalise(self, checked):
self.dialog.txtFondPlanURL.setEnabled(checked)
def exporter_courant(self):
if hasattr(self.dialog, "sauvegarder_champs_couche_actuelle"):
self.dialog.sauvegarder_champs_couche_actuelle()
# Sauvegarder les paramètres dans le projet QGIS avant l'export
if hasattr(self.dialog, "sauvegarder_configuration_projet"):
self.dialog.sauvegarder_configuration_projet()
self.exporter.exporter(self.dialog)