fully worked around bug in Qt

This commit is contained in:
Brennen Raimer
2019-05-25 12:27:18 -04:00
parent fdf8e7d0a2
commit d8bd206856
2 changed files with 14 additions and 4 deletions

View File

@@ -41,6 +41,7 @@ class InstallerWizard(QtWidgets.QWizard):
self.install_location.inputRejected.connect(self.install_location.clear)
except AttributeError:
pass #inputRejected signal added in Qt 5.12, I have 5.9
self.button(self.BackButton).clicked.connect(lambda x: self._location_validator.reset_state())
self.install_location.setValidator(self._location_validator)
self.location_page.registerField("Location*", self.install_location)
self.browse_button.clicked.connect(self._select_location)

View File

@@ -13,10 +13,6 @@ class Location_Validator(QtGui.QValidator):
_previous_location = None
def __init__(self, parent):
super().__init__(parent)
"""for some reason on my Linux system, selecting a directory validates the same location repatedly,
once for each subdir of the location. The only way to keep it from repeatedly validating and potentially
opening a warning window for each subdirectory in the location path was to track this and return the same
value that was returned the last time it was validated."""
@property
def ntfs_location_selected(self):
@@ -49,6 +45,9 @@ class Location_Validator(QtGui.QValidator):
input_ {str} -- The text entered in the installation location QLineEdit widget
pos {int} -- The current location of the cursor in the QLineEdit widget
"""
#there is a very obnoxious, nearly 10 year old bug in QLineEdit that causes validate to be called gratitously and rapidly especially on
#non-Windows platforms where it gets called every time the window focus changes. The bug has been in Qt since at least Qt4 and it doesn't
#look like anyone cares to fix it, so I did my best to supress gratitious input checking and modal dialog opening
if not input_.strip():
_previous_location = input_
return (QtGui.QValidator.Intermediate, input_, pos)
@@ -89,3 +88,13 @@ class Location_Validator(QtGui.QValidator):
self._previous_location = self._location
return (self._disposition, self._location, self._pos,)
@QtCore.pyqtSlot()
def reset_state(self):
"""Resets the internal state of the Location_Validator, including the previously validated location
"""
self._disposition = QtGui.QValidator.Intermediate
self._pos = 0
self._location = ""
self._ntfs_location_selected = False
self._previous_location = None