108 lines
4.0 KiB
Python
108 lines
4.0 KiB
Python
from tkinter import N, S, messagebox, ttk
|
|
from typing import Any
|
|
|
|
import sv_ttk
|
|
import requests
|
|
from ttkthemes import ThemedTk
|
|
from classes.custom.themed_frame import ThemedFrame
|
|
|
|
from modules.utils import configGet, get_string_mode
|
|
|
|
|
|
def try_connecting(master: Any):
|
|
try:
|
|
if requests.get(configGet("address")+"/apikey", headers={"apikey": configGet("apikey")}, verify=not configGet("allow_self_signed")).status_code == 403:
|
|
messagebox.showerror(title="Authentication error", message="Your API key seems to be invalid.")
|
|
return
|
|
# messagebox.showinfo(title="Connection succeeded", message="Server is reachable, apikey is valid, so your client is now ready to be used!")
|
|
master.destroy_everything()
|
|
except:
|
|
messagebox.showerror(title="Connection error", message="Server is not reachable or your client configuration is incorrect. Please check your network connection and client configuration.")
|
|
# master.destroy_everything()
|
|
|
|
|
|
class FrameErrorConnection(ThemedFrame):
|
|
|
|
def __init__(self, master: ThemedTk, **kwargs) -> None:
|
|
|
|
super().__init__(master, **kwargs)
|
|
|
|
self.grid_columnconfigure(0, weight=1)
|
|
|
|
self.grid_rowconfigure(0, weight=2)
|
|
self.grid_rowconfigure(1, weight=2)
|
|
|
|
master.columnconfigure(1, weight=1)
|
|
|
|
self.label = ttk.Label(self, text="Connection failed")
|
|
self.label.grid(column=0, row=0, padx=9, pady=9, sticky=S)
|
|
|
|
self.frame_buttons = ThemedFrame(self)
|
|
self.frame_buttons.grid(column=0, row=1, sticky=N)
|
|
|
|
self.button_retry = ttk.Button(self.frame_buttons, text="Retry", style="Accent.TButton", width=10, command=lambda:try_connecting(master))
|
|
self.button_settings = ttk.Button(self.frame_buttons, text="Settings", width=10, command=master.frame_settings)
|
|
self.button_retry.grid(column=0, row=0, padx=9, pady=9)
|
|
self.button_settings.grid(column=1, row=0, padx=9, pady=9)
|
|
|
|
|
|
class FrameErrorFirstStart(ThemedFrame):
|
|
|
|
def __init__(self, master: ThemedTk, **kwargs) -> None:
|
|
|
|
super().__init__(master, **kwargs)
|
|
|
|
self.grid_columnconfigure(0, weight=1)
|
|
|
|
self.grid_rowconfigure(0, weight=2)
|
|
self.grid_rowconfigure(1, weight=2)
|
|
|
|
master.columnconfigure(1, weight=1)
|
|
|
|
self.label = ttk.Label(self, text="Setup completed")
|
|
self.label.grid(column=0, row=0, padx=9, pady=9, sticky=S)
|
|
|
|
self.button_settings = ttk.Button(self, text="Refresh", style="Accent.TButton", width=10, command=lambda:try_connecting(master))
|
|
self.button_settings.grid(column=0, row=1, sticky=N)
|
|
|
|
|
|
class FrameErrorSavesFolder(ThemedFrame):
|
|
|
|
def __init__(self, master: ThemedTk, **kwargs) -> None:
|
|
|
|
super().__init__(master, **kwargs)
|
|
|
|
self.grid_columnconfigure(0, weight=1)
|
|
|
|
self.grid_rowconfigure(0, weight=2)
|
|
self.grid_rowconfigure(1, weight=2)
|
|
|
|
master.columnconfigure(1, weight=1)
|
|
|
|
self.label = ttk.Label(self, text="Invalid saves folder")
|
|
self.label.grid(column=0, row=0, padx=9, pady=9, sticky=S)
|
|
|
|
self.button_settings = ttk.Button(self, text="Settings", style="Accent.TButton", width=10, command=master.frame_settings)
|
|
self.button_settings.grid(column=0, row=1, sticky=N)
|
|
|
|
class FrameErrorUnconfigured(ThemedFrame):
|
|
|
|
def __init__(self, master: ThemedTk, **kwargs) -> None:
|
|
|
|
super().__init__(master, **kwargs)
|
|
|
|
self.grid_columnconfigure(0, weight=1)
|
|
|
|
self.grid_rowconfigure(0, weight=2)
|
|
self.grid_rowconfigure(1, weight=2)
|
|
|
|
master.columnconfigure(1, weight=1)
|
|
|
|
self.label = ttk.Label(self, text="Client not configured")
|
|
self.label.grid(column=0, row=0, padx=9, pady=9, sticky=S)
|
|
|
|
self.frame_buttons = ThemedFrame(self)
|
|
self.frame_buttons.grid(column=0, row=1, sticky=N)
|
|
|
|
self.button_settings = ttk.Button(self.frame_buttons, text="Settings", style="Accent.TButton", width=10, command=master.frame_settings)
|
|
self.button_settings.grid(column=0, row=0, padx=9, pady=9) |