From e901f0f1f5ab7350b665189f8e581b9607566a50 Mon Sep 17 00:00:00 2001 From: "Mike A. Trethewey" Date: Tue, 10 Mar 2020 17:23:23 -0700 Subject: [PATCH] Ugh, I think I did it --- Gui.py | 9 +- resources/app/gui/lang/en.json | 18 +- .../app/gui/randomize/dungeon/widgets.json | 26 +-- .../app/gui/randomize/enemizer/widgets.json | 46 ++--- .../app/gui/randomize/entrando/widgets.json | 28 +-- .../gui/randomize/gameoptions/widgets.json | 70 ++++---- .../gui/randomize/generation/checkboxes.json | 10 +- resources/app/gui/randomize/item/widgets.json | 170 +++++++++--------- source/classes/constants.py | 6 + source/gui/bottom.py | 24 ++- source/gui/loadcliargs.py | 108 ++++++----- source/gui/widgets.py | 78 ++++++-- 12 files changed, 339 insertions(+), 254 deletions(-) diff --git a/Gui.py b/Gui.py index 4c4c2959..5093ba5e 100755 --- a/Gui.py +++ b/Gui.py @@ -22,6 +22,7 @@ from GuiUtils import set_icon from Main import __version__ as ESVersion from source.classes.BabelFish import BabelFish +from source.classes.Empty import Empty def guiMain(args=None): @@ -152,13 +153,15 @@ def guiMain(args=None): self.fish = BabelFish(lang=lang) # bottom of window: Open Output Directory, Open Documentation (if exists) - self.frames["bottom"] = bottom_frame(self, self, None) + self.pages["bottom"] = Empty() + self.pages["bottom"].pages = {} + self.pages["bottom"].pages["content"] = bottom_frame(self, self, None) ## Save Settings Button - savesettingsButton = Button(self.frames["bottom"], text='Save Settings to File', command=lambda: save_settings_from_gui(True)) + savesettingsButton = Button(self.pages["bottom"].pages["content"], text='Save Settings to File', command=lambda: save_settings_from_gui(True)) savesettingsButton.pack(side=RIGHT) # set bottom frame to main window - self.frames["bottom"].pack(side=BOTTOM, fill=X, padx=5, pady=5) + self.pages["bottom"].pages["content"].pack(side=BOTTOM, fill=X, padx=5, pady=5) self.outputPath = StringVar() self.randomSprite = BooleanVar() diff --git a/resources/app/gui/lang/en.json b/resources/app/gui/lang/en.json index 07a6641f..2fc10054 100644 --- a/resources/app/gui/lang/en.json +++ b/resources/app/gui/lang/en.json @@ -83,7 +83,7 @@ "randomizer.enemizer.enemydamage": "Enemy Damage", "randomizer.enemizer.enemydamage.default": "Vanilla", "randomizer.enemizer.enemydamage.shuffled": "Shuffled", - "randomizer.enemizer.enemydamage.choas": "Chaos", + "randomizer.enemizer.enemydamage.chaos": "Chaos", "randomizer.enemizer.enemyhealth": "Enemy Health", "randomizer.enemizer.enemyhealth.default": "Vanilla", @@ -260,13 +260,13 @@ "randomizer.multiworld.names": "Player names", - "bottom.seed": "Seed #", - "bottom.generationcount": "Count", - "bottom.go": "Generate Patched Rom", - "bottom.dialog.error": "Error while creating seed", - "bottom.dialog.success": "Success", - "bottom.dialog.success.message": "Rom created successfully.", - "bottom.outputdir": "Open Output Directory", - "bottom.docs": "Open Documentation" + "bottom.content.seed": "Seed #", + "bottom.content.generationcount": "Count", + "bottom.content.go": "Generate Patched Rom", + "bottom.content.dialog.error": "Error while creating seed", + "bottom.content.dialog.success": "Success", + "bottom.content.dialog.success.message": "Rom created successfully.", + "bottom.content.outputdir": "Open Output Directory", + "bottom.content.docs": "Open Documentation" } } diff --git a/resources/app/gui/randomize/dungeon/widgets.json b/resources/app/gui/randomize/dungeon/widgets.json index 295f3098..be8973d8 100644 --- a/resources/app/gui/randomize/dungeon/widgets.json +++ b/resources/app/gui/randomize/dungeon/widgets.json @@ -11,13 +11,13 @@ "selectbox": { "side": "right" }, - "default": "Basic" + "default": "basic" }, - "options": { - "Vanilla": "vanilla", - "Basic": "basic", - "Crossed": "crossed" - } + "options": [ + "vanilla", + "basic", + "crossed" + ] }, "experimental": { "type": "checkbox", @@ -37,13 +37,13 @@ "selectbox": { "side": "right" }, - "default": "Auto" + "default": "default" }, - "options": { - "Auto": "default", - "Off": "off", - "On": "on", - "On Compass Pickup": "pickup" - } + "options": [ + "default", + "off", + "on", + "pickup" + ] } } diff --git a/resources/app/gui/randomize/enemizer/widgets.json b/resources/app/gui/randomize/enemizer/widgets.json index 4095ab5b..af18a221 100644 --- a/resources/app/gui/randomize/enemizer/widgets.json +++ b/resources/app/gui/randomize/enemizer/widgets.json @@ -21,11 +21,11 @@ "side": "right" } }, - "options": { - "Vanilla": "none", - "Shuffled": "shuffled", - "Chaos": "chaos" - } + "options": [ + "none", + "shuffled", + "chaos" + ] }, "bossshuffle": { "type": "selectbox", @@ -40,12 +40,12 @@ "side": "right" } }, - "options": { - "Vanilla": "none", - "Basic": "basic", - "Shuffled": "shuffled", - "Chaos": "chaos" - } + "options": [ + "none", + "basic", + "shuffled", + "chaos" + ] } }, "rightEnemizerFrame": { @@ -62,11 +62,11 @@ "side": "right" } }, - "options": { - "Vanilla": "default", - "Shuffled": "shuffled", - "Chaos": "chaos" - } + "options": [ + "default", + "shuffled", + "chaos" + ] }, "enemyhealth": { "type": "selectbox", @@ -81,13 +81,13 @@ "side": "right" } }, - "options": { - "Vanilla": "default", - "Easy": "easy", - "Normal": "normal", - "Hard": "hard", - "Expert": "expert" - } + "options": [ + "default", + "easy", + "normal", + "hard", + "expert" + ] } } } \ No newline at end of file diff --git a/resources/app/gui/randomize/entrando/widgets.json b/resources/app/gui/randomize/entrando/widgets.json index 1a3ae127..f1c8aad6 100644 --- a/resources/app/gui/randomize/entrando/widgets.json +++ b/resources/app/gui/randomize/entrando/widgets.json @@ -21,20 +21,20 @@ "label": { "side": "left" }, "selectbox": { "side": "right" } }, - "options": { - "Vanilla": "vanilla", - "Simple": "simple", - "Restricted": "restricted", - "Full": "full", - "Crossed": "crossed", - "Insanity": "insanity", - "Restricted (Legacy)": "restricted_legacy", - "Full (Legacy)": "full_legacy", - "Madness (Legacy)": "madness_legacy", - "Insanity (Legacy)": "insanity_legacy", - "Dungeons + Full": "dungeonsfull", - "Dungeons + Simple": "dungeonssimple" - } + "options": [ + "vanilla", + "simple", + "restricted", + "full", + "crossed", + "insanity", + "restricted_legacy", + "full_legacy", + "madness_legacy", + "insanity_legacy", + "dungeonsfull", + "dungeonssimple" + ] } } } diff --git a/resources/app/gui/randomize/gameoptions/widgets.json b/resources/app/gui/randomize/gameoptions/widgets.json index 0a0a11ce..f84ba3ee 100644 --- a/resources/app/gui/randomize/gameoptions/widgets.json +++ b/resources/app/gui/randomize/gameoptions/widgets.json @@ -18,7 +18,7 @@ "label": { "text": "L/R Quickswapping" } - } + } }, "leftRomOptionsFrame": { "heartcolor": { @@ -34,13 +34,13 @@ "side": "right" } }, - "options": { - "Red": "red", - "Blue": "blue", - "Green": "green", - "Yellow": "yellow", - "Random": "random" - } + "options": [ + "red", + "blue", + "green", + "yellow", + "random" + ] }, "heartbeep": { "type": "selectbox", @@ -54,15 +54,15 @@ "selectbox": { "side": "right" }, - "default": "Normal" + "default": "normal" }, - "options": { - "Double": "double", - "Normal": "normal", - "Half": "half", - "Quarter": "quarter", - "Off": "off" - } + "options": [ + "double", + "normal", + "half", + "quarter", + "off" + ] } }, "rightRomOptionsFrame": { @@ -78,16 +78,16 @@ "selectbox": { "side": "right" }, - "default": "Normal" + "default": "normal" }, - "options": { - "Instant": "instant", - "Quadruple": "quadruple", - "Triple": "triple", - "Double": "double", - "Normal": "normal", - "Half": "half" - } + "options": [ + "instant", + "quadruple", + "triple", + "double", + "normal", + "half" + ] }, "owpalettes": { "type": "selectbox", @@ -102,11 +102,11 @@ "side": "right" } }, - "options": { - "Default": "default", - "Random": "random", - "Blackout": "blackout" - } + "options": [ + "default", + "random", + "blackout" + ] }, "uwpalettes": { "type": "selectbox", @@ -121,11 +121,11 @@ "side": "right" } }, - "options": { - "Default": "default", - "Random": "random", - "Blackout": "blackout" - } + "options": [ + "default", + "random", + "blackout" + ] } } } diff --git a/resources/app/gui/randomize/generation/checkboxes.json b/resources/app/gui/randomize/generation/checkboxes.json index b7228c78..43693b72 100644 --- a/resources/app/gui/randomize/generation/checkboxes.json +++ b/resources/app/gui/randomize/generation/checkboxes.json @@ -36,10 +36,10 @@ "side": "right" } }, - "options": { - "Ask Me": "ask", - "Always": "always", - "Never": "never" - } + "options": [ + "ask", + "always", + "never" + ] } } diff --git a/resources/app/gui/randomize/item/widgets.json b/resources/app/gui/randomize/item/widgets.json index f63cffe7..96dcaa99 100644 --- a/resources/app/gui/randomize/item/widgets.json +++ b/resources/app/gui/randomize/item/widgets.json @@ -20,14 +20,14 @@ "selectbox": { "side": "right" }, - "default": "Open" + "default": "open" }, - "options": { - "Standard": "standard", - "Open": "open", - "Inverted": "inverted", - "Retro": "retro" - } + "options": [ + "standard", + "open", + "inverted", + "retro" + ] }, "logiclevel": { "type": "selectbox", @@ -42,11 +42,11 @@ "side": "right" } }, - "options": { - "No Glitches": "noglitches", - "Minor Glitches": "minorglitches", - "No Logic": "nologic" - } + "options": [ + "noglitches", + "minorglitches", + "nologic" + ] }, "goal": { "type": "selectbox", @@ -61,13 +61,13 @@ "side": "right" } }, - "options": { - "Defeat Ganon": "ganon", - "Master Sword Pedestal": "pedestal", - "All Dungeons": "dungeons", - "Triforce Hunt": "triforcehunt", - "Crystals": "crystals" - } + "options": [ + "ganon", + "pedestal", + "dungeons", + "triforcehunt", + "crystals" + ] }, "crystals_gt": { "type": "selectbox", @@ -82,17 +82,17 @@ "side": "right" } }, - "options": { - "0": "0", - "1": "1", - "2": "2", - "3": "3", - "4": "4", - "5": "5", - "6": "6", - "7": "7", - "Random": "random" - } + "options": [ + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "random" + ] }, "crystals_ganon": { "type": "selectbox", @@ -107,17 +107,17 @@ "side": "right" } }, - "options": { - "0": "0", - "1": "1", - "2": "2", - "3": "3", - "4": "4", - "5": "5", - "6": "6", - "7": "7", - "Random": "random" - } + "options": [ + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "random" + ] }, "weapons": { "type": "selectbox", @@ -132,12 +132,12 @@ "side": "right" } }, - "options": { - "Randomized": "random", - "Assured": "assured", - "Swordless": "swordless", - "Vanilla": "vanilla" - } + "options": [ + "random", + "assured", + "swordless", + "vanilla" + ] } }, "rightItemFrame": { @@ -154,11 +154,11 @@ "side": "right" } }, - "options": { - "Normal": "normal", - "Hard": "hard", - "Expert": "expert" - } + "options": [ + "normal", + "hard", + "expert" + ] }, "itemfunction": { "type": "selectbox", @@ -173,11 +173,11 @@ "side": "right" } }, - "options": { - "Normal": "normal", - "Hard": "hard", - "Expert": "expert" - } + "options": [ + "normal", + "hard", + "expert" + ] }, "timer": { "type": "selectbox", @@ -192,14 +192,14 @@ "side": "right" } }, - "options": { - "No Timer": "none", - "Stopwatch": "display", - "Timed": "timed", - "Timed OHKO": "timed-ohko", - "OHKO": "ohko", - "Timed Countdown": "timed-countdown" - } + "options": [ + "none", + "display", + "timed", + "timed-ohko", + "ohko", + "timed-countdown" + ] }, "progressives": { "type": "selectbox", @@ -214,11 +214,11 @@ "side": "right" } }, - "options": { - "On": "on", - "Off": "off", - "Random": "random" - } + "options": [ + "on", + "off", + "random" + ] }, "accessibility": { "type": "selectbox", @@ -233,11 +233,11 @@ "side": "right" } }, - "options": { - "100% Inventory": "items", - "100% Locations": "locations", - "Beatable": "none" - } + "options": [ + "items", + "locations", + "none" + ] }, "sortingalgo": { "type": "selectbox", @@ -251,17 +251,17 @@ "selectbox": { "side": "right" }, - "default": "Balanced" + "default": "balanced" }, - "options": { - "Freshness": "freshness", - "Flood": "flood", - "VT8.21": "vt21", - "VT8.22": "vt22", - "VT8.25": "vt25", - "VT8.26": "vt26", - "Balanced": "balanced" - } + "options": [ + "freshness", + "flood", + "vt21", + "vt22", + "vt25", + "vt26", + "balanced" + ] } } } diff --git a/source/classes/constants.py b/source/classes/constants.py index 8277cd3c..9e52ebc6 100644 --- a/source/classes/constants.py +++ b/source/classes/constants.py @@ -110,5 +110,11 @@ SETTINGSTOPROCESS = { "usecustompool": "custom", "saveonexit": "saveonexit" } + }, + "bottom": { + "content": { + "seed": "seed", + "generationcount": "count" + } } } diff --git a/source/gui/bottom.py b/source/gui/bottom.py index 54b859ec..56cd0e9a 100644 --- a/source/gui/bottom.py +++ b/source/gui/bottom.py @@ -36,11 +36,12 @@ def bottom_frame(self, parent, args=None): savedSeed = parent.settings["seed"] self.widgets[widget].storageVar = StringVar(value=savedSeed) # textbox + self.widgets[widget].type = "textbox" self.widgets[widget].pieces["textbox"] = Entry(self.widgets[widget].pieces["frame"], width=15, textvariable=self.widgets[widget].storageVar) self.widgets[widget].pieces["textbox"].pack(side=LEFT) def saveSeed(caller,_,mode): - savedSeed = self.seedVar.get() + savedSeed = self.widgets["seed"].storageVar.get() parent.settings["seed"] = int(savedSeed) if savedSeed.isdigit() else None self.widgets[widget].storageVar.trace_add("write",saveSeed) # frame: pack @@ -91,6 +92,7 @@ def bottom_frame(self, parent, args=None): self.widgets[widget].pieces = {} # button + self.widgets[widget].type = "button" self.widgets[widget].pieces["button"] = Button(self, text='Generate Patched Rom', command=generateRom) # button: pack self.widgets[widget].pieces["button"].pack(side=LEFT) @@ -114,22 +116,26 @@ def bottom_frame(self, parent, args=None): self.widgets[widget].storageVar = StringVar(value=parent.settings["outputpath"]) # button + self.widgets[widget].type = "button" self.widgets[widget].pieces["button"] = Button(self, text='Open Output Directory', command=open_output) # button: pack self.widgets[widget].pieces["button"].pack(side=RIGHT) ## Documentation Button + # widget ID + widget = "docs" + + # Empty object + self.widgets[widget] = Empty() + # pieces + self.widgets[widget].pieces = {} + # button + self.widgets[widget].type = "button" + self.widgets[widget].selectbox = Empty() + self.widgets[widget].selectbox.storageVar = Empty() if os.path.exists(local_path('README.html')): def open_readme(): open_file(local_path('README.html')) - # widget ID - widget = "docs" - - # Empty object - self.widgets[widget] = Empty() - # pieces - self.widgets[widget].pieces = {} - # button self.widgets[widget].pieces["button"] = Button(self, text='Open Documentation', command=open_readme) # button: pack self.widgets[widget].pieces["button"].pack(side=RIGHT) diff --git a/source/gui/loadcliargs.py b/source/gui/loadcliargs.py index 84cb3e10..172db9b3 100644 --- a/source/gui/loadcliargs.py +++ b/source/gui/loadcliargs.py @@ -24,36 +24,46 @@ def loadcliargs(gui, args, settings=None): for subpage in options[mainpage]: # Cycle through each widget for widget in options[mainpage][subpage]: - # Get the value and set it - arg = options[mainpage][subpage][widget] - label = fish.translate("gui","gui",mainpage + '.' + subpage + '.' + widget) - if hasattr(gui.pages[mainpage].pages[subpage].widgets[widget],"type"): - type = gui.pages[mainpage].pages[subpage].widgets[widget].type - if type == "checkbox": - gui.pages[mainpage].pages[subpage].widgets[widget].checkbox.configure(text=label) - elif type == "selectbox": - gui.pages[mainpage].pages[subpage].widgets[widget].label.configure(text=label) - elif type == "spinbox": - gui.pages[mainpage].pages[subpage].widgets[widget].label.configure(text=label) - gui.pages[mainpage].pages[subpage].widgets[widget].storageVar.set(args[arg]) - # If we're on the Game Options page and it's not about Hints - if subpage == "gameoptions" and not widget == "hints": - # Check if we've got settings - # Check if we've got the widget in Adjust settings - hasSettings = settings is not None - hasWidget = ("adjust." + widget) in settings if hasSettings else None - label = fish.translate("gui","gui","adjust." + widget) - if ("adjust." + widget) in label: - label = fish.translate("gui","gui","randomizer.gameoptions." + widget) - if hasattr(gui.pages["adjust"].content.widgets[widget],"type"): - type = gui.pages["adjust"].content.widgets[widget].type - if type == "checkbox": - gui.pages["adjust"].content.widgets[widget].checkbox.configure(text=label) - elif type == "selectbox": - gui.pages["adjust"].content.widgets[widget].label.configure(text=label) - if hasWidget is None: - # If we've got a Game Options val and we don't have an Adjust val, use the Game Options val - gui.pages["adjust"].content.widgets[widget].storageVar.set(args[arg]) + if widget in gui.pages[mainpage].pages[subpage].widgets: + thisType = "" + # Get the value and set it + arg = options[mainpage][subpage][widget] + label = fish.translate("gui","gui",mainpage + '.' + subpage + '.' + widget) + if hasattr(gui.pages[mainpage].pages[subpage].widgets[widget],"type"): + thisType = gui.pages[mainpage].pages[subpage].widgets[widget].type + if thisType == "checkbox": + gui.pages[mainpage].pages[subpage].widgets[widget].checkbox.configure(text=label) + elif thisType == "selectbox": + theseOptions = gui.pages[mainpage].pages[subpage].widgets[widget].selectbox.options + gui.pages[mainpage].pages[subpage].widgets[widget].label.configure(text=label) + i = 0 + for value in theseOptions["values"]: + gui.pages[mainpage].pages[subpage].widgets[widget].selectbox.options["labels"][i] = fish.translate("gui","gui",mainpage + '.' + subpage + '.' + widget + '.' + value) + i += 1 + for i in range(0, len(theseOptions["values"])): + gui.pages[mainpage].pages[subpage].widgets[widget].selectbox["menu"].entryconfigure(i, label=theseOptions["labels"][i]) + gui.pages[mainpage].pages[subpage].widgets[widget].selectbox.options = theseOptions + elif thisType == "spinbox": + gui.pages[mainpage].pages[subpage].widgets[widget].label.configure(text=label) + gui.pages[mainpage].pages[subpage].widgets[widget].storageVar.set(args[arg]) + # If we're on the Game Options page and it's not about Hints + if subpage == "gameoptions" and not widget == "hints": + # Check if we've got settings + # Check if we've got the widget in Adjust settings + hasSettings = settings is not None + hasWidget = ("adjust." + widget) in settings if hasSettings else None + label = fish.translate("gui","gui","adjust." + widget) + if ("adjust." + widget) in label: + label = fish.translate("gui","gui","randomizer.gameoptions." + widget) + if hasattr(gui.pages["adjust"].content.widgets[widget],"type"): + type = gui.pages["adjust"].content.widgets[widget].type + if type == "checkbox": + gui.pages["adjust"].content.widgets[widget].checkbox.configure(text=label) + elif type == "selectbox": + gui.pages["adjust"].content.widgets[widget].label.configure(text=label) + if hasWidget is None: + # If we've got a Game Options val and we don't have an Adjust val, use the Game Options val + gui.pages["adjust"].content.widgets[widget].storageVar.set(args[arg]) # Get EnemizerCLI setting mainpage = "randomizer" @@ -105,47 +115,53 @@ def loadcliargs(gui, args, settings=None): # Get Seed ID mainpage = "bottom" + subpage = "content" widget = "seed" setting = "seed" if args[setting]: - gui.frames[mainpage].widgets[widget].storageVar.set(str(args[setting])) + gui.pages[mainpage].widgets[widget].storageVar.set(str(args[setting])) # set textbox/frame label - label = fish.translate("gui","gui",mainpage + '.' + widget) - gui.frames[mainpage].widgets[widget].pieces["frame"].label.configure(text=label) + label = fish.translate("gui","gui",mainpage + '.' + subpage + '.' + widget) + gui.pages[mainpage].pages[subpage].widgets[widget].pieces["frame"].label.configure(text=label) # Get number of generations to run mainpage = "bottom" + subpage = "content" widget = "generationcount" setting = "count" if args[setting]: - gui.frames[mainpage].widgets[widget].storageVar.set(str(args[setting])) + gui.pages[mainpage].pages[subpage].widgets[widget].storageVar.set(str(args[setting])) # set textbox/frame label - label = fish.translate("gui","gui",mainpage + '.' + widget) - gui.frames[mainpage].widgets[widget].label.configure(text=label) + label = fish.translate("gui","gui",mainpage + '.' + subpage + '.' + widget) + gui.pages[mainpage].pages[subpage].widgets[widget].label.configure(text=label) # Set Generate button mainpage = "bottom" + subpage = "content" widget = "go" # set textbox/frame label - label = fish.translate("gui","gui",mainpage + '.' + widget) - gui.frames[mainpage].widgets[widget].pieces["button"].configure(text=label) + label = fish.translate("gui","gui",mainpage + '.' + subpage + '.' + widget) + gui.pages[mainpage].pages[subpage].widgets[widget].pieces["button"].configure(text=label) # Set Output Directory button mainpage = "bottom" + subpage = "content" widget = "outputdir" # set textbox/frame label - label = fish.translate("gui","gui",mainpage + '.' + widget) - gui.frames[mainpage].widgets[widget].pieces["button"].configure(text=label) + label = fish.translate("gui","gui",mainpage + '.' + subpage + '.' + widget) + gui.pages[mainpage].pages[subpage].widgets[widget].pieces["button"].configure(text=label) # Get output path - gui.frames[mainpage].widgets[widget].storageVar.set(args["outputpath"]) + gui.pages[mainpage].pages[subpage].widgets[widget].storageVar.set(args["outputpath"]) - # Set Output Directory button + # Set Documentation button mainpage = "bottom" + subpage = "content" widget = "docs" - # set textbox/frame label - label = fish.translate("gui","gui",mainpage + '.' + widget) - if widget in gui.frames[mainpage].widgets: - gui.frames[mainpage].widgets[widget].pieces["button"].configure(text=label) + if widget in gui.pages[mainpage].pages[subpage].widgets: + if "button" in gui.pages[mainpage].pages[subpage].widgets[widget].pieces: + # set textbox/frame label + label = fish.translate("gui","gui",mainpage + '.' + subpage + '.' + widget) + gui.pages[mainpage].pages[subpage].widgets[widget].pieces["button"].configure(text=label) # Figure out Sprite Selection def sprite_setter(spriteObject): diff --git a/source/gui/widgets.py b/source/gui/widgets.py index eed19272..7697328f 100644 --- a/source/gui/widgets.py +++ b/source/gui/widgets.py @@ -28,27 +28,81 @@ def make_checkbox(self, parent, label, storageVar, manager, managerAttrs): # Make an OptionMenu with a label and pretty option labels def make_selectbox(self, parent, label, options, storageVar, manager, managerAttrs): - def change_storage(*args): - self.storageVar.set(options[self.labelVar.get()]) - def change_selected(*args): - keys = options.keys() - vals = options.values() - keysList = list(keys) - valsList = list(vals) - self.labelVar.set(keysList[valsList.index(str(self.storageVar.get()))]) self = Frame(parent, name="selectframe-" + label.lower()) - self.storageVar = storageVar - self.storageVar.trace_add("write",change_selected) + + labels = options + + if isinstance(options,dict): + labels = options.keys() + self.labelVar = StringVar() + self.storageVar = storageVar + self.selectbox = OptionMenu(self, self.labelVar, *labels) + self.selectbox.options = {} + + if isinstance(options,dict): + self.selectbox.options["labels"] = list(options.keys()) + self.selectbox.options["values"] = list(options.values()) + else: + self.selectbox.options["labels"] = ["" for i in range(0,len(options))] + self.selectbox.options["values"] = options + + def change_thing(thing, *args): + labels = self.selectbox.options["labels"] + values = self.selectbox.options["values"] + check = "" + lbl = "" + val = "" + idx = 0 + + if thing == "storage": + check = self.labelVar.get() + elif thing == "label": + check = self.storageVar.get() + + if check in labels: + idx = labels.index(check) + if check in values: + idx = values.index(check) + + lbl = labels[idx] + val = values[idx] + + if thing == "storage": + self.storageVar.set(val) + elif thing == "label": + self.labelVar.set(lbl) + self.selectbox["menu"].entryconfigure(idx,label=lbl) + self.selectbox.configure(state="active") + + + def change_storage(*args): + change_thing("storage", *args) + def change_selected(*args): + change_thing("label", *args) + + self.storageVar.trace_add("write",change_selected) self.labelVar.trace_add("write",change_storage) self.label = Label(self, text=label) + if managerAttrs is not None and "label" in managerAttrs: self.label.pack(managerAttrs["label"]) else: self.label.pack() - self.selectbox = OptionMenu(self, self.labelVar, *options.keys()) + self.selectbox.config(width=20) - self.labelVar.set(managerAttrs["default"] if "default" in managerAttrs else list(options.keys())[0]) + idx = 0 + default = self.selectbox.options["values"][idx] + if "default" in managerAttrs: + default = managerAttrs["default"] + labels = self.selectbox.options["labels"] + values = self.selectbox.options["values"] + if default in values: + idx = values.index(default) + default = labels[idx] + self.labelVar.set(default) + self.selectbox["menu"].entryconfigure(idx,label=default) + if managerAttrs is not None and "selectbox" in managerAttrs: self.selectbox.pack(managerAttrs["selectbox"]) else: