removed code duplication, using 1 function for both of the key entry callbacks

This commit is contained in:
Adam Saudagar 2020-12-27 18:58:09 +05:30
parent bd4bf6e25b
commit 1a65908488

View File

@ -69,6 +69,10 @@ def start_semifisher_config(gui: 'GUI'):
gui.config.set("collect_allow_auto", collect_allow_auto.instate(['selected']), False) gui.config.set("collect_allow_auto", collect_allow_auto.instate(['selected']), False)
collect_key_entry['state'] = NORMAL if config.get("collect_allow_auto") else DISABLED collect_key_entry['state'] = NORMAL if config.get("collect_allow_auto") else DISABLED
def del_entry_key(event):
event.widget.delete(0,"end")
event.widget.insert(0, str(event.char))
top = PopUp(save, gui._root, background=gui._root["background"]) top = PopUp(save, gui._root, background=gui._root["background"])
controls_frame = Frame(top) controls_frame = Frame(top)
top.title("Config") top.title("Config")
@ -88,30 +92,22 @@ def start_semifisher_config(gui: 'GUI'):
borderless = Checkbutton(controls_frame, var=BooleanVar(value=config.get("borderless"))) borderless = Checkbutton(controls_frame, var=BooleanVar(value=config.get("borderless")))
borderless.grid(row=1, column=1) borderless.grid(row=1, column=1)
def del_action_key(event):
action_key_entry.delete(0,"end")
action_key_entry.insert(0, str(event.char))
Label(controls_frame, text="Action Key:").grid(row=2, column=0) Label(controls_frame, text="Action Key:").grid(row=2, column=0)
action_key_entry = Entry(controls_frame, justify=CENTER) action_key_entry = Entry(controls_frame, justify=CENTER)
action_key_entry.grid(row=2, column=1) action_key_entry.grid(row=2, column=1)
action_key_entry.insert(0, config.get("action_key", "e")) action_key_entry.insert(0, config.get("action_key", "e"))
action_key_entry.bind("<KeyRelease>", del_action_key) action_key_entry.bind("<KeyRelease>", del_entry_key)
Label(controls_frame, text="Auto-Looting: ").grid(row=3, column=0, pady=(15, 0)) Label(controls_frame, text="Auto-Looting: ").grid(row=3, column=0, pady=(15, 0))
collect_allow_auto = Checkbutton(controls_frame, command=toggle_collect, var=BooleanVar(value=config.get("collect_allow_auto"))) collect_allow_auto = Checkbutton(controls_frame, command=toggle_collect, var=BooleanVar(value=config.get("collect_allow_auto")))
collect_allow_auto.grid(row=3, column=1, pady=(15, 0)) collect_allow_auto.grid(row=3, column=1, pady=(15, 0))
def del_collect_key(event):
collect_key_entry.delete(0,"end")
collect_key_entry.insert(0, str(event.char))
Label(controls_frame, text="Looting Key:").grid(row=4, column=0, pady=(0, 15)) Label(controls_frame, text="Looting Key:").grid(row=4, column=0, pady=(0, 15))
collect_key_entry = Entry(controls_frame, justify=CENTER) collect_key_entry = Entry(controls_frame, justify=CENTER)
collect_key_entry.grid(row=4, column=1, pady=(0, 15)) collect_key_entry.grid(row=4, column=1, pady=(0, 15))
collect_key_entry.insert(0, config.get("collect_key", "r")) collect_key_entry.insert(0, config.get("collect_key", "r"))
collect_key_entry['state'] = NORMAL if config.get("collect_allow_auto") else DISABLED collect_key_entry['state'] = NORMAL if config.get("collect_allow_auto") else DISABLED
collect_key_entry.bind("<KeyRelease>", del_collect_key) collect_key_entry.bind("<KeyRelease>", del_entry_key)
Label(controls_frame, text="Sound Notification: ").grid(row=5, column=0, pady=(5, 5)) Label(controls_frame, text="Sound Notification: ").grid(row=5, column=0, pady=(5, 5))
sound = Checkbutton(controls_frame, var=BooleanVar(value=config.get("sound_notification"))) sound = Checkbutton(controls_frame, var=BooleanVar(value=config.get("sound_notification")))