Fix PySide2 issue for Ubuntu Focal

Provide a fallback for QRegularExpressionValidator specifically for
Ubuntu Focal, because it's not present in PySide2 5.14. Instead,
fallback to QRegExpValidator if it doesn't exist.

Fixes #339
This commit is contained in:
Alex Pyrgiotis 2023-02-16 23:49:30 +02:00
parent b94d0712c8
commit 79ccd14d5d
No known key found for this signature in database
GPG key ID: B6C15EBA0357C9AA

View file

@ -399,10 +399,15 @@ class SettingsWidget(QtWidgets.QWidget):
self.safe_extension_name_layout.addWidget(self.safe_extension_filename) self.safe_extension_name_layout.addWidget(self.safe_extension_filename)
self.safe_extension_name_layout.addWidget(self.safe_extension) self.safe_extension_name_layout.addWidget(self.safe_extension)
dot_pdf_regex = QtCore.QRegularExpression(r".*\.[Pp][Dd][Ff]") # FIXME: Workaround for https://github.com/freedomofpress/dangerzone/issues/339.
self.safe_extension.setValidator( # We should drop this once we drop Ubuntu Focal support.
QtGui.QRegularExpressionValidator(dot_pdf_regex) if hasattr(QtGui, "QRegularExpressionValidator"):
) dot_pdf_regex = QtCore.QRegularExpression(r".*\.[Pp][Dd][Ff]")
validator = QtGui.QRegularExpressionValidator(dot_pdf_regex)
else:
dot_pdf_regex = QtCore.QRegExp(r".*\.[Pp][Dd][Ff]") # type: ignore [assignment]
validator = QtGui.QRegExpValidator(dot_pdf_regex) # type: ignore [call-overload]
self.safe_extension.setValidator(validator)
self.safe_extension_layout = QtWidgets.QHBoxLayout() self.safe_extension_layout = QtWidgets.QHBoxLayout()
self.safe_extension_layout.addWidget(self.save_checkbox) self.safe_extension_layout.addWidget(self.save_checkbox)
self.safe_extension_layout.addWidget(self.safe_extension_label) self.safe_extension_layout.addWidget(self.safe_extension_label)