155 lines
5.9 KiB
Python
155 lines
5.9 KiB
Python
from os import path
|
|
from tkinter import NW, E, N, S, W, messagebox, ttk
|
|
|
|
import requests
|
|
import sv_ttk
|
|
from ttkthemes import ThemedTk
|
|
from classes.custom.themed_frame import ThemedFrame
|
|
|
|
from classes.frames.devices import FrameDevices
|
|
from classes.frames.saves import FrameSaves
|
|
from classes.frames.settings import FrameSettings
|
|
from classes.frames.errors import FrameErrorConnection, FrameErrorSavesFolder, FrameErrorUnconfigured
|
|
from classes.toplevel.welcome import ToplevelWelcome
|
|
from modules.theme_titlebar import theme_title_bar
|
|
from modules.utils import configGet, get_string_mode, use_dark_mode
|
|
|
|
|
|
class App(ThemedTk):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.window_width = 650
|
|
self.window_height = 400
|
|
|
|
self.screen_width = self.winfo_screenwidth()
|
|
self.screen_height = self.winfo_screenheight()
|
|
|
|
self.center_x = int(self.screen_width/2 - self.window_width / 2)
|
|
self.center_y = int(self.screen_height/2 - self.window_height / 2)
|
|
|
|
self.title("Stardew Sync")
|
|
self.geometry(f'{self.window_width}x{self.window_height}+{self.center_x}+{self.center_y}')
|
|
|
|
self.resizable(False, True)
|
|
|
|
sv_ttk.init_theme(self)
|
|
|
|
if use_dark_mode():
|
|
theme_title_bar(self, mode="dark")
|
|
self.update()
|
|
|
|
|
|
self.iconbitmap(path.join("assets", "favicon.ico"))
|
|
self.focus_set()
|
|
|
|
self.draw_main()
|
|
|
|
|
|
def verify_authorization(self):
|
|
try:
|
|
if requests.get(configGet("address")+"/apikey", headers={"apikey": configGet("apikey")}, verify=not configGet("allow_self_signed")).status_code == 200:
|
|
return True
|
|
else:
|
|
return False
|
|
except:
|
|
return False
|
|
|
|
def verify_saves_dir(self):
|
|
|
|
if configGet("saves_location") is None or path.exists(configGet("saves_location")) is False:
|
|
return False
|
|
else:
|
|
return True
|
|
|
|
|
|
def frame_saves(self):
|
|
self.frame_saves_object = FrameSaves(self)
|
|
self.frame_saves_object.grid(column=1, row=0, sticky=N+S+W+E)
|
|
return
|
|
|
|
def frame_devices(self):
|
|
self.frame_devices_object = FrameDevices(self)
|
|
self.frame_devices_object.grid(column=1, row=0, sticky=N+S+W+E)
|
|
return
|
|
|
|
def frame_settings(self):
|
|
self.frame_settings_object = FrameSettings(self)
|
|
self.frame_settings_object.grid(column=1, row=0, sticky=N+S+W+E)
|
|
return
|
|
|
|
|
|
def draw_main(self):
|
|
|
|
sv_ttk.set_theme(get_string_mode())
|
|
|
|
# self.grid_rowconfigure(1, weight=2)
|
|
# self.grid_rowconfigure(0, weight=2)
|
|
# self.grid_columnconfigure(1, weight=1)
|
|
# self.setup_label = ttk.Label(self, text="Your client seems to be unconfigured")
|
|
# self.setup_label.grid(column=1, row=0, padx=9, pady=9, sticky=S)
|
|
# self.setup_button = ttk.Button(self, text="Set up", style="Accent.TButton", width=10, command=self.open_window_config)
|
|
# self.setup_button.grid(column=1, row=1, padx=9, pady=9, sticky=N)
|
|
# return
|
|
|
|
if configGet("first_run") is True:
|
|
self.welcome_window = ToplevelWelcome(self)
|
|
self.welcome_window.grab_set()
|
|
|
|
self.frame_sidebar = ThemedFrame(self)
|
|
self.frame_sidebar.grid(column=0, row=0, columnspan=1, sticky=N+S+W+E)
|
|
|
|
self.item_saves = ttk.Button(self.frame_sidebar, text="Saves", width=10, command=self.frame_saves)
|
|
self.item_saves.grid(column=0, row=0, sticky=W, padx=9, pady=9)
|
|
|
|
self.item_devices = ttk.Button(self.frame_sidebar, text="Devices", width=10, command=self.frame_devices)
|
|
self.item_devices.grid(column=0, row=1, sticky=W, padx=9, pady=3)
|
|
|
|
self.item_settings = ttk.Button(self.frame_sidebar, text="Settings", width=10, command=self.frame_settings)
|
|
self.item_settings.grid(column=0, row=2, sticky=W+S, padx=9, pady=9)
|
|
|
|
if configGet("address") in ["", None] or configGet("apikey") in ["", None]:
|
|
self.item_saves.state(["disabled"])
|
|
self.item_devices.state(["disabled"])
|
|
self.connection_error = FrameErrorUnconfigured(self)
|
|
self.connection_error.grid(column=1, row=0, rowspan=2, sticky=N+S+W+E)
|
|
# messagebox.showerror(title="Configuration error", message="Your client is not properly configured.")
|
|
return
|
|
|
|
if self.verify_authorization() is False:
|
|
self.item_saves.state(["disabled"])
|
|
self.item_devices.state(["disabled"])
|
|
self.connection_error = FrameErrorConnection(self)
|
|
self.connection_error.grid(column=1, row=0, rowspan=2, sticky=N+S+W+E)
|
|
messagebox.showerror(title="Authentication error", message="Your API key seems to be invalid.")
|
|
return
|
|
|
|
if self.verify_saves_dir() is False:
|
|
self.item_saves.state(["disabled"])
|
|
self.connection_error = FrameErrorSavesFolder(self)
|
|
self.connection_error.grid(column=1, row=0, rowspan=2, sticky=N+S+W+E)
|
|
messagebox.showerror(title="Configuration error", message="Saves folder seems to be invalid.")
|
|
return
|
|
|
|
self.frame_saves()
|
|
|
|
|
|
def destroy_everything(self, draw=True):
|
|
for widget in self.winfo_children():
|
|
widget.destroy()
|
|
if draw is True:
|
|
self.draw_main()
|
|
|
|
|
|
# def open_window_config(self):
|
|
# window = WindowConfig(self)
|
|
# window.grab_set()
|
|
# self.setup_button.destroy()
|
|
# self.setup_label.destroy()
|
|
# self.grid_rowconfigure(1, weight=2)
|
|
# self.grid_rowconfigure(0, weight=2)
|
|
# self.grid_columnconfigure(1, weight=1)
|
|
# ttk.Label(self, text="Client configured, try to connect").grid(column=1, row=0, padx=9, pady=9, sticky=S)
|
|
# ttk.Button(self, text="Connect", style="Accent.TButton", width=10, command=self.try_connecting).grid(column=1, row=1, padx=9, pady=9, sticky=N) |