|
23 | 23 | # --------------------------------------------------------------------- |
24 | 24 |
|
25 | 25 |
|
| 26 | +import os |
| 27 | + |
26 | 28 | 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 |
29 | 31 |
|
30 | 32 | from ..utils.plugin_utils import PluginUtils |
31 | 33 |
|
32 | 34 | DIALOG_UI = PluginUtils.get_ui_class("about_dialog.ui") |
33 | 35 |
|
34 | 36 |
|
| 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 | + |
35 | 66 | class AboutDialog(QDialog, DIALOG_UI): |
36 | 67 | def __init__(self, parent=None): |
37 | 68 | QDialog.__init__(self, parent) |
@@ -59,3 +90,32 @@ def __init__(self, parent=None): |
59 | 90 | transformMode=Qt.TransformationMode.SmoothTransformation, |
60 | 91 | ) |
61 | 92 | 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