|
| 1 | +from trame.widgets import vuetify3 as v3 |
| 2 | +from trame.widgets.html import Div, Span |
| 3 | + |
| 4 | +SHORTCUTS = { |
| 5 | + "selection": [ |
| 6 | + (["alpha-a"], "Select all"), |
| 7 | + (["alpha-z"], "Select none"), |
| 8 | + (["alpha-i"], "Invert selection"), |
| 9 | + ], |
| 10 | + "modes": [ |
| 11 | + (["keyboard-tab"], "Switch mode"), |
| 12 | + (["alpha-c"], "Toggle calibration"), |
| 13 | + ], |
| 14 | + "tools": [ |
| 15 | + (["chevron-left", "chevron-right"], "Move time"), |
| 16 | + (["alpha-u", "alpha-d"], "Scale time up and down"), |
| 17 | + (["chevron-up", "chevron-down"], "Scale or calibrate up and down"), |
| 18 | + (["alpha-r"], "Reset scale"), |
| 19 | + (["keyboard-space"], "Next profile"), |
| 20 | + (["alpha-v"], "Next filter"), |
| 21 | + ], |
| 22 | + "annotations": [ |
| 23 | + (["keyboard-return"], "Add annotation"), |
| 24 | + (["alpha-k"], "Delete annotation"), |
| 25 | + (["alpha-p", "alpha-n"], "Change annotation type"), |
| 26 | + (["keyboard-esc"], "Cancel annotation"), |
| 27 | + ], |
| 28 | +} |
| 29 | + |
| 30 | + |
| 31 | +class ShortcutInfo(Div): |
| 32 | + def __init__(self, icons: list[str], desc: str, **kwargs) -> None: |
| 33 | + super().__init__(classes="d-flex justify-space-between pa-2", **kwargs) |
| 34 | + with self: |
| 35 | + with Div(classes="d-flex", style="gap: 8px;"): |
| 36 | + for icon in icons: |
| 37 | + v3.VIcon(icon=f"mdi-{icon}") |
| 38 | + Span(desc, classes="text-body-2") |
| 39 | + |
| 40 | + |
| 41 | +class ShortcutsPanel(Div): |
| 42 | + def __init__(self, **kwargs) -> None: |
| 43 | + super().__init__( |
| 44 | + classes="d-flex justify-end ma-7", style="inset: 0; position: absolute; pointer-events: none;", **kwargs |
| 45 | + ) |
| 46 | + |
| 47 | + self._build_ui() |
| 48 | + |
| 49 | + def _build_ui(self) -> None: |
| 50 | + with self, v3.VDialog(width=400): |
| 51 | + with ( |
| 52 | + v3.Template(v_slot_activator="{ props : activatorProps }"), |
| 53 | + v3.VBtn( |
| 54 | + v_bind="activatorProps", |
| 55 | + icon="mdi-plus", |
| 56 | + raw_attrs=['tabindex="-1"'], |
| 57 | + color="white", |
| 58 | + style="pointer-events: visible;", |
| 59 | + size="small", |
| 60 | + ), |
| 61 | + ): |
| 62 | + v3.VTooltip( |
| 63 | + activator="parent", |
| 64 | + close_delay=100, |
| 65 | + open_delay=500, |
| 66 | + text="Keyboard shortcuts", |
| 67 | + ) |
| 68 | + v3.VIcon(icon="mdi-information-outline") |
| 69 | + |
| 70 | + with v3.VCard(), v3.VCardText(): |
| 71 | + for shortcut_theme, shortcuts in SHORTCUTS.items(): |
| 72 | + Div(shortcut_theme, classes="text-uppercase text-overline") |
| 73 | + for shortcut_icons, shortcut_desc in shortcuts: |
| 74 | + ShortcutInfo(shortcut_icons, shortcut_desc) |
0 commit comments