mirror of
https://github.com/onyx-and-iris/nvda-voicemeeter.git
synced 2024-11-23 02:10:49 +00:00
adds a single menu to restart audio engine
keep track of focus, fixes bug when exiting contex menu
This commit is contained in:
parent
84e349f943
commit
10e99c5f78
@ -17,6 +17,8 @@ class Builder:
|
|||||||
self.kind = self.vm.kind
|
self.kind = self.vm.kind
|
||||||
|
|
||||||
def run(self) -> list:
|
def run(self) -> list:
|
||||||
|
menu = self.make_menu()
|
||||||
|
|
||||||
layout0 = []
|
layout0 = []
|
||||||
if self.kind.name == "basic":
|
if self.kind.name == "basic":
|
||||||
steps = (self.make_tab0_row0,)
|
steps = (self.make_tab0_row0,)
|
||||||
@ -40,7 +42,18 @@ class Builder:
|
|||||||
tab3 = psg.Tab("Virtual Strips", layout2, key="virtual strip")
|
tab3 = psg.Tab("Virtual Strips", layout2, key="virtual strip")
|
||||||
tab_group = psg.TabGroup([[tab1, tab2, tab3]], change_submits=True, key="tabs")
|
tab_group = psg.TabGroup([[tab1, tab2, tab3]], change_submits=True, key="tabs")
|
||||||
|
|
||||||
return [[tab_group]]
|
return [[menu], [tab_group]]
|
||||||
|
|
||||||
|
def make_menu(self) -> psg.Menu:
|
||||||
|
menu_def = [
|
||||||
|
[
|
||||||
|
"&Voicemeeter",
|
||||||
|
[
|
||||||
|
"Restart Audio Engine::MENU",
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
return [[psg.Menu(menu_def, key="menus")]]
|
||||||
|
|
||||||
def make_tab0_row0(self) -> psg.Frame:
|
def make_tab0_row0(self) -> psg.Frame:
|
||||||
"""row0 represents hardware outs"""
|
"""row0 represents hardware outs"""
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
from pyparsing import Group, OneOrMore, Optional, Suppress, Word, alphanums
|
from pyparsing import Group, OneOrMore, Optional, Suppress, Word, alphanums, restOfLine
|
||||||
|
|
||||||
|
|
||||||
class Parser:
|
class Parser:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.widget = Group(OneOrMore(Word(alphanums)))
|
self.widget = Group(OneOrMore(Word(alphanums)))
|
||||||
self.token = Suppress("||")
|
self.widget_token = Suppress("||")
|
||||||
self.identifier = Group(OneOrMore(Word(alphanums)))
|
self.identifier = Group(OneOrMore(Word(alphanums)))
|
||||||
self.event = Group(OneOrMore(Word(alphanums)))
|
self.event = Group(OneOrMore(Word(alphanums)))
|
||||||
self.match = self.widget + self.token + self.identifier + Optional(self.token) + Optional(self.event)
|
self.menu_token = Suppress("::")
|
||||||
|
self.match = (
|
||||||
|
self.widget + self.widget_token + self.identifier + Optional(self.widget_token) + Optional(self.event)
|
||||||
|
| self.identifier + self.menu_token + self.event
|
||||||
|
| restOfLine
|
||||||
|
)
|
||||||
|
@ -29,11 +29,12 @@ class NVDAVMWindow(psg.Window):
|
|||||||
self.parser = Parser()
|
self.parser = Parser()
|
||||||
self.builder = Builder(self)
|
self.builder = Builder(self)
|
||||||
layout = self.builder.run()
|
layout = self.builder.run()
|
||||||
super().__init__(title, layout, finalize=True)
|
super().__init__(title, layout, return_keyboard_events=True, finalize=True)
|
||||||
[self[f"HARDWARE OUT||A{i + 1}"].Widget.config(takefocus=1) for i in range(self.kind.phys_out)]
|
[self[f"HARDWARE OUT||A{i + 1}"].Widget.config(takefocus=1) for i in range(self.kind.phys_out)]
|
||||||
if self.kind.name != "basic":
|
if self.kind.name != "basic":
|
||||||
[self[f"PATCH COMPOSITE||PC{i + 1}"].Widget.config(takefocus=1) for i in range(self.kind.phys_out)]
|
[self[f"PATCH COMPOSITE||PC{i + 1}"].Widget.config(takefocus=1) for i in range(self.kind.phys_out)]
|
||||||
self.register_events()
|
self.register_events()
|
||||||
|
self.current_focus = None
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
@ -94,8 +95,29 @@ class NVDAVMWindow(psg.Window):
|
|||||||
elif event == "tabs":
|
elif event == "tabs":
|
||||||
self.nvda.speak(f"tab {values['tabs']}")
|
self.nvda.speak(f"tab {values['tabs']}")
|
||||||
continue
|
continue
|
||||||
|
elif event in ("Escape:27", "\r"):
|
||||||
|
self.logger.debug("escape key pressed event")
|
||||||
|
self.TKroot.after(100, self.refresh)
|
||||||
|
if self.current_focus:
|
||||||
|
self.current_focus.set_focus()
|
||||||
|
self.logger.debug(f"setting focus to {self.current_focus.Key}")
|
||||||
|
continue
|
||||||
|
|
||||||
match parsed_cmd := self.parser.match.parseString(event):
|
match parsed_cmd := self.parser.match.parseString(event):
|
||||||
|
# Utility
|
||||||
|
case [" "]:
|
||||||
|
self.current_focus = self.find_element_with_focus()
|
||||||
|
|
||||||
|
# Menus
|
||||||
|
case [["Restart", "Audio", "Engine"], ["MENU"]]:
|
||||||
|
self.perform_long_operation(self.vm.command.restart, "ENGINE RESTART||END")
|
||||||
|
case [["ENGINE", "RESTART"], ["END"]]:
|
||||||
|
self.TKroot.after(
|
||||||
|
200,
|
||||||
|
self.nvda.speak,
|
||||||
|
f"Audio Engine restarted",
|
||||||
|
)
|
||||||
|
|
||||||
# Tabs
|
# Tabs
|
||||||
case [["tabs"], ["FOCUS", "IN"]]:
|
case [["tabs"], ["FOCUS", "IN"]]:
|
||||||
self.nvda.speak(f"tab {values['tabs']}")
|
self.nvda.speak(f"tab {values['tabs']}")
|
||||||
@ -181,7 +203,7 @@ class NVDAVMWindow(psg.Window):
|
|||||||
self.nvda.speak(f"STRIP {index} {output} {label if label else ''} {'on' if val else 'off'}")
|
self.nvda.speak(f"STRIP {index} {output} {label if label else ''} {'on' if val else 'off'}")
|
||||||
case _:
|
case _:
|
||||||
self.logger.error(f"Unknown event {event}")
|
self.logger.error(f"Unknown event {event}")
|
||||||
self.logger.debug(parsed_cmd)
|
self.logger.debug(f"parsed::{parsed_cmd}")
|
||||||
|
|
||||||
|
|
||||||
def request_window_object(title, vm):
|
def request_window_object(title, vm):
|
||||||
|
Loading…
Reference in New Issue
Block a user