Téléverser les fichiers vers "CenRa_Metabase"

This commit is contained in:
Tom LAVEILLE 2024-10-07 17:16:57 +02:00
parent 8ee1d6d888
commit 7b6e77d17e
3 changed files with 273 additions and 252 deletions

View File

@ -1,199 +1,220 @@
__copyright__ = "Copyright 2021, 3Liz" __copyright__ = "Copyright 2021, 3Liz"
__license__ = "GPL version 3" __license__ = "GPL version 3"
__email__ = "info@3liz.org" __email__ = "info@3liz.org"
from qgis.core import QgsApplication from qgis.core import QgsApplication
from qgis.PyQt.QtCore import QCoreApplication, Qt, QTranslator, QUrl from qgis.PyQt.QtCore import QCoreApplication, Qt, QTranslator, QUrl
from qgis.PyQt.QtGui import QDesktopServices, QIcon from qgis.PyQt.QtGui import QDesktopServices, QIcon
from qgis.PyQt.QtWidgets import QAction, QMessageBox from qgis.PyQt.QtWidgets import QAction, QMessageBox
from qgis.utils import iface from qgis.utils import iface
''' import qgis
from pg_metadata.connection_manager import (
store_connections,
validate_connections_names, #include <QSettings>
) '''
from pg_metadata.connection_manager import (
store_connections,
from pg_metadata.locator import LocatorFilter validate_connections_names,
from pg_metadata.processing.provider import PgMetadataProvider )
from pg_metadata.qgis_plugin_tools.tools.custom_logging import setup_logger
'''
from CenRa_Metabase.resources.i18n import setup_translation, tr from pg_metadata.locator import LocatorFilter
import os from pg_metadata.processing.provider import PgMetadataProvider
from CenRa_Metabase.resources.resources import ( from pg_metadata.qgis_plugin_tools.tools.custom_logging import setup_logger
plugin_path, '''
resources_path, import os
maj_verif, from .tools.resources import (
) plugin_path,
from CenRa_Metabase.dock import CenRa_Metabase resources_path,
from CenRa_Metabase.editor import Metabase_Editor maj_verif,
#from CenRa_Metabase.issues import CenRa_Issues )
from .dock import CenRa_Metabase
from .editor import Metabase_Editor
class PgMetadata: from .about_form import MetabaseAboutDialog
def __init__(self): #from CenRa_Metabase.issues import CenRa_Issues
""" Constructor. """
self.dock = None from PyQt5.QtCore import *
self.editor = None
# self.issues = None
self.provider = None
self.locator_filter = None class PgMetadata:
self.dock_action = None def __init__(self):
self.help_action = None """ Constructor. """
plugin_dir = os.path.dirname(__file__) self.dock = None
end_find = plugin_dir.rfind('\\')+1 self.editor = None
global NAME # self.issues = None
NAME = plugin_dir[end_find:] self.provider = None
maj_verif(NAME) self.locator_filter = None
# setup_logger('pg_metadata') self.dock_action = None
self.help_action = None
locale, file_path = setup_translation( plugin_dir = os.path.dirname(__file__)
folder=plugin_path("i18n"), file_pattern="CenRa_Metabase_{}.qm") end_find = plugin_dir.rfind('\\')+1
if file_path: global NAME
self.translator = QTranslator() NAME = plugin_dir[end_find:]
self.translator.load(file_path) maj_verif(NAME)
# noinspection PyCallByClass,PyArgumentList
QCoreApplication.installTranslator(self.translator) # Display About window on first use
version = qgis.utils.pluginMetadata('CenRa_METABASE','version')
# noinspection PyPep8Naming s = QSettings()
#def initProcessing(self): versionUse = s.value("metadata/version", 1, type=str)
#""" Add the QGIS Processing provider. """ if str(versionUse) != str(version) :
#if not self.provider: s.setValue("metadata/version", str(version))
#self.provider = PgMetadataProvider() print(versionUse,version)
#QgsApplication.processingRegistry().addProvider(self.provider) self.open_about_dialog()
# setup_logger('pg_metadata')
# noinspection PyPep8Naming
def initGui(self): #locale, file_path = setup_translation(
""" Build the plugin GUI. """ # folder=plugin_path("i18n"), file_pattern="CenRa_Metabase_{}.qm")
#self.initProcessing() #if file_path:
# self.translator = QTranslator()
#self.check_invalid_connection_names() # self.translator.load(file_path)
# noinspection PyCallByClass,PyArgumentList
self.toolBar = iface.addToolBar("CenRa_Metabase") # QCoreApplication.installTranslator(self.translator)
self.toolBar.setObjectName("CenRa_Metabase")
# noinspection PyPep8Naming
icon = QIcon(resources_path('icons', 'icon.png')) #def initProcessing(self):
icon2 = QIcon(resources_path('icons', 'icon_2.png')) #""" Add the QGIS Processing provider. """
#if not self.provider:
# Open the online help #self.provider = PgMetadataProvider()
self.help_action = QAction(icon, 'CenRa_Metabase', iface.mainWindow()) #QgsApplication.processingRegistry().addProvider(self.provider)
iface.pluginHelpMenu().addAction(self.help_action)
self.help_action.triggered.connect(self.open_help) # noinspection PyPep8Naming
if not self.editor: def initGui(self):
self.editor = Metabase_Editor() """ Build the plugin GUI. """
#self.initProcessing()
self.editor_action = QAction(icon2, 'CenRa_Metabase',None) #self.check_invalid_connection_names()
self.toolBar.addAction(self.editor_action)
self.editor_action.triggered.connect(self.open_editor) self.toolBar = iface.addToolBar("CenRa_Metabase")
self.toolBar.setObjectName("CenRa_Metabase")
if not self.dock:
self.dock = CenRa_Metabase() icon = QIcon(resources_path('icons', 'icon.png'))
iface.addDockWidget(Qt.RightDockWidgetArea, self.dock) icon2 = QIcon(resources_path('icons', 'icon_2.png'))
# Open/close the dock from plugin menu # Open the online help
self.dock_action = QAction(icon, 'CenRa_Metabase', iface.mainWindow()) self.help_action = QAction(icon, 'CenRa_Metabase', iface.mainWindow())
iface.pluginMenu().addAction(self.dock_action) iface.pluginHelpMenu().addAction(self.help_action)
self.dock_action.triggered.connect(self.open_dock) self.help_action.triggered.connect(self.open_help)
# if not self.issues: if not self.editor:
# self.issues = CenRa_Issues() self.editor = Metabase_Editor()
# self.issues_action = QAction(icon, 'CenRa_Metabase',None) self.editor_action = QAction(icon2, 'CenRa_Metabase',None)
# self.toolBar.addAction(self.issues_action) self.toolBar.addAction(self.editor_action)
# self.issues_action.triggered.connect(self.open_issues) self.editor_action.triggered.connect(self.open_editor)
'''
if not self.locator_filter: if not self.dock:
self.locator_filter = LocatorFilter(iface) self.dock = CenRa_Metabase()
iface.registerLocatorFilter(self.locator_filter) iface.addDockWidget(Qt.RightDockWidgetArea, self.dock)
@staticmethod # Open/close the dock from plugin menu
def check_invalid_connection_names(): self.dock_action = QAction(icon, 'CenRa_Metabase', iface.mainWindow())
""" Check for invalid connection names in the QgsSettings. """ iface.pluginMenu().addAction(self.dock_action)
valid, invalid = validate_connections_names() self.dock_action.triggered.connect(self.open_dock)
n_invalid = len(invalid) # if not self.issues:
# self.issues = CenRa_Issues()
if n_invalid == 0:
return
# self.issues_action = QAction(icon, 'CenRa_Metabase',None)
invalid_text = ', '.join(invalid) # self.toolBar.addAction(self.issues_action)
msg = QMessageBox() # self.issues_action.triggered.connect(self.open_issues)
msg.setIcon(QMessageBox.Warning) '''
msg.setWindowTitle(tr('PgMetadata: Database connection(s) not available')) if not self.locator_filter:
msg.setText(tr( self.locator_filter = LocatorFilter(iface)
f'{n_invalid} connection(s) listed in PgMetadatas settings are invalid or ' iface.registerLocatorFilter(self.locator_filter)
f'no longer available: {invalid_text}'))
msg.setInformativeText(tr( @staticmethod
'Do you want to remove these connection(s) from the PgMetadata settings? ' def check_invalid_connection_names():
'(You can also do this later with the “Set Connections” tool.)')) """ Check for invalid connection names in the QgsSettings. """
msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No) valid, invalid = validate_connections_names()
clicked = msg.exec() n_invalid = len(invalid)
if clicked == QMessageBox.Yes: if n_invalid == 0:
iface.messageBar().pushSuccess('PgMetadata', tr(f'{n_invalid} invalid connection(s) removed.')) return
store_connections(valid)
if clicked == QMessageBox.No: invalid_text = ', '.join(invalid)
iface.messageBar().pushInfo('PgMetadata', tr(f'Keeping {n_invalid} invalid connections.')) msg = QMessageBox()
''' msg.setIcon(QMessageBox.Warning)
msg.setWindowTitle(tr('PgMetadata: Database connection(s) not available'))
def open_help(): msg.setText(tr(
""" Open the online help. """ f'{n_invalid} connection(s) listed in PgMetadatas settings are invalid or '
QDesktopServices.openUrl(QUrl('https://plateformesig.cenra-outils.org/')) f'no longer available: {invalid_text}'))
msg.setInformativeText(tr(
def open_dock(self): 'Do you want to remove these connection(s) from the PgMetadata settings? '
""" Open the dock. """ '(You can also do this later with the “Set Connections” tool.)'))
self.dock.show() msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
self.dock.raise_() clicked = msg.exec()
def open_editor(self): if clicked == QMessageBox.Yes:
self.editor.show() iface.messageBar().pushSuccess('PgMetadata', tr(f'{n_invalid} invalid connection(s) removed.'))
self.editor.raise_() store_connections(valid)
if clicked == QMessageBox.No:
# def open_issues(self): iface.messageBar().pushInfo('PgMetadata', tr(f'Keeping {n_invalid} invalid connections.'))
# self.issues.show() '''
# self.issues.raise_() def open_about_dialog(self):
"""
def unload(self): About dialog
""" Unload the plugin. """ """
if self.editor: dialog = MetabaseAboutDialog(iface)
iface.removePluginMenu(tr('CenRa_Metabase'),self.editor_action) dialog.exec_()
#self.editor.removeToolBarIcon(self.editor_action) def open_help():
""" Open the online help. """
QDesktopServices.openUrl(QUrl('https://plateformesig.cenra-outils.org/'))
if self.dock: def open_dock(self):
iface.removeDockWidget(self.dock) """ Open the dock. """
self.dock.deleteLater() self.dock.show()
self.dock.raise_()
if self.provider:
QgsApplication.processingRegistry().removeProvider(self.provider) def open_editor(self):
del self.provider self.editor.show()
self.editor.raise_()
if self.locator_filter:
iface.deregisterLocatorFilter(self.locator_filter) # def open_issues(self):
del self.locator_filter # self.issues.show()
# self.issues.raise_()
if self.dock_action:
iface.pluginMenu().removeAction(self.dock_action) def unload(self):
del self.dock_action """ Unload the plugin. """
if self.editor:
if self.help_action: iface.removePluginMenu('CenRa_Metabase',self.editor_action)
iface.pluginHelpMenu().removeAction(self.help_action) #self.editor.removeToolBarIcon(self.editor_action)
del self.help_action
@staticmethod
def run_tests(pattern='test_*.py', package=None): if self.dock:
"""Run the test inside QGIS.""" iface.removeDockWidget(self.dock)
try: self.dock.deleteLater()
from pathlib import Path
if self.provider:
from pg_metadata.qgis_plugin_tools.infrastructure.test_runner import ( QgsApplication.processingRegistry().removeProvider(self.provider)
test_package, del self.provider
)
if package is None: if self.locator_filter:
package = '{}.__init__'.format(Path(__file__).parent.name) iface.deregisterLocatorFilter(self.locator_filter)
test_package(package, pattern) del self.locator_filter
except (AttributeError, ModuleNotFoundError):
message = 'Could not load tests. Are you using a production package?' if self.dock_action:
print(message) # NOQA iface.pluginMenu().removeAction(self.dock_action)
del self.dock_action
if self.help_action:
iface.pluginHelpMenu().removeAction(self.help_action)
del self.help_action
@staticmethod
def run_tests(pattern='test_*.py', package=None):
"""Run the test inside QGIS."""
try:
from pathlib import Path
from pg_metadata.qgis_plugin_tools.infrastructure.test_runner import (
test_package,
)
if package is None:
package = '{}.__init__'.format(Path(__file__).parent.name)
test_package(package, pattern)
except (AttributeError, ModuleNotFoundError):
message = 'Could not load tests. Are you using a production package?'
print(message) # NOQA

View File

@ -18,6 +18,7 @@ from qgis.core import (
QgsSettings, QgsSettings,
QgsVectorLayer, QgsVectorLayer,
QgsGeometry, QgsGeometry,
QgsWkbTypes,
) )
from qgis.PyQt.QtCore import QLocale, QUrl, QDateTime from qgis.PyQt.QtCore import QLocale, QUrl, QDateTime
from qgis.PyQt.QtGui import QDesktopServices, QIcon from qgis.PyQt.QtGui import QDesktopServices, QIcon
@ -35,15 +36,14 @@ from qgis.PyQt.QtWidgets import (
QTableWidgetItem, QTableWidgetItem,
) )
from qgis.utils import iface from qgis.utils import iface
from CenRa_Metabase.resources.i18n import tr
from CenRa_Metabase.resources.resources import ( from .tools.resources import (
load_ui, load_ui,
resources_path, resources_path,
login_base, login_base,
send_issues, send_issues,
) )
from CenRa_Metabase.issues import CenRa_Issues from .issues import CenRa_Issues
EDITOR_CLASS = load_ui('CenRa_Metabase_editorwidget_base.ui') EDITOR_CLASS = load_ui('CenRa_Metabase_editorwidget_base.ui')
LOGGER = logging.getLogger('CenRa_Metabase') LOGGER = logging.getLogger('CenRa_Metabase')
@ -55,7 +55,6 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
super().__init__() super().__init__()
self.setupUi(self) self.setupUi(self)
self.settings = QgsSettings() self.settings = QgsSettings()
self.import_xml.setAutoRaise(True) self.import_xml.setAutoRaise(True)
self.import_xml.setText('') self.import_xml.setText('')
self.import_xml.setIcon(QIcon(QgsApplication.iconPath('mActionAddHtml.svg'))) self.import_xml.setIcon(QIcon(QgsApplication.iconPath('mActionAddHtml.svg')))
@ -207,6 +206,7 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
iface.layerTreeView().setCurrentLayer(layer) iface.layerTreeView().setCurrentLayer(layer)
def raise_(self): def raise_(self):
self.activateWindow()
global layer global layer
layer = iface.activeLayer() layer = iface.activeLayer()
global uid_delete_list_link,uid_delete_list_contact,array_link,array_contact global uid_delete_list_link,uid_delete_list_contact,array_link,array_contact
@ -354,7 +354,7 @@ class Metabase_Editor(QDialog, EDITOR_CLASS):
if qgstype != 'Raster' : if qgstype != 'Raster' :
count_layers = str(layer.featureCount()) count_layers = str(layer.featureCount())
geomtype = str(layer.wkbType())[8:] geomtype = QgsWkbTypes.displayString(layer.wkbType())
elif qgstype == 'Raster': elif qgstype == 'Raster':
count_layers = str(layer.dataProvider().bandCount()) count_layers = str(layer.dataProvider().bandCount())
geomtype = qgstype geomtype = qgstype

View File

@ -1,48 +1,48 @@
# This file contains metadata for your plugin. # This file contains metadata for your plugin.
# This file should be included when you package your plugin.# Mandatory items: # This file should be included when you package your plugin.# Mandatory items:
[general] [general]
name=CenRa_Metabase name=CenRa_Metabase
qgisMinimumVersion=3.0 qgisMinimumVersion=3.0
description=CenRa_Metabase description=CenRa_METABASE
version=1.0 version=1.2
author=Conservatoire d'Espaces Naturels de Rhône-Alpes author=Conservatoire d'Espaces Naturels de Rhône-Alpes
email=si_besoin@cen-rhonealpes.fr email=si_besoin@cen-rhonealpes.fr
about=Permet de saisire et de visualisé les information lier à la metadonné d'une couche ce trouvent sur PostgreSQL about=Permet de saisire et de visualisé les information lier à la metadonné d'une couche ce trouvent sur PostgreSQL
repository=https://gitea.cenra-outils.org/CEN-RA/Plugin_QGIS repository=https://gitea.cenra-outils.org/CEN-RA/Plugin_QGIS
homepage=https://plateformesig.cenra-outils.org/ homepage=https://plateformesig.cenra-outils.org/
tracker=https://gitea.cenra-outils.org/api/v1/repos/CEN-RA/Plugin_QGIS/issues tracker=https://gitea.cenra-outils.org/api/v1/repos/CEN-RA/Plugin_QGIS/issues
# End of mandatory metadata # End of mandatory metadata
# Recommended items: # Recommended items:
hasProcessingProvider=no hasProcessingProvider=no
# Uncomment the following line and add your changelog: # Uncomment the following line and add your changelog:
# changelog= changelog=<h2>CenRa_Metabase:</h2></br><p><h3>07/10/2024 - Version 1.2: </h3> - Correctif de bug.</p></br><p><h3>03/10/2024 - Version 1.1: </h3> - Remonte la fênetre dans la pille.</p></br><p><h3>26/08/2024 - Version 1.0: </h3> - Lancement du plugin CenRa_Metabase </p></br>
# Tags are comma separated with spaces allowed # Tags are comma separated with spaces allowed
tags=python tags=python
category=Plugins category=Plugins
icon=icon.png icon=icon.png
# experimental flag # experimental flag
experimental=False experimental=False
# deprecated flag (applies to the whole plugin, not just a single version) # deprecated flag (applies to the whole plugin, not just a single version)
deprecated=False deprecated=False
# Since QGIS 3.8, a comma separated list of plugins to be installed # Since QGIS 3.8, a comma separated list of plugins to be installed
# (or upgraded) can be specified. # (or upgraded) can be specified.
# Check the documentation for more information. # Check the documentation for more information.
# plugin_dependencies= # plugin_dependencies=
Category of the plugin: Raster, Vector, Database or Web Category of the plugin: Raster, Vector, Database or Web
# category=cenra,database,metadata # category=cenra,database,metadata
# If the plugin can run on QGIS Server. # If the plugin can run on QGIS Server.
server=False server=False