Skip to content

Commit 31ad46c

Browse files
committed
[ui] Qt6 Compatibility for ScriptEditor: Updated QRegexp -> QRegularExpression
1 parent c4a9c82 commit 31ad46c

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

meshroom/ui/components/scriptEditor.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import traceback
77

88
# Qt
9-
from PySide6 import QtCore, QtGui, QtQuick
9+
from PySide6 import QtCore, QtGui
1010
from PySide6.QtCore import Property, QObject, Slot, Signal, QSettings
1111

1212

@@ -198,7 +198,7 @@ def __init__(self, parent=None):
198198
# The Document to highlight
199199
self._document = None
200200

201-
# Build a QRegExp for each of the pattern
201+
# Build a QRegularExpression for each of the pattern
202202
self._rules = self.__rules()
203203

204204
# Private
@@ -209,34 +209,34 @@ def __rules(self):
209209
rules = []
210210

211211
# Keyword rules
212-
rules += [(QtCore.QRegExp(r"\b" + w + r"\s"), 0, PySyntaxHighlighter.STYLES["keyword"]) for w in PySyntaxHighlighter.keywords]
212+
rules += [(QtCore.QRegularExpression(r"\b" + w + r"\s"), 0, PySyntaxHighlighter.STYLES["keyword"]) for w in PySyntaxHighlighter.keywords]
213213
# Operator rules
214-
rules += [(QtCore.QRegExp(o), 0, PySyntaxHighlighter.STYLES["operator"]) for o in PySyntaxHighlighter.operators]
214+
rules += [(QtCore.QRegularExpression(o), 0, PySyntaxHighlighter.STYLES["operator"]) for o in PySyntaxHighlighter.operators]
215215
# Braces
216-
rules += [(QtCore.QRegExp(b), 0, PySyntaxHighlighter.STYLES["brace"]) for b in PySyntaxHighlighter.braces]
216+
rules += [(QtCore.QRegularExpression(b), 0, PySyntaxHighlighter.STYLES["brace"]) for b in PySyntaxHighlighter.braces]
217217

218218
# All other rules
219219
rules += [
220220
# self
221-
(QtCore.QRegExp(r'\bself\b'), 0, PySyntaxHighlighter.STYLES["self"]),
221+
(QtCore.QRegularExpression(r'\bself\b'), 0, PySyntaxHighlighter.STYLES["self"]),
222222

223223
# 'def' followed by an identifier
224-
(QtCore.QRegExp(r'\bdef\b\s*(\w+)'), 1, PySyntaxHighlighter.STYLES["deffunc"]),
224+
(QtCore.QRegularExpression(r'\bdef\b\s*(\w+)'), 1, PySyntaxHighlighter.STYLES["deffunc"]),
225225
# 'class' followed by an identifier
226-
(QtCore.QRegExp(r'\bclass\b\s*(\w+)'), 1, PySyntaxHighlighter.STYLES["defclass"]),
226+
(QtCore.QRegularExpression(r'\bclass\b\s*(\w+)'), 1, PySyntaxHighlighter.STYLES["defclass"]),
227227

228228
# Numeric literals
229-
(QtCore.QRegExp(r'\b[+-]?[0-9]+[lL]?\b'), 0, PySyntaxHighlighter.STYLES["numbers"]),
230-
(QtCore.QRegExp(r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b'), 0, PySyntaxHighlighter.STYLES["numbers"]),
231-
(QtCore.QRegExp(r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b'), 0, PySyntaxHighlighter.STYLES["numbers"]),
229+
(QtCore.QRegularExpression(r'\b[+-]?[0-9]+[lL]?\b'), 0, PySyntaxHighlighter.STYLES["numbers"]),
230+
(QtCore.QRegularExpression(r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b'), 0, PySyntaxHighlighter.STYLES["numbers"]),
231+
(QtCore.QRegularExpression(r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b'), 0, PySyntaxHighlighter.STYLES["numbers"]),
232232

233233
# Double-quoted string, possibly containing escape sequences
234-
(QtCore.QRegExp(r'"[^"\\]*(\\.[^"\\]*)*"'), 0, PySyntaxHighlighter.STYLES["string"]),
234+
(QtCore.QRegularExpression(r'"[^"\\]*(\\.[^"\\]*)*"'), 0, PySyntaxHighlighter.STYLES["string"]),
235235
# Single-quoted string, possibly containing escape sequences
236-
(QtCore.QRegExp(r"'[^'\\]*(\\.[^'\\]*)*'"), 0, PySyntaxHighlighter.STYLES["string"]),
236+
(QtCore.QRegularExpression(r"'[^'\\]*(\\.[^'\\]*)*'"), 0, PySyntaxHighlighter.STYLES["string"]),
237237

238238
# From '#' until a newline
239-
(QtCore.QRegExp(r'#[^\n]*'), 0, PySyntaxHighlighter.STYLES['comment']),
239+
(QtCore.QRegularExpression(r'#[^\n]*'), 0, PySyntaxHighlighter.STYLES['comment']),
240240
]
241241

242242
return rules
@@ -250,14 +250,17 @@ def highlightBlock(self, text):
250250
# Do other syntax formatting
251251
for expression, nth, _format in self._rules:
252252
# fetch the index of the expression in text
253-
index = expression.indexIn(text, 0)
253+
match = expression.match(text, 0)
254+
index = match.capturedStart()
254255

255256
while index >= 0:
256257
# We actually want the index of the nth match
257-
index = expression.pos(nth)
258-
length = len(expression.cap(nth))
258+
index = match.capturedStart(nth)
259+
length = len(match.captured(nth))
259260
self.setFormat(index, length, _format)
260-
index = expression.indexIn(text, index + length)
261+
# index = expression.indexIn(text, index + length)
262+
match = expression.match(text, index + length)
263+
index = match.capturedStart()
261264

262265
def textDoc(self):
263266
""" Returns the document being highlighted.
@@ -287,4 +290,4 @@ def setTextDocument(self, document):
287290
textDocumentChanged = Signal()
288291

289292
# Property
290-
textDocument = Property(QtQuick.QQuickTextDocument, textDoc, setTextDocument, notify=textDocumentChanged)
293+
textDocument = Property(QObject, textDoc, setTextDocument, notify=textDocumentChanged)

0 commit comments

Comments
 (0)