def showCritcalErrorDialog(self: Any, error: str = '', details: str = '') -> QMessageBox: import traceback messagebox = QMessageBox(self) messagebox.setWindowTitle( 'Critical Error' if self else getTitleString('Critical Error')) messagebox.setText(f''' <p><strong>\ Something unexpected happened. {'Detailed error message:' if error else ''}\ </strong></p> {f'<p><code>{error}</code></p>' if error else ''} <p><small> Please check if this is a known issue or create a report \ detailing the conditions of this error here:<br> <a href="{w3modmanager.URL_ISSUES}" style="text-decoration:none;"> {removeUrlScheme(w3modmanager.URL_ISSUES)} </a> </small></p> ''') if error: messagebox.setDetailedText( details if details else traceback.format_exc()) messagebox.setIconPixmap(messagebox.windowIcon().pixmap( messagebox.windowIcon().actualSize(QSize(64, 64)))) messagebox.layout().setContentsMargins(5, 5, 5, 5) messagebox.setModal(True) messagebox.open() return messagebox
def message_box(self, message: str, buttons: int = 1) -> int: ''' Message box with "Yes/No" or "OK" buttons. Defaults to "OK".\n Parameters:\n message (str): Message shown inside the message box. buttons (int): Amount of buttons, 1 - "OK" button, 2 - "Yes/No" buttons. Returns:\n choice (int): ID of the clicked button. ''' pixmap = QPixmap(resource_path('icon.ico')).scaledToWidth( 35, Qt.SmoothTransformation) msg_box = QMessageBox() msg_box.setFont(ui.font) msg_box.setText(message) if buttons == 2: msg_yes = msg_box.addButton(QMessageBox.Yes) msg_no = msg_box.addButton(QMessageBox.No) msg_yes.setText(self.dialog_yes) msg_no.setText(self.dialog_no) msg_yes.setProperty('class', 'button_yes') msg_no.setProperty('class', 'button_no') msg_box.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint) msg_box.setIconPixmap(pixmap) with open(resource_path('style.css'), 'r') as file: msg_box.setStyleSheet(file.read()) msg_box.move(ui.frameGeometry().center() - QRect(QPoint(), msg_box.sizeHint()).center()) choice = msg_box.exec_() return choice
def showOtherInstanceDialog(self: Any) -> QMessageBox: messagebox = QMessageBox(self) messagebox.setWindowTitle( 'Other instance' if self else getTitleString('Other instance')) messagebox.setText(f''' <p style="margin:10px 15px 10px 5px;"> <b>Another instance of the application is currently running.</b> </p> <p style="margin:10px 15px 10px 5px;"> Only one instance should be opened at the same time<br> to prevent data corruption. </p> <p style="margin:10px 15px 10px 5px;"> Continue anyway? </p> ''') messagebox.setTextFormat(Qt.RichText) messagebox.setIconPixmap(messagebox.windowIcon().pixmap( messagebox.windowIcon().actualSize(QSize(64, 64)))) messagebox.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel) messagebox.setDefaultButton(QMessageBox.Cancel) messagebox.layout().setContentsMargins(5, 5, 5, 5) messagebox.setModal(True) messagebox.open() return messagebox
def showInvalidPermissionsDialog(self: Any, path: Path) -> QMessageBox: messagebox = QMessageBox(self) messagebox.setWindowTitle('Invalid permissions' if self else getTitleString('Invalid permissions')) messagebox.setText(f''' <p style="margin:10px 15px 10px 5px;"> <b>Invalid permissions for directory:</b> </p> <p style="margin:10px 15px 10px 5px;"> <code>{path}</code> </p> <p style="margin:10px 15px 10px 5px;"> Write permissions to this directory are required for mod management.<br> Automatically set the correct permissions? </p> ''') messagebox.setTextFormat(Qt.RichText) messagebox.setIconPixmap(messagebox.windowIcon().pixmap( messagebox.windowIcon().actualSize(QSize(64, 64)))) messagebox.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel) messagebox.layout().setContentsMargins(5, 5, 5, 5) messagebox.setModal(True) messagebox.open() return messagebox
def showInvalidConfigErrorDialog(self: Any) -> QMessageBox: messagebox = QMessageBox(self) messagebox.setWindowTitle('Invalid game path' if self else getTitleString('Invalid game path')) messagebox.setText(f''' <p style="margin:10px 15px 10px 5px;"><b>Invalid game or config path.</b><br> Please restart w3modmanager and enter the paths of<br> your The Witcher 3 installation and the game config folder<br> (usually <code>User/Documents/The Witcher 3</code>). </p> <p style="margin:10px 15px 10px 5px;"><small> For updates and information visit <br> <a href="{w3modmanager.URL_WEB}" style="text-decoration:none;">\ {removeUrlScheme(w3modmanager.URL_WEB)}\ </a> </small></p> ''') messagebox.setTextFormat(Qt.RichText) messagebox.setIconPixmap(messagebox.windowIcon().pixmap( messagebox.windowIcon().actualSize(QSize(64, 64)))) messagebox.setStandardButtons(QMessageBox.Ok) messagebox.setAttribute(Qt.WA_DeleteOnClose) messagebox.layout().setContentsMargins(5, 5, 5, 5) messagebox.setModal(True) messagebox.open() return messagebox
def showAboutDialog(self: Any) -> QMessageBox: messagebox = QMessageBox(self) messagebox.setWindowTitle('About' if self else getTitleString('About')) messagebox.setText(f''' <p style="margin:0 15px 0 0;"> <b>{w3modmanager.TITLE} {w3modmanager.VERSION}</b> <small>{f'({w3modmanager.VERSION_HASH})' if w3modmanager.VERSION_HASH else ''}</small><br> {w3modmanager.SUBTITLE}<br> <br> For updates and information visit <br> <a href="{w3modmanager.URL_WEB}" style="text-decoration:none;">\ {removeUrlScheme(w3modmanager.URL_WEB)}\ </a><br> <br> Thank you for using {w3modmanager.TITLE}! </p> ''') # TODO: enhancement: check if new version is available messagebox.setTextFormat(Qt.RichText) messagebox.setIconPixmap(messagebox.windowIcon().pixmap( messagebox.windowIcon().actualSize(QSize(64, 64)))) messagebox.setMinimumSize(QSize(500, 500)) messagebox.setStandardButtons(QMessageBox.Ok) messagebox.setAttribute(Qt.WA_DeleteOnClose) messagebox.layout().setContentsMargins(5, 5, 5, 5) messagebox.setModal(True) messagebox.open() return messagebox
def showInvalidPermissionsErrorDialog(self: Any) -> QMessageBox: messagebox = QMessageBox(self) messagebox.setWindowTitle('Invalid permissions' if self else getTitleString('Invalid permissions')) messagebox.setText(f''' <p style="margin:10px 15px 10px 5px;"> <b>Invalid permissions for the game directory.</b> </p> <p style="margin:10px 15px 10px 5px;"> Please restart w3modmanager to try to automatically fix the permissions, or fix the permissions manually. </p> ''') messagebox.setTextFormat(Qt.RichText) messagebox.setIconPixmap(messagebox.windowIcon().pixmap( messagebox.windowIcon().actualSize(QSize(64, 64)))) messagebox.setStandardButtons(QMessageBox.Ok) messagebox.layout().setContentsMargins(5, 5, 5, 5) messagebox.setModal(True) messagebox.open() return messagebox