mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add a button to selection bar to search net
This commit is contained in:
parent
de76fbbda2
commit
a6dd65bea4
@ -268,6 +268,7 @@ class ViewerBridge(Bridge):
|
||||
scrollbar_context_menu = from_js(object, object, object)
|
||||
close_prep_finished = from_js(object)
|
||||
highlights_changed = from_js(object)
|
||||
open_url = from_js(object)
|
||||
|
||||
create_view = to_js()
|
||||
start_book_load = to_js()
|
||||
@ -511,6 +512,7 @@ class WebView(RestartingWebEngineView):
|
||||
self.bridge.scrollbar_context_menu.connect(self.scrollbar_context_menu)
|
||||
self.bridge.close_prep_finished.connect(self.close_prep_finished)
|
||||
self.bridge.highlights_changed.connect(self.highlights_changed)
|
||||
self.bridge.open_url.connect(safe_open_url)
|
||||
self.bridge.export_shortcut_map.connect(self.set_shortcut_map)
|
||||
self.shortcut_map = {}
|
||||
self.bridge.report_cfi.connect(self.call_callback)
|
||||
|
@ -18,7 +18,6 @@ from widgets import create_button
|
||||
|
||||
# TODO:
|
||||
# Custom colors for highlights
|
||||
# Google lookup for selections
|
||||
# Export all annots as plain text/JSON
|
||||
# Fix selection bar remaining open after removing highlight
|
||||
|
||||
|
@ -46,6 +46,7 @@ class SelectionBar:
|
||||
bar.appendChild(cb('copy', _('Copy to clipboard'), self.copy_to_clipboard))
|
||||
bar.appendChild(cb('library', _('Lookup/search selected word'), self.lookup))
|
||||
bar.appendChild(cb('highlight', _('Highlight selection'), self.create_highlight))
|
||||
bar.appendChild(cb('search', _('Search for selection on the net'), self.internet_search))
|
||||
bar.appendChild(cb('close', _('Clear the selection'), self.clear_selection))
|
||||
self.show_notes(bar_container, notes)
|
||||
return bar_container
|
||||
@ -83,6 +84,13 @@ class SelectionBar:
|
||||
else:
|
||||
self.view.overlay.show_word_actions(self.view.currently_showing.selection.text)
|
||||
|
||||
def internet_search(self):
|
||||
text = self.view.currently_showing.selection.text
|
||||
if text:
|
||||
q = encodeURIComponent(text)
|
||||
url = f'https://google.com/search?q={q}'
|
||||
ui_operations.open_url(url)
|
||||
|
||||
def clear_selection(self):
|
||||
self.view.on_handle_shortcut({'name': 'clear_selection'})
|
||||
|
||||
|
@ -75,6 +75,8 @@ class ReadUI:
|
||||
ui_operations.toggle_full_screen = self.toggle_full_screen.bind(self)
|
||||
ui_operations.highlights_changed = self.highlights_changed.bind(self)
|
||||
ui_operations.annotations_synced = self.annotations_synced.bind(self)
|
||||
ui_operations.open_url = def(url):
|
||||
window.open(url, '_blank')
|
||||
|
||||
def on_resize(self):
|
||||
self.view.on_resize()
|
||||
|
@ -9,12 +9,13 @@ from book_list.globals import get_session_data
|
||||
from book_list.item_list import create_item, create_item_list
|
||||
from dom import clear, ensure_id
|
||||
from modals import error_dialog
|
||||
from read_book.globals import ui_operations
|
||||
from widgets import create_button
|
||||
|
||||
|
||||
def lookup(close_panel_func, url):
|
||||
close_panel_func()
|
||||
window.open(url, '_blank')
|
||||
ui_operations.open_url(url)
|
||||
|
||||
|
||||
def toggle_custom_container(container_id, visible):
|
||||
|
@ -345,6 +345,8 @@ if window is window.top:
|
||||
sd.set('footer', defaults.footer)
|
||||
view.update_header_footer()
|
||||
to_python.reset_interface()
|
||||
ui_operations.open_url = def(url):
|
||||
to_python.open_url(url)
|
||||
ui_operations.quit = def():
|
||||
to_python.quit()
|
||||
ui_operations.toggle_lookup = def(force_show):
|
||||
|
Loading…
x
Reference in New Issue
Block a user