From 086fbc1b8c581b9329f241a6ca37352cc4b3a0fb Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 14 Sep 2023 13:46:26 +0100 Subject: [PATCH] start laying out nested tab structure focus in events added for tabgroups focus the settings tab on startup --- src/nvda_voicemeeter/builder.py | 43 ++++++++--- src/nvda_voicemeeter/window.py | 128 ++++++++++++++++++-------------- 2 files changed, 106 insertions(+), 65 deletions(-) diff --git a/src/nvda_voicemeeter/builder.py b/src/nvda_voicemeeter/builder.py index 36561a9..3f9be22 100644 --- a/src/nvda_voicemeeter/builder.py +++ b/src/nvda_voicemeeter/builder.py @@ -2,7 +2,6 @@ import PySimpleGUI as psg from .util import ( get_asio_checkbox_index, - get_asio_samples_list, get_input_device_list, get_insert_checkbox_index, get_output_device_list, @@ -41,25 +40,49 @@ class Builder: for step in steps: layout0.append([step()]) - layout1 = [] + layout1_1 = [] steps = (self.make_tab1_rows,) for step in steps: - layout1.append([step()]) + layout1_1.append([step()]) - layout2 = [] + layout2_1 = [] steps = (self.make_tab2_rows,) for step in steps: - layout2.append([step()]) + layout2_1.append([step()]) - layout3 = [] + layout3_1 = [] steps = (self.make_tab3_rows,) for step in steps: - layout3.append([step()]) + layout3_1.append([step()]) - layouts = [layout0, layout1, layout2, layout3] + def _make_inner_tabgroup(layouts, identifier) -> psg.TabGroup: + inner_layout = [] + for i, tabname in enumerate(("buttons", "sliders")): + inner_layout.append([psg.Tab(tabname.capitalize(), layouts[i], key=f"tab||{identifier}||{tabname}")]) + return psg.TabGroup( + inner_layout, + change_submits=True, + enable_events=True, + key=f"tabgroup||{identifier}", + ) - tabs = [psg.Tab(identifier, layouts[i], key=identifier) for i, identifier in enumerate(get_tabs_labels())] - tab_group = psg.TabGroup([tabs], change_submits=True, key="tabs") + def _make_tabs(identifier) -> psg.Tab: + match identifier: + case "Settings": + return psg.Tab("Settings", layout0, key="tab||Settings") + case "Physical Strip": + tabgroup = _make_inner_tabgroup((layout1_1, []), identifier) + case "Virtual Strip": + tabgroup = _make_inner_tabgroup((layout2_1, []), identifier) + case "Buses": + tabgroup = _make_inner_tabgroup((layout3_1, []), identifier) + return psg.Tab(identifier, [[tabgroup]], key=f"tab||{identifier}") + + tabs = [] + for tab in get_tabs_labels(): + tabs.append(_make_tabs(tab)) + + tab_group = psg.TabGroup([tabs], change_submits=True, enable_events=True, key="tabgroup") return [[menu], [tab_group]] diff --git a/src/nvda_voicemeeter/window.py b/src/nvda_voicemeeter/window.py index 23d10b0..a535a35 100644 --- a/src/nvda_voicemeeter/window.py +++ b/src/nvda_voicemeeter/window.py @@ -23,6 +23,7 @@ from .util import ( get_channel_identifier_list, get_insert_checkbox_index, get_patch_composite_list, + get_tabs_labels, open_context_menu_for_buttonmenu, ) @@ -65,6 +66,7 @@ class NVDAVMWindow(psg.Window): [self[f"PATCH COMPOSITE||PC{i + 1}"].Widget.config(**buttonmenu_opts) for i in range(self.kind.phys_out)] self.register_events() + self["tabgroup"].set_focus() def __enter__(self): settings_path = Path.cwd() / self.SETTINGS @@ -123,7 +125,10 @@ class NVDAVMWindow(psg.Window): """Registers events for widgets""" # TABS - self["tabs"].bind("", "||FOCUS IN") + self["tabgroup"].bind("", "||FOCUS IN") + for tabname in get_tabs_labels()[1:]: + self[f"tabgroup||{tabname}"].bind("", "||FOCUS IN") + self[f"tabgroup||{tabname}"].bind("", "||KEY SHIFT TAB") self.bind("", "CTRL-TAB") self.bind("", "CTRL-SHIFT-TAB") self.bind("", "CTRL-A") @@ -357,17 +362,16 @@ class NVDAVMWindow(psg.Window): self.logger.debug(f"values::{values}") if event in (psg.WIN_CLOSED, "Exit"): break - elif event == "tabs": - self.nvda.speak(f"tab {values['tabs']}") match parsed_cmd := self.parser.match.parseString(event): # Focus tabgroup case ["CTRL-TAB"] | ["CTRL-SHIFT-TAB"]: - self["tabs"].set_focus() + self["tabgroup"].set_focus() + self.nvda.speak(f"{values['tabgroup']}") # Rename popups case ["F2:113"]: - tab = values["tabs"] + tab = values["tabgroup"] if tab in ("Physical Strip", "Virtual Strip", "Buses"): data = self.popup_rename("Label", title=f"Rename {tab}", tab=tab) if not data: # cancel was pressed @@ -452,11 +456,18 @@ class NVDAVMWindow(psg.Window): else: with open(self.SETTINGS, "wb") as f: f.truncate() - self.logger.debug("default bin was truncated") + self.logger.debug("settings.json was truncated") # Tabs - case [["tabs"], ["FOCUS", "IN"]]: - self.nvda.speak(f"tab {values['tabs']}") + case ["tabgroup"] | [["tabgroup"], ["FOCUS", "IN"]]: + if self.find_element_with_focus() is None: + self.nvda.speak(f"{values['tabgroup']}") + case [["tabgroup"], tabname] | [["tabgroup"], tabname, ["FOCUS", "IN"]]: + if self.find_element_with_focus() is None: + name = " ".join(tabname) + self.nvda.speak(f"{values[f'tabgroup||{name}']}") + case [["tabgroup"], _, ["KEY", "SHIFT", "TAB"]]: + self.nvda.speak(values["tabgroup"]) # Hardware In case [["HARDWARE", "IN"], [key]]: @@ -475,7 +486,8 @@ class NVDAVMWindow(psg.Window): f"HARDWARE IN {key} set {phonetic.get(driver, driver)} {device_name}", ) case [["HARDWARE", "IN"], [key], ["FOCUS", "IN"]]: - self.nvda.speak(f"HARDWARE INPUT {key} {self.cache['hw_ins'][f'HARDWARE IN||{key}']}") + if self.find_element_with_focus() is not None: + self.nvda.speak(f"HARDWARE INPUT {key} {self.cache['hw_ins'][f'HARDWARE IN||{key}']}") case [["HARDWARE", "IN"], [key], ["KEY", "SPACE" | "ENTER"]]: open_context_menu_for_buttonmenu(self, f"HARDWARE IN||{key}") @@ -496,7 +508,8 @@ class NVDAVMWindow(psg.Window): f"HARDWARE OUT {key} set {phonetic.get(driver, driver)} {device_name}", ) case [["HARDWARE", "OUT"], [key], ["FOCUS", "IN"]]: - self.nvda.speak(f"HARDWARE OUT {key} {self.cache['hw_outs'][f'HARDWARE OUT||{key}']}") + if self.find_element_with_focus() is not None: + self.nvda.speak(f"HARDWARE OUT {key} {self.cache['hw_outs'][f'HARDWARE OUT||{key}']}") case [["HARDWARE", "OUT"], [key], ["KEY", "SPACE" | "ENTER"]]: open_context_menu_for_buttonmenu(self, f"HARDWARE OUT||{key}") @@ -508,10 +521,11 @@ class NVDAVMWindow(psg.Window): channel = ("left", "right")[int(channel)] self.nvda.speak(f"Patch ASIO {in_num} {channel} set to {val}") case [["ASIO", "CHECKBOX"], [in_num, channel], ["FOCUS", "IN"]]: - val = values[f"ASIO CHECKBOX||{in_num} {channel}"] - channel = ("left", "right")[int(channel)] - num = int(in_num[-1]) - self.nvda.speak(f"Patch ASIO inputs to strips IN#{num} {channel} {val}") + if self.find_element_with_focus() is not None: + val = values[f"ASIO CHECKBOX||{in_num} {channel}"] + channel = ("left", "right")[int(channel)] + num = int(in_num[-1]) + self.nvda.speak(f"Patch ASIO inputs to strips IN#{num} {channel} {val}") # Patch COMPOSITE case [["PATCH", "COMPOSITE"], [key]]: @@ -520,12 +534,13 @@ class NVDAVMWindow(psg.Window): self.vm.patch.composite[index].set(get_patch_composite_list(self.kind).index(val) + 1) self.TKroot.after(200, self.nvda.speak, f"PATCH COMPOSITE {key[-1]} set {val}") case [["PATCH", "COMPOSITE"], [key], ["FOCUS", "IN"]]: - if values[f"PATCH COMPOSITE||{key}"]: - val = values[f"PATCH COMPOSITE||{key}"] - else: - index = int(key[-1]) - 1 - val = get_patch_composite_list(self.kind)[self.vm.patch.composite[index].get() - 1] - self.nvda.speak(f"Patch COMPOSITE {key[-1]} {val}") + if self.find_element_with_focus() is not None: + if values[f"PATCH COMPOSITE||{key}"]: + val = values[f"PATCH COMPOSITE||{key}"] + else: + index = int(key[-1]) - 1 + val = get_patch_composite_list(self.kind)[self.vm.patch.composite[index].get() - 1] + self.nvda.speak(f"Patch COMPOSITE {key[-1]} {val}") case [["PATCH", "COMPOSITE"], [key], ["KEY", "SPACE" | "ENTER"]]: open_context_menu_for_buttonmenu(self, f"PATCH COMPOSITE||{key}") @@ -542,19 +557,20 @@ class NVDAVMWindow(psg.Window): f"PATCH INSERT {in_num} {_patch_insert_channels[int(channel)]} set to {'on' if val else 'off'}" ) case [["INSERT", "CHECKBOX"], [in_num, channel], ["FOCUS", "IN"]]: - index = get_insert_checkbox_index( - self.kind, - int(channel), - int(in_num[-1]), - ) - val = values[f"INSERT CHECKBOX||{in_num} {channel}"] - channel = _patch_insert_channels[int(channel)] - num = int(in_num[-1]) - self.nvda.speak(f"Patch INSERT IN#{num} {channel} {'on' if val else 'off'}") + if self.find_element_with_focus() is not None: + index = get_insert_checkbox_index( + self.kind, + int(channel), + int(in_num[-1]), + ) + val = values[f"INSERT CHECKBOX||{in_num} {channel}"] + channel = _patch_insert_channels[int(channel)] + num = int(in_num[-1]) + self.nvda.speak(f"Patch INSERT IN#{num} {channel} {'on' if val else 'off'}") # Advanced Settings case ["ADVANCED SETTINGS"] | ["CTRL-A"]: - if values["tabs"] == "Settings": + if values["tabgroup"] == "tab||Settings": self.popup_advanced_settings(title="Advanced Settings") case [["ADVANCED", "SETTINGS"], ["FOCUS", "IN"]]: self.nvda.speak("ADVANCED SETTINGS") @@ -593,25 +609,26 @@ class NVDAVMWindow(psg.Window): self.cache["strip"][f"STRIP {index}||{param}"] = val self.nvda.speak(f"{label} {param} {'on' if val else 'off'}") case [["STRIP", index], [param], ["FOCUS", "IN"]]: - val = self.cache["strip"][f"STRIP {index}||{param}"] - match param: - case "MONO": - if int(index) < self.kind.phys_in: - actual = param.lower() - elif int(index) == self.kind.phys_in + 1: - actual = "k" - else: - actual = "mc" - case _: - actual = param - phonetic = {"k": "karaoke"} - label = self.cache["labels"][f"STRIP {index}||LABEL"] - if actual == "k": - self.nvda.speak( - f"{label} {phonetic.get(actual, actual)} {['off', 'k m', 'k 1', 'k 2'][self.cache['strip'][f'STRIP {int(index)}||{param}']]}" - ) - else: - self.nvda.speak(f"{label} {phonetic.get(actual, actual)} {'on' if val else 'off'}") + if self.find_element_with_focus() is not None: + val = self.cache["strip"][f"STRIP {index}||{param}"] + match param: + case "MONO": + if int(index) < self.kind.phys_in: + actual = param.lower() + elif int(index) == self.kind.phys_in + 1: + actual = "k" + else: + actual = "mc" + case _: + actual = param + phonetic = {"k": "karaoke"} + label = self.cache["labels"][f"STRIP {index}||LABEL"] + if actual == "k": + self.nvda.speak( + f"{label} {phonetic.get(actual, actual)} {['off', 'k m', 'k 1', 'k 2'][self.cache['strip'][f'STRIP {int(index)}||{param}']]}" + ) + else: + self.nvda.speak(f"{label} {phonetic.get(actual, actual)} {'on' if val else 'off'}") case [["STRIP", index], [param], ["KEY", "ENTER"]]: self.find_element_with_focus().click() @@ -664,12 +681,13 @@ class NVDAVMWindow(psg.Window): f"{label} bus mode {phonetic.get(next_bus, next_bus)}", ) case [["BUS", index], [param], ["FOCUS", "IN"]]: - label = self.cache["labels"][f"BUS {index}||LABEL"] - val = self.cache["bus"][f"BUS {index}||{param}"] - if param == "MODE": - self.nvda.speak(f"{label} bus {param} {val}") - else: - self.nvda.speak(f"{label} bus {param} {'on' if val else 'off'}") + if self.find_element_with_focus() is not None: + label = self.cache["labels"][f"BUS {index}||LABEL"] + val = self.cache["bus"][f"BUS {index}||{param}"] + if param == "MODE": + self.nvda.speak(f"{label} bus {param} {val}") + else: + self.nvda.speak(f"{label} bus {param} {'on' if val else 'off'}") case [["BUS", index], [param], ["KEY", "ENTER"]]: self.find_element_with_focus().click()