Fix bug in menu so that first item in submenus gets read automatically.
This commit is contained in:
@@ -97,6 +97,14 @@ def build_game_actions(entry):
|
||||
return actions
|
||||
|
||||
|
||||
def submenu_command(callback):
|
||||
def wrapped():
|
||||
return callback()
|
||||
|
||||
wrapped.opensSubmenu = True
|
||||
return wrapped
|
||||
|
||||
|
||||
def run_service_action(action, serviceName, helper=SERVICE_STATE_HELPER, logPath=SERVICE_ACTION_LOG):
|
||||
command = ["sudo", "-n", str(helper), action, serviceName]
|
||||
result = subprocess.run(command, capture_output=True, text=True, check=False)
|
||||
@@ -785,9 +793,7 @@ class VoicedMenu:
|
||||
self.currentItemIndices = {sectionName: 0}
|
||||
self.menuSections = {sectionName: actions + [("Back", self.restore_saved_menu)]}
|
||||
self.draw_menu()
|
||||
self.announce_current_section()
|
||||
time.sleep(0.5)
|
||||
self.announce_current_item(interrupt=False)
|
||||
self.announce_current_item()
|
||||
|
||||
def show_game_actions(self, gameEntry):
|
||||
"""Show available actions for a game."""
|
||||
@@ -996,14 +1002,16 @@ class VoicedMenu:
|
||||
if 0 <= index < len(items):
|
||||
name, command = items[index]
|
||||
|
||||
# Announce we're launching the program
|
||||
self.speak(f"Launching {name}")
|
||||
|
||||
# Check if command is a function (for service toggles and other functions)
|
||||
if callable(command):
|
||||
if not getattr(command, "opensSubmenu", False):
|
||||
self.speak(f"Launching {name}")
|
||||
command()
|
||||
return
|
||||
|
||||
# Announce we're launching the program
|
||||
self.speak(f"Launching {name}")
|
||||
|
||||
# Save current terminal state before any changes
|
||||
savedTerminalState = None
|
||||
try:
|
||||
@@ -1373,9 +1381,9 @@ class VoicedMenu:
|
||||
def configure_system_menu(menu):
|
||||
"""Add the nested System menu."""
|
||||
menu.add_section("System")
|
||||
menu.add_item("System", "Settings", menu.show_settings_menu)
|
||||
menu.add_item("System", "Services", menu.show_services_menu)
|
||||
menu.add_item("System", "Power", menu.show_power_menu)
|
||||
menu.add_item("System", "Settings", submenu_command(menu.show_settings_menu))
|
||||
menu.add_item("System", "Services", submenu_command(menu.show_services_menu))
|
||||
menu.add_item("System", "Power", submenu_command(menu.show_power_menu))
|
||||
|
||||
|
||||
# Example usage
|
||||
@@ -1387,7 +1395,7 @@ if __name__ == "__main__":
|
||||
menu.add_item(
|
||||
gameEntry.section,
|
||||
gameEntry.name,
|
||||
lambda entry=gameEntry: menu.show_game_actions(entry),
|
||||
submenu_command(lambda entry=gameEntry: menu.show_game_actions(entry)),
|
||||
)
|
||||
|
||||
menu.add_section("Emulators")
|
||||
|
||||
Reference in New Issue
Block a user