-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
96 lines (79 loc) · 3.34 KB
/
gui.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
import abc
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
from manager import VideoManager
from util import threaded
class GUI(abc.ABC):
"""Abstract class for a GUI."""
def __init__(self, title, manager=VideoManager()):
self.manager = manager
self.root = Tk()
self.root.title(title)
self.mainframe = ttk.Frame()
self.mainframe.grid()
self.mainframe.grid(column=20, row=20, sticky=(N, W, E, S))
self.root.columnconfigure(0, weight=1)
self.root.rowconfigure(0, weight=1)
@abc.abstractmethod
def run(self):
"""Runs the GUI.
Must create and show all elements as well as run mainloop."""
pass
class HomeGUI(GUI):
"""GUI for home page."""
def __init__(self, title):
super().__init__(title)
self.folder = ""
def run(self):
def __login(s):
s.manager.login()
login_button['state'] = DISABLED
download_button['state'] = 'normal'
upload_button['state'] = 'normal'
url = ""
url_label = ttk.Label(self.mainframe,
text="Enter Video URL To Download")
url_input = ttk.Entry(self.mainframe, width=30, textvariable=url)
download_button = ttk.Button(self.mainframe,
text="Download",
command=lambda:
threaded(lambda:
self.manager.save_videos(
url_input.get())))
login_button = ttk.Button(self.mainframe,
text="Login",
command=lambda: threaded(lambda:
__login(self)))
browse_button = ttk.Button(self.mainframe,
text="Browse",
command=self.set_path)
upload_button = ttk.Button(self.mainframe,
text="Upload",
command=lambda:
self.threaded_with_path(
self.manager.post_video))
login_button.grid(column=0, row=0, sticky=W, pady=10, padx=10)
url_label.grid(column=0, row=1, padx=10)
url_input.grid(column=1, row=1, padx=10)
download_button.grid(column=1, row=3)
browse_button.grid(column=0, row=4, pady=10)
upload_button.grid(column=2, row=4, pady=10, padx=10)
download_button['state'] = DISABLED
upload_button['state'] = DISABLED
self.root.mainloop()
def threaded_with_path(self, func):
"""Runs the function in a separate thread while giving it the
current path."""
if self.folder != "":
threaded(lambda: func(self.folder))
def set_path(self):
"""Opens a new filedialog and sets selected file as current path."""
self.folder = filedialog.askdirectory()
self.manager.change_folder(self.folder)
current_video = ttk.Label(self.mainframe,
text=f"{self.folder}")
current_video.grid(column=1, row=4, pady=10)
if __name__ == '__main__':
gui = HomeGUI("Youtube Backup V1.1")
gui.run()