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

View File

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