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
This commit is contained in:
onyx-and-iris 2023-09-01 23:20:36 +01:00
parent 401887de46
commit 4f4a577af9

View File

@ -125,64 +125,32 @@ class NVDAVMWindow(psg.Window):
layout = [ layout = [
[psg.Text(message)], [psg.Text(message)],
[ [
psg.Input(key="Text Input"),
psg.FileSaveAs("Browse", initial_folder=str(initial_folder), file_types=(("XML", ".xml"),)), 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 = psg.Window(title, layout, finalize=True)
window["Text Input"].bind("<FocusIn>", "||FOCUS IN")
window["Browse"].bind("<FocusIn>", "||FOCUS IN") window["Browse"].bind("<FocusIn>", "||FOCUS IN")
window["Ok"].bind("<FocusIn>", "||FOCUS IN") window["Browse"].bind("<Return>", "||KEY ENTER")
window["Cancel"].bind("<FocusIn>", "||FOCUS IN") window["Cancel"].bind("<FocusIn>", "||FOCUS IN")
window["Cancel"].bind("<Return>", "||KEY ENTER")
filepath = None filepath = None
while True: while True:
event, values = window.read() event, values = window.read()
if event in (psg.WIN_CLOSED, "Cancel"): if event in (psg.WIN_CLOSED, "Cancel"):
break break
if event.endswith("||FOCUS IN"): if event.endswith("||FOCUS IN"):
if values["Browse"]:
filepath = values["Browse"]
break
label = event.split("||")[0] label = event.split("||")[0]
self.TKroot.after( self.TKroot.after(
200 if label == "Text Input" else 1, 200 if label == "Edit" else 1,
self.nvda.speak, self.nvda.speak,
label, label,
) )
elif event == "Ok": elif event.endswith("||KEY ENTER"):
filepath = values["Text Input"] window.find_element_with_focus().click()
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("<FocusIn>", "||FOCUS IN")
window["Browse"].bind("<FocusIn>", "||FOCUS IN")
window["Ok"].bind("<FocusIn>", "||FOCUS IN")
window["Cancel"].bind("<FocusIn>", "||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
window.close() window.close()
if filepath: if filepath:
return Path(filepath) return Path(filepath)
@ -219,7 +187,9 @@ class NVDAVMWindow(psg.Window):
) )
case [["Save", "Settings"], ["MENU"]]: case [["Save", "Settings"], ["MENU"]]:
initial_folder = Path.home() / "Documents" / "Voicemeeter" 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.vm.set("command.save", str(filepath))
self.logger.debug(f"saving config file to {filepath}") self.logger.debug(f"saving config file to {filepath}")
self.TKroot.after( self.TKroot.after(
@ -229,9 +199,14 @@ class NVDAVMWindow(psg.Window):
) )
case [["Load", "Settings"], ["MENU"]]: case [["Load", "Settings"], ["MENU"]]:
initial_folder = Path.home() / "Documents" / "Voicemeeter" initial_folder = Path.home() / "Documents" / "Voicemeeter"
if filepath := self.popup_files_browse( if filepath := psg.popup_get_file(
"Filename", title="Load Settings", initial_folder=initial_folder "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.vm.set("command.load", str(filepath))
self.logger.debug(f"loading config file from {filepath}") self.logger.debug(f"loading config file from {filepath}")
self.TKroot.after( self.TKroot.after(
@ -241,15 +216,20 @@ class NVDAVMWindow(psg.Window):
) )
case [["Load", "Settings", "on", "Startup"], ["MENU"]]: case [["Load", "Settings", "on", "Startup"], ["MENU"]]:
initial_folder = Path.home() / "Documents" / "Voicemeeter" initial_folder = Path.home() / "Documents" / "Voicemeeter"
if filename := self.popup_files_browse( if filepath := psg.popup_get_file(
"Filename", title="Load on startup", initial_folder=initial_folder "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: with open(self.DEFAULT_BIN, "wb") as f:
pickle.dump(str(filename), f) pickle.dump(str(filepath), f)
self.TKroot.after( self.TKroot.after(
200, 200,
self.nvda.speak, self.nvda.speak,
f"config {filename.stem} set as default on startup", f"config {filepath.stem} set as default on startup",
) )
else: else:
with open(self.DEFAULT_BIN, "wb") as f: with open(self.DEFAULT_BIN, "wb") as f: