E-book viewer: Add a button to directly open the viewer help section in the calibre user manual to the viewer controls

This commit is contained in:
Kovid Goyal 2021-10-24 21:21:08 +05:30
parent 6c45f4333d
commit ae437852be
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
8 changed files with 45 additions and 7 deletions

1
imgsrc/srv/help.svg Normal file
View File

@ -0,0 +1 @@
<svg height='300px' width='300px' xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" viewBox="0 0 128 128"><g><path d="M64,1C29.3,1,1,29.3,1,64s28.3,63,63,63s63-28.3,63-63S98.7,1,64,1z M64,7c11.8,0,22.8,3.6,32,9.8L78.8,34 c-4.5-2.2-9.5-3.5-14.8-3.5S53.7,31.8,49.2,34L32,16.8C41.2,10.6,52.2,7,64,7z M91.5,64c0,15.2-12.3,27.5-27.5,27.5 S36.5,79.2,36.5,64S48.8,36.5,64,36.5S91.5,48.8,91.5,64z M16.8,96C10.6,86.8,7,75.8,7,64c0-12.4,4-23.9,10.7-33.2l17,17 C32,52.6,30.5,58.1,30.5,64c0,5.3,1.3,10.3,3.5,14.8L16.8,96z M64,121c-12.4,0-23.9-4-33.2-10.7l17-17c4.8,2.7,10.3,4.2,16.2,4.2 c5.9,0,11.4-1.5,16.2-4.2l17,17C87.9,117,76.4,121,64,121z M121,64c0,11.8-3.6,22.8-9.8,32L94,78.8c2.2-4.5,3.5-9.5,3.5-14.8 c0-5.9-1.5-11.4-4.2-16.2l17-17C117,40.1,121,51.6,121,64z"></path></g></svg>

After

Width:  |  Height:  |  Size: 825 B

View File

@ -36,6 +36,7 @@ from calibre.gui2.webengine import (
secure_webengine, to_js secure_webengine, to_js
) )
from calibre.srv.code import get_translations_data from calibre.srv.code import get_translations_data
from calibre.utils.localization import localize_user_manual_link
from calibre.utils.serialize import json_loads from calibre.utils.serialize import json_loads
from calibre.utils.shared_file import share_open from calibre.utils.shared_file import share_open
from polyglot.builtins import as_bytes, iteritems from polyglot.builtins import as_bytes, iteritems
@ -275,6 +276,7 @@ class ViewerBridge(Bridge):
tts = from_js(object, object) tts = from_js(object, object)
edit_book = from_js(object, object, object) edit_book = from_js(object, object, object)
show_book_folder = from_js() show_book_folder = from_js()
show_help = from_js(object)
create_view = to_js() create_view = to_js()
start_book_load = to_js() start_book_load = to_js()
@ -538,6 +540,7 @@ class WebView(RestartingWebEngineView):
self.bridge.highlights_changed.connect(self.highlights_changed) self.bridge.highlights_changed.connect(self.highlights_changed)
self.bridge.edit_book.connect(self.edit_book) self.bridge.edit_book.connect(self.edit_book)
self.bridge.show_book_folder.connect(self.show_book_folder) self.bridge.show_book_folder.connect(self.show_book_folder)
self.bridge.show_help.connect(self.show_help)
self.bridge.open_url.connect(safe_open_url) self.bridge.open_url.connect(safe_open_url)
self.bridge.speak_simple_text.connect(self.tts.speak_simple_text) self.bridge.speak_simple_text.connect(self.tts.speak_simple_text)
self.bridge.tts.connect(self.tts.action) self.bridge.tts.connect(self.tts.action)
@ -744,5 +747,9 @@ class WebView(RestartingWebEngineView):
path = os.path.dirname(os.path.abspath(set_book_path.pathtoebook)) path = os.path.dirname(os.path.abspath(set_book_path.pathtoebook))
safe_open_url(QUrl.fromLocalFile(path)) safe_open_url(QUrl.fromLocalFile(path))
def show_help(self, which):
if which == 'viewer':
safe_open_url(localize_user_manual_link('https://manual.calibre-ebook.com/viewer.html'))
def repair_after_fullscreen_switch(self): def repair_after_fullscreen_switch(self):
self.execute_when_ready('repair_after_fullscreen_switch') self.execute_when_ready('repair_after_fullscreen_switch')

View File

@ -27,7 +27,7 @@ from calibre.srv.utils import get_library_data, get_use_roman
from calibre.utils.config import prefs, tweaks from calibre.utils.config import prefs, tweaks
from calibre.utils.icu import numeric_sort_key, sort_key from calibre.utils.icu import numeric_sort_key, sort_key
from calibre.utils.localization import ( from calibre.utils.localization import (
get_lang, lang_map_for_ui, localize_website_link get_lang, lang_map_for_ui, localize_website_link, lang_code_for_user_manual
) )
from calibre.utils.search_query_parser import ParseException from calibre.utils.search_query_parser import ParseException
from calibre.utils.serialize import json_dumps from calibre.utils.serialize import json_dumps
@ -156,7 +156,8 @@ def basic_interface_data(ctx, rd):
'search_the_net_urls': getattr(ctx, 'search_the_net_urls', None) or [], 'search_the_net_urls': getattr(ctx, 'search_the_net_urls', None) or [],
'num_per_page': rd.opts.num_per_page, 'num_per_page': rd.opts.num_per_page,
'default_book_list_mode': rd.opts.book_list_mode, 'default_book_list_mode': rd.opts.book_list_mode,
'donate_link': localize_website_link('https://calibre-ebook.com/donate') 'donate_link': localize_website_link('https://calibre-ebook.com/donate'),
'lang_code_for_user_manual': lang_code_for_user_manual(),
} }
ans['library_map'], ans['default_library_id'] = ctx.library_info(rd) ans['library_map'], ans['default_library_id'] = ctx.library_info(rd)
return ans return ans

View File

@ -528,12 +528,19 @@ def user_manual_stats():
return stats return stats
def localize_user_manual_link(url): def lang_code_for_user_manual():
lc = lang_as_iso639_1(get_lang()) lc = lang_as_iso639_1(get_lang())
if lc == 'en': if lc == 'en':
return url return ''
stats = user_manual_stats() stats = user_manual_stats()
if stats.get(lc, 0) < 0.3: if stats.get(lc, 0) < 0.3:
return ''
return lc
def localize_user_manual_link(url):
lc = lang_code_for_user_manual()
if not lc:
return url return url
from polyglot.urllib import urlparse, urlunparse from polyglot.urllib import urlparse, urlunparse
parts = urlparse(url) parts = urlparse(url)

View File

@ -430,11 +430,19 @@ class MainOverlay: # {{{
E.div( # bottom bar E.div( # bottom bar
style='position: fixed; width: 100%; bottom: 0; display: flex; justify-content: space-between; align-items: center;' style='position: fixed; width: 100%; bottom: 0; display: flex; justify-content: space-between; align-items: center;'
'user-select: none; background-color: {}'.format(get_color('window-background')), 'user-select: none; background-color: {}'.format(get_color('window-background')),
E.div(
style='display: flex; justify-content: space-between; align-items: center;',
E.div( E.div(
style='display: flex; align-items: center; cursor: pointer; padding: 0.5ex 1rem', class_='main-overlay-button', style='display: flex; align-items: center; cursor: pointer; padding: 0.5ex 1rem', class_='main-overlay-button',
title=_('Close the viewer controls'), title=_('Close the viewer controls'),
svgicon('close', icon_size, icon_size), '\xa0', _('Close') svgicon('close', icon_size, icon_size), '\xa0', _('Close')
), ),
E.div(
style='display: flex; align-items: center; cursor: pointer; padding: 0.5ex 1rem', class_='main-overlay-button',
svgicon('help', icon_size, icon_size), '\xa0', _('Help'), onclick=def(ev):
ui_operations.show_help('viewer')
)
),
E.div(style='padding: 0.5ex 1rem', '\xa0'), E.div(style='padding: 0.5ex 1rem', '\xa0'), E.div(style='padding: 0.5ex 1rem', '\xa0'), E.div(style='padding: 0.5ex 1rem', '\xa0'),
), ),
) )

View File

@ -18,6 +18,7 @@ from read_book.db import get_db
from read_book.globals import ui_operations from read_book.globals import ui_operations
from read_book.tts import Client from read_book.tts import Client
from read_book.view import View from read_book.view import View
from session import get_interface_data
from utils import debounce, full_screen_element, human_readable, request_full_screen from utils import debounce, full_screen_element, human_readable, request_full_screen
from widgets import create_button from widgets import create_button
@ -92,6 +93,16 @@ class ReadUI:
ui_operations.find_next = self.view.search_overlay.find_next ui_operations.find_next = self.view.search_overlay.find_next
ui_operations.open_url = def(url): ui_operations.open_url = def(url):
window.open(url, '_blank') window.open(url, '_blank')
ui_operations.show_help = def(which):
if which is 'viewer':
path = '/viewer.html'
else:
return
if get_interface_data().lang_code_for_user_manual:
path = f'/{get_interface_data().lang_code_for_user_manual}{path}'
url = 'https://manual.calibre-ebook.com' + path
window.open(url, '_blank')
ui_operations.copy_selection = def(text, html): ui_operations.copy_selection = def(text, html):
# try using document.execCommand which on chrome allows the # try using document.execCommand which on chrome allows the
# copy on non-secure origin if this is close to a user # copy on non-secure origin if this is close to a user

View File

@ -241,6 +241,7 @@ default_interface_data = {
'icon_path': '', 'icon_path': '',
'custom_list_template': None, 'custom_list_template': None,
'num_per_page': 50, 'num_per_page': 50,
'lang_code_for_user_manual': '',
} }
def get_interface_data(): def get_interface_data():

View File

@ -429,6 +429,8 @@ if window is window.top:
to_python.edit_book(spine_name, frac, selected_text or '') to_python.edit_book(spine_name, frac, selected_text or '')
ui_operations.show_book_folder = def(): ui_operations.show_book_folder = def():
to_python.show_book_folder() to_python.show_book_folder()
ui_operations.show_help = def(which):
to_python.show_help(which)
document.body.appendChild(E.div(id='view')) document.body.appendChild(E.div(id='view'))
window.onerror = onerror window.onerror = onerror