mirror of
https://github.com/onyx-and-iris/nvda-voicemeeter.git
synced 2024-11-25 03:10:50 +00:00
write default_config to json file
This commit is contained in:
parent
7357cacc30
commit
5cc8f1ae3d
2
.gitignore
vendored
2
.gitignore
vendored
@ -171,7 +171,7 @@ banana.py
|
|||||||
potato.py
|
potato.py
|
||||||
|
|
||||||
# persistent storage
|
# persistent storage
|
||||||
default.bin
|
settings.json
|
||||||
|
|
||||||
# quick test
|
# quick test
|
||||||
quick.py
|
quick.py
|
@ -1,5 +1,5 @@
|
|||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import pickle
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import PySimpleGUI as psg
|
import PySimpleGUI as psg
|
||||||
@ -24,7 +24,7 @@ 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"
|
SETTINGS = "settings.json"
|
||||||
|
|
||||||
def __init__(self, title, vm):
|
def __init__(self, title, vm):
|
||||||
self.vm = vm
|
self.vm = vm
|
||||||
@ -49,11 +49,12 @@ class NVDAVMWindow(psg.Window):
|
|||||||
self.register_events()
|
self.register_events()
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
default_config = Path.cwd() / self.DEFAULT_BIN
|
default_config = Path.cwd() / self.SETTINGS
|
||||||
if default_config.exists():
|
if default_config.exists():
|
||||||
try:
|
try:
|
||||||
with open(default_config, "rb") as f:
|
with open(default_config, "r") as f:
|
||||||
config = pickle.load(f)
|
data = json.load(f)
|
||||||
|
config = data["default_config"]
|
||||||
if Path(config).exists():
|
if Path(config).exists():
|
||||||
self.vm.set("command.load", config)
|
self.vm.set("command.load", config)
|
||||||
self.logger.debug(f"config {config} loaded")
|
self.logger.debug(f"config {config} loaded")
|
||||||
@ -62,8 +63,8 @@ class NVDAVMWindow(psg.Window):
|
|||||||
self.nvda.speak,
|
self.nvda.speak,
|
||||||
f"config {Path(config).stem} has been loaded",
|
f"config {Path(config).stem} has been loaded",
|
||||||
)
|
)
|
||||||
except EOFError:
|
except json.JSONDecodeError:
|
||||||
self.logger.debug("no data in default bin. silently continuing...")
|
self.logger.debug("no data in settings.json. silently continuing...")
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@ -305,15 +306,15 @@ class NVDAVMWindow(psg.Window):
|
|||||||
file_types=(("XML", ".xml"),),
|
file_types=(("XML", ".xml"),),
|
||||||
):
|
):
|
||||||
filepath = Path(filepath)
|
filepath = Path(filepath)
|
||||||
with open(self.DEFAULT_BIN, "wb") as f:
|
with open(self.SETTINGS, "w") as f:
|
||||||
pickle.dump(str(filepath), f)
|
json.dump({"default_config": str(filepath)}, f)
|
||||||
self.TKroot.after(
|
self.TKroot.after(
|
||||||
200,
|
200,
|
||||||
self.nvda.speak,
|
self.nvda.speak,
|
||||||
f"config {filepath.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.SETTINGS, "wb") as f:
|
||||||
f.truncate()
|
f.truncate()
|
||||||
self.logger.debug("default bin was truncated")
|
self.logger.debug("default bin was truncated")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user