mirror of
https://github.com/onyx-and-iris/nvda-voicemeeter.git
synced 2024-11-22 18:00:50 +00:00
file browsers now open for all config menu items
check if file from pickle file exists, before loading
This commit is contained in:
parent
9b49d97676
commit
401887de46
@ -49,14 +49,15 @@ class NVDAVMWindow(psg.Window):
|
|||||||
if default_config.exists():
|
if default_config.exists():
|
||||||
try:
|
try:
|
||||||
with open(default_config, "rb") as f:
|
with open(default_config, "rb") as f:
|
||||||
if config := pickle.load(f):
|
config = pickle.load(f)
|
||||||
self.vm.set("command.load", config)
|
if Path(config).exists():
|
||||||
self.logger.debug(f"config {config} loaded")
|
self.vm.set("command.load", config)
|
||||||
self.TKroot.after(
|
self.logger.debug(f"config {config} loaded")
|
||||||
200,
|
self.TKroot.after(
|
||||||
self.nvda.speak,
|
200,
|
||||||
f"config {Path(config).stem} has been loaded",
|
self.nvda.speak,
|
||||||
)
|
f"config {Path(config).stem} has been loaded",
|
||||||
|
)
|
||||||
except EOFError:
|
except EOFError:
|
||||||
self.logger.debug("no data in default bin. silently continuing...")
|
self.logger.debug("no data in default bin. silently continuing...")
|
||||||
|
|
||||||
@ -120,6 +121,72 @@ class NVDAVMWindow(psg.Window):
|
|||||||
self["ASIO BUFFER"].bind("<space>", "||KEY SPACE", propagate=False)
|
self["ASIO BUFFER"].bind("<space>", "||KEY SPACE", propagate=False)
|
||||||
self["ASIO BUFFER"].bind("<Return>", "||KEY ENTER", propagate=False)
|
self["ASIO BUFFER"].bind("<Return>", "||KEY ENTER", propagate=False)
|
||||||
|
|
||||||
|
def popup_save_as(self, message, title=None, initial_folder=None):
|
||||||
|
layout = [
|
||||||
|
[psg.Text(message)],
|
||||||
|
[
|
||||||
|
psg.Input(key="Text Input"),
|
||||||
|
psg.FileSaveAs("Browse", initial_folder=str(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()
|
||||||
|
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()
|
||||||
|
if filepath:
|
||||||
|
return Path(filepath)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""
|
"""
|
||||||
Parses the event string and matches it to events
|
Parses the event string and matches it to events
|
||||||
@ -151,126 +218,38 @@ class NVDAVMWindow(psg.Window):
|
|||||||
"Audio Engine restarted",
|
"Audio Engine restarted",
|
||||||
)
|
)
|
||||||
case [["Save", "Settings"], ["MENU"]]:
|
case [["Save", "Settings"], ["MENU"]]:
|
||||||
|
initial_folder = Path.home() / "Documents" / "Voicemeeter"
|
||||||
def popup_get_text(message, title=None):
|
if filepath := self.popup_save_as("Filename", title="Save As", initial_folder=initial_folder):
|
||||||
layout = [
|
self.vm.set("command.save", str(filepath))
|
||||||
[psg.Text(message)],
|
self.logger.debug(f"saving config file to {filepath}")
|
||||||
[psg.Input(key="Text Input")],
|
|
||||||
[psg.Button("Ok"), psg.Button("Cancel")],
|
|
||||||
]
|
|
||||||
window = psg.Window(title, layout, finalize=True)
|
|
||||||
window["Text Input"].bind("<FocusIn>", "||FOCUS IN")
|
|
||||||
window["Ok"].bind("<FocusIn>", "||FOCUS IN")
|
|
||||||
window["Cancel"].bind("<FocusIn>", "||FOCUS IN")
|
|
||||||
filename = 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":
|
|
||||||
filename = values["Text Input"]
|
|
||||||
break
|
|
||||||
window.close()
|
|
||||||
return filename
|
|
||||||
|
|
||||||
filename = popup_get_text("Filename", title="Save As")
|
|
||||||
if filename:
|
|
||||||
configpath = Path.home() / "Documents" / "Voicemeeter" / f"{filename.removesuffix('xml')}.xml"
|
|
||||||
self.vm.set("command.save", str(configpath))
|
|
||||||
self.logger.debug(f"saving config file to {configpath}")
|
|
||||||
self.TKroot.after(
|
self.TKroot.after(
|
||||||
200,
|
200,
|
||||||
self.nvda.speak,
|
self.nvda.speak,
|
||||||
f"config file {filename} has been saved",
|
f"config file {filepath.stem} has been saved",
|
||||||
)
|
)
|
||||||
case [["Load", "Settings"], ["MENU"]]:
|
case [["Load", "Settings"], ["MENU"]]:
|
||||||
|
initial_folder = Path.home() / "Documents" / "Voicemeeter"
|
||||||
def popup_get_file(message, title=None):
|
if filepath := self.popup_files_browse(
|
||||||
layout = [
|
"Filename", title="Load Settings", initial_folder=initial_folder
|
||||||
[psg.Text(message)],
|
):
|
||||||
[psg.Input(key="Text Input"), psg.FilesBrowse("Browse")],
|
self.vm.set("command.load", str(filepath))
|
||||||
[psg.Button("Ok"), psg.Button("Cancel")],
|
self.logger.debug(f"loading config file from {filepath}")
|
||||||
]
|
|
||||||
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")
|
|
||||||
filename = 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":
|
|
||||||
filename = values["Text Input"]
|
|
||||||
break
|
|
||||||
window.close()
|
|
||||||
return filename
|
|
||||||
|
|
||||||
configpath = Path.home() / "Documents" / "Voicemeeter"
|
|
||||||
filename = popup_get_file("Filename", title="Load Settings")
|
|
||||||
if filename:
|
|
||||||
configpath = configpath / filename
|
|
||||||
self.vm.set("command.load", str(configpath))
|
|
||||||
self.logger.debug(f"loading config file from {configpath}")
|
|
||||||
self.TKroot.after(
|
self.TKroot.after(
|
||||||
200,
|
200,
|
||||||
self.nvda.speak,
|
self.nvda.speak,
|
||||||
f"config file {Path(filename).stem} has been loaded",
|
f"config file {filepath.stem} has been loaded",
|
||||||
)
|
)
|
||||||
case [["Load", "Settings", "on", "Startup"], ["MENU"]]:
|
case [["Load", "Settings", "on", "Startup"], ["MENU"]]:
|
||||||
|
initial_folder = Path.home() / "Documents" / "Voicemeeter"
|
||||||
def popup_get_text(message, title=None):
|
if filename := self.popup_files_browse(
|
||||||
layout = [
|
"Filename", title="Load on startup", initial_folder=initial_folder
|
||||||
[psg.Text(message)],
|
):
|
||||||
[psg.Input(key="Text Input")],
|
|
||||||
[psg.Button("Ok"), psg.Button("Cancel")],
|
|
||||||
]
|
|
||||||
window = psg.Window(title, layout, finalize=True)
|
|
||||||
window["Text Input"].bind("<FocusIn>", "||FOCUS IN")
|
|
||||||
window["Ok"].bind("<FocusIn>", "||FOCUS IN")
|
|
||||||
window["Cancel"].bind("<FocusIn>", "||FOCUS IN")
|
|
||||||
filename = 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":
|
|
||||||
filename = values["Text Input"]
|
|
||||||
break
|
|
||||||
window.close()
|
|
||||||
return filename
|
|
||||||
|
|
||||||
filename = popup_get_text("Filename", title="Load on startup")
|
|
||||||
if filename:
|
|
||||||
configpath = Path.home() / "Documents" / "Voicemeeter" / f"{filename.removesuffix('xml')}.xml"
|
|
||||||
with open(self.DEFAULT_BIN, "wb") as f:
|
with open(self.DEFAULT_BIN, "wb") as f:
|
||||||
pickle.dump(str(configpath), f)
|
pickle.dump(str(filename), f)
|
||||||
self.TKroot.after(
|
self.TKroot.after(
|
||||||
200,
|
200,
|
||||||
self.nvda.speak,
|
self.nvda.speak,
|
||||||
f"config {filename} set as default on startup",
|
f"config {filename.stem} set as default on startup",
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
with open(self.DEFAULT_BIN, "wb") as f:
|
with open(self.DEFAULT_BIN, "wb") as f:
|
||||||
|
Loading…
Reference in New Issue
Block a user