Actualiser CenRa_AUTOMAP/CenRa_AutoMap.py
This commit is contained in:
parent
30a58ad9fd
commit
5a2ee3b1c0
@ -1,142 +1,142 @@
|
||||
__copyright__ = "Copyright 2021, 3Liz"
|
||||
__license__ = "GPL version 3"
|
||||
__email__ = "info@3liz.org"
|
||||
|
||||
|
||||
from qgis.core import QgsApplication
|
||||
from qgis.PyQt.QtCore import QCoreApplication, Qt, QTranslator, QUrl
|
||||
from qgis.PyQt.QtGui import QDesktopServices, QIcon
|
||||
from qgis.PyQt.QtWidgets import QAction, QMessageBox
|
||||
from qgis.utils import iface
|
||||
import qgis
|
||||
|
||||
|
||||
#include <QSettings>
|
||||
'''
|
||||
from pg_metadata.connection_manager import (
|
||||
store_connections,
|
||||
validate_connections_names,
|
||||
)
|
||||
|
||||
|
||||
from pg_metadata.locator import LocatorFilter
|
||||
from pg_metadata.processing.provider import PgMetadataProvider
|
||||
from pg_metadata.qgis_plugin_tools.tools.custom_logging import setup_logger
|
||||
'''
|
||||
import os
|
||||
from .tools.resources import (
|
||||
plugin_path,
|
||||
resources_path,
|
||||
maj_verif,
|
||||
)
|
||||
from .editor import AutoMap_Editor
|
||||
from .about_form import AutoMapAboutDialog
|
||||
|
||||
from PyQt5.QtCore import *
|
||||
|
||||
class PgAutoMap:
|
||||
def __init__(self):
|
||||
""" Constructor. """
|
||||
self.editor = None
|
||||
# self.issues = None
|
||||
self.provider = None
|
||||
self.locator_filter = None
|
||||
self.dock_action = None
|
||||
self.help_action = None
|
||||
plugin_dir = os.path.dirname(__file__)
|
||||
end_find = plugin_dir.rfind('\\')+1
|
||||
global NAME
|
||||
NAME = plugin_dir[end_find:]
|
||||
maj_verif(NAME)
|
||||
|
||||
# Display About window on first use
|
||||
version = qgis.utils.pluginMetadata('CenRa_AUTOMAP','version')
|
||||
s = QSettings()
|
||||
versionUse = s.value("automap/version", 1, type=str)
|
||||
if str(versionUse) != str(version) :
|
||||
s.setValue("automap/version", str(version))
|
||||
print(versionUse,version)
|
||||
self.open_about_dialog()
|
||||
|
||||
def initGui(self):
|
||||
""" Build the plugin GUI. """
|
||||
|
||||
self.toolBar = iface.addToolBar("CenRa_AutoMap")
|
||||
self.toolBar.setObjectName("CenRa_AutoMap")
|
||||
|
||||
icon = QIcon(resources_path('icons', 'icon.png'))
|
||||
|
||||
# Open the online help
|
||||
self.help_action = QAction(icon, 'CenRa_AutoMap', iface.mainWindow())
|
||||
iface.pluginHelpMenu().addAction(self.help_action)
|
||||
self.help_action.triggered.connect(self.open_help)
|
||||
if not self.editor:
|
||||
self.editor = AutoMap_Editor()
|
||||
|
||||
|
||||
self.automap_action = QAction(icon, 'CenRa_AutoMap',None)
|
||||
self.toolBar.addAction(self.automap_action)
|
||||
self.automap_action.triggered.connect(self.open_editor)
|
||||
'''
|
||||
if not self.locator_filter:
|
||||
self.locator_filter = LocatorFilter(iface)
|
||||
iface.registerLocatorFilter(self.locator_filter)
|
||||
|
||||
@staticmethod
|
||||
def check_invalid_connection_names():
|
||||
""" Check for invalid connection names in the QgsSettings. """
|
||||
valid, invalid = validate_connections_names()
|
||||
n_invalid = len(invalid)
|
||||
|
||||
if n_invalid == 0:
|
||||
return
|
||||
|
||||
invalid_text = ', '.join(invalid)
|
||||
msg = QMessageBox()
|
||||
msg.setIcon(QMessageBox.Warning)
|
||||
msg.setWindowTitle(tr('PgMetadata: Database connection(s) not available'))
|
||||
msg.setText(tr(
|
||||
f'{n_invalid} connection(s) listed in PgMetadata’s settings are invalid or '
|
||||
f'no longer available: {invalid_text}'))
|
||||
msg.setInformativeText(tr(
|
||||
'Do you want to remove these connection(s) from the PgMetadata settings? '
|
||||
'(You can also do this later with the “Set Connections” tool.)'))
|
||||
msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
|
||||
clicked = msg.exec()
|
||||
|
||||
if clicked == QMessageBox.Yes:
|
||||
iface.messageBar().pushSuccess('PgMetadata', tr(f'{n_invalid} invalid connection(s) removed.'))
|
||||
store_connections(valid)
|
||||
if clicked == QMessageBox.No:
|
||||
iface.messageBar().pushInfo('PgMetadata', tr(f'Keeping {n_invalid} invalid connections.'))
|
||||
'''
|
||||
def open_about_dialog(self):
|
||||
"""
|
||||
About dialog
|
||||
"""
|
||||
dialog = AutoMapAboutDialog(iface)
|
||||
dialog.exec_()
|
||||
def open_help():
|
||||
""" Open the online help. """
|
||||
QDesktopServices.openUrl(QUrl('https://plateformesig.cenra-outils.org/'))
|
||||
|
||||
def open_editor(self):
|
||||
self.editor.show()
|
||||
self.editor.raise_()
|
||||
|
||||
def unload(self):
|
||||
""" Unload the plugin. """
|
||||
if self.editor:
|
||||
iface.removePluginMenu('CenRa_AutoMap',self.automap_action)
|
||||
|
||||
if self.provider:
|
||||
QgsApplication.processingRegistry().removeProvider(self.provider)
|
||||
del self.provider
|
||||
|
||||
if self.locator_filter:
|
||||
iface.deregisterLocatorFilter(self.locator_filter)
|
||||
del self.locator_filter
|
||||
|
||||
if self.help_action:
|
||||
iface.pluginHelpMenu().removeAction(self.help_action)
|
||||
del self.help_action
|
||||
__copyright__ = "Copyright 2021, 3Liz"
|
||||
__license__ = "GPL version 3"
|
||||
__email__ = "info@3liz.org"
|
||||
|
||||
|
||||
from qgis.core import QgsApplication
|
||||
from qgis.PyQt.QtCore import QCoreApplication, Qt, QTranslator, QUrl
|
||||
from qgis.PyQt.QtGui import QDesktopServices, QIcon
|
||||
from qgis.PyQt.QtWidgets import QAction, QMessageBox
|
||||
from qgis.utils import iface
|
||||
import qgis
|
||||
|
||||
|
||||
#include <QSettings>
|
||||
'''
|
||||
from pg_metadata.connection_manager import (
|
||||
store_connections,
|
||||
validate_connections_names,
|
||||
)
|
||||
|
||||
|
||||
from pg_metadata.locator import LocatorFilter
|
||||
from pg_metadata.processing.provider import PgMetadataProvider
|
||||
from pg_metadata.qgis_plugin_tools.tools.custom_logging import setup_logger
|
||||
'''
|
||||
import os
|
||||
from .tools.resources import (
|
||||
plugin_path,
|
||||
resources_path,
|
||||
maj_verif,
|
||||
)
|
||||
from .editor import AutoMap_Editor
|
||||
from .about_form import AutoMapAboutDialog
|
||||
|
||||
from PyQt5.QtCore import *
|
||||
|
||||
class PgAutoMap:
|
||||
def __init__(self):
|
||||
""" Constructor. """
|
||||
self.editor = None
|
||||
# self.issues = None
|
||||
self.provider = None
|
||||
self.locator_filter = None
|
||||
self.dock_action = None
|
||||
self.help_action = None
|
||||
plugin_dir = os.path.dirname(__file__)
|
||||
end_find = plugin_dir.rfind('\\')+1
|
||||
global NAME
|
||||
NAME = plugin_dir[end_find:]
|
||||
maj_verif(NAME)
|
||||
|
||||
# Display About window on first use
|
||||
version = qgis.utils.pluginMetadata('CenRa_AUTOMAP','version')
|
||||
s = QSettings()
|
||||
versionUse = s.value("automap/version", 1, type=str)
|
||||
if str(versionUse) != str(version) :
|
||||
s.setValue("automap/version", str(version))
|
||||
print(versionUse,version)
|
||||
self.open_about_dialog()
|
||||
|
||||
def initGui(self):
|
||||
""" Build the plugin GUI. """
|
||||
|
||||
self.toolBar = iface.addToolBar("CenRa_AutoMap")
|
||||
self.toolBar.setObjectName("CenRa_AutoMap")
|
||||
|
||||
icon = QIcon(resources_path('icons', 'icon.png'))
|
||||
|
||||
# Open the online help
|
||||
self.help_action = QAction(icon, 'CenRa_AutoMap', iface.mainWindow())
|
||||
iface.pluginHelpMenu().addAction(self.help_action)
|
||||
self.help_action.triggered.connect(self.open_help)
|
||||
if not self.editor:
|
||||
self.editor = AutoMap_Editor()
|
||||
|
||||
|
||||
self.automap_action = QAction(icon, 'CenRa_AutoMap',None)
|
||||
self.toolBar.addAction(self.automap_action)
|
||||
self.automap_action.triggered.connect(self.open_editor)
|
||||
'''
|
||||
if not self.locator_filter:
|
||||
self.locator_filter = LocatorFilter(iface)
|
||||
iface.registerLocatorFilter(self.locator_filter)
|
||||
|
||||
@staticmethod
|
||||
def check_invalid_connection_names():
|
||||
""" Check for invalid connection names in the QgsSettings. """
|
||||
valid, invalid = validate_connections_names()
|
||||
n_invalid = len(invalid)
|
||||
|
||||
if n_invalid == 0:
|
||||
return
|
||||
|
||||
invalid_text = ', '.join(invalid)
|
||||
msg = QMessageBox()
|
||||
msg.setIcon(QMessageBox.Warning)
|
||||
msg.setWindowTitle(tr('PgMetadata: Database connection(s) not available'))
|
||||
msg.setText(tr(
|
||||
f'{n_invalid} connection(s) listed in PgMetadata’s settings are invalid or '
|
||||
f'no longer available: {invalid_text}'))
|
||||
msg.setInformativeText(tr(
|
||||
'Do you want to remove these connection(s) from the PgMetadata settings? '
|
||||
'(You can also do this later with the “Set Connections” tool.)'))
|
||||
msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
|
||||
clicked = msg.exec()
|
||||
|
||||
if clicked == QMessageBox.Yes:
|
||||
iface.messageBar().pushSuccess('PgMetadata', tr(f'{n_invalid} invalid connection(s) removed.'))
|
||||
store_connections(valid)
|
||||
if clicked == QMessageBox.No:
|
||||
iface.messageBar().pushInfo('PgMetadata', tr(f'Keeping {n_invalid} invalid connections.'))
|
||||
'''
|
||||
def open_about_dialog(self):
|
||||
"""
|
||||
About dialog
|
||||
"""
|
||||
dialog = AutoMapAboutDialog(iface)
|
||||
dialog.exec_()
|
||||
def open_help():
|
||||
""" Open the online help. """
|
||||
QDesktopServices.openUrl(QUrl('https://plateformesig.cenra-outils.org/'))
|
||||
|
||||
def open_editor(self):
|
||||
self.editor.show()
|
||||
self.editor.raise_()
|
||||
|
||||
def unload(self):
|
||||
""" Unload the plugin. """
|
||||
if self.editor:
|
||||
iface.removePluginMenu('CenRa_AutoMap',self.automap_action)
|
||||
|
||||
if self.provider:
|
||||
QgsApplication.processingRegistry().removeProvider(self.provider)
|
||||
del self.provider
|
||||
|
||||
if self.locator_filter:
|
||||
iface.deregisterLocatorFilter(self.locator_filter)
|
||||
del self.locator_filter
|
||||
|
||||
if self.help_action:
|
||||
iface.pluginHelpMenu().removeAction(self.help_action)
|
||||
del self.help_action
|
||||
Loading…
x
Reference in New Issue
Block a user