Skip to content

Commit cb67180

Browse files
authored
show version in about dialog (#185)
1 parent 467759f commit cb67180

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

oqtopus/gui/about_dialog.py

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,46 @@
2323
# ---------------------------------------------------------------------
2424

2525

26+
import os
27+
2628
from qgis.PyQt.QtCore import QSettings, Qt
27-
from qgis.PyQt.QtGui import QPixmap
28-
from qgis.PyQt.QtWidgets import QDialog
29+
from qgis.PyQt.QtGui import QFont, QPixmap
30+
from qgis.PyQt.QtWidgets import QDialog, QLabel
2931

3032
from ..utils.plugin_utils import PluginUtils
3133

3234
DIALOG_UI = PluginUtils.get_ui_class("about_dialog.ui")
3335

3436

37+
def _lib_version(package_name: str, package_path: str) -> str:
38+
"""Return the version of a bundled library.
39+
40+
Tries ``importlib.metadata`` first, then falls back to scanning for a
41+
``<package>-*.dist-info/METADATA`` file next to *package_path*.
42+
"""
43+
try:
44+
from importlib.metadata import version
45+
46+
return version(package_name)
47+
except Exception:
48+
pass
49+
50+
# Fallback: look for a dist-info directory next to the package
51+
libs_dir = os.path.dirname(package_path)
52+
prefix = f"{package_name}-"
53+
for entry in os.listdir(libs_dir):
54+
if entry.startswith(prefix) and entry.endswith(".dist-info"):
55+
metadata_file = os.path.join(libs_dir, entry, "METADATA")
56+
if os.path.isfile(metadata_file):
57+
with open(metadata_file) as f:
58+
for line in f:
59+
if line.startswith("Version:"):
60+
return line.split(":", 1)[1].strip()
61+
# Extract from directory name as last resort
62+
return entry[len(prefix) : -len(".dist-info")]
63+
return "?"
64+
65+
3566
class AboutDialog(QDialog, DIALOG_UI):
3667
def __init__(self, parent=None):
3768
QDialog.__init__(self, parent)
@@ -59,3 +90,32 @@ def __init__(self, parent=None):
5990
transformMode=Qt.TransformationMode.SmoothTransformation,
6091
)
6192
self.iconLabel.setPixmap(scaled_logo)
93+
94+
# --- Library versions ---
95+
oqtopus_path = PluginUtils.plugin_root_path()
96+
oqtopus_version = _lib_version("oqtopus", oqtopus_path)
97+
98+
from ..libs import pum as _pum_pkg
99+
100+
pum_path = os.path.dirname(_pum_pkg.__file__)
101+
pum_version = _lib_version("pum", pum_path)
102+
103+
bold_font = QFont()
104+
bold_font.setBold(True)
105+
106+
grid = self.gridLayout_2
107+
next_row = grid.rowCount()
108+
109+
oqtopus_label = QLabel("oQtopus version:")
110+
oqtopus_label.setFont(bold_font)
111+
oqtopus_value = QLabel(oqtopus_version)
112+
oqtopus_value.setToolTip(oqtopus_path)
113+
grid.addWidget(oqtopus_label, next_row, 0)
114+
grid.addWidget(oqtopus_value, next_row, 1)
115+
116+
pum_label = QLabel("PUM version:")
117+
pum_label.setFont(bold_font)
118+
pum_value = QLabel(pum_version)
119+
pum_value.setToolTip(pum_path)
120+
grid.addWidget(pum_label, next_row + 1, 0)
121+
grid.addWidget(pum_value, next_row + 1, 1)

0 commit comments

Comments
 (0)