save,load and load on startup implemented

This commit is contained in:
onyx-and-iris 2023-09-01 03:04:39 +01:00
parent 2de1b379f5
commit 50d2fa3de8
3 changed files with 66 additions and 3 deletions

3
.gitignore vendored
View File

@ -170,5 +170,8 @@ basic.py
banana.py banana.py
potato.py potato.py
# persistent storage
default.bin
# quick test # quick test
quick.py quick.py

View File

@ -63,6 +63,9 @@ class Builder:
"&Voicemeeter", "&Voicemeeter",
[ [
"Restart Audio Engine::MENU", "Restart Audio Engine::MENU",
"Save Settings::MENU",
"Load Settings::MENU",
"Load Settings on Startup ::MENU",
], ],
], ],
] ]
@ -209,7 +212,7 @@ class Builder:
[ [
psg.ButtonMenu( psg.ButtonMenu(
"ASIO BUFFER", "ASIO BUFFER",
size=(12, 2), size=(14, 2),
menu_def=["", samples], menu_def=["", samples],
key="ASIO BUFFER", key="ASIO BUFFER",
) )
@ -271,7 +274,7 @@ class Builder:
"""tab3 row represents bus composite toggle""" """tab3 row represents bus composite toggle"""
def add_strip_outputs(layout): def add_strip_outputs(layout):
layout.append([psg.Button(f"BUSMODE", size=(16, 2), key=f"BUS {i}||MODE")]) layout.append([psg.Button(f"BUSMODE", size=(12, 2), key=f"BUS {i}||MODE")])
buses = list() buses = list()
[step(buses) for step in (add_strip_outputs,)] [step(buses) for step in (add_strip_outputs,)]

View File

@ -1,4 +1,6 @@
import logging import logging
import pickle
from pathlib import Path
import PySimpleGUI as psg import PySimpleGUI as psg
@ -22,6 +24,8 @@ psg.theme("Dark Blue 3")
class NVDAVMWindow(psg.Window): class NVDAVMWindow(psg.Window):
"""Represents the main window of the Voicemeeter NVDA application""" """Represents the main window of the Voicemeeter NVDA application"""
DEFAULT_BIN = "default.bin"
def __init__(self, title, vm): def __init__(self, title, vm):
self.vm = vm self.vm = vm
self.kind = self.vm.kind self.kind = self.vm.kind
@ -41,6 +45,21 @@ class NVDAVMWindow(psg.Window):
self.register_events() self.register_events()
def __enter__(self): def __enter__(self):
default_config = Path.cwd() / self.DEFAULT_BIN
if default_config.exists():
try:
with open(default_config, "rb") as f:
if config := pickle.load(f):
self.vm.set("command.load", config)
self.logger.debug(f"config {config} loaded")
self.TKroot.after(
200,
self.nvda.speak,
f"config {Path(config).stem} has been loaded",
)
except EOFError:
self.logger.debug("no data in default bin. silently continuing...")
return self return self
def __exit__(self, exc_type, exc_value, traceback): def __exit__(self, exc_type, exc_value, traceback):
@ -129,8 +148,46 @@ class NVDAVMWindow(psg.Window):
self.TKroot.after( self.TKroot.after(
200, 200,
self.nvda.speak, self.nvda.speak,
f"Audio Engine restarted", "Audio Engine restarted",
) )
case [["Save", "Settings"], ["MENU"]]:
filename = psg.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(
200,
self.nvda.speak,
f"config file {filename} has been saved",
)
case [["Load", "Settings"], ["MENU"]]:
configpath = Path.home() / "Documents" / "Voicemeeter"
filename = psg.popup_get_file("Load Settings", default_path=str(configpath))
if filename:
configpath = configpath / filename
self.vm.set("command.load", str(configpath))
self.logger.debug(f"loading config file from {configpath}")
self.TKroot.after(
200,
self.nvda.speak,
f"config file {Path(filename).stem} has been loaded",
)
case [["Load", "Settings", "on", "Startup"], ["MENU"]]:
filename = psg.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:
pickle.dump(str(configpath), f)
self.TKroot.after(
200,
self.nvda.speak,
f"config {filename} set as default on startup",
)
else:
with open(self.DEFAULT_BIN, "wb") as f:
f.truncate()
self.logger.debug("default bin was truncated")
# Tabs # Tabs
case [["tabs"], ["FOCUS", "IN"]]: case [["tabs"], ["FOCUS", "IN"]]: