-
Notifications
You must be signed in to change notification settings - Fork 2
/
GUI.py
executable file
·102 lines (87 loc) · 3.56 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
97
98
99
100
101
102
from Tkinter import *
from main import *
from song_finder import *
import crawler
class GUI(Frame):
def __init__(self, master):
"""
Initial setup of GUI
***************No error section starts****************
"""
Frame.__init__(self, master)
#self.pack()
self.grid()
self.widgets()
"""
***************No error section ends******************
"""
#Function to populate the RHS Listbox with metadata.
def populate_Song_Metadata(self, relevant_data):
"""
relevant_data: a dictionary containing (key:value) pairs of metadata.
"""
self.lbox2.delete(0, END)
print(relevant_data)
for key in relevant_data.keys():
insert_string = key + ': ' + str(relevant_data[key])
self.lbox2.insert(END, insert_string)
#Function to generate a list of similar songs.
def populate_Similar_Songs(self, search):
"""
This function populates the LHS Listbox with similar songs
based on the text entered in the search bar.
search: the text entered in the search bar.
"""
songs = populateSongs(search)
self.lbox.delete(0, END)
self.lbox.insert(END, songs)
#Function to initiate a search for the song.
def search(self):
"""
This function initiates a new search based on the text entered in the search bar.
"""
search_string = self.search_var.get()
print(search_string)
self.populate_Similar_Songs(search_string)
metadata = initiate_Search(search_string)
self.populate_Song_Metadata(metadata)
initiate_Download(search_string, metadata)
#Function to trigger on double click of self.lbox
def onDouble(self, event):
"""
The event parameter provides the text that has been doubled click.
This function initiates a new search based on the text selected.
"""
widget = event.widget
selection=widget.curselection()
value = widget.get(selection[0])
self.entry.delete(0, END)
self.entry.insert(END, value)
#Function to setup the basic layout of the Graphical User Interface
def widgets(self):
"""
Loads the heading label, a box to enter the search (entry), a button to search
and two boxes to display various data (Listbox).
"""
Label(self, text="Song Downloader System", background="#CC0001", font= ("Comic Sans MS",16)).grid(row=0, column=0, padx=20)
self.search_var = StringVar()
self.entry = Entry(self, textvariable=self.search_var, width=45)
self.b1=Button(self, text='Search', command=self.search)
self.b1.grid(row=1, column=1, sticky=W, padx=20, pady=10)
self.lbox = Listbox(self, width=45, height=15)
self.lbox.grid(row=2, column=0, columnspan=6,sticky=W, padx=20, pady=10)
self.lbox.bind("<Double-Button-1>", self.onDouble)
self.lbox2 = Listbox(self, width=45, height=15)
self.lbox2.grid(row=2, column=1, columnspan=6,sticky=W, padx=2000, pady=10)
"""
Initial setup of GUI
***************No error section starts****************
"""
r = Tk()
r.geometry("800x600")
r.title("Song Downloader")
s = GUI(r)
s.mainloop()
"""
***************No error section ends******************
"""