Major GUI reorganization

This commit is contained in:
codemann8
2023-03-29 08:58:48 -06:00
committed by aerinon
parent 09550cd546
commit f13880eee9
24 changed files with 522 additions and 263 deletions

View File

@@ -1,4 +1,4 @@
from tkinter import Checkbutton, Entry, Frame, IntVar, Label, OptionMenu, Spinbox, StringVar, LEFT, RIGHT, X
from tkinter import messagebox, Checkbutton, Entry, Frame, IntVar, Label, OptionMenu, Spinbox, StringVar, LEFT, RIGHT, X
from source.classes.Empty import Empty
# Override Spinbox to include mousewheel support for changing value
@@ -16,7 +16,7 @@ class mySpinbox(Spinbox):
self.invoke('buttonup')
# Make a Checkbutton with a label
def make_checkbox(self, parent, label, storageVar, manager, managerAttrs):
def make_checkbox(self, parent, label, storageVar, manager, managerAttrs, config):
self = Frame(parent)
self.storageVar = storageVar
if managerAttrs is not None and "default" in managerAttrs:
@@ -25,7 +25,10 @@ def make_checkbox(self, parent, label, storageVar, manager, managerAttrs):
elif managerAttrs["default"] == "false" or managerAttrs["default"] == False:
self.storageVar.set(False)
del managerAttrs["default"]
self.checkbox = Checkbutton(self, text=label, variable=self.storageVar)
options = {"text":label, "variable":self.storageVar}
if config and "command" in config:
options.update({"command":lambda m=config["command"]: widget_command(self, m)})
self.checkbox = Checkbutton(self, options)
if managerAttrs is not None:
self.checkbox.pack(managerAttrs)
else:
@@ -43,7 +46,11 @@ def make_selectbox(self, parent, label, options, storageVar, manager, managerAtt
self.labelVar = StringVar()
self.storageVar = storageVar
self.selectbox = OptionMenu(self, self.labelVar, *labels)
if config and "command" in config:
self.command = config["command"]
self.selectbox = OptionMenu(self, self.labelVar, *labels, command=lambda m: widget_command(self, self.command))
else:
self.selectbox = OptionMenu(self, self.labelVar, *labels)
self.selectbox.options = {}
if isinstance(options,dict):
@@ -96,7 +103,7 @@ def make_selectbox(self, parent, label, options, storageVar, manager, managerAtt
else:
self.label.pack(side=LEFT)
self.selectbox.config(width=config['width'] if config and config['width'] else 20)
self.selectbox.config(width=config['width'] if config and 'width' in config else 20)
idx = 0
default = self.selectbox.options["values"][idx]
if managerAttrs is not None and "default" in managerAttrs:
@@ -181,7 +188,7 @@ def make_widget(self, type, parent, label, storageVar=None, manager=None, manage
if type == "checkbox":
if thisStorageVar is None:
thisStorageVar = IntVar()
widget = make_checkbox(self, parent, label, thisStorageVar, manager, managerAttrs)
widget = make_checkbox(self, parent, label, thisStorageVar, manager, managerAttrs, config)
elif type == "selectbox":
if thisStorageVar is None:
thisStorageVar = StringVar()
@@ -221,3 +228,51 @@ def make_widgets_from_dict(self, defns, parent):
for key,defn in defns.items():
widgets[key] = make_widget_from_dict(self, defn, parent)
return widgets
# Add padding to widget
def add_padding_from_config(packAttrs, defn):
if "config" in defn:
config = defn["config"]
if 'padx' in config:
packAttrs["padx"] = config['padx']
if 'pady' in config:
packAttrs["pady"] = config['pady']
return packAttrs
# Callback when a widget issues a command
def widget_command(widget, command=""):
root = widget.winfo_toplevel()
text_output = ""
if command == "worldstate":
if widget.storageVar.get() == 'retro':
temp_widget = root.pages["randomizer"].pages["dungeon"].widgets["smallkeyshuffle"]
text_output += f'\n {temp_widget.label.cget("text")}'
temp_widget.storageVar.set('universal')
temp_widget = root.pages["randomizer"].pages["item"].widgets["bow_mode"]
text_output += f'\n {temp_widget.label.cget("text")}'
if temp_widget.storageVar.get() == 'progressive':
temp_widget.storageVar.set('retro')
elif temp_widget.storageVar.get() == 'silvers':
temp_widget.storageVar.set('retro_silvers')
temp_widget = root.pages["randomizer"].pages["item"].widgets["take_any"]
text_output += f'\n {temp_widget.label.cget("text")}'
if temp_widget.storageVar.get() == 'none':
temp_widget.storageVar.set('random')
widget.storageVar.set('open')
messagebox.showinfo('', f'The following settings were changed:{text_output}')
elif command == "keydropshuffle":
if widget.storageVar.get() > 0:
temp_widget = root.pages["randomizer"].pages["item"].widgets["pottery"]
text_output += f'\n {temp_widget.label.cget("text")}'
if temp_widget.storageVar.get() == 'none':
temp_widget.storageVar.set('keys')
temp_widget = root.pages["randomizer"].pages["item"].widgets["dropshuffle"]
temp_widget.storageVar.set(1)
text_output += f'\n {temp_widget.checkbox.cget("text")}'
widget.storageVar.set(0)
messagebox.showinfo('', f'The following settings were changed:{text_output}')