4 # |
4 # |
5 |
5 |
6 """ |
6 """ |
7 Module implementing QMessageBox replacements and more convenience function. |
7 Module implementing QMessageBox replacements and more convenience function. |
8 """ |
8 """ |
|
9 |
|
10 import contextlib |
9 |
11 |
10 from PyQt6.QtCore import QCoreApplication, Qt |
12 from PyQt6.QtCore import QCoreApplication, Qt |
11 from PyQt6.QtWidgets import QApplication, QMessageBox |
13 from PyQt6.QtWidgets import QApplication, QMessageBox |
12 |
14 |
13 ############################################################################### |
15 ############################################################################### |
141 @type Qt.TextFormat |
143 @type Qt.TextFormat |
142 @return button pressed by the user |
144 @return button pressed by the user |
143 @rtype QMessageBox.StandardButton |
145 @rtype QMessageBox.StandardButton |
144 """ |
146 """ |
145 if parent is None: |
147 if parent is None: |
146 parent = QCoreApplication.instance().getMainWindow() |
148 with contextlib.suppress(AttributeError): |
|
149 parent = QCoreApplication.instance().getMainWindow() |
147 |
150 |
148 messageBox = QMessageBox(parent) |
151 messageBox = QMessageBox(parent) |
149 messageBox.setIcon(icon) |
152 messageBox.setIcon(icon) |
150 if parent is not None: |
153 if parent is not None: |
151 messageBox.setWindowModality(Qt.WindowModality.WindowModal) |
154 messageBox.setWindowModality(Qt.WindowModality.WindowModal) |