diff --git a/src/calibre/gui2/convert/bulk.py b/src/calibre/gui2/convert/bulk.py index b97ab1a2dc..591ac92b2b 100644 --- a/src/calibre/gui2/convert/bulk.py +++ b/src/calibre/gui2/convert/bulk.py @@ -94,7 +94,7 @@ class BulkConfig(Config): if not c: break self.stack.removeWidget(c) - widgets = [lf, hw, sr, ps, sd, toc] + widgets = [lf, hw, ps, sd, toc, sr] if output_widget is not None: widgets.append(output_widget) for w in widgets: diff --git a/src/calibre/gui2/convert/search_and_replace.py b/src/calibre/gui2/convert/search_and_replace.py index c85e4fe414..88f7a2d4a0 100644 --- a/src/calibre/gui2/convert/search_and_replace.py +++ b/src/calibre/gui2/convert/search_and_replace.py @@ -15,6 +15,7 @@ class SearchAndReplaceWidget(Widget, Ui_Form): TITLE = _('Search &\nReplace') HELP = _('Modify the document text and structure using user defined patterns.') COMMIT_NAME = 'search_and_replace' + ICON = I('search.png') def __init__(self, parent, get_option, get_help, db=None, book_id=None): Widget.__init__(self, parent, @@ -24,19 +25,19 @@ class SearchAndReplaceWidget(Widget, Ui_Form): ) self.db, self.book_id = db, book_id self.initialize_options(get_option, get_help, db, book_id) - self.opt_sr1_search.set_msg(_('Search Regular Expression')) + self.opt_sr1_search.set_msg(_('&Search Regular Expression')) self.opt_sr1_search.set_book_id(book_id) self.opt_sr1_search.set_db(db) - self.opt_sr2_search.set_msg(_('Search Regular Expression')) + self.opt_sr2_search.set_msg(_('&Search Regular Expression')) self.opt_sr2_search.set_book_id(book_id) self.opt_sr2_search.set_db(db) - self.opt_sr3_search.set_msg(_('Search Regular Expression')) + self.opt_sr3_search.set_msg(_('&Search Regular Expression')) self.opt_sr3_search.set_book_id(book_id) self.opt_sr3_search.set_db(db) - + def break_cycles(self): Widget.break_cycles(self) - + self.opt_sr1_search.break_cycles() self.opt_sr2_search.break_cycles() self.opt_sr3_search.break_cycles() @@ -45,10 +46,11 @@ class SearchAndReplaceWidget(Widget, Ui_Form): for x in ('sr1_search', 'sr2_search', 'sr3_search'): x = getattr(self, 'opt_'+x) try: - pat = unicode(x.regex) - re.compile(pat) + pat = unicode(x.regex).strip() + if pat: + re.compile(pat) except Exception, err: error_dialog(self, _('Invalid regular expression'), - _('Invalid regular expression: %s')%err).exec_() + _('Invalid regular expression: %s')%err, show=True) return False return True diff --git a/src/calibre/gui2/convert/search_and_replace.ui b/src/calibre/gui2/convert/search_and_replace.ui index e0e9570f8c..b7447f8feb 100644 --- a/src/calibre/gui2/convert/search_and_replace.ui +++ b/src/calibre/gui2/convert/search_and_replace.ui @@ -6,8 +6,8 @@ 0 0 - 198 - 350 + 468 + 451 @@ -23,7 +23,7 @@ QLayout::SetDefaultConstraint - + @@ -32,7 +32,7 @@ - 1. + First expression @@ -57,7 +57,10 @@ - Replacement Text + &Replacement Text + + + opt_sr1_replace @@ -74,7 +77,7 @@ - + @@ -83,7 +86,7 @@ - 2. + Second Expression @@ -108,7 +111,10 @@ - Replacement Text + &Replacement Text + + + opt_sr2_replace @@ -125,7 +131,7 @@ - + @@ -134,7 +140,7 @@ - 3. + Third expression @@ -159,7 +165,10 @@ - Replacement Text + &Replacement Text + + + opt_sr3_replace @@ -176,6 +185,19 @@ + + + + <p>Search and replace uses <i>regular expressions</i>. See the <a href="http://calibre-ebook.com/user_manual/regexp.html">regular expressions tutorial</a> to get started with regular expressions. Also clicking the wizard buttons below will allow you to test your regular expression against the current input document. + + + true + + + true + + + diff --git a/src/calibre/gui2/convert/single.py b/src/calibre/gui2/convert/single.py index 8826d398f5..da58de545b 100644 --- a/src/calibre/gui2/convert/single.py +++ b/src/calibre/gui2/convert/single.py @@ -207,7 +207,7 @@ class Config(ResizableDialog, Ui_Dialog): if not c: break self.stack.removeWidget(c) - widgets = [self.mw, lf, hw, sr, ps, sd, toc] + widgets = [self.mw, lf, hw, ps, sd, toc, sr] if input_widget is not None: widgets.append(input_widget) if output_widget is not None: diff --git a/src/calibre/gui2/preferences/conversion.py b/src/calibre/gui2/preferences/conversion.py index 0a8fc375ea..8de9ee1661 100644 --- a/src/calibre/gui2/preferences/conversion.py +++ b/src/calibre/gui2/preferences/conversion.py @@ -85,8 +85,8 @@ class CommonOptions(Base): def load_conversion_widgets(self): self.conversion_widgets = [LookAndFeelWidget, HeuristicsWidget, - SearchAndReplaceWidget, PageSetupWidget, - StructureDetectionWidget, TOCWidget] + PageSetupWidget, + StructureDetectionWidget, TOCWidget, SearchAndReplaceWidget,] class InputOptions(Base): diff --git a/src/calibre/manual/regexp.rst b/src/calibre/manual/regexp.rst index 5cd9a8b097..c8661cd427 100644 --- a/src/calibre/manual/regexp.rst +++ b/src/calibre/manual/regexp.rst @@ -21,7 +21,7 @@ This is, inevitably, going to be somewhat technical- after all, regular expressi Where in |app| can you use regular expressions? --------------------------------------------------- -There are a few places |app| uses regular expressions. There's the header/footer removal in conversion options, metadata detection from filenames in the import settings and, since last version, there's the option to use regular expressions to search and replace in metadata of multiple books. +There are a few places |app| uses regular expressions. There's the Search & Replace in conversion options, metadata detection from filenames in the import settings and Search & Replace when editing the metadata of books in bulk. What on earth *is* a regular expression? ------------------------------------------------