import tkinter as tk
import tkinter.ttk as ttk
import tkinter.filedialog as fd
import backend
import pathlib
def tryDownload() -> None :
if backend.checkSettings() :
if backend.downloadGodot(strvar.get(),mono.get()) == 0 :
print('Download was successful')
else :
print('Something went wrong')
else :
openSettings()
isInstalled()
def tryLaunch() -> None :
if backend.checkSettings() :
if backend.launch(strvar.get(),mono.get()) == 0 :
print("Launched successfully")
else :
print("Godot couldn't be launched")
else :
openSettings()
def tryRemove() -> None :
if backend.checkSettings() :
if backend.removeGodot(strvar.get(),mono.get()) == 0 :
print(f"Godot {strvar.get()} was removed.")
else :
print("Couldn't be removed.")
else :
openSettings()
isInstalled()
def getAppDir() -> None :
app_path.set(fd.askdirectory(initialdir=pathlib.Path.home(),mustexist=True))
def isInstalled(*event) -> None :
global strvar
DOWNLOAD_BUTTON = tk.Button(CANVAS,activebackground="#aaa",bg="#888",text="Download",command=tryDownload)
REMOVE_BUTTON = tk.Button(CANVAS,activebackground="#aaa",bg="#888",text="Remove",command=tryRemove)
if backend.getFile(strvar.get(),mono.get()) == 1 and backend.TOKEN != '' :
try :
REMOVE_BUTTON.destroy()
except :
pass
finally :
DOWNLOAD_BUTTON.place(width=72,height=36,relx=0.34,y=380)
else :
try :
DOWNLOAD_BUTTON.destroy()
except :
pass
finally :
REMOVE_BUTTON.place(width=72,height=36,relx=0.34,y=380)
def quit() -> None :
FRONTEND.quit()
def openSettings() -> None :
def saveSettings() -> None :
backend.suddenSet(dirSetting.get(),tokenSetting.get())
updateVersionList()
FRONTEND.event_generate('<<VersionChanged>>',when='tail')
settingsWindow.destroy()
settingsWindow = tk.Toplevel(FRONTEND)
settingsWindow.resizable(False,False)
settingsWindow.title('Settings')
settingsWindow.geometry("480x320")
settingsCanvas = tk.Canvas(settingsWindow,bg="#5095A7")
settingsCanvas.place(relheight=1,relwidth=1)
tk.Label(settingsCanvas,bg="#5095A7",text="PATH:").place(x=100,y=36,height=24,width=40)
tk.Label(settingsCanvas,bg="#5095A7",text="GitHub-Token:").place(x=100,y=100,height=24,width=90)
dirSetting: tk.Entry = tk.Entry(settingsCanvas,bd=1,bg="#aaa",textvariable=app_path)
dirSetting.place(height=24,width=240,x=96,y=60)
tk.Button(settingsCanvas,text="...",activebackground='#aaa',bg='#888',command=getAppDir).place(height=24,width=24,x=336,y=60)
tokenSetting: tk.Entry = tk.Entry(settingsCanvas,bd=1,bg="#aaa",show='*')
tokenSetting.place(height=24,width=264,x=96,y=124)
tk.Button(settingsCanvas,text="Save",activebackground='#aaa',bg='#888',command=saveSettings).place(height=36,width=90,x=195,y=180)
def updateVersionList() -> None :
global CUR_VERSION
global VERSION_MENU
global strvar
updatedList = backend.verOptions(mono.get(),CUR_VERSION)
if CUR_VERSION != updatedList or VERSION_MENU.winfo_exists() :
CUR_VERSION = updatedList
strvar = tk.StringVar(CANVAS,CUR_VERSION[0])
VERSION_MENU = ttk.Combobox(master=CANVAS,textvariable=strvar,values=CUR_VERSION,state='readonly',font="Sans 12",style='M.TCombobox')
VERSION_MENU.bind('<<VersionChanged>>',isInstalled)
VERSION_MENU.bind('<FocusIn>',isInstalled)
VERSION_MENU.place(width=256,height=36,relx=0.31,y=120)
isInstalled()
def setMono() -> None :
MONO_CHECK.event_generate('<<VersionChanged>>',when='tail')
CUR_VERSION = None
FRONTEND = tk.Tk()
FRONTEND.geometry("650x480")
FRONTEND.resizable(False,False)
FRONTEND.title("GVM")
icon = tk.PhotoImage("img/icon.png")
FRONTEND.iconphoto(True,icon)
app_path = tk.StringVar(FRONTEND,backend.APP_PATH)
ttk.Style().configure("M.TCombobox",background="#888")
ttk.Style().map("M.TCombobox",background=[('active','#aaa')])
CANVAS = tk.Canvas(FRONTEND,bg="#11a9a9")
LAUNCH_BUTTON = tk.Button(CANVAS,activebackground="#aaa",bg="#888",text="Launch",command=tryLaunch)
DOWNLOAD_BUTTON = tk.Button(CANVAS,activebackground="#aaa",bg="#888",text="Download",command=tryDownload)
REMOVE_BUTTON = tk.Button(CANVAS,activebackground="#aaa",bg="#888",text="Remove",command=tryRemove)
mono = tk.StringVar(CANVAS,'no_mono')
MONO_CHECK = tk.Checkbutton(CANVAS,text="Mono Version",bg="#45b6be",fg='#000',activebackground="#4ed8cc",activeforeground="#000",offvalue='no_mono',onvalue='mono',variable=mono,command=updateVersionList)
Menubar = tk.Menu(CANVAS,type='menubar')
file_menu = tk.Menu(Menubar,tearoff=False)
file_menu.add_command(label='Settings',command=openSettings)
file_menu.add_separator()
file_menu.add_command(label='Exit',command=quit)
Menubar.add_cascade(label='File',menu=file_menu)
CANVAS.place(relheight=1,relwidth=1)
CANVAS.create_image(120,20)
CANVAS.create_text(325,36,font="JetBrainsMono 24",text="Godot Version Manager")
LAUNCH_BUTTON.place(width=72,height=36,relx=0.55,y=380)
updateVersionList()
MONO_CHECK.place(width=128,height=24,relx=0.75,y=126)
#help line
#tk.Canvas(bg="#ff0000").place(relheight=1,width=2,x=325)
FRONTEND.configure(menu=Menubar)
FRONTEND.mainloop()