From 24159f9bd42eaa6ec3c9d6bfa844d4b0d1201874 Mon Sep 17 00:00:00 2001 From: Miikka Kallio Date: Mon, 24 Feb 2025 15:01:03 +0200 Subject: [PATCH 1/2] Add check and warning for time zone variable Check if PGTZ is set to expected value. Warn user if not. --- arho_feature_template/plugin.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arho_feature_template/plugin.py b/arho_feature_template/plugin.py index b7ab8a7..3411ac2 100644 --- a/arho_feature_template/plugin.py +++ b/arho_feature_template/plugin.py @@ -1,5 +1,6 @@ from __future__ import annotations +import os from typing import TYPE_CHECKING, Callable from qgis.core import QgsApplication @@ -42,6 +43,17 @@ def __init__(self) -> None: self.toolbar = iface.addToolBar("ARHO Toolbar") self.toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) + self.check_timezone_variable() + + def check_timezone_variable(self): + """Check if PGTZ environment variable is correctly set.""" + + if os.environ.get("PGTZ") != "Europe/Helsinki": + iface.messageBar().pushWarning( + "Varoitus", + "Ympäristömuuttuja PGTZ ei ole asetettu arvoon 'Europe/Helsinki'.\n" + "Tämä voi johtaa väärään aikavyöhykkeeseen tallennettuihin kellonaikoihin.", + ) def add_action( self, From 49fd24aaf30fc5fe57c0fc791c9aea1fe6972e95 Mon Sep 17 00:00:00 2001 From: Miikka Kallio Date: Mon, 24 Feb 2025 15:40:23 +0200 Subject: [PATCH 2/2] Move check to initGui Moved time zone check to initGui(), removed unnecessary line change from warning message. --- arho_feature_template/plugin.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arho_feature_template/plugin.py b/arho_feature_template/plugin.py index 3411ac2..a742048 100644 --- a/arho_feature_template/plugin.py +++ b/arho_feature_template/plugin.py @@ -43,7 +43,6 @@ def __init__(self) -> None: self.toolbar = iface.addToolBar("ARHO Toolbar") self.toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) - self.check_timezone_variable() def check_timezone_variable(self): """Check if PGTZ environment variable is correctly set.""" @@ -51,8 +50,10 @@ def check_timezone_variable(self): if os.environ.get("PGTZ") != "Europe/Helsinki": iface.messageBar().pushWarning( "Varoitus", - "Ympäristömuuttuja PGTZ ei ole asetettu arvoon 'Europe/Helsinki'.\n" - "Tämä voi johtaa väärään aikavyöhykkeeseen tallennettuihin kellonaikoihin.", + ( + "Ympäristömuuttuja PGTZ ei ole asetettu arvoon 'Europe/Helsinki'." + "Tämä voi johtaa väärään aikavyöhykkeeseen tallennettuihin kellonaikoihin." + ), ) def add_action( @@ -251,6 +252,8 @@ def initGui(self) -> None: # noqa N802 lambda: self.identify_plan_features_action.setChecked(False) ) + self.check_timezone_variable() + def toggle_dock_visibility(self, dock_widget: QgsDockWidget): if dock_widget.isUserVisible(): dock_widget.hide()