From e6b5bb7e04bca0faa2104b55baa899600a78d38b Mon Sep 17 00:00:00 2001 From: "Mike A. Trethewey" Date: Sat, 15 Feb 2020 06:15:13 -0800 Subject: [PATCH] Streamline guiargs --- gui/bottom.py | 130 +++++++++++++++++++++--------------- gui/loadcliargs.py | 102 ++++++++++++++-------------- gui/randomize/multiworld.py | 19 +++--- gui/widgets.py | 31 +++++---- 4 files changed, 158 insertions(+), 124 deletions(-) diff --git a/gui/bottom.py b/gui/bottom.py index 8ca29586..503cb193 100644 --- a/gui/bottom.py +++ b/gui/bottom.py @@ -88,68 +88,94 @@ def bottom_frame(self, parent, args=None): def create_guiargs(parent): guiargs = Namespace() - guiargs.retro = bool(parent.pages["randomizer"].pages["item"].widgets["retro"].storageVar.get()) - guiargs.mode = parent.pages["randomizer"].pages["item"].widgets["worldstate"].storageVar.get() - guiargs.logic = parent.pages["randomizer"].pages["item"].widgets["logiclevel"].storageVar.get() - guiargs.goal = parent.pages["randomizer"].pages["item"].widgets["goal"].storageVar.get() - guiargs.crystals_gt = parent.pages["randomizer"].pages["item"].widgets["crystals_gt"].storageVar.get() - guiargs.crystals_ganon = parent.pages["randomizer"].pages["item"].widgets["crystals_ganon"].storageVar.get() - guiargs.swords = parent.pages["randomizer"].pages["item"].widgets["weapons"].storageVar.get() - guiargs.difficulty = parent.pages["randomizer"].pages["item"].widgets["itempool"].storageVar.get() - guiargs.item_functionality = parent.pages["randomizer"].pages["item"].widgets["itemfunction"].storageVar.get() - guiargs.timer = parent.pages["randomizer"].pages["item"].widgets["timer"].storageVar.get() - guiargs.progressive = parent.pages["randomizer"].pages["item"].widgets["progressives"].storageVar.get() - guiargs.accessibility = parent.pages["randomizer"].pages["item"].widgets["accessibility"].storageVar.get() - guiargs.algorithm = parent.pages["randomizer"].pages["item"].widgets["sortingalgo"].storageVar.get() - guiargs.openpyramid = bool(parent.pages["randomizer"].pages["entrance"].widgets["openpyramid"].storageVar.get()) - guiargs.shuffleganon = bool(parent.pages["randomizer"].pages["entrance"].widgets["shuffleganon"].storageVar.get()) - guiargs.shuffle = parent.pages["randomizer"].pages["entrance"].widgets["entranceshuffle"].storageVar.get() - - guiargs.shufflepots = bool(parent.pages["randomizer"].pages["enemizer"].widgets["potshuffle"].storageVar.get()) - guiargs.enemizercli = parent.pages["randomizer"].pages["enemizer"].enemizerCLIpathVar.get() - guiargs.shuffleenemies = parent.pages["randomizer"].pages["enemizer"].widgets["enemyshuffle"].storageVar.get() - guiargs.shufflebosses = parent.pages["randomizer"].pages["enemizer"].widgets["bossshuffle"].storageVar.get() - guiargs.enemy_damage = parent.pages["randomizer"].pages["enemizer"].widgets["enemydamage"].storageVar.get() - guiargs.enemy_health = parent.pages["randomizer"].pages["enemizer"].widgets["enemyhealth"].storageVar.get() - - guiargs.mapshuffle = bool(parent.pages["randomizer"].pages["dungeon"].widgets["mapshuffle"].storageVar.get()) - guiargs.compassshuffle = bool(parent.pages["randomizer"].pages["dungeon"].widgets["compassshuffle"].storageVar.get()) - guiargs.keyshuffle = bool(parent.pages["randomizer"].pages["dungeon"].widgets["smallkeyshuffle"].storageVar.get()) - guiargs.bigkeyshuffle = bool(parent.pages["randomizer"].pages["dungeon"].widgets["bigkeyshuffle"].storageVar.get()) - guiargs.door_shuffle = parent.pages["randomizer"].pages["dungeon"].widgets["dungeondoorshuffle"].storageVar.get() - guiargs.experimental = parent.pages["randomizer"].pages["dungeon"].widgets["experimental"].storageVar.get() + # set up settings to gather + # Page::Subpage::GUI-id::param-id + options = { + "randomizer": { + "item": { + "retro": "retro", + "worldstate": "mode", + "logiclevel": "logic", + "goal": "goal", + "crystals_gt": "crystals_gt", + "crystals_ganon": "crystals_ganon", + "weapons": "swords", + "itempool": "difficulty", + "itemfunction": "item_functionality", + "timer": "timer", + "progressives": "progressive", + "accessibility": "accessibility", + "sortingalgo": "algorithm" + }, + "entrance": { + "openpyramid": "openpyramid", + "shuffleganon": "shuffleganon", + "entranceshuffle": "shuffle" + }, + "enemizer": { + "potshuffle": "shufflepots", + "enemyshuffle": "shuffleenemies", + "bossshuffle": "shufflebosses", + "enemydamage": "enemy_damage", + "enemyhealth": "enemy_health" + }, + "dungeon": { + "mapshuffle": "mapshuffle", + "compassshuffle": "compassshuffle", + "smallkeyshuffle": "keyshuffle", + "bigkeyshuffle": "bigkeyshuffle", + "dungeondoorshuffle": "door_shuffle", + "experimental": "experimental" + }, + "multiworld": { + "names": "names" + }, + "gameoptions": { + "hints": "hints", + "nobgm": "disablemusic", + "quickswap": "quickswap", + "heartcolor": "heartcolor", + "heartbeep": "heartbeep", + "menuspeed": "fastmenu", + "owpalettes": "ow_palettes", + "uwpalettes": "uw_palettes" + }, + "generation": { + "spoiler": "create_spoiler", + "suppressrom": "suppress_rom" + } + } + } + for mainpage in options: + for subpage in options[mainpage]: + for widget in options[mainpage][subpage]: + arg = options[mainpage][subpage][widget] + setattr(guiargs, arg, parent.pages[mainpage].pages[subpage].widgets[widget].storageVar.get()) guiargs.multi = int(parent.pages["randomizer"].pages["multiworld"].widgets["worlds"].storageVar.get()) - guiargs.names = parent.pages["randomizer"].pages["multiworld"].namesVar.get() - guiargs.hints = bool(parent.pages["randomizer"].pages["gameoptions"].widgets["hints"].storageVar.get()) - guiargs.disablemusic = bool(parent.pages["randomizer"].pages["gameoptions"].widgets["nobgm"].storageVar.get()) - guiargs.quickswap = bool(parent.pages["randomizer"].pages["gameoptions"].widgets["quickswap"].storageVar.get()) - guiargs.heartcolor = parent.pages["randomizer"].pages["gameoptions"].widgets["heartcolor"].storageVar.get() - guiargs.heartbeep = parent.pages["randomizer"].pages["gameoptions"].widgets["heartbeep"].storageVar.get() - guiargs.fastmenu = parent.pages["randomizer"].pages["gameoptions"].widgets["menuspeed"].storageVar.get() - guiargs.ow_palettes = parent.pages["randomizer"].pages["gameoptions"].widgets["owpalettes"].storageVar.get() - guiargs.uw_palettes = parent.pages["randomizer"].pages["gameoptions"].widgets["uwpalettes"].storageVar.get() - - guiargs.create_spoiler = bool(parent.pages["randomizer"].pages["generation"].widgets["spoiler"].storageVar.get()) - guiargs.skip_playthrough = not bool(parent.pages["randomizer"].pages["generation"].widgets["spoiler"].storageVar.get()) - guiargs.suppress_rom = bool(parent.pages["randomizer"].pages["generation"].widgets["suppressrom"].storageVar.get()) guiargs.rom = parent.pages["randomizer"].pages["generation"].romVar.get() guiargs.custom = bool(parent.pages["randomizer"].pages["generation"].widgets["usecustompool"].storageVar.get()) guiargs.seed = int(parent.frames["bottom"].seedVar.get()) if parent.frames["bottom"].seedVar.get() else None guiargs.count = int(parent.frames["bottom"].widgets["generationcount"].storageVar.get()) if parent.frames["bottom"].widgets["generationcount"].storageVar.get() != '1' else None - guiargs.customitemarray = [int(parent.pages["custom"].content.customWidgets["bow"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["silversupgrade"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["boomerang"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["redmerang"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["hookshot"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["mushroom"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["powder"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["firerod"].storageVar.get()), - int(parent.pages["custom"].content.customWidgets["icerod"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["bombos"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["ether"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["quake"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["lamp"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["hammer"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["shovel"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["flute"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["bugnet"].storageVar.get()), - int(parent.pages["custom"].content.customWidgets["book"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["bottle"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["somaria"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["byrna"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["cape"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["mirror"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["boots"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["powerglove"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["titansmitt"].storageVar.get()), - int(parent.pages["custom"].content.customWidgets["progressiveglove"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["flippers"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["pearl"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["heartpiece"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["heartcontainer"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["sancheart"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["sword1"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["sword2"].storageVar.get()), - int(parent.pages["custom"].content.customWidgets["sword3"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["sword4"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["progressivesword"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["shield1"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["shield2"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["shield3"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["progressiveshield"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["mail2"].storageVar.get()), - int(parent.pages["custom"].content.customWidgets["mail3"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["progressivemail"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["halfmagic"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["quartermagic"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["bombsplus5"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["bombsplus10"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["arrowsplus5"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["arrowsplus10"].storageVar.get()), - int(parent.pages["custom"].content.customWidgets["arrow1"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["arrow10"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["bomb1"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["bomb3"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["rupee1"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["rupee5"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["rupee20"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["rupee50"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["rupee100"].storageVar.get()), - int(parent.pages["custom"].content.customWidgets["rupee300"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["rupoor"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["blueclock"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["greenclock"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["redclock"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["progressivebow"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["bomb10"].storageVar.get()), int(parent.pages["custom"].content.customWidgets["triforcepieces"].storageVar.get()),int(parent.pages["custom"].content.customWidgets["triforcepiecesgoal"].storageVar.get()), - int(parent.pages["custom"].content.customWidgets["triforce"].storageVar.get()),int(parent.pages["custom"].content.customWidgets["rupoorcost"].storageVar.get()),int(parent.pages["custom"].content.customWidgets["generickeys"].storageVar.get())] + customitems = [ + "bow", "silversupgrade", "boomerang", "redmerang", "hookshot", "mushroom", "powder", "firerod", + "icerod", "bombos", "ether", "quake", "lamp", "hammer", "shovel", "flute", "bugnet", + "book", "bottle", "somaria", "byrna", "cape", "mirror", "boots", "powerglove", "titansmitt", + "progressiveglove", "flippers", "pearl", "heartpiece", "heartcontainer", "sancheart", "sword1", "sword2", + "sword3", "sword4", "progressivesword", "shield1", "shield2", "shield3", "progressiveshield", "mail2", + "mail3", "progressivemail", "halfmagic", "quartermagic", "bombsplus5", "bombsplus10", "arrowsplus5", "arrowsplus10", + "arrow1", "arrow10", "bomb1", "bomb3", "rupee1", "rupee5", "rupee20", "rupee50", "rupee100", + "rupee300", "rupoor", "blueclock", "greenclock", "redclock", "progressivebow", "bomb10", "triforcepieces", "triforcepiecesgoal", + "triforce", "rupoorcost", "generickeys" + ] + guiargs.customitemarray = [] + for customitem in customitems: + guiargs.customitemarray.append(int(parent.pages["custom"].content.customWidgets[customitem].storageVar.get())) + guiargs.sprite = parent.pages["randomizer"].pages["gameoptions"].widgets["sprite"]["spriteObject"] guiargs.randomSprite = parent.randomSprite.get() guiargs.outputpath = parent.outputPath.get() diff --git a/gui/loadcliargs.py b/gui/loadcliargs.py index 5ae18c22..26adbde7 100644 --- a/gui/loadcliargs.py +++ b/gui/loadcliargs.py @@ -13,57 +13,57 @@ def loadcliargs(gui, args, settings=None): # set up options to get # Page::Subpage::GUI-id::param-id options = { - "randomizer": { - "item": { - "retro": "retro", - "worldstate": "mode", - "logiclevel": "logic", - "goal": "goal", - "crystals_gt": "crystals_gt", - "crystals_ganon": "crystals_ganon", - "weapons": "swords", - "itempool": "difficulty", - "itemfunction": "item_functionality", - "timer": "timer", - "progressives": "progressive", - "accessibility": "accessibility", - "sortingalgo": "algorithm" - }, - "entrance": { - "openpyramid": "openpyramid", - "shuffleganon": "shuffleganon", - "entranceshuffle": "shuffle" - }, - "enemizer": { - "potshuffle": "shufflepots", - "enemyshuffle": "shuffleenemies", - "bossshuffle": "shufflebosses", - "enemydamage": "enemy_damage", - "enemyhealth": "enemy_health" - }, - "dungeon": { - "mapshuffle": "mapshuffle", - "compassshuffle": "compassshuffle", - "smallkeyshuffle": "keyshuffle", - "bigkeyshuffle": "bigkeyshuffle", - "dungeondoorshuffle": "door_shuffle", - "experimental": "experimental" - }, - "gameoptions": { - "hints": "hints", - "nobgm": "disablemusic", - "quickswap": "quickswap", - "heartcolor": "heartcolor", - "heartbeep": "heartbeep", - "menuspeed": "fastmenu", - "owpalettes": "ow_palettes", - "uwpalettes": "uw_palettes" - }, - "generation": { - "spoiler": "create_spoiler", - "suppressrom": "suppress_rom" - } - } + "randomizer": { + "item": { + "retro": "retro", + "worldstate": "mode", + "logiclevel": "logic", + "goal": "goal", + "crystals_gt": "crystals_gt", + "crystals_ganon": "crystals_ganon", + "weapons": "swords", + "itempool": "difficulty", + "itemfunction": "item_functionality", + "timer": "timer", + "progressives": "progressive", + "accessibility": "accessibility", + "sortingalgo": "algorithm" + }, + "entrance": { + "openpyramid": "openpyramid", + "shuffleganon": "shuffleganon", + "entranceshuffle": "shuffle" + }, + "enemizer": { + "potshuffle": "shufflepots", + "enemyshuffle": "shuffleenemies", + "bossshuffle": "shufflebosses", + "enemydamage": "enemy_damage", + "enemyhealth": "enemy_health" + }, + "dungeon": { + "mapshuffle": "mapshuffle", + "compassshuffle": "compassshuffle", + "smallkeyshuffle": "keyshuffle", + "bigkeyshuffle": "bigkeyshuffle", + "dungeondoorshuffle": "door_shuffle", + "experimental": "experimental" + }, + "gameoptions": { + "hints": "hints", + "nobgm": "disablemusic", + "quickswap": "quickswap", + "heartcolor": "heartcolor", + "heartbeep": "heartbeep", + "menuspeed": "fastmenu", + "owpalettes": "ow_palettes", + "uwpalettes": "uw_palettes" + }, + "generation": { + "spoiler": "create_spoiler", + "suppressrom": "suppress_rom" + } + } } for mainpage in options: for subpage in options[mainpage]: diff --git a/gui/randomize/multiworld.py b/gui/randomize/multiworld.py index 2bfbe06a..22b4a161 100644 --- a/gui/randomize/multiworld.py +++ b/gui/randomize/multiworld.py @@ -21,15 +21,16 @@ def multiworld_page(parent,settings): self.widgets[key].pack(side=LEFT, anchor=N) ## List of Player Names - namesFrame = Frame(self) - namesLabel = Label(namesFrame, text='Player names') - self.namesVar = StringVar(value=settings["names"]) + key = "names" + self.widgets[key] = Frame(self) + self.widgets[key].label = Label(self.widgets[key], text='Player names') + self.widgets[key].storageVar = StringVar(value=settings["names"]) def saveMultiNames(caller,_,mode): - settings["names"] = self.namesVar.get() - self.namesVar.trace_add("write",saveMultiNames) - namesEntry = Entry(namesFrame, textvariable=self.namesVar) - namesLabel.pack(side=LEFT) - namesEntry.pack(side=LEFT, fill=X, expand=True) - namesFrame.pack(anchor=N, fill=X, expand=True) + settings["names"] = self.widgets[key].storageVar.get() + self.widgets[key].storageVar.trace_add("write",saveMultiNames) + self.widgets[key].textbox = Entry(self.widgets[key], textvariable=self.widgets[key].storageVar) + self.widgets[key].label.pack(side=LEFT) + self.widgets[key].textbox.pack(side=LEFT, fill=X, expand=True) + self.widgets[key].pack(anchor=N, fill=X, expand=True) return self,settings diff --git a/gui/widgets.py b/gui/widgets.py index aec2f31c..20f7d1f8 100644 --- a/gui/widgets.py +++ b/gui/widgets.py @@ -14,10 +14,11 @@ class mySpinbox(Spinbox): self.invoke('buttonup') def make_checkbox(self, parent, label, storageVar, packAttrs): - self = Frame(parent) + self = Frame(parent, name="checkframe-" + label.lower()) self.storageVar = storageVar - self.checkbox = Checkbutton(self, text=label, variable=self.storageVar) - self.checkbox.pack(packAttrs) + self.checkbox = Checkbutton(self, text=label, variable=self.storageVar, name="checkbox-" + label.lower()) + if packAttrs is not None: + self.checkbox.pack(packAttrs) return self def make_selectbox(self, parent, label, options, storageVar, packAttrs): @@ -29,24 +30,27 @@ def make_selectbox(self, parent, label, options, storageVar, packAttrs): keysList = list(keys) valsList = list(vals) self.labelVar.set(keysList[valsList.index(str(self.storageVar.get()))]) - self = Frame(parent) + self = Frame(parent, name="selectframe-" + label.lower()) self.storageVar = storageVar self.storageVar.trace_add("write",change_selected) self.labelVar = StringVar() self.labelVar.trace_add("write",change_storage) self.label = Label(self, text=label) - self.label.pack(packAttrs["label"]) + if packAttrs is not None and "label" in packAttrs: + self.label.pack(packAttrs["label"]) self.selectbox = OptionMenu(self, self.labelVar, *options.keys()) self.selectbox.config(width=20) self.labelVar.set(packAttrs["default"] if "default" in packAttrs else list(options.keys())[0]) - self.selectbox.pack(packAttrs["selectbox"]) + if packAttrs is not None and "selectbox" in packAttrs: + self.selectbox.pack(packAttrs["selectbox"]) return self def make_spinbox(self, parent, label, storageVar, packAttrs): - self = Frame(parent) + self = Frame(parent, name="spinframe-" + label.lower()) self.storageVar = storageVar self.label = Label(self, text=label) - self.label.pack(packAttrs["label"]) + if packAttrs is not None and "label" in packAttrs: + self.label.pack(packAttrs["label"]) fromNum = 1 toNum = 100 if "spinbox" in packAttrs: @@ -54,19 +58,22 @@ def make_spinbox(self, parent, label, storageVar, packAttrs): fromNum = packAttrs["spinbox"]["from"] if "to" in packAttrs: toNum = packAttrs["spinbox"]["to"] - self.spinbox = mySpinbox(self, from_=fromNum, to=toNum, width=5, textvariable=self.storageVar) - self.spinbox.pack(packAttrs["spinbox"]) + self.spinbox = mySpinbox(self, from_=fromNum, to=toNum, width=5, textvariable=self.storageVar, name="spinbox-" + label.lower()) + if packAttrs is not None and "spinbox" in packAttrs: + self.spinbox.pack(packAttrs["spinbox"]) return self def make_textbox(self, parent, label, storageVar, packAttrs): self = Frame(parent) self.storageVar = storageVar self.label = Label(self, text=label) - self.label.pack(packAttrs["label"]) + if packAttrs is not None and "label" in packAttrs: + self.label.pack(packAttrs["label"]) self.textbox = Entry(self, justify=RIGHT, textvariable=self.storageVar, width=3) if "default" in packAttrs: self.storageVar.set(packAttrs["default"]) - self.textbox.pack(packAttrs["textbox"]) + if packAttrs is not None and "textbox" in packAttrs: + self.textbox.pack(packAttrs["textbox"]) return self