Implement display of notes in notes browser

This commit is contained in:
Kovid Goyal 2023-09-27 15:58:49 +05:30
parent 25fdaa735b
commit 89251da81c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -12,6 +12,7 @@ from qt.core import (
from calibre.db.backend import FTSQueryError from calibre.db.backend import FTSQueryError
from calibre.db.cache import Cache from calibre.db.cache import Cache
from calibre.gui2 import Application, error_dialog, gprefs from calibre.gui2 import Application, error_dialog, gprefs
from calibre.gui2.dialogs.show_category_note import Display
from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox
from calibre.gui2.widgets import BusyCursor from calibre.gui2.widgets import BusyCursor
from calibre.gui2.widgets2 import Dialog, FlowLayout from calibre.gui2.widgets2 import Dialog, FlowLayout
@ -157,6 +158,9 @@ class ResultsList(QTreeWidget):
if self.item_map: if self.item_map:
self.setCurrentItem(self.item_map[0]) self.setCurrentItem(self.item_map[0])
def sizeHint(self):
return QSize(500, 500)
class RestrictFields(QWidget): class RestrictFields(QWidget):
@ -288,6 +292,42 @@ class SearchInput(QWidget):
self.show_previous_signal.emit() self.show_previous_signal.emit()
class NoteDisplay(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.l = l = QVBoxLayout(self)
l.setContentsMargins(0, 0, 0, 0)
self.title = la = QLabel('')
l.addWidget(la)
la.setWordWrap(True)
self.html_display = hd = Display(self)
l.addWidget(hd)
def sizeHint(self):
return QSize(400, 500)
@property
def db(self):
return current_db()
def show_note(self, field='', item_id=0):
if field:
self.title.setText('<h2>{}</h2>'.format(self.db.get_item_name(field, item_id) or ''))
self.html_display.setHtml(self.db.notes_for(field, item_id))
else:
self.title.setText('')
self.html_display.setHtml('')
def current_result_changed(self, r):
if r is None:
self.show_note()
else:
self.show_note(r['field'], r['item_id'])
class NotesBrowser(Dialog): class NotesBrowser(Dialog):
current_query = None current_query = None
@ -315,6 +355,10 @@ class NotesBrowser(Dialog):
si.show_previous_signal.connect(partial(rl.show_next, backwards=True)) si.show_previous_signal.connect(partial(rl.show_next, backwards=True))
s.addWidget(rl) s.addWidget(rl)
self.notes_display = nd = NoteDisplay(self)
rl.current_result_changed.connect(nd.current_result_changed)
s.addWidget(nd)
self.use_stemmer = us = QCheckBox(_('&Match on related words')) self.use_stemmer = us = QCheckBox(_('&Match on related words'))
us.setChecked(gprefs['browse_notes_use_stemmer']) us.setChecked(gprefs['browse_notes_use_stemmer'])
us.setToolTip('<p>' + _( us.setToolTip('<p>' + _(