Save preference added

This commit is contained in:
Profitroll 2023-01-26 11:10:25 +01:00
parent b1aeb06a09
commit 8e9d74652d
3 changed files with 37 additions and 17 deletions

View File

@ -25,7 +25,7 @@ class App(ThemedTk):
self.__version__ = "0.1.0" self.__version__ = "0.1.0"
resize_window(self, 610, 400) resize_window(self, 610, 400)
self.resizable(False, True) self.resizable(True, True)
self.minsize(610, 200) self.minsize(610, 200)
self.title("Stardew Sync") self.title("Stardew Sync")
@ -63,7 +63,7 @@ class App(ThemedTk):
def frame_saves(self): def frame_saves(self):
self.grid_rowconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(1, weight=1) self.grid_columnconfigure(1, weight=1)
self.frame_saves_saves = requests.get(f'{configGet("address")}/saves?only_ids=True', headers={"apikey": configGet("apikey")}, verify=not configGet("allow_self_signed")) self.frame_saves_saves = requests.get(f'{configGet("address")}/saves?only_ids=True&sort={(configGet("prefer_saves").split())[1]}', headers={"apikey": configGet("apikey")}, verify=not configGet("allow_self_signed"))
if self.frame_saves_saves.status_code == 200 and isinstance(self.frame_saves_saves.json(), list) is True and len(self.frame_saves_saves.json()) > 0: if self.frame_saves_saves.status_code == 200 and isinstance(self.frame_saves_saves.json(), list) is True and len(self.frame_saves_saves.json()) > 0:
self.frame_saves_object = FrameSaves(self, self.frame_saves_saves.json(), vscroll=True) self.frame_saves_object = FrameSaves(self, self.frame_saves_saves.json(), vscroll=True)
else: else:

View File

@ -72,22 +72,37 @@ class FrameSettings(ThemedFrame):
self.saves_location_label.grid(column=0, row=3, sticky=W, padx=9, pady=9) self.saves_location_label.grid(column=0, row=3, sticky=W, padx=9, pady=9)
self.saves_frame = ThemedFrame(self) self.saves_frame = ThemedFrame(self)
self.saves_frame.grid(column=1, row=3, sticky=N+S+E+W, padx=9, pady=9) self.saves_frame.grid(column=1, row=3, sticky=NSEW, padx=9, pady=9)
self.saves_frame.grid_columnconfigure(0, weight=1) self.saves_frame.grid_columnconfigure(0, weight=1)
self.saves_frame.grid_columnconfigure(1, weight=3) # self.saves_frame.grid_columnconfigure(1, weight=3)
self.saves_location_entry = ttk.Entry(self.saves_frame, width=30) self.saves_location_entry = ttk.Entry(self.saves_frame) #, width=30)
self.saves_location_entry.grid(column=0, row=0, sticky=NSEW) self.saves_location_entry.grid(column=0, row=0, sticky=N+S+E+W)
if configGet("saves_location") is not None: if configGet("saves_location") is not None:
self.saves_location_entry.insert(0, configGet("saves_location")) self.saves_location_entry.insert(0, configGet("saves_location"))
self.saves_location_divider = ttk.Separator(self.saves_frame, orient="vertical")
self.saves_location_divider.grid(column=1, row=0, padx=3)
self.saves_location_button = ttk.Button(self.saves_frame, text="Browse", width=6, command=lambda:self.select_location(self.saves_location_entry)) self.saves_location_button = ttk.Button(self.saves_frame, text="Browse", width=6, command=lambda:self.select_location(self.saves_location_entry))
self.saves_location_button.grid(column=1, row=0, sticky=E) self.saves_location_button.grid(column=2, row=0, sticky=E)
# ============== # ==============
# Saves preference
self.saves_preference_label = ttk.Label(self, text="Saves preference:")
self.saves_preference_label.grid(column=0, row=4, sticky=W, padx=9, pady=9)
self.default_preference = "Latest upload " if configGet("prefer_saves") == "latest upload" else "Latest progress "
self.chosen_preference = StringVar()
self.preferences = ("Latest upload ", "Latest progress ")
self.saves_preference_button = ttk.OptionMenu(self, self.chosen_preference, self.default_preference, *self.preferences, direction="below")
self.saves_preference_button.grid(column=1, row=4, sticky=W, padx=9, pady=9)
# ================
# Software theme # Software theme
self.saves_location_label = ttk.Label(self, text="Color theme:") self.saves_location_label = ttk.Label(self, text="Color theme:")
self.saves_location_label.grid(column=0, row=4, sticky=W, padx=9, pady=9) self.saves_location_label.grid(column=0, row=5, sticky=W, padx=9, pady=9)
if configGet("dark_mode_auto") is True: if configGet("dark_mode_auto") is True:
self.default_theme = "Auto " self.default_theme = "Auto "
@ -97,17 +112,17 @@ class FrameSettings(ThemedFrame):
self.chosen_theme = StringVar() self.chosen_theme = StringVar()
self.themes = ("Auto ", "Light ", "Dark ") self.themes = ("Auto ", "Light ", "Dark ")
self.saves_location_button = ttk.OptionMenu(self, self.chosen_theme, self.default_theme, *self.themes, direction="below", command=self.change_theme) self.saves_location_button = ttk.OptionMenu(self, self.chosen_theme, self.default_theme, *self.themes, direction="below", command=self.change_theme)
self.saves_location_button.grid(column=1, row=4, sticky=W, padx=9, pady=9) self.saves_location_button.grid(column=1, row=5, sticky=W, padx=9, pady=9)
# ============== # ==============
self.buttons_frame = ThemedFrame(self) self.buttons_frame = ThemedFrame(self)
self.buttons_frame.grid(column=0, columnspan=2, row=5, sticky=NSEW, padx=9, pady=9) self.buttons_frame.grid(column=0, columnspan=2, row=6, sticky=NSEW, padx=9, pady=9)
self.buttons_frame.grid_columnconfigure(0, weight=1) self.buttons_frame.grid_columnconfigure(0, weight=1)
self.validate_button = ttk.Button(self.buttons_frame, text="Validate", width=11, command=self.validate_configuration) # self.validate_button = ttk.Button(self.buttons_frame, text="Validate", width=11, command=self.validate_configuration)
self.validate_button.grid(column=0, row=0, sticky=E, padx=9) # self.validate_button.grid(column=0, row=0, sticky=E, padx=9)
self.save_button = ttk.Button(self.buttons_frame, text="Save", style="Accent.TButton", width=11, state="disabled", command=self.save_configuration) self.save_button = ttk.Button(self.buttons_frame, text="Save", style="Accent.TButton", width=11, command=self.validate_configuration)
self.save_button.grid(column=1, row=0, sticky=E) self.save_button.grid(column=1, row=0, sticky=E)
def change_theme(self, *args): def change_theme(self, *args):
@ -175,9 +190,11 @@ class FrameSettings(ThemedFrame):
else: else:
configSet(["dark_mode"], False) configSet(["dark_mode"], False)
# messagebox.showinfo(title="Configuration saved", message="Your client's configuration has been saved") configSet(["prefer_saves"], self.chosen_preference.get().strip().lower())
self.save_button.state(["disabled"]) messagebox.showinfo(title="Configuration saved", message="Your client's configuration has been saved")
# self.save_button.state(["disabled"])
self.master.item_saves.state(["!disabled"]) self.master.item_saves.state(["!disabled"])
self.master.item_devices.state(["!disabled"]) self.master.item_devices.state(["!disabled"])
@ -231,6 +248,8 @@ class FrameSettings(ThemedFrame):
# return # return
# # ========================= # # =========================
self.save_button.state(["!disabled"]) # self.save_button.state(["!disabled"])
self.save_configuration()
# messagebox.showinfo(title="Configuration completed", message="Your client is now configured and ready to use!") # messagebox.showinfo(title="Configuration completed", message="Your client is now configured and ready to use!")

View File

@ -13,7 +13,8 @@ if not path.exists("config.json"):
"saves_location": None, "saves_location": None,
"dark_mode": False, "dark_mode": False,
"dark_mode_auto": True, "dark_mode_auto": True,
"first_run": True "first_run": True,
"prefer_saves": "latest upload"
}, },
"config.json" "config.json"
) )