Sun, 03 Nov 2024 17:50:34 +0100
Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
--- a/src/eric7/APIs/Python3/eric7.api Sun Nov 03 12:34:02 2024 +0100 +++ b/src/eric7/APIs/Python3/eric7.api Sun Nov 03 17:50:34 2024 +0100 @@ -1465,6 +1465,7 @@ eric7.EricWidgets.EricAnimatedWidget.EricAnimationDirection.Down?7 eric7.EricWidgets.EricAnimatedWidget.EricAnimationDirection.Up?7 eric7.EricWidgets.EricApplication.EricApplication.PaletteRoleMapping?7 +eric7.EricWidgets.EricApplication.EricApplication.getMainWindow?4() eric7.EricWidgets.EricApplication.EricApplication.getObject?4(name) eric7.EricWidgets.EricApplication.EricApplication.getPluginObject?4(name) eric7.EricWidgets.EricApplication.EricApplication.getPluginObjectType?4(name) @@ -1472,6 +1473,7 @@ eric7.EricWidgets.EricApplication.EricApplication.getStyleIconsPath?4(universal=False) eric7.EricWidgets.EricApplication.EricApplication.registerObject?4(name, objectRef) eric7.EricWidgets.EricApplication.EricApplication.registerPluginObject?4(name, objectRef, pluginType=None) +eric7.EricWidgets.EricApplication.EricApplication.setMainWindow?4(mainWindow) eric7.EricWidgets.EricApplication.EricApplication.setStyleSheetFile?4(filename) eric7.EricWidgets.EricApplication.EricApplication.unregisterPluginObject?4(name) eric7.EricWidgets.EricApplication.EricApplication.usesDarkPalette?4() @@ -1691,8 +1693,8 @@ eric7.EricWidgets.EricMessageBox.Yes?7 eric7.EricWidgets.EricMessageBox.YesRole?7 eric7.EricWidgets.EricMessageBox.YesToAll?7 -eric7.EricWidgets.EricMessageBox.about?7 -eric7.EricWidgets.EricMessageBox.aboutQt?7 +eric7.EricWidgets.EricMessageBox.about?4(parent, title, text) +eric7.EricWidgets.EricMessageBox.aboutQt?4(parent, title="") eric7.EricWidgets.EricMessageBox.critical?4(parent, title, text, buttons=QMessageBox.StandardButton.Ok, defaultButton=QMessageBox.StandardButton.NoButton, ) eric7.EricWidgets.EricMessageBox.information?4(parent, title, text, buttons=QMessageBox.StandardButton.Ok, defaultButton=QMessageBox.StandardButton.NoButton, ) eric7.EricWidgets.EricMessageBox.okToClearData?4(parent, title, text, saveFunc, textFormat=Qt.TextFormat.AutoText)
--- a/src/eric7/CondaInterface/CondaPackagesWidget.py Sun Nov 03 12:34:02 2024 +0100 +++ b/src/eric7/CondaInterface/CondaPackagesWidget.py Sun Nov 03 17:50:34 2024 +0100 @@ -737,7 +737,7 @@ # check, if the destination is writeable if not os.access(cfgFile, os.W_OK): EricMessageBox.critical( - None, + self, self.tr("Edit Configuration"), self.tr( """The configuration file "{0}" does not exist"""
--- a/src/eric7/Documentation/Help/source.qhp Sun Nov 03 12:34:02 2024 +0100 +++ b/src/eric7/Documentation/Help/source.qhp Sun Nov 03 17:50:34 2024 +0100 @@ -5436,6 +5436,7 @@ <keyword name="EricApplication (Constructor)" id="EricApplication (Constructor)" ref="eric7.EricWidgets.EricApplication.html#EricApplication.__init__" /> <keyword name="EricApplication (Module)" id="EricApplication (Module)" ref="eric7.EricWidgets.EricApplication.html" /> <keyword name="EricApplication.__setPaletteFromStyleSheet" id="EricApplication.__setPaletteFromStyleSheet" ref="eric7.EricWidgets.EricApplication.html#EricApplication.__setPaletteFromStyleSheet" /> + <keyword name="EricApplication.getMainWindow" id="EricApplication.getMainWindow" ref="eric7.EricWidgets.EricApplication.html#EricApplication.getMainWindow" /> <keyword name="EricApplication.getObject" id="EricApplication.getObject" ref="eric7.EricWidgets.EricApplication.html#EricApplication.getObject" /> <keyword name="EricApplication.getPluginObject" id="EricApplication.getPluginObject" ref="eric7.EricWidgets.EricApplication.html#EricApplication.getPluginObject" /> <keyword name="EricApplication.getPluginObjectType" id="EricApplication.getPluginObjectType" ref="eric7.EricWidgets.EricApplication.html#EricApplication.getPluginObjectType" /> @@ -5443,6 +5444,7 @@ <keyword name="EricApplication.getStyleIconsPath" id="EricApplication.getStyleIconsPath" ref="eric7.EricWidgets.EricApplication.html#EricApplication.getStyleIconsPath" /> <keyword name="EricApplication.registerObject" id="EricApplication.registerObject" ref="eric7.EricWidgets.EricApplication.html#EricApplication.registerObject" /> <keyword name="EricApplication.registerPluginObject" id="EricApplication.registerPluginObject" ref="eric7.EricWidgets.EricApplication.html#EricApplication.registerPluginObject" /> + <keyword name="EricApplication.setMainWindow" id="EricApplication.setMainWindow" ref="eric7.EricWidgets.EricApplication.html#EricApplication.setMainWindow" /> <keyword name="EricApplication.setStyleSheetFile" id="EricApplication.setStyleSheetFile" ref="eric7.EricWidgets.EricApplication.html#EricApplication.setStyleSheetFile" /> <keyword name="EricApplication.unregisterPluginObject" id="EricApplication.unregisterPluginObject" ref="eric7.EricWidgets.EricApplication.html#EricApplication.unregisterPluginObject" /> <keyword name="EricApplication.usesDarkPalette" id="EricApplication.usesDarkPalette" ref="eric7.EricWidgets.EricApplication.html#EricApplication.usesDarkPalette" /> @@ -20176,8 +20178,10 @@ <keyword name="_stylesheet" id="_stylesheet" ref="eric7.UI.CodeDocumentationViewerTemplate.html#_stylesheet" /> <keyword name="_weakCryptoKeySizeCryptography" id="_weakCryptoKeySizeCryptography" ref="eric7.Plugins.CheckerPlugins.CodeStyleChecker.Security.Checks.weakCryptographicKey.html#_weakCryptoKeySizeCryptography" /> <keyword name="_weakCryptoKeySizePycrypto" id="_weakCryptoKeySizePycrypto" ref="eric7.Plugins.CheckerPlugins.CodeStyleChecker.Security.Checks.weakCryptographicKey.html#_weakCryptoKeySizePycrypto" /> + <keyword name="about" id="about" ref="eric7.EricWidgets.EricMessageBox.html#about" /> <keyword name="aboutBlack" id="aboutBlack" ref="eric7.CodeFormatting.BlackUtilities.html#aboutBlack" /> <keyword name="aboutIsort" id="aboutIsort" ref="eric7.CodeFormatting.IsortUtilities.html#aboutIsort" /> + <keyword name="aboutQt" id="aboutQt" ref="eric7.EricWidgets.EricMessageBox.html#aboutQt" /> <keyword name="absolutePath" id="absolutePath" ref="eric7.SystemUtilities.FileSystemUtilities.html#absolutePath" /> <keyword name="absoluteUniversalPath" id="absoluteUniversalPath" ref="eric7.SystemUtilities.FileSystemUtilities.html#absoluteUniversalPath" /> <keyword name="activate" id="activate" ref="eric7.Plugins.WizardPlugins.EricPluginWizard.Templates.html#activate" />
--- a/src/eric7/Documentation/Source/eric7.EricWidgets.EricApplication.html Sun Nov 03 12:34:02 2024 +0100 +++ b/src/eric7/Documentation/Source/eric7.EricWidgets.EricApplication.html Sun Nov 03 17:50:34 2024 +0100 @@ -60,6 +60,10 @@ <td>Private method to set the palette from a style sheet.</td> </tr> <tr> +<td><a href="#EricApplication.getMainWindow">getMainWindow</a></td> +<td>Public method to get a reference to the application main window.</td> +</tr> +<tr> <td><a href="#EricApplication.getObject">getObject</a></td> <td>Public method to get a reference to a registered object.</td> </tr> @@ -88,6 +92,10 @@ <td>Public method to register a plugin object in the object registry.</td> </tr> <tr> +<td><a href="#EricApplication.setMainWindow">setMainWindow</a></td> +<td>Public method to set the reference to the application main window.</td> +</tr> +<tr> <td><a href="#EricApplication.setStyleSheetFile">setStyleSheetFile</a></td> <td>Public method to read a QSS style sheet file and set the application style sheet based on its contents.</td> </tr> @@ -139,6 +147,25 @@ style sheet </dd> </dl> +<a NAME="EricApplication.getMainWindow" ID="EricApplication.getMainWindow"></a> +<h4>EricApplication.getMainWindow</h4> +<b>getMainWindow</b>(<i></i>) +<p> + Public method to get a reference to the application main window. +</p> + +<dl> +<dt>Return:</dt> +<dd> +reference to the application main window +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +QWidget +</dd> +</dl> <a NAME="EricApplication.getObject" ID="EricApplication.getObject"></a> <h4>EricApplication.getObject</h4> <b>getObject</b>(<i>name</i>) @@ -339,6 +366,20 @@ raised when the given name is already in use </dd> </dl> +<a NAME="EricApplication.setMainWindow" ID="EricApplication.setMainWindow"></a> +<h4>EricApplication.setMainWindow</h4> +<b>setMainWindow</b>(<i>mainWindow</i>) +<p> + Public method to set the reference to the application main window. +</p> + +<dl> + +<dt><i>mainWindow</i> (QWidget)</dt> +<dd> +reference to the application main window +</dd> +</dl> <a NAME="EricApplication.setStyleSheetFile" ID="EricApplication.setStyleSheetFile"></a> <h4>EricApplication.setStyleSheetFile</h4> <b>setStyleSheetFile</b>(<i>filename</i>)
--- a/src/eric7/Documentation/Source/eric7.EricWidgets.EricMessageBox.html Sun Nov 03 12:34:02 2024 +0100 +++ b/src/eric7/Documentation/Source/eric7.EricWidgets.EricMessageBox.html Sun Nov 03 17:50:34 2024 +0100 @@ -47,8 +47,6 @@ <tr><td>Yes</td></tr> <tr><td>YesRole</td></tr> <tr><td>YesToAll</td></tr> -<tr><td>about</td></tr> -<tr><td>aboutQt</td></tr> </table> <h3>Classes</h3> @@ -66,6 +64,14 @@ <td>Private module function to show a modal message box.</td> </tr> <tr> +<td><a href="#about">about</a></td> +<td>Function to show a modal dialog with some text about the application.</td> +</tr> +<tr> +<td><a href="#aboutQt">aboutQt</a></td> +<td>Function to show a modal dialog with text about Qt.</td> +</tr> +<tr> <td><a href="#critical">critical</a></td> <td>Function to show a modal critical message box.</td> </tr> @@ -219,6 +225,52 @@ <div align="right"><a href="#top">Up</a></div> <hr /> <hr /> +<a NAME="about" ID="about"></a> +<h2>about</h2> +<b>about</b>(<i>parent, title, text</i>) +<p> + Function to show a modal dialog with some text about the application. +</p> + +<dl> + +<dt><i>parent</i> (QWidget)</dt> +<dd> +parent widget of the message box +</dd> +<dt><i>title</i> (str)</dt> +<dd> +caption of the message box +</dd> +<dt><i>text</i> (str)</dt> +<dd> +text to be shown by the message box +</dd> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /> +<hr /> +<a NAME="aboutQt" ID="aboutQt"></a> +<h2>aboutQt</h2> +<b>aboutQt</b>(<i>parent, title=""</i>) +<p> + Function to show a modal dialog with text about Qt. +</p> + +<dl> + +<dt><i>parent</i> (QWidget)</dt> +<dd> +parent widget of the message box +</dd> +<dt><i>title</i> (str (optional))</dt> +<dd> +caption of the message box (defaults to "") +</dd> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /> +<hr /> <a NAME="critical" ID="critical"></a> <h2>critical</h2> <b>critical</b>(<i>parent, title, text, buttons=QMessageBox.StandardButton.Ok, defaultButton=QMessageBox.StandardButton.NoButton, </i>)
--- a/src/eric7/EricWidgets/EricApplication.py Sun Nov 03 12:34:02 2024 +0100 +++ b/src/eric7/EricWidgets/EricApplication.py Sun Nov 03 17:50:34 2024 +0100 @@ -73,6 +73,8 @@ self.__hasNonStandardPalette = False + self.__mainWindow = None + def usesSmallScreen(self): """ Public method to determine, if the application is used on a small @@ -291,5 +293,23 @@ > palette.color(QPalette.ColorRole.Window).lightness() ) + def setMainWindow(self, mainWindow): + """ + Public method to set the reference to the application main window. + + @param mainWindow reference to the application main window + @type QWidget + """ + self.__mainWindow = mainWindow + + def getMainWindow(self): + """ + Public method to get a reference to the application main window. + + @return reference to the application main window + @rtype QWidget + """ + return self.__mainWindow + ericApp = QCoreApplication.instance
--- a/src/eric7/EricWidgets/EricMessageBox.py Sun Nov 03 12:34:02 2024 +0100 +++ b/src/eric7/EricWidgets/EricMessageBox.py Sun Nov 03 17:50:34 2024 +0100 @@ -7,7 +7,7 @@ Module implementing QMessageBox replacements and more convenience function. """ -from PyQt6.QtCore import Qt +from PyQt6.QtCore import QCoreApplication, Qt from PyQt6.QtWidgets import QApplication, QMessageBox ############################################################################### @@ -142,6 +142,9 @@ @return button pressed by the user @rtype QMessageBox.StandardButton """ + if parent is None: + parent = QCoreApplication.instance().getMainWindow() + messageBox = QMessageBox(parent) messageBox.setIcon(icon) if parent is not None: @@ -164,9 +167,36 @@ return messageBox.standardButton(clickedButton) -# the about functions are here for consistency -about = QMessageBox.about -aboutQt = QMessageBox.aboutQt +def about(parent, title, text): + """ + Function to show a modal dialog with some text about the application. + + @param parent parent widget of the message box + @type QWidget + @param title caption of the message box + @type str + @param text text to be shown by the message box + @type str + """ + if parent is None: + parent = QCoreApplication.instance().getMainWindow() + + QMessageBox.about(parent, title, text) + + +def aboutQt(parent, title=""): + """ + Function to show a modal dialog with text about Qt. + + @param parent parent widget of the message box + @type QWidget + @param title caption of the message box (defaults to "") + @type str (optional) + """ + if parent is None: + parent = QCoreApplication.instance().getMainWindow() + + QMessageBox.aboutQt(parent, title) def critical(
--- a/src/eric7/MicroPython/Devices/EspDevices.py Sun Nov 03 12:34:02 2024 +0100 +++ b/src/eric7/MicroPython/Devices/EspDevices.py Sun Nov 03 17:50:34 2024 +0100 @@ -391,7 +391,7 @@ url = QUrl(FirmwareGithubUrls["circuitpython"]) else: EricMessageBox.critical( - None, + self.microPython, self.tr("Show MicroPython Versions"), self.tr( """The firmware of the connected device cannot be""" @@ -444,7 +444,7 @@ msg += self.tr("<p><b>Update available!</b></p>") EricMessageBox.information( - None, + self.microPython, self.tr("{0} Version").format(kind), msg, )
--- a/src/eric7/MicroPython/Devices/GenericMicroPythonDevices.py Sun Nov 03 12:34:02 2024 +0100 +++ b/src/eric7/MicroPython/Devices/GenericMicroPythonDevices.py Sun Nov 03 17:50:34 2024 +0100 @@ -264,7 +264,7 @@ if self.microPython.isConnected(): if self._deviceData["mpy_name"] != "micropython": EricMessageBox.critical( - None, + self.microPython, self.tr("Show MicroPython Versions"), self.tr( """The firmware of the connected device cannot be""" @@ -326,7 +326,7 @@ msg += self.tr("<p><b>Update available!</b></p>") EricMessageBox.information( - None, + self.microPython, self.tr("MicroPython Version"), msg, )
--- a/src/eric7/MicroPython/Devices/MicrobitDevices.py Sun Nov 03 12:34:02 2024 +0100 +++ b/src/eric7/MicroPython/Devices/MicrobitDevices.py Sun Nov 03 17:50:34 2024 +0100 @@ -373,7 +373,7 @@ shutil.copy2(firmware, deviceDirectories[0]) else: EricMessageBox.warning( - self, + self.microPython, self.tr("Flash MicroPython/Firmware"), self.tr( "There are multiple devices ready for flashing." @@ -390,7 +390,7 @@ if self.microPython.isConnected() and self.checkDeviceData(quiet=False): if self._deviceData["mpy_name"] not in ("micropython", "circuitpython"): EricMessageBox.critical( - None, + self.microPython, self.tr("Show MicroPython Versions"), self.tr( """The firmware of the connected device cannot be""" @@ -419,7 +419,7 @@ url = QUrl(FirmwareGithubUrls["circuitpython"]) else: EricMessageBox.critical( - None, + self.microPython, self.tr("Show MicroPython Versions"), self.tr( """<p>The firmware URL for the device type <b>{0}</b>""" @@ -480,7 +480,7 @@ msg += self.tr("<p><b>Update available!</b></p>") EricMessageBox.information( - None, + self.microPython, self.tr("{0} Version").format(kind), msg, )
--- a/src/eric7/MicroPython/Devices/PyBoardDevices.py Sun Nov 03 12:34:02 2024 +0100 +++ b/src/eric7/MicroPython/Devices/PyBoardDevices.py Sun Nov 03 17:50:34 2024 +0100 @@ -451,7 +451,7 @@ if self.microPython.isConnected(): if self._deviceData["mpy_name"] != "micropython": EricMessageBox.critical( - None, + self.microPython, self.tr("Show MicroPython Versions"), self.tr( """The firmware of the connected device cannot be""" @@ -498,7 +498,7 @@ msg += self.tr("<p><b>Update available!</b></p>") EricMessageBox.information( - None, + self.microPython, self.tr("MicroPython Version"), msg, )
--- a/src/eric7/MicroPython/Devices/RP2Devices.py Sun Nov 03 12:34:02 2024 +0100 +++ b/src/eric7/MicroPython/Devices/RP2Devices.py Sun Nov 03 17:50:34 2024 +0100 @@ -258,7 +258,7 @@ if self.microPython.isConnected(): if self._deviceData["mpy_name"] != "micropython": EricMessageBox.critical( - None, + self.microPython, self.tr("Show MicroPython Versions"), self.tr( """The firmware of the connected device cannot be""" @@ -330,7 +330,7 @@ msg += self.tr("<p><b>Update available!</b></p>") EricMessageBox.information( - None, + self.microPython, self.tr("MicroPython Version"), msg, )
--- a/src/eric7/MicroPython/Devices/STLinkDevices.py Sun Nov 03 12:34:02 2024 +0100 +++ b/src/eric7/MicroPython/Devices/STLinkDevices.py Sun Nov 03 17:50:34 2024 +0100 @@ -419,7 +419,7 @@ if self.microPython.isConnected(): if self._deviceData["mpy_name"] != "micropython": EricMessageBox.critical( - None, + self.microPython, self.tr("Show MicroPython Versions"), self.tr( """The firmware of the connected device cannot be""" @@ -466,7 +466,7 @@ msg += self.tr("<p><b>Update available!</b></p>") EricMessageBox.information( - None, + self.microPython, self.tr("MicroPython Version"), msg, )
--- a/src/eric7/MicroPython/Devices/TeensyDevices.py Sun Nov 03 12:34:02 2024 +0100 +++ b/src/eric7/MicroPython/Devices/TeensyDevices.py Sun Nov 03 17:50:34 2024 +0100 @@ -186,7 +186,7 @@ if self.microPython.isConnected(): if self._deviceData["mpy_name"] != "micropython": EricMessageBox.critical( - None, + self.microPython, self.tr("Show MicroPython Versions"), self.tr( """The firmware of the connected device cannot be""" @@ -233,7 +233,7 @@ msg += self.tr("<p><b>Update available!</b></p>") EricMessageBox.information( - None, + self.microPython, self.tr("MicroPython Version"), msg, )
--- a/src/eric7/Toolbox/Startup.py Sun Nov 03 12:34:02 2024 +0100 +++ b/src/eric7/Toolbox/Startup.py Sun Nov 03 17:50:34 2024 +0100 @@ -235,6 +235,8 @@ w = mwFactory(args) if w is None: return 100 + else: + app.setMainWindow(mainWindow=w) if quitOnLastWindowClosed: app.lastWindowClosed.connect(app.quit)