Skip to content

Commit ed153bd

Browse files
committed
add database
1 parent 324bcb6 commit ed153bd

File tree

4 files changed

+202
-82
lines changed

4 files changed

+202
-82
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.venv
2-
__pycache__
2+
__pycache__
3+
tempCodeRunnerFile.py

UI.py

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
from functions import *
22

3+
default_path = os.path.join(os.path.expanduser("~"), "Downloads")
34

4-
class Window():
5+
6+
class Window:
57
def __init__(self, frame):
6-
customtkinter.set_appearance_mode("light")
8+
create_database()
9+
self.id = get_user_id()
710

11+
customtkinter.set_appearance_mode("light")
812
self.frame = frame
9-
1013
font = ("Roboto mono", 15)
1114
self.notebook = customtkinter.CTkTabview(
12-
self.frame, fg_color=("#EBEBEB", "#242424"),
15+
self.frame,
16+
fg_color=("#EBEBEB", "#242424"),
1317
text_color=("#242424", "#EBEBEB"),
1418
segmented_button_fg_color=("#EBEBEB", "#242424"),
1519
segmented_button_selected_color=("#EBEBEB", "#242424"),
1620
segmented_button_selected_hover_color=("#EBEBEB", "#242424"),
1721
segmented_button_unselected_color=("#EBEBEB", "#242424"),
1822
segmented_button_unselected_hover_color=("#EBEBEB", "#242424"),
19-
2023
)
2124

2225
self.notebook.pack(fill="both", expand=True)
@@ -25,7 +28,6 @@ def __init__(self, frame):
2528
self.notebook.add("Home")
2629
self.tab = self.notebook.tab("Home")
2730

28-
2931
self.frame.title("Youtube downloader")
3032
self.frame.geometry("800x600")
3133
self.label = customtkinter.CTkLabel(
@@ -57,9 +59,13 @@ def __init__(self, frame):
5759

5860
self.entry.bind("<Return>", lambda event: search(self))
5961

60-
customtkinter.CTkLabel(self.tab,
61-
text=None,
62-
image=customtkinter.CTkImage(PIL.Image.open("Icons/sticker1.png"), size=(350, 200))).place(relx=1, rely=0.35, anchor="e")
62+
customtkinter.CTkLabel(
63+
self.tab,
64+
text=None,
65+
image=customtkinter.CTkImage(
66+
PIL.Image.open("Icons/sticker1.png"), size=(350, 200)
67+
),
68+
).place(relx=1, rely=0.35, anchor="e")
6369

6470

6571
class setting(Window):
@@ -74,11 +80,20 @@ def __init__(self, Frame):
7480
self.animate = StringVar()
7581

7682
# default value
77-
self.ex.set("Mp4")
78-
self.x.set("Light")
79-
self.ql.set("720p")
80-
self.t.set(r"C:\Users\User\Downloads")
81-
self.animate.set("Enable")
83+
84+
setting_dict = {
85+
"type": "Mp4",
86+
"theme": "Light",
87+
"ql": "720p",
88+
"location": str(default_path),
89+
"text": "Enable",
90+
}
91+
default_setting(self.id, setting_dict=setting_dict)
92+
self.ex.set(get_setting(self.id, "type"))
93+
self.x.set(get_setting(self.id, "theme"))
94+
self.ql.set(get_setting(self.id, "ql"))
95+
self.t.set(get_setting(self.id, "location"))
96+
self.animate.set(get_setting(self.id, "text"))
8297

8398
self.notebook.add("Setting")
8499
self.setting = self.notebook.tab("Setting")
@@ -170,14 +185,13 @@ def __init__(self, Frame):
170185
font=("Roboto mono", 15),
171186
state="readonly",
172187
variable=self.ex,
173-
command=lambda e: ((
174-
self.quality_option.configure(state="readonly"),
175-
self.ql.set("720p"))
188+
command=lambda e: (
189+
(self.quality_option.configure(state="readonly"), self.ql.set("720p"))
176190
if self.ex.get() == "Mp4"
177191
else (
178192
self.quality_option.configure(state="disabled"),
179193
self.ql.set("Mp3 quality"),
180-
)
194+
)
181195
),
182196
)
183197
self.type.grid(row=1, column=1, pady=5)
@@ -193,7 +207,11 @@ def __init__(self, Frame):
193207
for i in option:
194208
place += 1
195209
self.theme_option = customtkinter.CTkRadioButton(
196-
self.setting, text=i, font=("Roboto mono", 15), value=i, variable=self.animate
210+
self.setting,
211+
text=i,
212+
font=("Roboto mono", 15),
213+
value=i,
214+
variable=self.animate,
197215
)
198216
self.theme_option.grid(row=5, column=place, pady=20)
199217

@@ -225,8 +243,18 @@ def __init__(self, frame):
225243
).grid(row=6, column=3)
226244

227245
def apply(self):
246+
# update setting
247+
248+
setting_dict = {
249+
"type": self.ex.get(),
250+
"theme": self.x.get(),
251+
"ql": self.ql.get(),
252+
"location": self.t.get(),
253+
"text": self.animate.get(),
254+
}
255+
update_setting(self.id, setting_dict=setting_dict)
228256
# theme
229-
if self.x.get() == "Light":
257+
if get_setting(self.id, "theme") == "Light":
230258
customtkinter.set_appearance_mode("light")
231259

232260
self.search_icon = customtkinter.CTkImage(
@@ -235,12 +263,13 @@ def apply(self):
235263

236264
else:
237265
customtkinter.set_appearance_mode("dark")
238-
self.search_icon = customtkinter.CTkImage(PIL.Image.open(
239-
"Icons/search-interface-symbol-white.png"), size=(25, 25))
266+
self.search_icon = customtkinter.CTkImage(
267+
PIL.Image.open("Icons/search-interface-symbol-white.png"), size=(25, 25)
268+
)
240269

241270
self.button.configure(image=self.search_icon)
242271

243-
if self.animate.get() == "Enable":
272+
if get_setting(self.id, "text") == "Enable":
244273
self.background_text.start()
245274
else:
246275

@@ -254,10 +283,12 @@ def __init__(self, frame):
254283
self.credit = self.notebook.tab("Credit")
255284

256285
credit_frame = customtkinter.CTkScrollableFrame(
257-
self.credit, orientation="horizontal")
286+
self.credit, orientation="horizontal"
287+
)
258288
credit_frame.pack(fill="both", expand=True)
259-
text = customtkinter.CTkTextbox(credit_frame, font=(
260-
"Roboto mono", 15), width=1920, height=1080)
289+
text = customtkinter.CTkTextbox(
290+
credit_frame, font=("Roboto mono", 15), width=1920, height=1080
291+
)
261292
text.pack(fill="both", expand=True)
262293
with open("Credit.txt", "r") as f:
263294
text.insert("1.0", f.read())
@@ -266,15 +297,17 @@ def __init__(self, frame):
266297
def close(frame, a):
267298

268299
a.bool = False
269-
a.close_win = True
270-
271300
a.background_text.stop()
301+
272302
frame.destroy()
273303

304+
274305
root = customtkinter.CTk()
275306

276307

277308
window = credit(root)
309+
window.apply()
310+
278311
root.protocol("WM_DELETE_WINDOW", lambda: close(root, window))
279312
root.resizable(False, False)
280313

data/setting.db

Whitespace-only changes.

0 commit comments

Comments
 (0)