mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Pass results back from worker to UI
This commit is contained in:
parent
4ad95b38c2
commit
a365ac1862
@ -29,6 +29,7 @@ class SearchOverlay:
|
|||||||
|
|
||||||
def __init__(self, view):
|
def __init__(self, view):
|
||||||
self.view = view
|
self.view = view
|
||||||
|
self.search_in_flight_id = None
|
||||||
c = self.container
|
c = self.container
|
||||||
c.classList.add(CLASS_NAME)
|
c.classList.add(CLASS_NAME)
|
||||||
next_button = E.div(class_='simple-link', svgicon('chevron-down'), title=_('Next match'))
|
next_button = E.div(class_='simple-link', svgicon('chevron-down'), title=_('Next match'))
|
||||||
@ -51,16 +52,26 @@ class SearchOverlay:
|
|||||||
def worker(self):
|
def worker(self):
|
||||||
if not self._worker:
|
if not self._worker:
|
||||||
self._worker = start_worker('read_book.search')
|
self._worker = start_worker('read_book.search')
|
||||||
|
self._worker.onmessage = self.on_worker_message
|
||||||
return self._worker
|
return self._worker
|
||||||
|
|
||||||
def queue_search(self, query, book, current_name):
|
def queue_search(self, query, book, current_name):
|
||||||
spine = book.manifest.spine
|
spine = book.manifest.spine
|
||||||
self.request_counter += 1
|
self.request_counter += 1
|
||||||
|
self.search_in_flight_id = self.request_counter
|
||||||
self.worker.postMessage({
|
self.worker.postMessage({
|
||||||
'type': 'search', 'book_hash': book.book_hash, 'spine': spine, 'current_name': current_name,
|
'type': 'search', 'book_hash': book.book_hash, 'spine': spine, 'current_name': current_name,
|
||||||
'id': self.request_counter, 'stored_files': book.stored_files, 'query': query
|
'id': self.request_counter, 'stored_files': book.stored_files, 'query': query
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def on_worker_message(self, evt):
|
||||||
|
msg = evt.data
|
||||||
|
if msg.type is 'error':
|
||||||
|
pass
|
||||||
|
elif msg.id is self.search_in_flight_id:
|
||||||
|
if msg.type is 'search_complete':
|
||||||
|
self.search_in_flight_id = None
|
||||||
|
|
||||||
def clear_caches(self):
|
def clear_caches(self):
|
||||||
if self._worker:
|
if self._worker:
|
||||||
self.worker.postMessage({'type': 'clear_caches'})
|
self.worker.postMessage({'type': 'clear_caches'})
|
||||||
|
@ -100,9 +100,9 @@ def search_in_text_of(name):
|
|||||||
result = {
|
result = {
|
||||||
'file_name': name, 'spine_idx': spine_idx, 'index': match_counts[q],
|
'file_name': name, 'spine_idx': spine_idx, 'index': match_counts[q],
|
||||||
'text': text, 'before': before, 'after': after, 'mode': wc.current_query.query.mode,
|
'text': text, 'before': before, 'after': after, 'mode': wc.current_query.query.mode,
|
||||||
'q': q, 'result_num': wc.result_num, 'on_discovery': wc.query_id, 'query_id': wc.query_id
|
'q': q, 'result_num': wc.result_num, 'on_discovery': wc.current_query_id,
|
||||||
}
|
}
|
||||||
self.postMessage({'type': 'search_result', 'result': result})
|
self.postMessage({'type': 'search_result', 'id': wc.current_query_id, 'result': result})
|
||||||
match_counts[q] += 1
|
match_counts[q] += 1
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user