mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Search for a highlight
This commit is contained in:
parent
b957e43faf
commit
e00b12ca70
@ -4,9 +4,15 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
from PyQt5.Qt import QListWidget, QListWidgetItem, Qt, QVBoxLayout, QWidget
|
from itertools import chain
|
||||||
|
|
||||||
|
from PyQt5.Qt import (
|
||||||
|
QItemSelectionModel, QListWidget, QListWidgetItem, Qt, QVBoxLayout, QWidget
|
||||||
|
)
|
||||||
|
|
||||||
|
from calibre.gui2 import error_dialog
|
||||||
from calibre.gui2.viewer.search import SearchInput
|
from calibre.gui2.viewer.search import SearchInput
|
||||||
|
from polyglot.builtins import range
|
||||||
|
|
||||||
|
|
||||||
class Highlights(QListWidget):
|
class Highlights(QListWidget):
|
||||||
@ -22,6 +28,28 @@ class Highlights(QListWidget):
|
|||||||
i = QListWidgetItem(h['highlighted_text'], self)
|
i = QListWidgetItem(h['highlighted_text'], self)
|
||||||
i.setData(Qt.UserRole, h)
|
i.setData(Qt.UserRole, h)
|
||||||
|
|
||||||
|
def find_query(self, query):
|
||||||
|
cr = self.currentRow()
|
||||||
|
pat = query.regex
|
||||||
|
if query.backwards:
|
||||||
|
if cr < 0:
|
||||||
|
cr = self.count()
|
||||||
|
indices = chain(range(cr - 1, -1, -1), range(self.count() - 1, cr, -1))
|
||||||
|
else:
|
||||||
|
if cr < 0:
|
||||||
|
cr = -1
|
||||||
|
indices = chain(range(cr + 1, self.count()), range(0, cr + 1))
|
||||||
|
for i in indices:
|
||||||
|
item = self.item(i)
|
||||||
|
h = item.data(Qt.UserRole)
|
||||||
|
if pat.search(h['highlighted_text']) is not None or pat.search(h.get('notes') or '') is not None:
|
||||||
|
self.set_current_row(i)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def set_current_row(self, row):
|
||||||
|
self.setCurrentRow(row, QItemSelectionModel.ClearAndSelect)
|
||||||
|
|
||||||
|
|
||||||
class HighlightsPanel(QWidget):
|
class HighlightsPanel(QWidget):
|
||||||
|
|
||||||
@ -38,7 +66,9 @@ class HighlightsPanel(QWidget):
|
|||||||
self.load = h.load
|
self.load = h.load
|
||||||
|
|
||||||
def search_requested(self, query):
|
def search_requested(self, query):
|
||||||
pass
|
if not self.highlights.find_query(query):
|
||||||
|
error_dialog(self, _('No matches'), _(
|
||||||
|
'No highlights match the search: {}').format(query.text), show=True)
|
||||||
|
|
||||||
def focus(self):
|
def focus(self):
|
||||||
self.highlights_list.setFocus(Qt.OtherFocusReason)
|
self.highlights_list.setFocus(Qt.OtherFocusReason)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user