From cda0a0d18135dca36b3d51c388b2efe4e199aa31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Thu, 19 Oct 2006 19:53:53 +0200 Subject: [PATCH] TaggerScript syntax highlighter. --- picard/ui/options/scripting.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/picard/ui/options/scripting.py b/picard/ui/options/scripting.py index 77bab5918..ec2d247dd 100644 --- a/picard/ui/options/scripting.py +++ b/picard/ui/options/scripting.py @@ -17,11 +17,37 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -from PyQt4 import QtGui +from PyQt4 import QtCore, QtGui from picard.api import IOptionsPage from picard.component import Component, implements from picard.config import BoolOption, TextOption + +class TaggerScriptSyntaxHighlighter(QtGui.QSyntaxHighlighter): + + def __init__(self, document): + QtGui.QSyntaxHighlighter.__init__(self, document) + self.func_re = QtCore.QRegExp(r"\$[a-zA-Z]+\(") + self.func_fmt = QtGui.QTextCharFormat() + self.func_fmt.setFontWeight(QtGui.QFont.Bold) + self.func_fmt.setForeground(QtCore.Qt.blue) + self.var_re = QtCore.QRegExp(r"%[a-zA-Z]*%") + self.var_fmt = QtGui.QTextCharFormat() + self.var_fmt.setForeground(QtCore.Qt.darkCyan) + self.rules = [ + (self.func_re, self.func_fmt, 0, -1), + (self.var_re, self.var_fmt, 0, 0), + ] + + def highlightBlock(self, text): + for expr, fmt, a, b in self.rules: + index = text.indexOf(expr) + while index >= 0: + length = expr.matchedLength() + self.setFormat(index + a, length + b, fmt) + index = text.indexOf(expr, index + length) + + class ScriptingOptionsPage(Component): implements(IOptionsPage) @@ -39,6 +65,8 @@ class ScriptingOptionsPage(Component): self.page = QtGui.QWidget(parent) self.ui = Ui_Form() self.ui.setupUi(self.page) + self.highlighter = TaggerScriptSyntaxHighlighter( + self.ui.tagger_script.document()) self.ui.enable_tagger_script.setChecked( self.config.setting["enable_tagger_script"]) self.ui.tagger_script.document().setPlainText(