""" """ import logging import os import platform from qgis.core import QgsProject import subprocess import unittest from PyQt5 import QtWidgets from PyQt5 import uic from PyQt5.QtCore import Qt, QFileInfo from PyQt5.QtGui import QIcon, QPixmap from PyQt5.QtWidgets import QTextBrowser from core.constants import MAIN, LOGDIR, RSCDIR, CONTACT, TESTDIR, DEBUG from path import Path from test._stream import TestStream logger = logging.getLogger("mncheck") Ui_Contact, _ = uic.loadUiType(MAIN / 'ui'/ 'dlg_contact.ui') class DlgContact(QtWidgets.QDialog): def __init__(self, parent=None): super().__init__(parent) self.createWidgets() def createWidgets(self): """ set up the interface """ self.ui = Ui_Contact() self.ui.setupUi(self) self.setWindowIcon(QIcon(MAIN / "icon.png")) self.ui.lbl_mn_logo.setPixmap(QPixmap(RSCDIR / "mn_logo_mini.png")) self.ui.lbl_warning_logo.setPixmap(QPixmap(RSCDIR / "warning_16.png")) self.ui.lbl_mail.setText(f"{CONTACT}") self.ui.lbl_mail.setTextFormat(Qt.RichText) self.ui.lbl_mail.setTextInteractionFlags(Qt.TextBrowserInteraction) self.ui.lbl_mail.setOpenExternalLinks(True) self.ui.btn_open_log_dir.clicked.connect(self.open_log_dir) self.ui.btn_test.setVisible(DEBUG) self.ui.btn_test.clicked.connect(self.run_tests) def open_log_dir(self): path = Path(LOGDIR).abspath() if platform.system() == "Windows": os.startfile(path) else: subprocess.Popen(["open", path]) def run_tests(self): _initial_project = QgsProject.instance().absoluteFilePath() if _initial_project: QgsProject.instance().write(QFileInfo(_initial_project)) loader = unittest.TestLoader() tests = loader.discover(Path(TESTDIR).abspath()) with open(LOGDIR / "checkup.txt", "w+") as f: runner = unittest.TextTestRunner(stream=f) runner.run(tests) if _initial_project: QgsProject.instance().clear() QgsProject.read(QFileInfo(_initial_project)) with open(LOGDIR / "checkup.txt", "r") as f: dlg = QTextBrowser() dlg.setText(f.read()) dlg.show()