Compare commits

...

3 Commits

Author SHA1 Message Date
4fa2a3ad9a Debugging 2023-01-26 11:11:04 +01:00
557ee221d5 Cards size depending on OS 2023-01-26 11:10:49 +01:00
8e9d74652d Save preference added 2023-01-26 11:10:25 +01:00
7 changed files with 66 additions and 30 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

@@ -1,4 +1,4 @@
from tkinter import NSEW, Canvas, Event, ttk from tkinter import E, N, NSEW, S, Canvas, Event, ttk
from classes.custom.themed_frame import ThemedFrame from classes.custom.themed_frame import ThemedFrame
@@ -33,6 +33,8 @@ class ScrollableFrame(ThemedFrame):
self.scroll_speed = scroll_speed self.scroll_speed = scroll_speed
self.master_frame = ThemedFrame(master) self.master_frame = ThemedFrame(master)
# self.master_frame["borderwidth"] = 1
# self.master_frame["relief"] = "solid"
self.master_frame.grid_rowconfigure(0, weight=1) self.master_frame.grid_rowconfigure(0, weight=1)
self.master_frame.grid_columnconfigure(0, weight=1) self.master_frame.grid_columnconfigure(0, weight=1)
self.dummy_canvas = Canvas(self.master_frame, highlightthickness=0, **kwargs) self.dummy_canvas = Canvas(self.master_frame, highlightthickness=0, **kwargs)
@@ -41,7 +43,7 @@ class ScrollableFrame(ThemedFrame):
# Create the 2 scrollbars # Create the 2 scrollbars
if vscroll: if vscroll:
self.v_scrollbar = ttk.Scrollbar(self.master_frame, orient="vertical", command=self.dummy_canvas.yview, **scrollbar_kwargs) self.v_scrollbar = ttk.Scrollbar(self.master_frame, orient="vertical", command=self.dummy_canvas.yview, **scrollbar_kwargs)
self.v_scrollbar.grid(row=0, column=1, sticky=NSEW) self.v_scrollbar.grid(row=0, column=1, sticky=N+S+E)
self.dummy_canvas.configure(yscrollcommand=self.v_scrollbar.set) self.dummy_canvas.configure(yscrollcommand=self.v_scrollbar.set)
if hscroll: if hscroll:
self.h_scrollbar = ttk.Scrollbar(self.master_frame, orient="horizontal", command=self.dummy_canvas.xview, **scrollbar_kwargs) self.h_scrollbar = ttk.Scrollbar(self.master_frame, orient="horizontal", command=self.dummy_canvas.xview, **scrollbar_kwargs)

View File

@@ -9,7 +9,7 @@ import requests
from classes.custom.themed_frame import ThemedFrame from classes.custom.themed_frame import ThemedFrame
from modules.logger import logger from modules.logger import logger
from modules.utils import configGet, configSet from modules.utils import configGet, configSet, osname
class FrameDevice(ThemedFrame): class FrameDevice(ThemedFrame):
@@ -18,17 +18,19 @@ class FrameDevice(ThemedFrame):
super().__init__(master, style="Card.TFrame", **kwargs) super().__init__(master, style="Card.TFrame", **kwargs)
self.widget_width = 47 if osname == "nt" else 42
self.grid_columnconfigure(0, weight=1) self.grid_columnconfigure(0, weight=1)
self.grid_columnconfigure(1, weight=3) self.grid_columnconfigure(1, weight=3)
self.grid_columnconfigure(2, weight=3) self.grid_columnconfigure(2, weight=3)
self.name = device_dict["name"] self.name = device_dict["name"]
self.title = ttk.Label(self, text=self.name, font=("SunValleyBodyStrongFont", 12, "bold"), justify=LEFT, width=46) self.title = ttk.Label(self, text=self.name, font=("SunValleyBodyStrongFont", 12, "bold"), justify=LEFT, width=self.widget_width)
self.title.grid(column=0, row=0, padx=9, pady=9, sticky=W) self.title.grid(column=0, row=0, padx=9, pady=9, sticky=W)
last_upload = "N/A" if device_dict["last_save"] == 0 else datetime.utcfromtimestamp(device_dict["last_save"]).strftime("%d.%m.%Y %H:%M") last_upload = "N/A" if device_dict["last_save"] == 0 else datetime.utcfromtimestamp(device_dict["last_save"]).strftime("%d.%m.%Y %H:%M")
self.description = ttk.Label(self, text=f'OS: {device_dict["os"]}\nClient: {device_dict["client"]}\nLast upload: {last_upload}', width=46) self.description = ttk.Label(self, text=f'OS: {device_dict["os"]}\nClient: {device_dict["client"]}\nLast upload: {last_upload}', width=self.widget_width)
self.description.grid(column=0, row=1, padx=9, pady=9, sticky=W) self.description.grid(column=0, row=1, padx=9, pady=9, sticky=W)
self.buttons = ThemedFrame(self) self.buttons = ThemedFrame(self)
@@ -94,7 +96,7 @@ class FrameDevice(ThemedFrame):
if isinstance(widget, ttk.Entry): if isinstance(widget, ttk.Entry):
widget.destroy() widget.destroy()
device_title = ttk.Label(self, text=self.name, font=("SunValleyBodyStrongFont", 12, "bold"), justify=LEFT, width=46) device_title = ttk.Label(self, text=self.name, font=("SunValleyBodyStrongFont", 12, "bold"), justify=LEFT, width=self.widget_width)
device_title.grid(column=0, row=0, padx=9, pady=9, sticky=W) device_title.grid(column=0, row=0, padx=9, pady=9, sticky=W)
button_device_rename_action = partial(self.rename) button_device_rename_action = partial(self.rename)
@@ -117,7 +119,7 @@ class FrameDevice(ThemedFrame):
if isinstance(widget, ttk.Entry): if isinstance(widget, ttk.Entry):
widget.destroy() widget.destroy()
device_title = ttk.Label(self, text=self.name, font=("SunValleyBodyStrongFont", 12, "bold"), justify=LEFT, width=46) device_title = ttk.Label(self, text=self.name, font=("SunValleyBodyStrongFont", 12, "bold"), justify=LEFT, width=self.widget_width)
device_title.grid(column=0, row=0, padx=9, pady=9, sticky=W) device_title.grid(column=0, row=0, padx=9, pady=9, sticky=W)
button_device_rename_action = partial(self.rename) button_device_rename_action = partial(self.rename)

View File

@@ -2,6 +2,7 @@ from datetime import datetime, timezone
from tkinter import LEFT, NSEW, Misc, S, W, ttk from tkinter import LEFT, NSEW, Misc, S, W, ttk
from classes.custom.themed_frame import ThemedFrame from classes.custom.themed_frame import ThemedFrame
from modules.utils import osname
class FrameSave(ThemedFrame): class FrameSave(ThemedFrame):
@@ -10,14 +11,16 @@ class FrameSave(ThemedFrame):
super().__init__(master, style="Card.TFrame", **kwargs) super().__init__(master, style="Card.TFrame", **kwargs)
self.widget_width = 47 if osname == "nt" else 42
self.grid_columnconfigure(0, weight=1) self.grid_columnconfigure(0, weight=1)
self.grid_columnconfigure(1, weight=3) self.grid_columnconfigure(1, weight=3)
self.grid_columnconfigure(2, weight=3) self.grid_columnconfigure(2, weight=3)
self.title = ttk.Label(self, text=save_dict["data"]["farmer"], font=("SunValleyBodyStrongFont", 12, "bold"), justify=LEFT, width=46) self.title = ttk.Label(self, text=save_dict["data"]["farmer"], font=("SunValleyBodyStrongFont", 12, "bold"), justify=LEFT, width=self.widget_width)
self.title.grid(column=0, row=0, padx=9, pady=9, sticky=W) self.title.grid(column=0, row=0, padx=9, pady=9, sticky=W)
self.description = ttk.Label(self, text=f'Money: {save_dict["data"]["money"]}\nGame version: {save_dict["data"]["game_version"]}\nID: {save_dict["id"]}', width=46) self.description = ttk.Label(self, text=f'Money: {save_dict["data"]["money"]}\nGame version: {save_dict["data"]["game_version"]}\nID: {save_dict["id"]}', width=self.widget_width)
self.description.grid(column=0, row=1, padx=9, pady=9, sticky=W) self.description.grid(column=0, row=1, padx=9, pady=9, sticky=W)
self.buttons = ThemedFrame(self) self.buttons = ThemedFrame(self)
@@ -25,7 +28,7 @@ class FrameSave(ThemedFrame):
self.buttons.grid_columnconfigure(0, weight=1) self.buttons.grid_columnconfigure(0, weight=1)
upload_date = datetime.utcfromtimestamp(save_dict["date"]).replace(tzinfo=timezone.utc).astimezone(tz=None) upload_date = datetime.utcfromtimestamp(save_dict["date"]).replace(tzinfo=timezone.utc).astimezone(tz=None)
self.last_upload = ttk.Label(self.buttons, text=f'{upload_date.strftime("%A, %d %b %Y")}\nUploaded at {upload_date.strftime("%H:%M")} by {save_dict["device"]}', font=("SunValleyBodyFont", 8), justify=LEFT, width=46) self.last_upload = ttk.Label(self.buttons, text=f'{upload_date.strftime("%A, %d %b %Y")}\nUploaded at {upload_date.strftime("%H:%M")} by {save_dict["device"]}', font=("SunValleyBodyFont", 8), justify=LEFT, width=self.widget_width)
self.last_upload.grid(column=0, row=0, sticky=W+S) self.last_upload.grid(column=0, row=0, sticky=W+S)
# self.button_device_rename_action = partial(self.rename) # self.button_device_rename_action = partial(self.rename)
@@ -34,4 +37,10 @@ class FrameSave(ThemedFrame):
#self.button_device_delete_action = partial(self.delete) #self.button_device_delete_action = partial(self.delete)
self.button_device_delete = ttk.Button(self.buttons, text="Synchronize", style="Accent.TButton", width=11) #, command=self.button_device_delete_action) self.button_device_delete = ttk.Button(self.buttons, text="Synchronize", style="Accent.TButton", width=11) #, command=self.button_device_delete_action)
self.button_device_delete.grid(column=1, row=0, sticky=W) self.button_device_delete.grid(column=1, row=0, sticky=W)
def convert_date(self, year: int, month: int, day: int) -> str:
pass
def convert_playtime(self, seconds: int) -> str:
pass

View File

@@ -1,5 +1,5 @@
from os import path, walk from os import path, walk
from tkinter import NSEW, ttk from tkinter import E, NSEW, W, ttk
import xmltodict import xmltodict
from ttkthemes import ThemedTk from ttkthemes import ThemedTk
@@ -21,6 +21,9 @@ class FrameSaves(ScrollableFrame):
self.saves = saves self.saves = saves
self.saves_local = [] self.saves_local = []
# self["borderwidth"] = 1
# self["relief"] = "solid"
for subdir, dirs, files in walk(configGet("saves_location")): for subdir, dirs, files in walk(configGet("saves_location")):
try: try:
for dir in dirs: for dir in dirs:
@@ -66,7 +69,7 @@ class FrameSaves(ScrollableFrame):
for save in self.saves: for save in self.saves:
save_frame = FrameSave(self, save_dict=save) save_frame = FrameSave(self, save_dict=save)
save_frame.grid(column=0, row=i, pady=9, padx=9, sticky=NSEW) save_frame.grid(column=0, row=i, pady=9, padx=9, sticky=W+E)
i += 1 i += 1

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"
) )