Skip to content

Commit

Permalink
run pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jun 27, 2024
1 parent 020229c commit 7b7f28c
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 164 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ __pycache__
i18n
.DS_Store
.tokens

2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ repos:

ci:
autofix_prs: true
autoupdate_schedule: quarterly
autoupdate_schedule: quarterly
2 changes: 1 addition & 1 deletion .qgis-plugin-ci
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
plugin_path: geomapfish_locator
github_organization_slug: opengisch
project_slug: qgis_geomapfish_locator
project_slug: qgis_geomapfish_locator
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ Validate and start searching in the locator bar at the bottom left of the applic

## Advanced configuration

Each service will create its own locator filter. All the filters can be seen under the locator settings
Each service will create its own locator filter. All the filters can be seen under the locator settings
(in `Settings` -> `Options` -> `Locator`) and can be configured from there, including the prefix configuration.
If you want to avoid typing the prefix of the filter (`gmf`), enable the filter by default.
6 changes: 4 additions & 2 deletions geomapfish_locator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------
#
# QGIS Geomapfish Locator Plugin
Expand Down Expand Up @@ -32,5 +31,8 @@ def classFactory(iface):
:type iface: QgsInterface
"""
#
from geomapfish_locator.core.geomapfish_locator_plugin import GeomapfishLocatorPlugin
from geomapfish_locator.core.geomapfish_locator_plugin import (
GeomapfishLocatorPlugin,
)

return GeomapfishLocatorPlugin(iface)
62 changes: 39 additions & 23 deletions geomapfish_locator/core/geomapfish_locator_plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Expand All @@ -17,19 +16,27 @@
***************************************************************************/
"""


import os
from qgis.PyQt.QtCore import QCoreApplication, QLocale, QSettings, QTranslator, pyqtSlot, QObject
from qgis.PyQt.QtWidgets import QAction, QMenu, QMessageBox

from qgis.core import NULL
from qgis.gui import QgisInterface
from qgis.PyQt.QtCore import (
QCoreApplication,
QLocale,
QObject,
QSettings,
QTranslator,
pyqtSlot,
)
from qgis.PyQt.QtWidgets import QAction, QMenu, QMessageBox

from geomapfish_locator.core.locator_filter import GeomapfishLocatorFilter
from geomapfish_locator.core.old_version_import import old_version_import
from geomapfish_locator.core.settings import Settings
from geomapfish_locator.core.service import Service
from geomapfish_locator.core.settings import Settings
from geomapfish_locator.core.utils import info
from geomapfish_locator.gui.geomapfish_settings_dialog import GeomapfishSettingsDialog
from geomapfish_locator.gui.filter_configuration_dialog import FilterConfigurationDialog
from geomapfish_locator.gui.geomapfish_settings_dialog import GeomapfishSettingsDialog

DEBUG = True

Expand All @@ -43,15 +50,19 @@ def __init__(self, iface: QgisInterface):
self.iface = iface
self.locator_filters = []
self.settings = Settings()
menu_action_new = QAction(QCoreApplication.translate('Geomapfish', 'Add new service'), self.iface.mainWindow())
menu_action_new = QAction(
QCoreApplication.translate("Geomapfish", "Add new service"), self.iface.mainWindow()
)
menu_action_new.triggered.connect(self.new_service)
self.iface.addPluginToMenu(self.plugin_name, menu_action_new)
menu_action_settings = QAction(QCoreApplication.translate('Geomapfish', 'Settings'), self.iface.mainWindow())
menu_action_settings = QAction(
QCoreApplication.translate("Geomapfish", "Settings"), self.iface.mainWindow()
)
menu_action_settings.triggered.connect(self.show_settings)
self.iface.addPluginToMenu(self.plugin_name, menu_action_settings)
self.menu_entries = [menu_action_new, menu_action_settings]

for definition in self.settings.value('services'):
for definition in self.settings.value("services"):
self.add_service(Service(definition))

import_service = old_version_import()
Expand All @@ -62,20 +73,22 @@ def __init__(self, iface: QgisInterface):
qgis_locale = QLocale(
str(QSettings().value("locale/userLocale")).replace(str(NULL), "en_CH")
)
locale_path = os.path.join(os.path.dirname(__file__), 'i18n')
locale_path = os.path.join(os.path.dirname(__file__), "i18n")
self.translator = QTranslator()
self.translator.load(qgis_locale, 'geomapfish_locator', '_', locale_path)
self.translator.load(qgis_locale, "geomapfish_locator", "_", locale_path)
QCoreApplication.installTranslator(self.translator)

def initGui(self):
pass

def add_locator_menu_action(self, locator_filter: GeomapfishLocatorFilter):
menu = QMenu(locator_filter.service.name, self.iface.mainWindow())
edit_action = menu.addAction(self.tr('edit'))
edit_action = menu.addAction(self.tr("edit"))
edit_action.triggered.connect(lambda _: locator_filter.openConfigWidget())
remove_action = menu.addAction(self.tr('remove'))
remove_action.triggered.connect(lambda _: GeomapfishLocatorPlugin.remove_service(self, locator_filter, menu))
remove_action = menu.addAction(self.tr("remove"))
remove_action.triggered.connect(
lambda _: GeomapfishLocatorPlugin.remove_service(self, locator_filter, menu)
)
self.iface.addPluginToMenu(self.plugin_name, menu.menuAction())
self.menu_entries.append(menu)

Expand All @@ -84,18 +97,18 @@ def new_service(self):
dlg = FilterConfigurationDialog(service)
if dlg.exec_():
if not dlg.service.is_valid():
info("Service {}({}) is not valid".format(service.name, service.url))
info(f"Service {service.name}({service.url}) is not valid")
else:
self.add_service(dlg.service.clone())

def add_service(self, service):
if not service.is_valid():
info("Service {}({}) is not valid".format(service.name, service.url))
info(f"Service {service.name}({service.url}) is not valid")
return

for locator_filter in self.locator_filters:
if service.name == locator_filter.service.name:
service.name = QCoreApplication.translate('Geomapfish', '{service} copy'.format(service=service.name))
service.name = QCoreApplication.translate("Geomapfish", f"{service.name} copy")

locator_filter = GeomapfishLocatorFilter(service, self.iface)
locator_filter.changed.connect(self.filter_changed)
Expand All @@ -106,9 +119,12 @@ def add_service(self, service):

def remove_service(self, locator_filter, menu):
reply = QMessageBox.question(
self.iface.mainWindow(), self.plugin_name,
self.tr('Are you sure to remove service "{}"'.format(locator_filter.service.name)),
QMessageBox.Yes, QMessageBox.No)
self.iface.mainWindow(),
self.plugin_name,
self.tr(f'Are you sure to remove service "{locator_filter.service.name}"'),
QMessageBox.Yes,
QMessageBox.No,
)
if reply == QMessageBox.Yes:
self.iface.removePluginMenu(self.plugin_name, menu.menuAction())
self.menu_entries.remove(menu)
Expand All @@ -119,7 +135,7 @@ def remove_service(self, locator_filter, menu):
def unload(self):
self.iface.invalidateLocatorResults()
for menu_entry in self.menu_entries:
if type(menu_entry) == QAction:
if isinstance(menu_entry, QAction):
self.iface.removePluginMenu(self.plugin_name, menu_entry)
else:
self.iface.removePluginMenu(self.plugin_name, menu_entry.menuAction())
Expand All @@ -132,11 +148,11 @@ def save_services(self):
services = []
for locator_filter in self.locator_filters:
services.append(locator_filter.service.as_dict())
self.settings.set_value('services', services)
self.settings.set_value("services", services)

def refresh_menu(self):
for menu_entry in self.menu_entries[1:]:
if type(menu_entry) == QAction:
if isinstance(menu_entry, QAction):
self.iface.removePluginMenu(self.plugin_name, menu_entry)
else:
self.iface.removePluginMenu(self.plugin_name, menu_entry.menuAction())
Expand Down
Loading

0 comments on commit 7b7f28c

Please sign in to comment.