From edcc1e0686737aa2f4ca37504a9b077650b5f204 Mon Sep 17 00:00:00 2001 From: Darkimage Date: Sat, 26 Sep 2020 21:58:28 +0200 Subject: [PATCH] Added DependencyErrorDialog --- megascan_link_python/dialogs.py | 47 +++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/megascan_link_python/dialogs.py b/megascan_link_python/dialogs.py index 36e9954..0835b87 100644 --- a/megascan_link_python/dialogs.py +++ b/megascan_link_python/dialogs.py @@ -5,16 +5,18 @@ """ import importlib +import webbrowser import PySide2 -from PySide2 import QtWidgets, QtGui, QtCore +from PySide2 import QtCore, QtGui, QtWidgets from PySide2.QtCore import Qt -from .ui import settings_dialog, icon, painterslider from . import config, log, sockets +from .ui import error_dialog, icon, painterslider, settings_dialog importlib.reload(settings_dialog) importlib.reload(painterslider) +importlib.reload(error_dialog) class SettingsDialog(QtWidgets.QDialog, settings_dialog.Ui_Dialog): """Dialog displayed to the user for editing the plugin settings @@ -104,3 +106,44 @@ def _saveSettings(self): self._socketRef.restart() self.close() + +class DependencyErrorDialog(QtWidgets.QDialog, error_dialog.Ui_Dialog): + """ + Generic Error dialog for displaying error messages + """ + def __init__(self, parent, helpLink = None): + super().__init__(parent=parent) + self.helpLink = helpLink + self.setupUi(self) + self.descriptionLabel.setOpenExternalLinks(True) + for btn in self.buttonBox.buttons(): + if (btn.text() == "Help"): + btn.setFocus() + btn.clicked.connect(self.openHelp) + else: + btn.clicked.connect(self.close) + + def close(self): + """ + Close the dialog and updates the ini file if necessary + """ + dontShowAgainState = True if self.dontShowAgain.checkState() != Qt.CheckState.Checked else False + config.ConfigSettings.updateConfigSetting("General", "showDependencyError", dontShowAgainState, False) + config.ConfigSettings.flush() + super().close() + + def show(self): + """ + Shows the error dialog only if the users has not checked before the "don't show again" checkbox + """ + if (config.ConfigSettings.checkIfOptionIsSet("General", "showDependencyError", 'True')): + super().show() + + def openHelp(self): + """ + Summon a browser with the documentation page opened + """ + if (self.helpLink): + webbrowser.open(self.helpLink) + else: + self.close()