Preferences: Show the keyboard shortcut for each category in preferences in the tooltip. Fixes #2122257 [[Enhancement] show preferences shortcuts](https://bugs.launchpad.net/calibre/+bug/2122257)

This commit is contained in:
Kovid Goyal 2025-09-25 11:45:50 +05:30
parent f92bfac622
commit 40f5df12cf
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 2 deletions

View File

@ -42,6 +42,7 @@ class PreferencesAction(InterfaceAction):
self.preferences_menu = pm
for x in (self.gui.preferences_action, self.qaction):
x.triggered.connect(self.do_config)
self.action_map = {}
def initialization_complete(self):
# Add the individual preferences to the menu.
@ -60,7 +61,7 @@ class PreferencesAction(InterfaceAction):
current_cat = p.category_order
cm = pm.addMenu(p.gui_category.replace('&', '&&'))
cm.setIcon(config_icon)
self.create_menu_action(cm, p.name, p.gui_name.replace('&', '&&'),
self.action_map[p.name] = self.create_menu_action(cm, p.name, p.gui_name.replace('&', '&&'),
icon=QIcon.ic(p.icon), shortcut=None, shortcut_name=p.gui_name,
triggered=partial(self.do_config, initial_plugin=(p.category, p.name),
close_after_initial=True))

View File

@ -18,6 +18,7 @@ from qt.core import (
QFrame,
QHBoxLayout,
QIcon,
QKeySequence,
QLabel,
QPainter,
QPointF,
@ -150,10 +151,16 @@ class Category(QWidget): # {{{
self.bar.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextUnderIcon)
self._layout.addWidget(self.bar)
self.actions = []
from calibre.gui2.ui import get_gui
iac = get_gui().iactions['Preferences']
for p in plugins:
sc = iac.action_map.get(p.name).shortcut().toString(QKeySequence.SequenceFormat.NativeText)
target = partial(self.triggered, p)
ac = self.bar.addAction(QIcon.ic(p.icon), p.gui_name.replace('&', '&&'), target)
ac.setToolTip(textwrap.fill(p.description))
tt = '<p>' + p.description
if sc:
tt += '<br>' + _('Shortcut: <i>{}').format(sc)
ac.setToolTip(tt)
ac.setWhatsThis(textwrap.fill(p.description))
ac.setStatusTip(p.description)
self.actions.append(ac)