Skip to content

Commit

Permalink
Use global property to store QtWebKit availability
Browse files Browse the repository at this point in the history
  • Loading branch information
gacarrillor committed May 21, 2024
1 parent 9fd5d40 commit 36222e0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 0 additions & 2 deletions swiss_locator/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,3 @@ 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))
3 changes: 2 additions & 1 deletion swiss_locator/gui/config_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from ..core.settings import Settings
from ..core.language import get_language
from ..map_geo_admin.layers import searchable_layers
from .qtwebkit_conf import with_qt_web_kit

DialogUi, _ = loadUiType(os.path.join(os.path.dirname(__file__), "../ui/config.ui"))

Expand Down Expand Up @@ -98,7 +99,7 @@ def __init__(self, parent=None):
self.settings = settings
self.init_widgets()

if not settings.value("with_qtwebkit"):
if not with_qt_web_kit():
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."))
Expand Down
19 changes: 8 additions & 11 deletions swiss_locator/gui/maptip.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,20 @@
"""

from PyQt5.QtCore import Qt, QPoint, pyqtSignal
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
from qgis.gui import QgisInterface

from swiss_locator import DEBUG
from swiss_locator.gui.qtwebkit_conf import with_qt_web_kit
if with_qt_web_kit():
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
else:
from swiss_locator.core.settings import Settings
settings = Settings()
settings.set_value("show_map_tip", False)


class MapTip(QDockWidget):
Expand Down
16 changes: 16 additions & 0 deletions swiss_locator/gui/qtwebkit_conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

_WITH_QTWEBKIT = None


def with_qt_web_kit() -> bool:
global _WITH_QTWEBKIT
if _WITH_QTWEBKIT is None:
try:
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
except ModuleNotFoundError:
_WITH_QTWEBKIT = False
else:
_WITH_QTWEBKIT = True

return _WITH_QTWEBKIT

0 comments on commit 36222e0

Please sign in to comment.