diff --git a/src/calibre/gui2/fts/search.py b/src/calibre/gui2/fts/search.py index 2622e90fbd..2e1e6f0f6a 100644 --- a/src/calibre/gui2/fts/search.py +++ b/src/calibre/gui2/fts/search.py @@ -47,9 +47,9 @@ from qt.core import ( from calibre import fit_image, prepare_string_for_xml from calibre.db import FTSQueryError from calibre.ebooks.metadata import authors_to_string, fmt_sidx -from calibre.gui2 import config, error_dialog, gprefs, info_dialog, question_dialog, safe_open_url +from calibre.gui2 import config, error_dialog, gprefs, info_dialog, question_dialog from calibre.gui2.fts.cards import CardsView -from calibre.gui2.fts.utils import get_db, jump_shortcut, markup_text +from calibre.gui2.fts.utils import fts_url, get_db, help_panel, jump_shortcut, markup_text from calibre.gui2.library.models import render_pin from calibre.gui2.ui import get_gui from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox @@ -59,7 +59,6 @@ from calibre.utils.localization import ngettext ROOT = QModelIndex() sanitize_text_pat = re.compile(r'\s+') -fts_url = 'https://www.sqlite.org/fts5.html#full_text_query_syntax' def mark_books(*book_ids): @@ -803,42 +802,8 @@ class DetailsPanel(QStackedWidget): def __init__(self, parent=None): super().__init__(parent) - - # help panel {{{ - self.help_panel = hp = HTMLDisplay(self) - hp.setDefaultStyleSheet('a { text-decoration: none; }') - hp.setHtml(''' -
- ''' + _(''' -
Search for single words
-

Simply type the word:

-
awesome
calibre
- -
Search for phrases
-

Enclose the phrase in quotes:

-
"early run"
"song of love"
- -
Boolean searches
-
(calibre AND ebook) NOT gun
simple NOT ("high bar" OR hard)
- -
Phrases near each other
-
NEAR("people" "in Asia" "try")
NEAR("Kovid" "calibre", 30)
-

Here, 30 is the most words allowed between near groups. Defaults to 10 when unspecified.

- -
Complete syntax reference
\ -''' + '
').format(fts_url=fts_url)) - hp.setFocusPolicy(Qt.FocusPolicy.NoFocus) - hp.document().setDocumentMargin(0) - hp.anchor_clicked.connect(safe_open_url) + self.help_panel = hp = help_panel(self) self.addWidget(hp) - # }}} - self.result_details = rd = ResultDetails(self) rd.show_in_viewer.connect(self.show_in_viewer) rd.remove_book_from_results.connect(self.remove_book_from_results) diff --git a/src/calibre/gui2/fts/utils.py b/src/calibre/gui2/fts/utils.py index 9f2c1fd836..2110be1047 100644 --- a/src/calibre/gui2/fts/utils.py +++ b/src/calibre/gui2/fts/utils.py @@ -4,8 +4,12 @@ import re +from qt.core import Qt + from calibre import prepare_string_for_xml +from calibre.gui2 import safe_open_url from calibre.gui2.ui import get_gui +from calibre.gui2.widgets2 import HTMLDisplay def get_db(): @@ -29,3 +33,45 @@ def jump_shortcut(new_val: str = '') -> str: if new_val: setattr(jump_shortcut, 'ans', new_val) return getattr(jump_shortcut, 'ans', '') + + +fts_url = 'https://www.sqlite.org/fts5.html#full_text_query_syntax' + + +def help_html() -> str: + return ''' +
+ ''' + _(''' +
Search for single words
+

Simply type the word:

+
awesome
calibre
+ +
Search for phrases
+

Enclose the phrase in quotes:

+
"early run"
"song of love"
+ +
Boolean searches
+
(calibre AND ebook) NOT gun
simple NOT ("high bar" OR hard)
+ +
Phrases near each other
+
NEAR("people" "in Asia" "try")
NEAR("Kovid" "calibre", 30)
+

Here, 30 is the most words allowed between near groups. Defaults to 10 when unspecified.

+ +
Complete syntax reference
\ +''' + '
').format(fts_url=fts_url) + + +def help_panel(parent=None) -> HTMLDisplay: + hp = HTMLDisplay(parent) + hp.setDefaultStyleSheet('a { text-decoration: none; }') + hp.setHtml(help_html()) + hp.setFocusPolicy(Qt.FocusPolicy.NoFocus) + hp.document().setDocumentMargin(0) + hp.anchor_clicked.connect(safe_open_url) + return hp