mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Map a few more shortcuts from JS to Qt for the viewer toolbar
Fixes #1946791 [[Enhancement - E-book viewer] Add shortcuts to tooltips of the viewer controls](https://bugs.launchpad.net/calibre/+bug/1946791)
This commit is contained in:
parent
5afde7a808
commit
fae5391146
@ -6,6 +6,16 @@
|
||||
from qt.core import QKeySequence, QMainWindow, Qt
|
||||
|
||||
|
||||
key_name_to_qt_name = {
|
||||
'ArrowRight': 'Right',
|
||||
'ArrowLeft': 'Left',
|
||||
'ArrowUp': 'Up',
|
||||
'ArrowDown': 'Down',
|
||||
'PageUp': 'PgUp',
|
||||
'PageDown': 'PgDown',
|
||||
}
|
||||
|
||||
|
||||
def get_main_window_for(widget):
|
||||
p = widget
|
||||
while p is not None:
|
||||
@ -19,7 +29,8 @@ def index_to_key_sequence(idx):
|
||||
for i, x in enumerate(('ALT', 'CTRL', 'META', 'SHIFT')):
|
||||
if idx[i] == 'y':
|
||||
mods.append(x.capitalize())
|
||||
mods.append(idx[4:])
|
||||
key = idx[4:]
|
||||
mods.append(key_name_to_qt_name.get(key, key))
|
||||
return QKeySequence('+'.join(mods))
|
||||
|
||||
|
||||
|
@ -20,7 +20,6 @@ from calibre.gui2.viewer.shortcuts import index_to_key_sequence
|
||||
from calibre.gui2.viewer.web_view import set_book_path, vprefs
|
||||
from calibre.gui2.widgets2 import Dialog
|
||||
from calibre.utils.icu import primary_sort_key
|
||||
from polyglot.builtins import iteritems
|
||||
|
||||
|
||||
class Action:
|
||||
@ -69,6 +68,7 @@ def all_actions():
|
||||
'toggle_highlights': Action('highlight_only_on.png', _('Browse highlights in book'), 'toggle_highlights'),
|
||||
'select_all': Action('edit-select-all.png', _('Select all text in the current file')),
|
||||
'edit_book': Action('edit_book.png', _('Edit this book'), 'edit_book'),
|
||||
'reload_book': Action('reload.png', _('Reload this book'), 'reload_book'),
|
||||
}
|
||||
all_actions.ans = Actions(amap)
|
||||
return all_actions.ans
|
||||
@ -201,6 +201,7 @@ class ActionsToolBar(ToolBar):
|
||||
self.preferences_action = shortcut_action('preferences')
|
||||
self.metadata_action = shortcut_action('metadata')
|
||||
self.edit_book_action = shortcut_action('edit_book')
|
||||
self.reload_book_action = shortcut_action('reload_book')
|
||||
self.update_mode_action()
|
||||
self.color_scheme_action = a = QAction(aa.color_scheme.icon, aa.color_scheme.text, self)
|
||||
self.color_scheme_menu = m = QMenu(self)
|
||||
@ -253,19 +254,25 @@ class ActionsToolBar(ToolBar):
|
||||
ac.setChecked(visibility_map[k])
|
||||
|
||||
def set_tooltips(self, rmap):
|
||||
for sc, a in iteritems(self.shortcut_actions):
|
||||
if a.isCheckable():
|
||||
continue
|
||||
aliases = {'show_chrome_force': 'show_chrome'}
|
||||
|
||||
def as_text(idx):
|
||||
return index_to_key_sequence(idx).toString(QKeySequence.SequenceFormat.NativeText)
|
||||
|
||||
def set_it(a, sc):
|
||||
x = rmap.get(sc)
|
||||
if x is not None:
|
||||
|
||||
def as_text(idx):
|
||||
return index_to_key_sequence(idx).toString(QKeySequence.SequenceFormat.NativeText)
|
||||
|
||||
keys = sorted(filter(None, map(as_text, x)))
|
||||
if keys:
|
||||
a.setToolTip('{} [{}]'.format(a.text(), ', '.join(keys)))
|
||||
|
||||
for sc, a in self.shortcut_actions.items():
|
||||
sc = aliases.get(sc, sc)
|
||||
set_it(a, sc)
|
||||
|
||||
for a, sc in ((self.forward_action, 'forward'), (self.back_action, 'back'), (self.search_action, 'start_search')):
|
||||
set_it(a, sc)
|
||||
|
||||
def populate_open_menu(self):
|
||||
m = self.open_menu
|
||||
m.clear()
|
||||
|
Loading…
x
Reference in New Issue
Block a user