Implement ticket #5172: Use test button in Regex Builder instead of updating as the user types.

This commit is contained in:
John Schember 2010-03-27 21:36:00 -04:00
parent a36729be1c
commit d62e9ed908
2 changed files with 29 additions and 10 deletions

View File

@ -25,7 +25,7 @@ class RegexHighlighter(QSyntaxHighlighter):
self.regex = u''
def update_regex(self, regex):
self.regex = qstring_to_unicode(regex)
self.regex = regex
self.rehighlight()
def highlightBlock(self, text):
@ -59,14 +59,22 @@ class RegexBuilder(QDialog, Ui_RegexBuilder):
self.select_format(db, book_id)
self.connect(self.button_box, SIGNAL('clicked(QAbstractButton*)'), self.button_clicked)
self.connect(self.regex, SIGNAL('textChanged(QString)'), self.highlighter.update_regex)
self.connect(self.highlighter, SIGNAL('regex_valid(PyQt_PyObject)'), self.regex_valid)
self.connect(self.regex, SIGNAL('textChanged(QString)'), self.regex_valid)
self.connect(self.test, SIGNAL('clicked()'), self.do_test)
def regex_valid(self, valid):
if valid:
self.regex.setStyleSheet('QLineEdit { color: black; background-color: white; }')
regex = qstring_to_unicode(self.regex.text())
if regex:
try:
re.compile(regex)
self.regex.setStyleSheet('QLineEdit { color: black; background-color: rgba(0,255,0,20%); }')
except:
self.regex.setStyleSheet('QLineEdit { color: black; background-color: rgb(255,0,0,20%); }')
else:
self.regex.setStyleSheet('QLineEdit { color: black; background-color: rgb(255,0,0,20%); }')
self.regex.setStyleSheet('QLineEdit { color: black; background-color: white; }')
def do_test(self):
self.highlighter.update_regex(qstring_to_unicode(self.regex.text()))
def select_format(self, db, book_id):
format = None

View File

@ -14,7 +14,7 @@
<string>Regex Builder</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<item row="1" column="0" colspan="5">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Preview</string>
@ -36,7 +36,7 @@
</layout>
</widget>
</item>
<item row="2" column="1">
<item row="2" column="4">
<widget class="QDialogButtonBox" name="button_box">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -53,8 +53,19 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="regex"/>
<item row="0" column="1" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="regex"/>
</item>
<item>
<widget class="QPushButton" name="test">
<property name="text">
<string>Test</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>