1
1
from functions import *
2
2
3
+ default_path = os .path .join (os .path .expanduser ("~" ), "Downloads" )
3
4
4
- class Window ():
5
+
6
+ class Window :
5
7
def __init__ (self , frame ):
6
- customtkinter .set_appearance_mode ("light" )
8
+ create_database ()
9
+ self .id = get_user_id ()
7
10
11
+ customtkinter .set_appearance_mode ("light" )
8
12
self .frame = frame
9
-
10
13
font = ("Roboto mono" , 15 )
11
14
self .notebook = customtkinter .CTkTabview (
12
- self .frame , fg_color = ("#EBEBEB" , "#242424" ),
15
+ self .frame ,
16
+ fg_color = ("#EBEBEB" , "#242424" ),
13
17
text_color = ("#242424" , "#EBEBEB" ),
14
18
segmented_button_fg_color = ("#EBEBEB" , "#242424" ),
15
19
segmented_button_selected_color = ("#EBEBEB" , "#242424" ),
16
20
segmented_button_selected_hover_color = ("#EBEBEB" , "#242424" ),
17
21
segmented_button_unselected_color = ("#EBEBEB" , "#242424" ),
18
22
segmented_button_unselected_hover_color = ("#EBEBEB" , "#242424" ),
19
-
20
23
)
21
24
22
25
self .notebook .pack (fill = "both" , expand = True )
@@ -25,7 +28,6 @@ def __init__(self, frame):
25
28
self .notebook .add ("Home" )
26
29
self .tab = self .notebook .tab ("Home" )
27
30
28
-
29
31
self .frame .title ("Youtube downloader" )
30
32
self .frame .geometry ("800x600" )
31
33
self .label = customtkinter .CTkLabel (
@@ -57,9 +59,13 @@ def __init__(self, frame):
57
59
58
60
self .entry .bind ("<Return>" , lambda event : search (self ))
59
61
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" )
63
69
64
70
65
71
class setting (Window ):
@@ -74,11 +80,20 @@ def __init__(self, Frame):
74
80
self .animate = StringVar ()
75
81
76
82
# 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" ))
82
97
83
98
self .notebook .add ("Setting" )
84
99
self .setting = self .notebook .tab ("Setting" )
@@ -170,14 +185,13 @@ def __init__(self, Frame):
170
185
font = ("Roboto mono" , 15 ),
171
186
state = "readonly" ,
172
187
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" ))
176
190
if self .ex .get () == "Mp4"
177
191
else (
178
192
self .quality_option .configure (state = "disabled" ),
179
193
self .ql .set ("Mp3 quality" ),
180
- )
194
+ )
181
195
),
182
196
)
183
197
self .type .grid (row = 1 , column = 1 , pady = 5 )
@@ -193,7 +207,11 @@ def __init__(self, Frame):
193
207
for i in option :
194
208
place += 1
195
209
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 ,
197
215
)
198
216
self .theme_option .grid (row = 5 , column = place , pady = 20 )
199
217
@@ -225,8 +243,18 @@ def __init__(self, frame):
225
243
).grid (row = 6 , column = 3 )
226
244
227
245
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 )
228
256
# theme
229
- if self .x . get ( ) == "Light" :
257
+ if get_setting ( self .id , "theme" ) == "Light" :
230
258
customtkinter .set_appearance_mode ("light" )
231
259
232
260
self .search_icon = customtkinter .CTkImage (
@@ -235,12 +263,13 @@ def apply(self):
235
263
236
264
else :
237
265
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
+ )
240
269
241
270
self .button .configure (image = self .search_icon )
242
271
243
- if self .animate . get ( ) == "Enable" :
272
+ if get_setting ( self .id , "text" ) == "Enable" :
244
273
self .background_text .start ()
245
274
else :
246
275
@@ -254,10 +283,12 @@ def __init__(self, frame):
254
283
self .credit = self .notebook .tab ("Credit" )
255
284
256
285
credit_frame = customtkinter .CTkScrollableFrame (
257
- self .credit , orientation = "horizontal" )
286
+ self .credit , orientation = "horizontal"
287
+ )
258
288
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
+ )
261
292
text .pack (fill = "both" , expand = True )
262
293
with open ("Credit.txt" , "r" ) as f :
263
294
text .insert ("1.0" , f .read ())
@@ -266,15 +297,17 @@ def __init__(self, frame):
266
297
def close (frame , a ):
267
298
268
299
a .bool = False
269
- a .close_win = True
270
-
271
300
a .background_text .stop ()
301
+
272
302
frame .destroy ()
273
303
304
+
274
305
root = customtkinter .CTk ()
275
306
276
307
277
308
window = credit (root )
309
+ window .apply ()
310
+
278
311
root .protocol ("WM_DELETE_WINDOW" , lambda : close (root , window ))
279
312
root .resizable (False , False )
280
313
0 commit comments