mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
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:
parent
2f07353be9
commit
344baecb90
@ -238,6 +238,12 @@ class View(QWebEngineView):
|
||||
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):
|
||||
|
||||
def __init__(self, parent):
|
||||
@ -275,6 +281,7 @@ class Lookup(QWidget):
|
||||
l.addLayout(h)
|
||||
h.addWidget(b), h.addWidget(rb)
|
||||
self.auto_update_query = a = QCheckBox(_('Update on selection change'), self)
|
||||
self.disallow_auto_update = False
|
||||
a.setToolTip(textwrap.fill(
|
||||
_('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.')))
|
||||
@ -282,6 +289,12 @@ class Lookup(QWidget):
|
||||
a.stateChanged.connect(self.auto_update_state_changed)
|
||||
l.addWidget(a)
|
||||
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):
|
||||
vprefs['auto_update_lookup'] = self.auto_update_query.isChecked()
|
||||
@ -370,7 +383,7 @@ class Lookup(QWidget):
|
||||
def selected_text_changed(self, text, annot_id):
|
||||
already_has_text = bool(self.current_query)
|
||||
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.update_refresh_button_status()
|
||||
|
||||
|
@ -1,13 +1,18 @@
|
||||
#!/usr/bin/env python
|
||||
# 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.viewer.config import get_pref_group, vprefs
|
||||
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):
|
||||
|
||||
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)
|
||||
|
||||
def play(self, data):
|
||||
set_sync_override(False)
|
||||
self.tts_client.speak_marked_text(data['marked_text'], self.callback)
|
||||
|
||||
def pause(self, data):
|
||||
set_sync_override(True)
|
||||
self.tts_client.pause()
|
||||
|
||||
def resume(self, data):
|
||||
set_sync_override(False)
|
||||
self.tts_client.resume()
|
||||
|
||||
def resume_after_configure(self, data):
|
||||
set_sync_override(False)
|
||||
self.tts_client.resume_after_configure()
|
||||
|
||||
def callback(self, event):
|
||||
@ -107,6 +116,7 @@ class TTS(QObject):
|
||||
self.event_received.emit(event.type.name, data)
|
||||
|
||||
def stop(self, data):
|
||||
set_sync_override(True)
|
||||
self.tts_client.stop()
|
||||
|
||||
@property
|
||||
|
Loading…
x
Reference in New Issue
Block a user