-
Notifications
You must be signed in to change notification settings - Fork 39
docs: changed read_config docstring & made use off it #379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "python-envs.defaultEnvManager": "ms-python.python:system" | ||
| } | ||
|
merydian marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,12 +28,14 @@ | |
| """ | ||
|
|
||
| from qgis.gui import QgisInterface | ||
| from qgis.utils import iface | ||
| from qgis.core import QgsApplication, QgsSettings | ||
| from qgis.PyQt.QtCore import QTranslator, qVersion, QCoreApplication, QLocale | ||
| import os.path | ||
|
|
||
| from .gui import ORStoolsDialog | ||
| from .proc import provider, ENDPOINTS, DEFAULT_SETTINGS | ||
| from .utils import configmanager | ||
|
|
||
|
|
||
| class ORStools: | ||
|
|
@@ -49,6 +51,7 @@ def __init__(self, iface: QgisInterface) -> None: | |
| application at run time. | ||
| :type iface: QgsInterface | ||
| """ | ||
| self.iface = iface | ||
| self.dialog = ORStoolsDialog.ORStoolsDialogMain(iface) | ||
| self.provider = provider.ORStoolsProvider() | ||
|
|
||
|
|
@@ -80,6 +83,8 @@ def initGui(self) -> None: | |
|
|
||
| QgsApplication.processingRegistry().addProvider(self.provider) | ||
| self.dialog.initGui() | ||
| # starts deprecated url dialog after QGIS Main-Window opened | ||
| iface.initializationCompleted.connect(self.check_provider_url) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't trigger somehow, what about just calling the function here? |
||
|
|
||
| def unload(self) -> None: | ||
| """remove menu entry and toolbar icons""" | ||
|
|
@@ -88,7 +93,7 @@ def unload(self) -> None: | |
|
|
||
| def add_default_provider_to_settings(self): | ||
| s = QgsSettings() | ||
| settings = s.value("ORStools/config") | ||
| settings = configmanager.read_config() | ||
|
|
||
| settings_keys = ["ENV_VARS", "base_url", "key", "name", "endpoints"] | ||
|
|
||
|
|
@@ -105,3 +110,28 @@ def add_default_provider_to_settings(self): | |
| s.setValue("ORStools/config", settings) | ||
| else: | ||
| s.setValue("ORStools/config", DEFAULT_SETTINGS) | ||
|
|
||
| def url_is_deprecated(self) -> bool: | ||
| settings = configmanager.read_config() | ||
|
|
||
| if not settings: | ||
| return False | ||
|
|
||
| return settings["providers"][0]["base_url"] != DEFAULT_SETTINGS["providers"][0]["base_url"] | ||
|
|
||
| def reset_provider_url(self): | ||
| """Reset the first provider URL to the default.""" | ||
|
|
||
| settings = configmanager.read_config() | ||
|
|
||
| if not settings: | ||
| return | ||
|
|
||
| settings["providers"][0]["base_url"] = DEFAULT_SETTINGS["providers"][0]["base_url"] | ||
|
|
||
| configmanager.write_config(settings) | ||
|
|
||
| def check_provider_url(self): | ||
| if self.url_is_deprecated(): | ||
| if ORStoolsDialog.url_dialog_reset_button(self.iface.mainWindow()): | ||
| self.reset_provider_url() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,6 +153,35 @@ def on_about_click(parent: QWidget) -> None: | |
| ) | ||
|
|
||
|
|
||
| class DeprecatedUrlDialog(QMessageBox): | ||
| """Dialog informing the user that the configured URL is deprecated.""" | ||
|
|
||
| def __init__(self, parent=None): | ||
| super().__init__(parent) | ||
|
|
||
| self.setIcon(QMessageBox.Warning) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't compatible with Qt6, try to use QGIS4 for development to check for these errors. |
||
| self.setWindowTitle(self.tr("Deprecated URL")) | ||
|
|
||
| self.setText( | ||
| self.tr( | ||
| "The configured ORS provider URL is deprecated.\n" | ||
| "Would you like to reset it to the new default URL?" | ||
| ) | ||
| ) | ||
|
|
||
| self.reset_button = self.addButton(self.tr("Reset URL"), QMessageBox.AcceptRole) | ||
|
|
||
| self.addButton(self.tr("Close"), QMessageBox.RejectRole) | ||
|
|
||
|
|
||
| def url_dialog_reset_button(parent=None) -> bool: | ||
| """Shows the deprecated URL dialog and returns bool.""" | ||
|
|
||
| url_dlg = DeprecatedUrlDialog(parent) | ||
| url_dlg.exec() | ||
| return url_dlg.clickedButton() == url_dlg.reset_button | ||
|
|
||
|
|
||
| class ORStoolsDialogMain: | ||
| """Defines all mandatory QGIS things about dialog.""" | ||
|
|
||
|
|
@@ -535,7 +564,7 @@ def reload_geocode_completer_ors(self, request, lineEdit, text): | |
|
|
||
| encoded = quote(lineEdit.text()) | ||
|
|
||
| url = f"https://api.openrouteservice.org/geocode/search?api_key={api_key}&text={encoded}&focus.point.lat={middle.y()}&focus.point.lon={middle.x()}" | ||
| url = f"https://api.heigit.org/geocode/search?api_key={api_key}&text={encoded}&focus.point.lat={middle.y()}&focus.point.lon={middle.x()}" | ||
| error_code = request.get(QNetworkRequest(QUrl(url))) | ||
| if error_code == QgsBlockingNetworkRequest.ErrorCode.NoError: | ||
| reply = request.reply() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file here intentionally?