From 9a45b3c8393a7892240f6d28559f83ce6e6d63d1 Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Mon, 24 Apr 2023 14:56:21 -0400 Subject: [PATCH] Disable and hide hotkeys for top level menus since I can't detect Alt --- menus.py | 7 ++++--- paint.py | 15 ++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/menus.py b/menus.py index 4650899..96d6c1c 100644 --- a/menus.py +++ b/menus.py @@ -6,7 +6,7 @@ from textual.reactive import var from textual.widgets import Button, Static from textual.message import Message from rich.text import Text -from localization.i18n import markup_hotkey, get_hotkey, get_direction +from localization.i18n import markup_hotkey, remove_hotkey, get_hotkey, get_direction def to_snake_case(name: str) -> str: name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) @@ -61,8 +61,9 @@ class Menu(Container): if self.parent_menu: self.parent_menu.focus() elif event.is_printable: - # TODO: alt+hotkey for top level menus, globally. - # This is pretty useless when you have to click a menu first. + # There doesn't seem to be a way to detect if alt is pressed + if isinstance(self, MenuBar): #and not event.alt: + return for item in self.items: if isinstance(item, MenuItem) and item.hotkey and event.character: if item.hotkey.lower() == event.character.lower(): diff --git a/paint.py b/paint.py index d04abf3..a2f6176 100755 --- a/paint.py +++ b/paint.py @@ -30,7 +30,7 @@ from textual.color import Color from menus import MenuBar, Menu, MenuItem, Separator from windows import Window, DialogWindow, CharacterSelectorDialogWindow, MessageBox, get_warning_icon from edit_colors import EditColorsDialogWindow -from localization.i18n import get as _, load_language +from localization.i18n import get as _, load_language, remove_hotkey from enhanced_directory_tree import EnhancedDirectoryTree observer = None @@ -1786,8 +1786,9 @@ class PaintApp(App[None]): """Add our widgets.""" yield Header() with Container(id="paint"): + # I'm not supporting hotkeys for the top level menus, because I can't detect Alt. yield MenuBar([ - MenuItem(_("&File"), submenu=Menu([ + MenuItem(remove_hotkey(_("&File")), submenu=Menu([ MenuItem(_("&New\tCtrl+N"), self.action_new, 57600, description=_("Creates a new document.")), MenuItem(_("&Open...\tCtrl+O"), self.action_open, 57601, description=_("Opens an existing document.")), MenuItem(_("&Save\tCtrl+S"), self.action_save, 57603, description=_("Saves the active document.")), @@ -1807,7 +1808,7 @@ class PaintApp(App[None]): # MenuItem(_("E&xit\tAlt+F4"), self.action_exit, 57665, description=_("Quits Paint.")), MenuItem(_("E&xit\tCtrl+Q"), self.action_exit, 57665, description=_("Quits Paint.")), ])), - MenuItem(_("&Edit"), submenu=Menu([ + MenuItem(remove_hotkey(_("&Edit")), submenu=Menu([ MenuItem(_("&Undo\tCtrl+Z"), self.action_undo, 57643, description=_("Undoes the last action.")), MenuItem(_("&Repeat\tF4"), self.action_redo, 57644, description=_("Redoes the previously undone action.")), Separator(), @@ -1820,7 +1821,7 @@ class PaintApp(App[None]): MenuItem(_("C&opy To..."), self.action_copy_to, 37663, grayed=True, description=_("Copies the selection to a file.")), MenuItem(_("Paste &From..."), self.action_paste_from, 37664, grayed=True, description=_("Pastes a file into the selection.")), ])), - MenuItem(_("&View"), submenu=Menu([ + MenuItem(remove_hotkey(_("&View")), submenu=Menu([ MenuItem(_("&Tool Box\tCtrl+T"), self.action_toggle_tools_box, 59415, description=_("Shows or hides the tool box.")), MenuItem(_("&Color Box\tCtrl+L"), self.action_toggle_colors_box, 59416, description=_("Shows or hides the color box.")), MenuItem(_("&Status Bar"), self.action_toggle_status_bar, 59393, description=_("Shows or hides the status bar.")), @@ -1836,7 +1837,7 @@ class PaintApp(App[None]): ])), MenuItem(_("&View Bitmap\tCtrl+F"), self.action_view_bitmap, 37673, grayed=True, description=_("Displays the entire picture.")), ])), - MenuItem(_("&Image"), submenu=Menu([ + MenuItem(remove_hotkey(_("&Image")), submenu=Menu([ MenuItem(_("&Flip/Rotate...\tCtrl+R"), self.action_flip_rotate, 37680, grayed=True, description=_("Flips or rotates the picture or a selection.")), MenuItem(_("&Stretch/Skew...\tCtrl+W"), self.action_stretch_skew, 37681, grayed=True, description=_("Stretches or skews the picture or a selection.")), MenuItem(_("&Invert Colors\tCtrl+I"), self.action_invert_colors, 37682, grayed=True, description=_("Inverts the colors of the picture or a selection.")), @@ -1844,10 +1845,10 @@ class PaintApp(App[None]): MenuItem(_("&Clear Image\tCtrl+Shft+N"), self.action_clear_image, 37684, grayed=True, description=_("Clears the picture or selection.")), MenuItem(_("&Draw Opaque"), self.action_draw_opaque, 6868, grayed=True, description=_("Makes the current selection either opaque or transparent.")), ])), - MenuItem(_("&Colors"), submenu=Menu([ + MenuItem(remove_hotkey(_("&Colors")), submenu=Menu([ MenuItem(_("&Edit Colors..."), self.action_edit_colors, 6869, description=_("Creates a new color.")), ])), - MenuItem(_("&Help"), submenu=Menu([ + MenuItem(remove_hotkey(_("&Help")), submenu=Menu([ MenuItem(_("&Help Topics"), self.action_help_topics, 57670, description=_("Displays Help for the current task or command.")), Separator(), MenuItem(_("&About Paint"), self.action_about_paint, 57664, description=_("Displays program information, version number, and copyright.")),