-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
147 lines (123 loc) · 6.1 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import json
import get_info
import keybind
import custom_theme
from repair import repair
import backup
import logger as l
from CTkMessagebox import CTkMessagebox
import update
def get_setting(setting: str, default = False):
with open("save.json","r") as f:
settings_file = json.load(f)
return settings_file.get("settings",{}).get(setting, default)
def change_setting(setting:str, value):
l.log(type="INFO", message=f"Changing '{setting}' to '{value}'")
repair()
with open("save.json","r") as f:
settings_file = json.load(f)
if "settings" not in settings_file:
settings_file["settings"] = {}
settings_file["settings"][setting] = value
backup.backup()
with open("save.json","w") as f:
json.dump(settings_file,f,indent=2)
def get_custom_theme():
"""
Returns dict
Example: {"hover": "#30566E", "frame_bg": "#30566E", "main_bg": "#30566E", "button_color": "#30566E", "opacity": "1.0"}
"""
repair()
with open("save.json","r") as f:
settings_file = json.load(f)
return settings_file.get("settings",{}).get("custom_theme")
def check_for_updates__(event=None):
event = None
update.check_for_updates()
def gui():
repair()
l.log(type="DEBUG",message="Loading settings GUI")
import customtkinter as ctk
root = ctk.CTk()
root.title("Settings")
root.geometry("500x500")
frame_ = ctk.CTkFrame(root,width=450,height=450)
frame_.place(relx=0.5,rely=0.5,anchor=ctk.CENTER)
check_for_updates_ = ctk.CTkButton(frame_,text="Check For Updates",command=check_for_updates__)
def sca():
msg = CTkMessagebox(title="Warning Message!", message="Restart is required for this setting to apply.",icon="warning", option_1="Apply", option_2="Cancel")
if msg.get()=="Apply":
mode_ = scaling_option.get()
change_setting(setting="scaling",value=mode_)
confirm = CTkMessagebox(title="Restart", message="Do you want to restart now?",icon="question", option_1="Yes", option_2="No")
if confirm.get() == "Yes":
import os, sys
python = sys.executable
os.execl(python,python,* sys.argv)
else:
if scaling_option.get() == 1:
scaling_option.deselect()
else:
scaling_option.select()
def sou():
mode_ = switch.get()
change_setting(setting="sound",value=mode_)
def che():
mode_ = check_for_updates_switch.get()
change_setting(setting="check",value=mode_)
cfu = mode_
if mode_ == False:
check_for_updates_.place(relx=0.5,rely=0.08,anchor=ctk.CENTER)
else:
check_for_updates_.place(relx=12,rely=0.08,anchor=ctk.CENTER)
def mus():
mode_ = music_switch.get()
change_setting(setting="music",value=mode_)
mus_ = mode_
def hid():
mode_ = auto_hide.get()
change_setting(setting="autohide",value=mode_)
ah = mode_
scaling_option = ctk.CTkSwitch(frame_,onvalue=True,offvalue=False,text="",switch_width=50,switch_height=25,width=50,height=25,command=sca)
scaling_option.place(relx=0.1,rely=0.2,anchor=ctk.CENTER)
scaling_label = ctk.CTkLabel(frame_,text="Dynamic Scaling",font=("Helvetica",18))
scaling_label.place(relx=0.31,rely=0.2,anchor=ctk.CENTER)
switch = ctk.CTkSwitch(master=frame_, onvalue=True, offvalue=False,text="",switch_width=50,switch_height=25,width=50,height=25,command=sou)
switch.place(relx=0.1,rely=0.3,anchor=ctk.CENTER)
switch_label = ctk.CTkLabel(frame_,text="SFX",font=("Helvetica",18))
switch_label.place(relx=0.2,rely=0.3,anchor=ctk.CENTER)
auto_hide = ctk.CTkSwitch(frame_,text="",onvalue=True,offvalue=False,switch_width=50,switch_height=25,width=50,height=25,command=hid)
auto_hide.place(relx=0.9,rely=0.3,anchor=ctk.CENTER)
auto_close_label = ctk.CTkLabel(frame_,text="Auto hide results",font=("Helvetica",18))
auto_close_label.place(relx=0.67,rely=0.3,anchor=ctk.CENTER)
check_for_updates_switch = ctk.CTkSwitch(frame_,text="",onvalue=True,offvalue=False,switch_width=50,switch_height=25,command=che,width=50,height=25)
check_for_updates_switch.place(relx=0.1,rely=0.4,anchor=ctk.CENTER)
check_for_updates_label = ctk.CTkLabel(frame_,text="Automatically check for updates",font=("Helvetica",18))
check_for_updates_label.place(relx=0.45,rely=0.4,anchor=ctk.CENTER)
music_switch = ctk.CTkSwitch(frame_,text="",command=mus,switch_width=50,switch_height=25,width=50,height=25,onvalue=True,offvalue=False)
music_switch.place(relx=0.9,rely=0.2,anchor=ctk.CENTER)
music_label = ctk.CTkLabel(frame_,text="Music",font=("Helvetica",18))
music_label.place(relx=0.765,rely=0.2,anchor=ctk.CENTER)
warn = ctk.CTkLabel(frame_,text="",text_color="#cc3300",font=("Helvetica",24))
warn.place(relx=0.5,rely=0.1,anchor=ctk.CENTER)
keybinds = ctk.CTkButton(frame_,text="Change keybinds",command=keybind.GUI)
keybinds.place(relx=0.83,rely=0.08,anchor=ctk.CENTER)
update = ctk.CTkButton(frame_,text="Change keybinds",command=keybind.GUI)
#share_button = ctk.CTkButton(frame_,text="Share",command=share)
#share_button.place(relx=0.5,rely=0.94,anchor=ctk.CENTER)
sc = get_setting("scaling")
so = get_setting("sound")
cfu = get_setting("check")
mus_ = get_setting("music")
ah = get_setting("autohide")
theme_button = ctk.CTkButton(frame_,text="Theme",command=custom_theme.GUI)
theme_button.place(relx=0.5,rely=0.7,anchor=ctk.CENTER)
version_label = ctk.CTkLabel(frame_,text=f"Application: v{float(get_info.application_ver())}({get_info.release_type()}), Theme: v{float(get_info.theme_ver())}, Save: v{float(get_info.save_ver())} ",font=("Helvetica",12))
version_label.place(relx=0.4,rely=0.95,anchor=ctk.CENTER)
if sc == True: scaling_option.select()
if cfu == True: check_for_updates_switch.select()
else: check_for_updates_.place(relx=0.5,rely=0.08,anchor=ctk.CENTER)
if so == True: switch.select()
if mus_ == True: music_switch.select()
if ah == True: auto_hide.select()
root.mainloop()