From e2f4b969bc6d36fbb285818cb50184cf83efed6e Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 20 Sep 2010 19:49:03 +0100 Subject: [PATCH] 1) add tooltips 2) change main heading text depending on the mode 3) add an error if attempting to assign '' to authors or title --- src/calibre/gui2/dialogs/metadata_bulk.py | 48 +++++++++++++++++---- src/calibre/gui2/dialogs/metadata_bulk.ui | 52 +++++++++++++++++++---- 2 files changed, 84 insertions(+), 16 deletions(-) diff --git a/src/calibre/gui2/dialogs/metadata_bulk.py b/src/calibre/gui2/dialogs/metadata_bulk.py index b01869deaa..681f65b19e 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.py +++ b/src/calibre/gui2/dialogs/metadata_bulk.py @@ -208,25 +208,43 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): self.book_1_text.setObjectName(name) self.testgrid.addWidget(w, i+offset, 2, 1, 1) - self.s_r_heading.setText('

'+ _( + self.main_heading = _( 'You can destroy your library using this feature. ' 'Changes are permanent. There is no undo function. ' ' This feature is experimental, and there may be bugs. ' 'You are strongly encouraged to back up your library ' 'before proceeding.' - ) + '

' + _( + + '

' + 'Search and replace in text fields using character matching ' - 'or regular expressions. In character mode, search text ' - 'found in the specified field is replaced with replace ' - 'text. In regular expression mode, the search text is an ' + 'or regular expressions. ') + + self.character_heading = _( + 'In character mode, the field is searched for the entered ' + 'search text. The text is replaced by the specified replacement ' + 'text everywhere it is found in the specified field. After ' + 'replacement is finished, the text can be changed to ' + 'upper-case, lower-case, or title-case. If the case-sensitive ' + 'check box is checked, the search text must match exactly. If ' + 'it is unchecked, the search text will match both upper- and ' + 'lower-case letters' + ) + + self.regexp_heading = _( + 'In regular expression mode, the search text is an ' 'arbitrary python-compatible regular expression. The ' 'replacement text can contain backreferences to parenthesized ' 'expressions in the pattern. The search is not anchored, ' 'and can match and replace multiple times on the same string. ' + 'The modification functions (lower-case etc) are applied to the ' + 'matched text, not to the field as a whole. ' + 'The destination box specifies the field where the result after ' + 'matching and replacement is to be assigned. You can replace ' + 'the text in the field, or prepend or append the matched text. ' 'See ' - 'this reference for more information, and in particular ' - 'the \'sub\' function.' - )) + 'this reference for more information on python\'s regular ' + 'expressions, and in particular the \'sub\' function.' + ) + self.search_mode.addItems(self.s_r_match_modes) self.search_mode.setCurrentIndex(dynamic.get('s_r_search_mode', 0)) self.replace_mode.addItems(self.s_r_replace_modes) @@ -298,12 +316,14 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): self.replace_mode.setVisible(False) self.replace_mode_label.setVisible(False) self.comma_separated.setVisible(False) + self.s_r_heading.setText('

'+self.main_heading + self.character_heading) else: self.destination_field.setVisible(True) self.destination_field_label.setVisible(True) self.replace_mode.setVisible(True) self.replace_mode_label.setVisible(True) self.comma_separated.setVisible(True) + self.s_r_heading.setText('

'+self.main_heading + self.regexp_heading) self.s_r_paint_results(None) def s_r_set_colors(self): @@ -434,8 +454,20 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): # The standard tags and authors values want to be lists. # All custom columns are to be strings val = dfm['is_multiple'].join(val) + if dest == 'authors' and len(val) == 0: + error_dialog(self, _('Search/replace invalid'), + _('Authors cannot be set to the empty string. ' + 'Book title %s not processed')%mi.title, + show=True) + continue else: val = self.s_r_replace_mode_separator().join(val) + if dest == 'title' and len(val) == 0: + error_dialog(self, _('Search/replace invalid'), + _('Title cannot be set to the empty string. ' + 'Book title %s not processed')%mi.title, + show=True) + continue if dfm['is_custom']: extra = self.db.get_custom_extra(id, label=dfm['label'], index_is_id=True) diff --git a/src/calibre/gui2/dialogs/metadata_bulk.ui b/src/calibre/gui2/dialogs/metadata_bulk.ui index e433aaf327..b2a3e11b4a 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.ui +++ b/src/calibre/gui2/dialogs/metadata_bulk.ui @@ -351,7 +351,11 @@ Future conversion of these books will use the default settings. - + + + The name of the field that you want to search + + @@ -361,12 +365,16 @@ Future conversion of these books will use the default settings. Search mode: - search_field + search_mode - + + + Choose whether to use basic text matching or advanced regular expression matching + + @@ -394,7 +402,11 @@ Future conversion of these books will use the default settings. - + + + Enter the what you are looking for, either plain text or a regular expression, depending on the mode + + @@ -404,6 +416,9 @@ Future conversion of these books will use the default settings. true + + Check this box if the search string must match exactly upper and lower case. Uncheck it if case is to be ignored + @@ -417,7 +432,11 @@ Future conversion of these books will use the default settings. - + + + The replacement text. The matched search text will be replaced with this string + + @@ -432,7 +451,12 @@ Future conversion of these books will use the default settings. - + + + Specify how the text is to be processed after matching and replacement. In character mode, the entire +field is processed. In regular expression mode, only the matched text is processed + + @@ -460,7 +484,11 @@ Future conversion of these books will use the default settings. - + + + The field that the text will be put into after all replacements. If blank, the source field is used. + + @@ -475,7 +503,11 @@ Future conversion of these books will use the default settings. - + + + Specify how the text should be copied into the destination. + + @@ -485,6 +517,10 @@ Future conversion of these books will use the default settings. true + + If the replace mode is prepend or append, then this box indicates whether a comma or +nothing should be put between the original text and the inserted text +