E-book viewer: When using Read aloud do not automatically lookup the highlighted word until read aloud is paused or stopped. Fixes #1959207 [E-book viewer's "read the text aloud" function conflicts with dictionary lookup](https://bugs.launchpad.net/calibre/+bug/1959207)

This commit is contained in:
Kovid Goyal 2022-01-27 21:19:05 +05:30
parent 2f07353be9
commit 344baecb90
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 25 additions and 2 deletions

View File

@ -238,6 +238,12 @@ class View(QWebEngineView):
self.inspect_element.emit() self.inspect_element.emit()
def set_sync_override(allowed):
li = getattr(set_sync_override, 'instance', None)
if li is not None:
li.set_sync_override(allowed)
class Lookup(QWidget): class Lookup(QWidget):
def __init__(self, parent): def __init__(self, parent):
@ -275,6 +281,7 @@ class Lookup(QWidget):
l.addLayout(h) l.addLayout(h)
h.addWidget(b), h.addWidget(rb) h.addWidget(b), h.addWidget(rb)
self.auto_update_query = a = QCheckBox(_('Update on selection change'), self) self.auto_update_query = a = QCheckBox(_('Update on selection change'), self)
self.disallow_auto_update = False
a.setToolTip(textwrap.fill( a.setToolTip(textwrap.fill(
_('Automatically update the displayed result when selected text in the book changes. With this disabled' _('Automatically update the displayed result when selected text in the book changes. With this disabled'
' the lookup is changed only when clicking the Refresh button.'))) ' the lookup is changed only when clicking the Refresh button.')))
@ -282,6 +289,12 @@ class Lookup(QWidget):
a.stateChanged.connect(self.auto_update_state_changed) a.stateChanged.connect(self.auto_update_state_changed)
l.addWidget(a) l.addWidget(a)
self.update_refresh_button_status() self.update_refresh_button_status()
set_sync_override.instance = self
def set_sync_override(self, allowed):
self.disallow_auto_update = not allowed
if self.auto_update_query.isChecked() and allowed:
self.update_query()
def auto_update_state_changed(self, state): def auto_update_state_changed(self, state):
vprefs['auto_update_lookup'] = self.auto_update_query.isChecked() vprefs['auto_update_lookup'] = self.auto_update_query.isChecked()
@ -370,7 +383,7 @@ class Lookup(QWidget):
def selected_text_changed(self, text, annot_id): def selected_text_changed(self, text, annot_id):
already_has_text = bool(self.current_query) already_has_text = bool(self.current_query)
self.selected_text = text or '' self.selected_text = text or ''
if self.auto_update_query.isChecked() or not already_has_text: if not self.disallow_auto_update and (self.auto_update_query.isChecked() or not already_has_text):
self.debounce_timer.start() self.debounce_timer.start()
self.update_refresh_button_status() self.update_refresh_button_status()

View File

@ -1,13 +1,18 @@
#!/usr/bin/env python #!/usr/bin/env python
# License: GPL v3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net> # License: GPL v3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
from qt.core import QDialogButtonBox, QObject, QVBoxLayout, pyqtSignal, QDialog from qt.core import QDialog, QDialogButtonBox, QObject, QVBoxLayout, pyqtSignal
from calibre.gui2 import error_dialog from calibre.gui2 import error_dialog
from calibre.gui2.viewer.config import get_pref_group, vprefs from calibre.gui2.viewer.config import get_pref_group, vprefs
from calibre.gui2.widgets2 import Dialog from calibre.gui2.widgets2 import Dialog
def set_sync_override(allowed):
from calibre.gui2.viewer.lookup import set_sync_override
set_sync_override(allowed)
class Config(Dialog): class Config(Dialog):
def __init__(self, tts_client, ui_settings, backend_settings, parent): def __init__(self, tts_client, ui_settings, backend_settings, parent):
@ -89,15 +94,19 @@ class TTS(QObject):
return error_dialog(self.parent(), _('Text-to-Speech unavailable'), str(err), show=True) return error_dialog(self.parent(), _('Text-to-Speech unavailable'), str(err), show=True)
def play(self, data): def play(self, data):
set_sync_override(False)
self.tts_client.speak_marked_text(data['marked_text'], self.callback) self.tts_client.speak_marked_text(data['marked_text'], self.callback)
def pause(self, data): def pause(self, data):
set_sync_override(True)
self.tts_client.pause() self.tts_client.pause()
def resume(self, data): def resume(self, data):
set_sync_override(False)
self.tts_client.resume() self.tts_client.resume()
def resume_after_configure(self, data): def resume_after_configure(self, data):
set_sync_override(False)
self.tts_client.resume_after_configure() self.tts_client.resume_after_configure()
def callback(self, event): def callback(self, event):
@ -107,6 +116,7 @@ class TTS(QObject):
self.event_received.emit(event.type.name, data) self.event_received.emit(event.type.name, data)
def stop(self, data): def stop(self, data):
set_sync_override(True)
self.tts_client.stop() self.tts_client.stop()
@property @property