mirror of
https://github.com/chidiwilliams/buzz.git
synced 2026-03-14 22:55:46 +01:00
23 lines
708 B
Python
23 lines
708 B
Python
import typing
|
|
|
|
from PyQt6.QtGui import QAction, QKeySequence
|
|
|
|
|
|
class Action(QAction):
|
|
def setShortcut(
|
|
self,
|
|
shortcut: typing.Union["QKeySequence", "QKeySequence.StandardKey", str, int],
|
|
) -> None:
|
|
super().setShortcut(shortcut)
|
|
self.setToolTip(Action.get_tooltip(self))
|
|
|
|
@classmethod
|
|
def get_tooltip(cls, action: QAction):
|
|
tooltip = action.toolTip()
|
|
shortcut = action.shortcut()
|
|
|
|
if shortcut.isEmpty():
|
|
return tooltip
|
|
|
|
shortcut_text = shortcut.toString(QKeySequence.SequenceFormat.NativeText)
|
|
return f"<p style='white-space:pre'>{tooltip} <code style='font-size:small'>{shortcut_text}</code></p>"
|