2023-01-22 21:06:55 +02:00
from os import path
2023-01-23 17:38:47 +02:00
from tkinter import CENTER , END , E , LEFT , NSEW , Image , IntVar , N , S , PhotoImage , Toplevel , W , messagebox , ttk
2023-01-22 21:06:55 +02:00
import requests
import sv_ttk
from classes . custom . image_label import ImageLabel
2023-01-23 17:38:47 +02:00
from classes . custom . themed_frame import ThemedFrame
2023-01-22 21:06:55 +02:00
from classes . custom . themed_toplevel import ThemedToplevel
from modules . logger import logger
from modules . theme_titlebar import theme_title_bar
2023-01-23 17:38:47 +02:00
from modules . utils import configGet , configSet , resize_window , set_icon , use_dark_mode
2023-01-22 21:06:55 +02:00
class ToplevelWelcome ( ThemedToplevel ) :
def __init__ ( self , parent ) :
super ( ) . __init__ ( parent )
2023-01-23 17:38:47 +02:00
self . protocol ( " WM_DELETE_WINDOW " , self . __exit )
2023-01-22 21:06:55 +02:00
2023-01-23 17:38:47 +02:00
resize_window ( self , 380 , 350 )
2023-01-22 21:06:55 +02:00
self . title ( " Welcome to Stardew Sync " )
2023-01-23 17:38:47 +02:00
self . resizable ( False , False )
2023-01-22 21:06:55 +02:00
sv_ttk . init_theme ( self )
if use_dark_mode ( ) :
theme_title_bar ( self , mode = " dark " )
self . update ( )
2023-01-23 13:22:54 +02:00
set_icon ( self )
2023-01-22 21:06:55 +02:00
self . focus_set ( )
self . grid_columnconfigure ( 0 , weight = 1 )
2023-01-23 17:38:47 +02:00
self . window_frame = ThemedFrame ( self )
self . window_frame . grid ( column = 0 , row = 0 , sticky = NSEW )
self . window_frame [ " borderwidth " ] = 1
self . window_frame [ " relief " ] = " solid "
self . window_frame . grid_columnconfigure ( 0 , weight = 1 )
self . welcome_pic = ImageLabel ( self . window_frame )
2023-01-22 21:06:55 +02:00
self . welcome_pic . grid ( column = 0 , row = 0 , pady = 20 )
self . welcome_pic . load ( path . join ( " assets " , " welcome.gif " ) )
2023-01-23 17:38:47 +02:00
self . welcome_text = ttk . Label ( self . window_frame , text = " Welcome to Stardew Sync " , font = ( " SunValleyBodyFont " , 14 ) )
2023-01-22 21:06:55 +02:00
self . welcome_text . grid ( column = 0 , row = 1 , pady = 10 )
2023-01-23 17:38:47 +02:00
self . welcome_subtext = ttk . Label ( self . window_frame , text = " This small open-source application will help you \n to synchronize your Stardew Valley save files \n between all your devices " , justify = CENTER )
2023-01-22 21:06:55 +02:00
self . welcome_subtext . grid ( column = 0 , row = 2 )
2023-01-23 17:38:47 +02:00
self . welcome_button = ttk . Button ( self . window_frame , text = " Begin " , style = " Accent.TButton " , width = 10 , command = self . stage_address )
2023-01-22 21:06:55 +02:00
self . welcome_button . grid ( column = 0 , row = 3 , pady = 20 )
2023-01-23 17:38:47 +02:00
def stage_address ( self ) :
for widget in self . window_frame . winfo_children ( ) :
widget . destroy ( )
self . window_frame . grid_rowconfigure ( 0 , weight = 2 )
self . window_frame . grid_rowconfigure ( 1 , weight = 2 )
#self.window_frame.grid_rowconfigure(2, weight=3)
self . stage_label = ttk . Label ( self . window_frame , text = " Connection " , font = ( " SunValleyBodyFont " , 14 ) )
self . stage_label . grid ( column = 0 , row = 0 , pady = 40 )
self . stage_label_1 = ttk . Label ( self . window_frame , text = " Server address " , justify = LEFT )
self . stage_label_1 . grid ( column = 0 , row = 1 , pady = 5 , padx = 35 , sticky = W )
self . stage_entry_1 = ttk . Entry ( self . window_frame )
self . stage_entry_1 . grid ( column = 0 , row = 2 , pady = 5 , padx = 35 , sticky = W + E )
self . stage_label_1 = ttk . Label ( self . window_frame , text = " Personal API key " , justify = LEFT )
self . stage_label_1 . grid ( column = 0 , row = 3 , pady = 5 , padx = 35 , sticky = W )
self . stage_entry_1 = ttk . Entry ( self . window_frame )
self . stage_entry_1 . grid ( column = 0 , row = 4 , pady = 5 , padx = 35 , sticky = W + E )
self . stage_button = ttk . Button ( self . window_frame , text = " Continue " , style = " Accent.TButton " , width = 10 )
self . stage_button . grid ( column = 0 , row = 5 , pady = 40 )
2023-01-22 21:06:55 +02:00
def acknowledged ( self ) :
configSet ( [ " first_run " ] , False )
2023-01-23 17:38:47 +02:00
self . destroy ( )
def __exit ( self ) :
decision = messagebox . askyesno ( title = " Exit confirmation " , message = " Are you sure? If you exit now, your app will remain unconfigured. " )
if decision is True :
self . quit ( )