mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Wire up the FTS input
This commit is contained in:
parent
1b12b9c79e
commit
6beefbe100
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
|
from contextlib import suppress
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
QAbstractItemModel, QCheckBox, QDialog, QDialogButtonBox, QHBoxLayout, QIcon,
|
QAbstractItemModel, QCheckBox, QDialog, QDialogButtonBox, QHBoxLayout, QIcon,
|
||||||
@ -15,9 +16,8 @@ from threading import Event, Thread
|
|||||||
from calibre.gui2 import gprefs
|
from calibre.gui2 import gprefs
|
||||||
from calibre.gui2.fts.utils import get_db
|
from calibre.gui2.fts.utils import get_db
|
||||||
from calibre.gui2.library.annotations import BusyCursor
|
from calibre.gui2.library.annotations import BusyCursor
|
||||||
from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox
|
|
||||||
from calibre.gui2.progress_indicator import ProgressIndicator
|
from calibre.gui2.progress_indicator import ProgressIndicator
|
||||||
|
from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox
|
||||||
|
|
||||||
ROOT = QModelIndex()
|
ROOT = QModelIndex()
|
||||||
|
|
||||||
@ -101,6 +101,8 @@ class ResultsModel(QAbstractItemModel):
|
|||||||
sk = fts_engine_query, use_stemming, restrict_to_book_ids, id(db)
|
sk = fts_engine_query, use_stemming, restrict_to_book_ids, id(db)
|
||||||
if sk == self.current_search_key:
|
if sk == self.current_search_key:
|
||||||
return False
|
return False
|
||||||
|
self.current_thread_abort.set()
|
||||||
|
self.current_search_key = sk
|
||||||
self.search_started.emit()
|
self.search_started.emit()
|
||||||
self.beginResetModel()
|
self.beginResetModel()
|
||||||
db.fts_search(
|
db.fts_search(
|
||||||
@ -109,7 +111,6 @@ class ResultsModel(QAbstractItemModel):
|
|||||||
)
|
)
|
||||||
self.endResetModel()
|
self.endResetModel()
|
||||||
self.current_query_id = next(self.query_id_counter)
|
self.current_query_id = next(self.query_id_counter)
|
||||||
self.current_thread_abort.set()
|
|
||||||
self.current_thread_abort = Event()
|
self.current_thread_abort = Event()
|
||||||
self.current_thread = Thread(
|
self.current_thread = Thread(
|
||||||
name='FTSQuery', daemon=True, target=self.search_text_in_thread, args=(
|
name='FTSQuery', daemon=True, target=self.search_text_in_thread, args=(
|
||||||
@ -125,6 +126,7 @@ class ResultsModel(QAbstractItemModel):
|
|||||||
generator = db.fts_search(*a, **kw, result_type=lambda x: x)
|
generator = db.fts_search(*a, **kw, result_type=lambda x: x)
|
||||||
for result in generator:
|
for result in generator:
|
||||||
if abort.is_set():
|
if abort.is_set():
|
||||||
|
with suppress(StopIteration):
|
||||||
generator.send(True)
|
generator.send(True)
|
||||||
return
|
return
|
||||||
self.result_found.emit(query_id, result)
|
self.result_found.emit(query_id, result)
|
||||||
@ -303,6 +305,7 @@ class ResultsPanel(QWidget):
|
|||||||
self.search = rv.search
|
self.search = rv.search
|
||||||
rv.search_started.connect(self.sip.start)
|
rv.search_started.connect(self.sip.start)
|
||||||
rv.search_complete.connect(self.sip.stop)
|
rv.search_complete.connect(self.sip.stop)
|
||||||
|
sip.search_signal.connect(self.search)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -318,5 +321,5 @@ if __name__ == '__main__':
|
|||||||
w = ResultsPanel(parent=d)
|
w = ResultsPanel(parent=d)
|
||||||
l.addWidget(w)
|
l.addWidget(w)
|
||||||
l.addWidget(bb)
|
l.addWidget(bb)
|
||||||
w.search('asimov')
|
w.sip.search_box.setText('asimov')
|
||||||
d.exec()
|
d.exec()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user