Boutton déroulant pour choisir le style du projet

This commit is contained in:
Djedouas 2021-03-06 18:45:02 +01:00
parent 06435601d4
commit d1d57cbb6d
3 changed files with 4479 additions and 721 deletions

View File

@ -23,7 +23,7 @@
""" """
from qgis.PyQt.QtCore import Qt, QSettings, QTranslator, QCoreApplication from qgis.PyQt.QtCore import Qt, QSettings, QTranslator, QCoreApplication
from qgis.PyQt.QtGui import QIcon from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction, qApp, QFileDialog, QProgressBar, QMessageBox from qgis.PyQt.QtWidgets import QAction, qApp, QFileDialog, QProgressBar, QMessageBox, QMenu, QToolButton
from qgis.core import QgsCoordinateReferenceSystem, QgsProject, QgsVectorFileWriter, QgsVectorLayer, QgsFeatureRequest from qgis.core import QgsCoordinateReferenceSystem, QgsProject, QgsVectorFileWriter, QgsVectorLayer, QgsFeatureRequest
from qgis.utils import OverrideCursor from qgis.utils import OverrideCursor
@ -172,11 +172,21 @@ class Orientation:
"""Create the menu entries and toolbar icons inside the QGIS GUI.""" """Create the menu entries and toolbar icons inside the QGIS GUI."""
icon_path = ':/plugins/caliec/icon.png' icon_path = ':/plugins/caliec/icon.png'
self.add_action(
my_menu = QMenu()
my_menu.addActions([self.add_action(icon_path=":/plugins/caliec/vignette_caliec", text=self.tr("Style CaLiÉc"), parent=my_menu,
add_to_toolbar=False, add_to_menu=False,
callback=lambda: self.run("style_caliec")),
self.add_action(icon_path=":/plugins/caliec/vignette_jardin", text=self.tr("Style jardin"), parent=my_menu,
add_to_toolbar=False, add_to_menu=False,
callback=lambda: self.run("style_jardin"))])
menu_action = self.add_action(
icon_path, icon_path,
text=self.tr('DEV - Créer le projet'), text=self.tr('DEV - Créer le projet'),
callback=self.run, callback=lambda: None,
parent=self.iface.mainWindow()) parent=self.iface.mainWindow())
menu_action.setMenu(my_menu)
self.iface.pluginToolBar().widgetForAction(menu_action).setPopupMode(QToolButton.InstantPopup)
# will be set False in run() # will be set False in run()
self.first_start = True self.first_start = True
@ -191,17 +201,17 @@ class Orientation:
self.iface.removeToolBarIcon(action) self.iface.removeToolBarIcon(action)
def run(self): def run(self, main_style):
try: try:
self.main() self.main(main_style)
finally: finally:
self.iface.messageBar().popWidget() self.iface.messageBar().popWidget()
qApp.restoreOverrideCursor() qApp.restoreOverrideCursor()
def main(self): def main(self, main_style):
# Paramètres du projet # Paramètres du projet
tempdir = tempfile.TemporaryDirectory() tempdir = tempfile.TemporaryDirectory()
styles_url = 'https://forge.chapril.org/linux_alpes/caliec/raw/branch/master/styles/' styles_url = f'https://forge.chapril.org/linux_alpes/caliec/raw/branch/master/{main_style}/styles/'
lambert93 = QgsCoordinateReferenceSystem("EPSG:2154") lambert93 = QgsCoordinateReferenceSystem("EPSG:2154")
wgspm = QgsCoordinateReferenceSystem("EPSG:3857") wgspm = QgsCoordinateReferenceSystem("EPSG:3857")
scr = wgspm scr = wgspm

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,7 @@
<RCC> <RCC>
<qresource prefix="/plugins/caliec" > <qresource prefix="/plugins/caliec" >
<file>icon.png</file> <file>icon.png</file>
<file alias="vignette_jardin">../style_jardin/vignette_jardin.png</file>
<file alias="vignette_caliec">../style_caliec/vignette_caliec.png</file>
</qresource> </qresource>
</RCC> </RCC>