Modified some of the EricWidgets dialogs to ensure a valid parent widget. eric7

Sun, 03 Nov 2024 18:12:28 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 03 Nov 2024 18:12:28 +0100
branch
eric7
changeset 11035
e1e1d6e317c7
parent 11034
7b8a21fd2d58
child 11036
326ae637285d

Modified some of the EricWidgets dialogs to ensure a valid parent widget.

src/eric7/EricWidgets/EricApplication.py file | annotate | diff | comparison | revisions
src/eric7/EricWidgets/EricAuthenticationDialog.py file | annotate | diff | comparison | revisions
src/eric7/EricWidgets/EricComboSelectionDialog.py file | annotate | diff | comparison | revisions
src/eric7/EricWidgets/EricDirFileDialog.py file | annotate | diff | comparison | revisions
src/eric7/EricWidgets/EricErrorMessage.py file | annotate | diff | comparison | revisions
src/eric7/EricWidgets/EricFileDialog.py file | annotate | diff | comparison | revisions
src/eric7/EricWidgets/EricFileSaveConfirmDialog.py file | annotate | diff | comparison | revisions
src/eric7/EricWidgets/EricPathPickerDialog.py file | annotate | diff | comparison | revisions
src/eric7/EricWidgets/EricProgressDialog.py file | annotate | diff | comparison | revisions
src/eric7/EricWidgets/EricTextInputDialog.py file | annotate | diff | comparison | revisions
--- a/src/eric7/EricWidgets/EricApplication.py	Sun Nov 03 17:50:34 2024 +0100
+++ b/src/eric7/EricWidgets/EricApplication.py	Sun Nov 03 18:12:28 2024 +0100
@@ -305,7 +305,7 @@
     def getMainWindow(self):
         """
         Public method to get a reference to the application main window.
-        
+
         @return reference to the application main window
         @rtype QWidget
         """
--- a/src/eric7/EricWidgets/EricAuthenticationDialog.py	Sun Nov 03 17:50:34 2024 +0100
+++ b/src/eric7/EricWidgets/EricAuthenticationDialog.py	Sun Nov 03 18:12:28 2024 +0100
@@ -7,6 +7,7 @@
 Module implementing the authentication dialog for the help browser.
 """
 
+from PyQt6.QtCore import QCoreApplication
 from PyQt6.QtWidgets import QDialog, QStyle
 
 from .Ui_EricAuthenticationDialog import Ui_EricAuthenticationDialog
@@ -32,6 +33,9 @@
         @param parent reference to the parent widget
         @type QWidget
         """
+        if parent is None:
+            parent = QCoreApplication.instance().getMainWindow()
+
         super().__init__(parent)
         self.setupUi(self)
 
--- a/src/eric7/EricWidgets/EricComboSelectionDialog.py	Sun Nov 03 17:50:34 2024 +0100
+++ b/src/eric7/EricWidgets/EricComboSelectionDialog.py	Sun Nov 03 18:12:28 2024 +0100
@@ -7,7 +7,7 @@
 Module implementing a dialog to select one entry from a list of strings.
 """
 
-from PyQt6.QtCore import pyqtSlot
+from PyQt6.QtCore import QCoreApplication, pyqtSlot
 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
 
 from .Ui_EricComboSelectionDialog import Ui_EricComboSelectionDialog
@@ -31,6 +31,9 @@
         @param parent reference to the parent widget (defaults to None)
         @type QWidget (optional)
         """
+        if parent is None:
+            parent = QCoreApplication.instance().getMainWindow()
+
         super().__init__(parent)
         self.setupUi(self)
 
--- a/src/eric7/EricWidgets/EricDirFileDialog.py	Sun Nov 03 17:50:34 2024 +0100
+++ b/src/eric7/EricWidgets/EricDirFileDialog.py	Sun Nov 03 18:12:28 2024 +0100
@@ -9,7 +9,7 @@
 
 import pathlib
 
-from PyQt6.QtCore import QItemSelection, pyqtSlot
+from PyQt6.QtCore import QCoreApplication, QItemSelection, pyqtSlot
 from PyQt6.QtGui import QFileSystemModel
 from PyQt6.QtWidgets import QFileDialog, QLineEdit, QPushButton, QTreeView
 
@@ -35,6 +35,8 @@
         @type str
         """
         self.__selectedFilesFolders = []
+        if parent is None:
+            parent = QCoreApplication.instance().getMainWindow()
 
         super().__init__(parent, caption, directory, filterStr)
         self.setFileMode(QFileDialog.FileMode.ExistingFiles)
--- a/src/eric7/EricWidgets/EricErrorMessage.py	Sun Nov 03 17:50:34 2024 +0100
+++ b/src/eric7/EricWidgets/EricErrorMessage.py	Sun Nov 03 18:12:28 2024 +0100
@@ -81,6 +81,9 @@
         @param parent reference to the parent widget
         @type QWidget
         """
+        if parent is None:
+            parent = QCoreApplication.instance().getMainWindow()
+
         super().__init__(parent)
 
     def showMessage(self, message, msgType=""):
--- a/src/eric7/EricWidgets/EricFileDialog.py	Sun Nov 03 17:50:34 2024 +0100
+++ b/src/eric7/EricWidgets/EricFileDialog.py	Sun Nov 03 18:12:28 2024 +0100
@@ -9,6 +9,7 @@
 
 import pathlib
 
+from PyQt6.QtCore import QCoreApplication
 from PyQt6.QtWidgets import QFileDialog
 
 from eric7.SystemUtilities import OSUtilities
@@ -72,6 +73,9 @@
     @return name of file to be opened
     @rtype str
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     return getOpenFileNameAndFilter(
         parent, caption, directory, filterStr, initialFilter, options
     )[0]
@@ -99,6 +103,9 @@
     @return name of file to be opened and selected filter
     @rtype tuple of (str, str)
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     if options is None:
         options = QFileDialog.Option(0)
     newfilter = __reorderFilter(filterStr, initialFilter)
@@ -128,6 +135,9 @@
     @return list of file names to be opened
     @rtype list of str
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     return getOpenFileNamesAndFilter(
         parent, caption, directory, filterStr, initialFilter, options
     )[0]
@@ -155,6 +165,9 @@
     @return list of file names to be opened and selected filter
     @rtype tuple of (list of str, str)
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     if options is None:
         options = QFileDialog.Option(0)
     newfilter = __reorderFilter(filterStr, initialFilter)
@@ -184,6 +197,9 @@
     """
     from .EricDirFileDialog import EricDirFileDialog
 
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     return EricDirFileDialog.getOpenFileAndDirNames(
         parent, caption, directory, filterStr, options
     )
@@ -210,6 +226,9 @@
     @return name of file to be saved
     @rtype str
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     return getSaveFileNameAndFilter(
         parent, caption, directory, filterStr, initialFilter, options
     )[0]
@@ -237,6 +256,9 @@
     @return name of file to be saved and selected filte
     @rtype tuple of (str, str)
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     if options is None:
         options = QFileDialog.Option(0)
     newfilter = __reorderFilter(filterStr, initialFilter)
@@ -263,6 +285,9 @@
     @return name of selected directory
     @rtype str
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     if options is None:
         options = QFileDialog.Option(0)
     return QFileDialog.getExistingDirectory(parent, caption, directory, options)
@@ -294,6 +319,9 @@
     @return path of file to be opened
     @rtype pathlib.Path
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     return getOpenFilePathAndFilter(
         parent, caption, directory, filterStr, initialFilter, options
     )[0]
@@ -321,6 +349,9 @@
     @return path of file to be opened and selected filter
     @rtype tuple of (pathlib.Path, str)
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     if options is None:
         options = QFileDialog.Option(0)
     newfilter = __reorderFilter(filterStr, initialFilter)
@@ -351,6 +382,9 @@
     @return list of file paths to be opened
     @rtype list of pathlib.Path
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     return getOpenFilPathsAndFilter(
         parent, caption, directory, filterStr, initialFilter, options
     )[0]
@@ -378,6 +412,9 @@
     @return list of file paths to be opened and selected filter
     @rtype tuple of (list of pathlib.Path, str)
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     if options is None:
         options = QFileDialog.Option(0)
     newfilter = __reorderFilter(filterStr, initialFilter)
@@ -408,6 +445,9 @@
     """
     from .EricDirFileDialog import EricDirFileDialog
 
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     return EricDirFileDialog.getOpenFileAndDirPaths(
         parent, caption, directory, filterStr, options
     )
@@ -434,6 +474,9 @@
     @return path of file to be saved
     @rtype pathlib.Path
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     return getSaveFilePathAndFilter(
         parent, caption, str(directory), filterStr, initialFilter, options
     )[0]
@@ -461,6 +504,9 @@
     @return path of file to be saved and selected filte
     @rtype tuple of (pathlib.Path, str)
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     if options is None:
         options = QFileDialog.Option(0)
     newfilter = __reorderFilter(filterStr, initialFilter)
@@ -488,6 +534,9 @@
     @return path of selected directory
     @rtype pathlib.Path
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     if options is None:
         options = QFileDialog.Option(0)
     dirname = QFileDialog.getExistingDirectory(parent, caption, str(directory), options)
--- a/src/eric7/EricWidgets/EricFileSaveConfirmDialog.py	Sun Nov 03 17:50:34 2024 +0100
+++ b/src/eric7/EricWidgets/EricFileSaveConfirmDialog.py	Sun Nov 03 18:12:28 2024 +0100
@@ -9,6 +9,7 @@
 
 import os
 
+from PyQt6.QtCore import QCoreApplication
 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QLabel, QLineEdit, QVBoxLayout
 
 from .EricPathPicker import EricPathPicker, EricPathPickerModes
@@ -144,6 +145,9 @@
         overwrite) and the filename (in case of 'rename' or 'overwrite')
     @rtype tuple of (str, str)
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     dlg = EricFileSaveConfirmDialog(
         filename, title, message=message, picker=picker, parent=parent
     )
--- a/src/eric7/EricWidgets/EricPathPickerDialog.py	Sun Nov 03 17:50:34 2024 +0100
+++ b/src/eric7/EricWidgets/EricPathPickerDialog.py	Sun Nov 03 18:12:28 2024 +0100
@@ -7,6 +7,7 @@
 Module implementing a dialog to enter a file system path using a file picker.
 """
 
+from PyQt6.QtCore import QCoreApplication
 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QLabel, QVBoxLayout
 
 from .EricPathPicker import EricPathPicker, EricPathPickerModes
@@ -169,6 +170,9 @@
         user pressed the OK button
     @rtype tuple of (str, bool)
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     # step 1: setup of the dialog
     dlg = EricPathPickerDialog(parent)
     if title:
@@ -227,6 +231,9 @@
         user pressed the OK button
     @rtype tuple of (pathlib.Path, bool)
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     # step 1: setup of the dialog
     dlg = EricPathPickerDialog(parent)
     if title:
--- a/src/eric7/EricWidgets/EricProgressDialog.py	Sun Nov 03 17:50:34 2024 +0100
+++ b/src/eric7/EricWidgets/EricProgressDialog.py	Sun Nov 03 18:12:28 2024 +0100
@@ -7,7 +7,7 @@
 Module implementing a progress dialog allowing a customized progress bar label.
 """
 
-from PyQt6.QtCore import Qt
+from PyQt6.QtCore import QCoreApplication, Qt
 from PyQt6.QtWidgets import QProgressBar, QProgressDialog
 
 
@@ -45,6 +45,9 @@
         @param flags window flags of the dialog
         @type Qt.WindowFlags
         """
+        if parent is None:
+            parent = QCoreApplication.instance().getMainWindow()
+
         if flags is None:
             flags = Qt.WindowType(0)
         super().__init__(labelText, cancelButtonText, minimum, maximum, parent, flags)
--- a/src/eric7/EricWidgets/EricTextInputDialog.py	Sun Nov 03 17:50:34 2024 +0100
+++ b/src/eric7/EricWidgets/EricTextInputDialog.py	Sun Nov 03 18:12:28 2024 +0100
@@ -7,6 +7,7 @@
 Module implementing a dialog to enter some text.
 """
 
+from PyQt6.QtCore import QCoreApplication
 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QLabel, QLineEdit, QVBoxLayout
 
 
@@ -128,6 +129,9 @@
         entered text
     @rtype tuple of (bool, str)
     """
+    if parent is None:
+        parent = QCoreApplication.instance().getMainWindow()
+
     dlg = EricTextInputDialog(parent)
     dlg.setWindowTitle(title)
     dlg.setLabelText(label)

eric ide

mercurial