From c9837994f6d6f27a764b6ad25ef1e672a273e5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Mon, 20 May 2024 12:38:06 -0500 Subject: [PATCH] Make sure map tips are not shown if QtWebKit is not installed (if that's the case, disable map tips and its correspondant widget, showing a nice tooltip) --- swiss_locator/core/settings.py | 2 ++ swiss_locator/gui/config_dialog.py | 5 +++++ swiss_locator/gui/maptip.py | 13 +++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/swiss_locator/core/settings.py b/swiss_locator/core/settings.py index c2889a6..a1b75df 100644 --- a/swiss_locator/core/settings.py +++ b/swiss_locator/core/settings.py @@ -103,3 +103,5 @@ def __init__(self): self.add_setting(Stringlist("feature_search_layers_list", Scope.Global, None)) self.add_setting(Bool("layers_include_opendataswiss", Scope.Global, True)) + + self.add_setting(Bool("with_qtwebkit", Scope.Global, True)) diff --git a/swiss_locator/gui/config_dialog.py b/swiss_locator/gui/config_dialog.py index 32abfe1..5939e81 100644 --- a/swiss_locator/gui/config_dialog.py +++ b/swiss_locator/gui/config_dialog.py @@ -97,6 +97,11 @@ def __init__(self, parent=None): self.settings = settings self.init_widgets() + if not settings.value("with_qtwebkit"): + map_tip = self.setting_widget("show_map_tip") + map_tip.widget.setEnabled(False) + map_tip.widget.setToolTip(self.tr("You need to install QtWebKit to use map tips.")) + def select_all(self, select: bool = True): for r in range(self.feature_search_layers_list.rowCount()): item = self.feature_search_layers_list.item(r, 0) diff --git a/swiss_locator/gui/maptip.py b/swiss_locator/gui/maptip.py index f1e24db..57ed4e6 100644 --- a/swiss_locator/gui/maptip.py +++ b/swiss_locator/gui/maptip.py @@ -22,8 +22,17 @@ """ from PyQt5.QtCore import Qt, QPoint, pyqtSignal -from PyQt5.QtWebKit import QWebSettings -from PyQt5.QtWebKitWidgets import QWebView, QWebPage +try: + from PyQt5.QtWebKit import QWebSettings + from PyQt5.QtWebKitWidgets import QWebView, QWebPage +except ModuleNotFoundError: + from swiss_locator.core.settings import Settings + settings = Settings() + settings.set_value("show_map_tip", False) + settings.set_value("with_qtwebkit", False) +else: + from swiss_locator.core.settings import Settings + Settings().set_value("with_qtwebkit", True) from PyQt5.QtWidgets import QSizePolicy, QDockWidget from PyQt5.QtGui import QPalette, QDesktopServices, QCloseEvent from qgis.core import Qgis, QgsPointXY, QgsMessageLog