Skip to content

Commit

Permalink
Modernize the use of QRegExp to use QRegularExpression
Browse files Browse the repository at this point in the history
Apparently this was available since 5.0

TODO: read this to see if there is any incompatibility:
https://doc.qt.io/qt-6/qregexp.html
  • Loading branch information
hmaarrfk committed Jul 16, 2024
1 parent c72b4e5 commit 322b611
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
10 changes: 6 additions & 4 deletions spyder/plugins/editor/widgets/codeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
from packaging.version import parse
from qtpy import QT_VERSION
from qtpy.compat import to_qvariant
from qtpy.QtCore import (QEvent, QEventLoop, QRegExp, Qt, QTimer, QThread,
QUrl, Signal, Slot)
from qtpy.QtCore import (QEvent, QEventLoop, QRegularExpression, Qt, QTimer,
QThread, QUrl, Signal, Slot)
from qtpy.QtGui import (QColor, QCursor, QFont, QKeySequence, QPaintEvent,
QPainter, QMouseEvent, QTextCursor, QDesktopServices,
QKeyEvent, QTextDocument, QTextFormat, QTextOption,
Expand Down Expand Up @@ -2590,15 +2590,17 @@ def __find_first(self, text):
cursor = self.textCursor()
# Scanning whole document
cursor.movePosition(QTextCursor.Start)
regexp = QRegExp(r"\b%s\b" % QRegExp.escape(text), Qt.CaseSensitive)
regexp = QRegularExpression(
r"\b%s\b" % QRegularExpression.escape(text), Qt.CaseSensitive)
cursor = self.document().find(regexp, cursor, flags)
self.__find_first_pos = cursor.position()
return cursor

def __find_next(self, text, cursor):
"""Find next occurrence"""
flags = QTextDocument.FindCaseSensitively|QTextDocument.FindWholeWords
regexp = QRegExp(r"\b%s\b" % QRegExp.escape(text), Qt.CaseSensitive)
regexp = QRegularExpression(
r"\b%s\b" % QRegularExpression.escape(text), Qt.CaseSensitive)
cursor = self.document().find(regexp, cursor, flags)
if cursor.position() != self.__find_first_pos:
return cursor
Expand Down
6 changes: 3 additions & 3 deletions spyder/plugins/explorer/widgets/fileassociations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

# Third party imports
from qtpy.compat import getopenfilename
from qtpy.QtCore import QRegExp, QSize, Qt, Signal, Slot
from qtpy.QtGui import QCursor, QRegExpValidator
from qtpy.QtCore import QRegularExpression, QSize, Qt, Signal, Slot
from qtpy.QtGui import QCursor, QRegularExpressionValidator
from qtpy.QtWidgets import (QApplication, QDialog, QDialogButtonBox,
QHBoxLayout, QLabel, QLineEdit,
QListWidget, QListWidgetItem, QPushButton,
Expand Down Expand Up @@ -83,7 +83,7 @@ def set_regex_validation(self, regex):
"""Set the regular expression to validate content."""
self._regex = regex
self._reg = re.compile(regex, re.IGNORECASE)
validator = QRegExpValidator(QRegExp(regex))
validator = QRegularExpressionValidator(QRegularExpression(regex))
self.lineedit.setValidator(validator)

def text(self):
Expand Down
7 changes: 4 additions & 3 deletions spyder/plugins/preferences/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from qtpy import API
from qtpy.compat import (getexistingdirectory, getopenfilename, from_qvariant,
to_qvariant)
from qtpy.QtCore import Qt, Signal, Slot, QRegExp
from qtpy.QtGui import QColor, QRegExpValidator, QTextOption
from qtpy.QtCore import Qt, Signal, Slot, QRegularExpression
from qtpy.QtGui import QColor, QRegularExpressionValidator, QTextOption
from qtpy.QtWidgets import (QButtonGroup, QCheckBox, QComboBox, QDoubleSpinBox,
QFileDialog, QFontComboBox, QGridLayout, QGroupBox,
QHBoxLayout, QLabel, QLineEdit, QMessageBox,
Expand Down Expand Up @@ -494,7 +494,8 @@ def create_lineedit(self, text, option, default=NoDefault,
if tip:
edit.setToolTip(tip)
if regex:
edit.setValidator(QRegExpValidator(QRegExp(regex)))
edit.setValidator(
QRegularExpressionValidator(QRegularExpression(regex)))
if placeholder:
edit.setPlaceholderText(placeholder)
self.lineedits[edit] = (section, option, default)
Expand Down
9 changes: 5 additions & 4 deletions spyder/widgets/helperwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
# Third party imports
import qstylizer.style
from qtpy import PYQT5
from qtpy.QtCore import QPoint, QRegExp, QSize, QSortFilterProxyModel, Qt
from qtpy.QtCore import (QPoint, QRegularExpression, QSize,
QSortFilterProxyModel, Qt)
from qtpy.QtGui import (QAbstractTextDocumentLayout, QColor, QFontMetrics,
QPainter, QRegExpValidator, QTextDocument, )
QPainter, QRegularExpressionValidator, QTextDocument)
from qtpy.QtWidgets import (QApplication, QCheckBox, QLineEdit, QMessageBox,
QSpacerItem, QStyle, QStyledItemDelegate,
QStyleOptionFrame, QStyleOptionViewItem,
Expand Down Expand Up @@ -345,8 +346,8 @@ def __init__(self, parent, callback=None, main=None,
self.main = main

# Widget setup
regex = QRegExp(regex_base + "{100}")
self.setValidator(QRegExpValidator(regex))
regex = QRegularExpression(regex_base + "{100}")
self.setValidator(QRegularExpressionValidator(regex))

# Signals
if callback:
Expand Down

0 comments on commit 322b611

Please sign in to comment.