From 997595dfd46d08903e1e135048cd68011035168b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 17 Sep 2019 19:47:00 +0530 Subject: [PATCH] Viewer: Add option to hide mouse-over tooltips --- src/pyj/read_book/prefs/misc.pyj | 7 +++++++ src/pyj/read_book/resources.pyj | 8 +++++++- src/pyj/read_book/settings.pyj | 1 + src/pyj/read_book/view.pyj | 1 + src/pyj/session.pyj | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/pyj/read_book/prefs/misc.pyj b/src/pyj/read_book/prefs/misc.pyj index 0912bd8639..152403caa9 100644 --- a/src/pyj/read_book/prefs/misc.pyj +++ b/src/pyj/read_book/prefs/misc.pyj @@ -8,6 +8,7 @@ from gettext import gettext as _ from book_list.globals import get_session_data from dom import unique_id from widgets import create_button +from session import defaults CONTAINER = unique_id('standalone-misc-settings') DEFAULTS = { @@ -21,6 +22,7 @@ def restore_defaults(): container = get_container() for q in Object.keys(DEFAULTS): container.querySelector(f'[name={q}]').checked = DEFAULTS[q] + container.querySelector(f'[name=hide_tooltips]').checked = defaults.hide_tooltips def get_container(): @@ -32,6 +34,7 @@ def create_misc_panel(container): container = container.lastChild sd = get_session_data() settings = sd.get('standalone_misc_settings') + settings.hide_tooltips = sd.get('hide_tooltips') def cb(name, text): ans = E.input(type='checkbox', name=name) @@ -41,6 +44,7 @@ def create_misc_panel(container): container.append(cb('remember_window_geometry', _('Remember last used window size and position'))) container.append(cb('remember_last_read', _('Remember current page when quitting'))) container.append(cb('save_annotations_in_ebook', _('Keep a copy of annotations/bookmarks in the e-book file, for easy sharing'))) + container.append(cb('hide_tooltips', _('Hide mouse-over tooltips in the book text'))) container.appendChild(E.div( style='margin-top: 1rem', create_button(_('Restore defaults'), action=restore_defaults) @@ -59,3 +63,6 @@ def commit_misc(onchange): if val is not DEFAULTS[q]: vals[q] = val sd.set('standalone_misc_settings', vals) + hide_tooltips = container.querySelector(f'[name=hide_tooltips]').checked + sd.set('hide_tooltips', None if hide_tooltips is defaults.hide_tooltips else hide_tooltips) + onchange() diff --git a/src/pyj/read_book/resources.pyj b/src/pyj/read_book/resources.pyj index 4c5ea4a14e..05cdf617e0 100644 --- a/src/pyj/read_book/resources.pyj +++ b/src/pyj/read_book/resources.pyj @@ -6,7 +6,8 @@ from elementmaker import E from encodings import base64decode, utf8_decode from dom import clear, remove_all_attributes -from read_book.globals import ui_operations, runtime +from read_book.globals import runtime, ui_operations +from read_book.settings import opts JSON_XHTML_MIMETYPE = 'application/calibre+xhtml+json' @@ -168,6 +169,7 @@ js_types = {k: True for k in 'text/javascript text/ecmascript application/javasc resource_tag_names = {'script':'src', 'link':'href', 'img':'src', 'image':'xlink:href'} ns_rmap = {'http://www.w3.org/2000/svg':'svg', 'http://www.w3.org/1999/xlink':'xlink', 'http://www.w3.org/1998/Math/MathML':'math', 'http://www.w3.org/XML/1998/namespace': 'xml'} ns_count = 0 +hide_tooltips = False def get_prefix(ns): nonlocal ns_count @@ -186,6 +188,8 @@ def apply_attributes(src, elem, ns_map): ns = ns_map[a[2]] elem.setAttributeNS(ns, get_prefix(ns) + a[0], a[1]) else: + if hide_tooltips and (a[0] is 'title' or a[0] is 'alt'): + continue elem.setAttribute(a[0], a[1]) def process_stack(stack, tag_map, ns_map, load_required, onload, resource_urls): @@ -225,6 +229,7 @@ def process_stack(stack, tag_map, ns_map, load_required, onload, resource_urls): stack.push(v'[node[i], elem]') def unserialize_html(serialized_data, proceed, postprocess_dom): + nonlocal hide_tooltips tag_map = serialized_data.tag_map tree = serialized_data.tree ns_map = serialized_data.ns_map @@ -243,6 +248,7 @@ def unserialize_html(serialized_data, proceed, postprocess_dom): load_required = set() proceeded = False hang_timeout = 5 + hide_tooltips = opts.hide_tooltips def hangcheck(): nonlocal proceeded diff --git a/src/pyj/read_book/settings.pyj b/src/pyj/read_book/settings.pyj index d8adc85187..35aa58fc61 100644 --- a/src/pyj/read_book/settings.pyj +++ b/src/pyj/read_book/settings.pyj @@ -15,6 +15,7 @@ def update_settings(settings): opts.color_scheme = settings.color_scheme opts.base_font_size = max(8, min(settings.base_font_size or 16, 64)) opts.user_stylesheet = settings.user_stylesheet or '' + opts.hide_tooltips = settings.hide_tooltips or False update_settings() diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index f4b4622c8a..e99bef036c 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -531,6 +531,7 @@ class View: 'base_font_size': sd.get('base_font_size'), 'user_stylesheet': sd.get('user_stylesheet'), 'keyboard_shortcuts': sd.get('keyboard_shortcuts'), + 'hide_tooltips': sd.get('hide_tooltips'), } def show_name(self, name, initial_position=None): diff --git a/src/pyj/session.pyj b/src/pyj/session.pyj index 551f00a64f..e336391869 100644 --- a/src/pyj/session.pyj +++ b/src/pyj/session.pyj @@ -40,6 +40,7 @@ defaults = { 'header': {}, 'footer': {'right': 'progress'}, 'word_actions': v'[]', + 'hide_tooltips': False, 'keyboard_shortcuts': {}, 'standalone_font_settings': {}, 'standalone_misc_settings': {},