diff --git a/cadastre/dialogs/about_dialog.py b/cadastre/dialogs/about_dialog.py index 9e13d973..6cc6aa2a 100644 --- a/cadastre/dialogs/about_dialog.py +++ b/cadastre/dialogs/about_dialog.py @@ -10,6 +10,8 @@ from qgis.PyQt.QtGui import QPixmap from qgis.PyQt.QtWidgets import QDialog +from cadastre.tools import set_window_title + ABOUT_FORM_CLASS, _ = uic.loadUiType( os.path.join( str(Path(__file__).resolve().parent.parent), @@ -28,6 +30,8 @@ def __init__(self, iface, parent=None): self.iface = iface self.setupUi(self) + self.setWindowTitle('{} {}'.format(self.windowTitle(), set_window_title())) + # Signals/Slot Connections self.rejected.connect(self.onReject) self.buttonBox.rejected.connect(self.onReject) diff --git a/cadastre/dialogs/cadastre_export_dialog.py b/cadastre/dialogs/cadastre_export_dialog.py index 3b4fc845..0cc782b0 100644 --- a/cadastre/dialogs/cadastre_export_dialog.py +++ b/cadastre/dialogs/cadastre_export_dialog.py @@ -28,6 +28,7 @@ import cadastre.cadastre_common_base as cadastre_common from cadastre.cadastre_export import CadastreExport as cadastreExportBase +from cadastre.tools import set_window_title PRINT_FORM_CLASS, _ = uic.loadUiType( os.path.join( @@ -43,6 +44,7 @@ def __init__(self, parent=None): super(cadastrePrintProgress, self).__init__(parent) # Set up the user interface self.setupUi(self) + self.setWindowTitle('{} {}'.format(self.windowTitle(), set_window_title())) from contextlib import contextmanager diff --git a/cadastre/dialogs/cadastre_load_dialog.py b/cadastre/dialogs/cadastre_load_dialog.py index a5ce1212..0c4ec5c8 100644 --- a/cadastre/dialogs/cadastre_load_dialog.py +++ b/cadastre/dialogs/cadastre_load_dialog.py @@ -10,6 +10,7 @@ from qgis.PyQt.QtWidgets import QDialog from cadastre.cadastre_loading import cadastreLoading +from cadastre.tools import set_window_title LOAD_FORM_CLASS, _ = uic.loadUiType( os.path.join( @@ -28,6 +29,7 @@ def __init__(self, iface, cadastre_search_dialog, parent=None): super(CadastreLoadDialog, self).__init__(parent) self.iface = iface self.setupUi(self) + self.setWindowTitle('{} {}'.format(self.windowTitle(), set_window_title())) self.mc = self.iface.mapCanvas() self.cadastre_search_dialog = cadastre_search_dialog diff --git a/cadastre/dialogs/import_dialog.py b/cadastre/dialogs/import_dialog.py index 7a784501..67c1c422 100644 --- a/cadastre/dialogs/import_dialog.py +++ b/cadastre/dialogs/import_dialog.py @@ -17,6 +17,7 @@ from cadastre.cadastre_import import cadastreImport from cadastre.dialogs.dialog_common import CadastreCommon +from cadastre.tools import set_window_title IMPORT_FORM_CLASS, _ = uic.loadUiType( os.path.join( @@ -32,6 +33,7 @@ def __init__(self, iface, parent=None): self.iface = iface super(CadastreImportDialog, self).__init__(parent) self.setupUi(self) + self.setWindowTitle('{} {}'.format(self.windowTitle(), set_window_title())) # Images plugin_dir = str(Path(__file__).resolve().parent.parent) diff --git a/cadastre/dialogs/message_dialog.py b/cadastre/dialogs/message_dialog.py index 4f526edb..813843e6 100644 --- a/cadastre/dialogs/message_dialog.py +++ b/cadastre/dialogs/message_dialog.py @@ -9,6 +9,8 @@ from qgis.PyQt import uic from qgis.PyQt.QtWidgets import QDialog +from cadastre.tools import set_window_title + MESSAGE_FORM_CLASS, _ = uic.loadUiType( os.path.join( str(Path(__file__).resolve().parent.parent), @@ -26,6 +28,7 @@ def __init__(self, iface, message, parent=None): super(CadastreMessageDialog, self).__init__(parent) self.iface = iface self.setupUi(self) + self.setWindowTitle('{} {}'.format(self.windowTitle(), set_window_title())) self.teMessage.setText(message) diff --git a/cadastre/dialogs/options_dialog.py b/cadastre/dialogs/options_dialog.py index 4fef7ed0..6e359709 100644 --- a/cadastre/dialogs/options_dialog.py +++ b/cadastre/dialogs/options_dialog.py @@ -12,6 +12,8 @@ from qgis.PyQt.QtGui import QIcon from qgis.PyQt.QtWidgets import QDialog, QFileDialog, QMessageBox +from cadastre.tools import set_window_title + OPTION_FORM_CLASS, _ = uic.loadUiType( os.path.join( str(Path(__file__).resolve().parent.parent), @@ -29,6 +31,7 @@ def __init__(self, iface, parent=None): super(CadastreOptionDialog, self).__init__(parent) self.iface = iface self.setupUi(self) + self.setWindowTitle('{} {}'.format(self.windowTitle(), set_window_title())) # Images self.plugin_dir = str(Path(__file__).resolve().parent.parent) diff --git a/cadastre/dialogs/parcelle_dialog.py b/cadastre/dialogs/parcelle_dialog.py index d19fd97d..1104f084 100644 --- a/cadastre/dialogs/parcelle_dialog.py +++ b/cadastre/dialogs/parcelle_dialog.py @@ -24,6 +24,7 @@ from cadastre.dialogs.cadastre_export_dialog import CadastreExport from cadastre.dialogs.dialog_common import CadastreCommon +from cadastre.tools import set_window_title PARCELLE_FORM_CLASS, _ = uic.loadUiType( os.path.join( @@ -48,6 +49,7 @@ def __init__(self, iface, layer, feature, cadastre_search_dialog, parent=None): self.layer = layer self.mc = iface.mapCanvas() self.setupUi(self) + self.setWindowTitle('{} {}'.format(self.windowTitle(), set_window_title())) self.cadastre_search_dialog = cadastre_search_dialog self.setWindowIcon(QIcon( os.path.join( diff --git a/cadastre/tools.py b/cadastre/tools.py index 59c8c2a7..91459134 100644 --- a/cadastre/tools.py +++ b/cadastre/tools.py @@ -2,8 +2,13 @@ __license__ = "GPL version 3" __email__ = "info@3liz.org" +import subprocess import time +from pathlib import Path + +from qgis.utils import pluginMetadata + def timing(f): """ @@ -19,3 +24,53 @@ def wrap(*args): return ret return wrap + + +def current_git_hash() -> str: + """ Retrieve the current git hash number of the git repo (first 6 digit). """ + repo_dir = Path(__file__).parent + git_show = subprocess.Popen( + 'git rev-parse --short=6 HEAD', + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + shell=True, + cwd=repo_dir, + universal_newlines=True, + encoding='utf8' + ) + hash_number = git_show.communicate()[0].partition('\n')[0] + if hash_number == '': + hash_number = 'unknown' + return hash_number + + +def next_git_tag(): + """ Using Git command, trying to guess the next tag. """ + repo_dir = Path(__file__).parent + git_show = subprocess.Popen( + 'git describe --tags $(git rev-list --tags --max-count=1)', + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + shell=True, + cwd=repo_dir, + universal_newlines=True, + encoding='utf8' + ) + tag = git_show.communicate()[0].partition('\n')[0] + if not tag: + return 'next' + versions = tag.split('.') + text = '{}.{}.{}-pre'.format(versions[0], versions[1], int(versions[2]) + 1) + return text + + +def set_window_title() -> str: + """ Set the window title if on a dev version. """ + version = pluginMetadata('cadastre', 'version') + if version != 'master': + return '' + + # return 'branch {}, commit {}, next {}'.format( + # version, current_git_hash(), next_git_tag()) + + return 'next {}'.format(next_git_tag())