From 4f4a577af9ab70bea1409a98a20cbe5b1706b375 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 1 Sep 2023 23:20:36 +0100 Subject: [PATCH] removed popup for file browse now it opens the file browser directly popup_save_as reworked. input box removed. return binds for browse,cancel added --- src/nvda_voicemeeter/window.py | 76 +++++++++++++--------------------- 1 file changed, 28 insertions(+), 48 deletions(-) diff --git a/src/nvda_voicemeeter/window.py b/src/nvda_voicemeeter/window.py index c1c4aee..6ae6617 100644 --- a/src/nvda_voicemeeter/window.py +++ b/src/nvda_voicemeeter/window.py @@ -125,64 +125,32 @@ class NVDAVMWindow(psg.Window): layout = [ [psg.Text(message)], [ - psg.Input(key="Text Input"), psg.FileSaveAs("Browse", initial_folder=str(initial_folder), file_types=(("XML", ".xml"),)), + psg.Button("Cancel"), ], - [psg.Button("Ok"), psg.Button("Cancel")], ] window = psg.Window(title, layout, finalize=True) - window["Text Input"].bind("", "||FOCUS IN") window["Browse"].bind("", "||FOCUS IN") - window["Ok"].bind("", "||FOCUS IN") + window["Browse"].bind("", "||KEY ENTER") window["Cancel"].bind("", "||FOCUS IN") + window["Cancel"].bind("", "||KEY ENTER") filepath = None while True: event, values = window.read() if event in (psg.WIN_CLOSED, "Cancel"): break if event.endswith("||FOCUS IN"): + if values["Browse"]: + filepath = values["Browse"] + break label = event.split("||")[0] self.TKroot.after( - 200 if label == "Text Input" else 1, + 200 if label == "Edit" else 1, self.nvda.speak, label, ) - elif event == "Ok": - filepath = values["Text Input"] - break - window.close() - if filepath: - return Path(filepath) - - def popup_files_browse(self, message, title=None, initial_folder=None): - layout = [ - [psg.Text(message)], - [ - psg.Input(key="Text Input"), - psg.FilesBrowse("Browse", initial_folder=initial_folder, file_types=(("XML", ".xml"),)), - ], - [psg.Button("Ok"), psg.Button("Cancel")], - ] - window = psg.Window(title, layout, finalize=True) - window["Text Input"].bind("", "||FOCUS IN") - window["Browse"].bind("", "||FOCUS IN") - window["Ok"].bind("", "||FOCUS IN") - window["Cancel"].bind("", "||FOCUS IN") - filepath = None - while True: - event, values = window.read() - if event in (psg.WIN_CLOSED, "Cancel"): - break - if event.endswith("||FOCUS IN"): - label = event.split("||")[0] - self.TKroot.after( - 200 if label == "Text Input" else 1, - self.nvda.speak, - label, - ) - elif event == "Ok": - filepath = values["Text Input"] - break + elif event.endswith("||KEY ENTER"): + window.find_element_with_focus().click() window.close() if filepath: return Path(filepath) @@ -219,7 +187,9 @@ class NVDAVMWindow(psg.Window): ) case [["Save", "Settings"], ["MENU"]]: initial_folder = Path.home() / "Documents" / "Voicemeeter" - if filepath := self.popup_save_as("Filename", title="Save As", initial_folder=initial_folder): + if filepath := self.popup_save_as( + "Open the file browser", title="Save As", initial_folder=initial_folder + ): self.vm.set("command.save", str(filepath)) self.logger.debug(f"saving config file to {filepath}") self.TKroot.after( @@ -229,9 +199,14 @@ class NVDAVMWindow(psg.Window): ) case [["Load", "Settings"], ["MENU"]]: initial_folder = Path.home() / "Documents" / "Voicemeeter" - if filepath := self.popup_files_browse( - "Filename", title="Load Settings", initial_folder=initial_folder + if filepath := psg.popup_get_file( + "Filename", + title="Load Settings", + initial_folder=initial_folder, + no_window=True, + file_types=(("XML", ".xml"),), ): + filepath = Path(filepath) self.vm.set("command.load", str(filepath)) self.logger.debug(f"loading config file from {filepath}") self.TKroot.after( @@ -241,15 +216,20 @@ class NVDAVMWindow(psg.Window): ) case [["Load", "Settings", "on", "Startup"], ["MENU"]]: initial_folder = Path.home() / "Documents" / "Voicemeeter" - if filename := self.popup_files_browse( - "Filename", title="Load on startup", initial_folder=initial_folder + if filepath := psg.popup_get_file( + "Filename", + title="Load Settings", + initial_folder=initial_folder, + no_window=True, + file_types=(("XML", ".xml"),), ): + filepath = Path(filepath) with open(self.DEFAULT_BIN, "wb") as f: - pickle.dump(str(filename), f) + pickle.dump(str(filepath), f) self.TKroot.after( 200, self.nvda.speak, - f"config {filename.stem} set as default on startup", + f"config {filepath.stem} set as default on startup", ) else: with open(self.DEFAULT_BIN, "wb") as f: