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