2023-01-22 18:53:55 +02:00
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 :
2023-01-26 14:29:30 +02:00
if requests . get ( configGet ( " address " ) + " /apikey " , headers = { " apikey " : configGet ( " apikey " ) } , verify = not configGet ( " allow_self_signed " ) ) . status_code == 403 :
2023-01-22 18:53:55 +02:00
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 :
2023-01-26 14:29:30 +02:00
messagebox . showerror ( title = " Connection error " , message = " Server is not reachable or your client configuration is incorrect. Please check your network connection and client configuration. " )
2023-01-22 18:53:55 +02:00
# 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 )
2023-01-24 16:27:07 +02:00
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 )
2023-01-22 18:53:55 +02:00
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 )
2023-01-23 17:38:47 +02:00
self . label = ttk . Label ( self , text = " Client not configured " )
2023-01-22 18:53:55 +02:00
self . label . grid ( column = 0 , row = 0 , padx = 9 , pady = 9 , sticky = S )
2023-01-23 17:38:47 +02:00
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 )