Replacing Save Settings on Exit with Settings on Load
This commit is contained in:
8
CLI.py
8
CLI.py
@@ -355,7 +355,7 @@ def parse_settings():
|
||||
},
|
||||
"randomSprite": False,
|
||||
"outputpath": os.path.join("."),
|
||||
"saveonexit": "ask",
|
||||
"settingsonload": "saved",
|
||||
"outputname": "",
|
||||
"startinventoryarray": {},
|
||||
"notes": ""
|
||||
@@ -367,6 +367,12 @@ def parse_settings():
|
||||
# read saved settings file if it exists and set these
|
||||
settings_path = os.path.join(".", "resources", "user", "settings.json")
|
||||
settings = apply_settings_file(settings, settings_path)
|
||||
if settings["settingsonload"] == "saved":
|
||||
settings_path = os.path.join(".", "resources", "user", "saved.json")
|
||||
settings = apply_settings_file(settings, settings_path)
|
||||
elif settings["settingsonload"] == "lastused":
|
||||
settings_path = os.path.join(".", "resources", "user", "last.json")
|
||||
settings = apply_settings_file(settings, settings_path)
|
||||
return settings
|
||||
|
||||
# Priority fallback is:
|
||||
|
||||
51
Gui.py
51
Gui.py
@@ -37,19 +37,31 @@ def check_python_version(fish):
|
||||
messagebox.showinfo("Door Shuffle " + ESVersion, fish.translate("cli","cli","old.python.version") % sys.version)
|
||||
|
||||
|
||||
def guiMain(args=None):
|
||||
# Save settings to file
|
||||
def save_settings(args):
|
||||
user_resources_path = os.path.join(".", "resources", "user")
|
||||
settings_path = os.path.join(user_resources_path)
|
||||
if not os.path.exists(settings_path):
|
||||
os.makedirs(settings_path)
|
||||
for widget in self.pages["adjust"].content.widgets:
|
||||
args["adjust." + widget] = self.pages["adjust"].content.widgets[widget].storageVar.get()
|
||||
with open(os.path.join(settings_path, "settings.json"), "w+") as f:
|
||||
f.write(json.dumps(args, indent=2))
|
||||
os.chmod(os.path.join(settings_path, "settings.json"),0o755)
|
||||
# Save settings to file
|
||||
def save_settings(gui, args, filename):
|
||||
user_resources_path = os.path.join(".", "resources", "user")
|
||||
settings_path = os.path.join(user_resources_path)
|
||||
if not os.path.exists(settings_path):
|
||||
os.makedirs(settings_path)
|
||||
output_args = {}
|
||||
settings = ["create_rom", "suppress_rom", "bps", "create_spoiler", "suppress_spoiler",
|
||||
"calc_playthrough", "skip_playthrough", "print_custom_yaml", "settingsonload",
|
||||
"rom", "enemizercli", "outputpath"]
|
||||
if filename == "settings.json":
|
||||
for s in settings:
|
||||
output_args[s] = args[s]
|
||||
for widget in gui.pages["adjust"].content.widgets:
|
||||
output_args["adjust." + widget] = gui.pages["adjust"].content.widgets[widget].storageVar.get()
|
||||
else:
|
||||
for k, v in args.items():
|
||||
if k not in settings and not k.startswith("adjust."):
|
||||
output_args[k] = v
|
||||
with open(os.path.join(settings_path, filename), "w+") as f:
|
||||
f.write(json.dumps(output_args, indent=2))
|
||||
os.chmod(os.path.join(settings_path, filename),0o755)
|
||||
|
||||
|
||||
def guiMain(args=None):
|
||||
# Save settings from GUI
|
||||
def save_settings_from_gui(confirm):
|
||||
gui_args = vars(create_guiargs(self))
|
||||
@@ -57,23 +69,14 @@ def guiMain(args=None):
|
||||
gui_args['sprite'] = 'random'
|
||||
elif gui_args['sprite']:
|
||||
gui_args['sprite'] = gui_args['sprite'].name
|
||||
save_settings(gui_args)
|
||||
save_settings(self, gui_args, "saved.json")
|
||||
save_settings(self, gui_args, "settings.json")
|
||||
if confirm:
|
||||
messagebox.showinfo("Overworld Shuffle " + ORVersion, "Settings saved from GUI.")
|
||||
|
||||
# routine for exiting the app
|
||||
def guiExit():
|
||||
skip_exit = False
|
||||
if self.settings['saveonexit'] == 'ask':
|
||||
dosave = messagebox.askyesnocancel("Overworld Shuffle " + ORVersion, "Save settings before exit?")
|
||||
if dosave:
|
||||
save_settings_from_gui(True)
|
||||
if dosave is None:
|
||||
skip_exit = True
|
||||
elif self.settings['saveonexit'] == 'always':
|
||||
save_settings_from_gui(False)
|
||||
if not skip_exit:
|
||||
sys.exit(0)
|
||||
sys.exit(0)
|
||||
|
||||
# make main window
|
||||
# add program title & version number
|
||||
|
||||
@@ -575,11 +575,11 @@
|
||||
"action": "store_true",
|
||||
"type": "bool"
|
||||
},
|
||||
"saveonexit": {
|
||||
"settingsonload": {
|
||||
"choices": [
|
||||
"ask",
|
||||
"always",
|
||||
"never"
|
||||
"default",
|
||||
"saved",
|
||||
"lastused"
|
||||
]
|
||||
},
|
||||
"outputname": {},
|
||||
|
||||
@@ -236,10 +236,10 @@
|
||||
"randomizer.generation.calcplaythrough": "Calculate Playthrough",
|
||||
"randomizer.generation.print_custom_yaml": "Print Customizer File",
|
||||
|
||||
"randomizer.generation.saveonexit": "Save Settings on Exit",
|
||||
"randomizer.generation.saveonexit.ask": "Ask Me",
|
||||
"randomizer.generation.saveonexit.always": "Always",
|
||||
"randomizer.generation.saveonexit.never": "Never",
|
||||
"randomizer.generation.settingsonload": "Settings On Load",
|
||||
"randomizer.generation.settingsonload.default": "Default",
|
||||
"randomizer.generation.settingsonload.saved": "Saved",
|
||||
"randomizer.generation.settingsonload.lastused": "Last Used",
|
||||
|
||||
"randomizer.generation.rom": "Base Rom: ",
|
||||
"randomizer.generation.rom.button": "Select Rom",
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"widgets": {
|
||||
"saveonexit": {
|
||||
"settingsonload": {
|
||||
"type": "selectbox",
|
||||
"options": [
|
||||
"ask",
|
||||
"always",
|
||||
"never"
|
||||
"default",
|
||||
"saved",
|
||||
"lastused"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ SETTINGSTOPROCESS = {
|
||||
"createrom": "create_rom",
|
||||
"calcplaythrough": "calc_playthrough",
|
||||
"print_custom_yaml": "print_custom_yaml",
|
||||
"saveonexit": "saveonexit"
|
||||
"settingsonload": "settingsonload"
|
||||
}
|
||||
},
|
||||
"startinventory": {
|
||||
|
||||
@@ -68,6 +68,15 @@ def bottom_frame(self, parent, args=None):
|
||||
self.widgets[key].pack(side=LEFT)
|
||||
|
||||
def generateRom():
|
||||
guiargs = create_guiargs(parent)
|
||||
argsDump = vars(guiargs)
|
||||
from Gui import save_settings
|
||||
if parent.randomSprite.get():
|
||||
argsDump['sprite'] = 'random'
|
||||
elif argsDump['sprite']:
|
||||
argsDump['sprite'] = argsDump['sprite'].name
|
||||
save_settings(parent, argsDump, "last.json")
|
||||
|
||||
guiargs = create_guiargs(parent)
|
||||
# get default values for missing parameters
|
||||
for k,v in vars(parse_cli(['--multi', str(guiargs.multi)])).items():
|
||||
|
||||
Reference in New Issue
Block a user