-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
130 lines (91 loc) · 4.15 KB
/
Main.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
from SpotiPlus import SpotiPlus
import kivy
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivy.config import Config
from kivy.uix.popup import Popup
from kivy.clock import Clock
from kivy.uix.anchorlayout import AnchorLayout
# Setting the window size and making it non resizable
Config.set("graphics", "width", "300")
Config.set("graphics", "height", "285")
Config.set("graphics", "resizable", False)
class HomeWindow(Screen):
"""This will represent the home window"""
pass
class SettingsWindow(Screen):
"""This will represent the settings window"""
pass
class Popups(AnchorLayout):
"""This will represent the popup window"""
pass
sm = Builder.load_file("SpotiPlus.kv")
class SpotiPlusApp(App):
def build(self):
self.sp = SpotiPlus()
return sm
def on_start(self):
"""This function is called on the start of the application"""
# Getting the previously set playlist if existing.
self.sp.readSettingFromFile()
# Setting the correct text values in the gui for selected playlist
self.setPlaylistInGUI()
def setPlaylistInGUI(self):
"""This function will set the name of the currently selected playlist in the GUI"""
# Checking if a playlist id has been set. setting currentplaylist value to "no playlist selected" otherwise
if (self.sp.checkIfPlaylistIDHasBeenSet()):
currentPlaylist = self.sp.getCurrentPlaylistName()
else:
currentPlaylist = "No playlist selected!"
self.root.get_screen("home").ids.selectedPlaylist.text = currentPlaylist
self.root.get_screen("settings").ids.selectedPlaylist.text = currentPlaylist
def showPopup(self, msg):
"""Will display a popup with the given msg"""
def autoClose(dt):
popupWindow.dismiss()
# Creating an instance of the popup once and setting the msg text.
show = Popups()
show.ids.pu.text = msg
# Making a popup instance which uses our Popups class as the content (what was created in the kv file)
popupWindow = Popup(title ="Alert", content = show, size_hint =(None, None), size = (300, 150))
# open popup window
popupWindow.open()
# Closing the popup automatically in X seconds
Clock.schedule_once(autoClose, 2)
def addCurrentSongToPlaylist(self):
"""This function will handle anything needed to add the current song to the selected playlist"""
# Checking if current playlist has been set or not
if not (self.sp.checkIfPlaylistIDHasBeenSet()):
self.showPopup("Please select a playlist first!")
return
# Adding current song to selected playlist
self.sp.addCurrentSongToSelectedPlaylist()
self.showPopup("Current song has been added to playlist!")
def setSelectedPlaylist(self):
"""This function will handle anything needed to set the users given playlist as the selected playlist"""
# Getting the input from the gui by the ID
playlistID = self.root.get_screen("settings").ids.uInput.text
# Checking if input isn't empty
if (len(playlistID) < 1):
self.showPopup("Playlist ID is too short!")
return
# Checking if playlist exists
playlistValid = self.sp.checkIfValidPlaylist(playlistID)
if not (playlistValid):
self.showPopup(f"Playlist {playlistID} does not exist!")
return
# Checking if the user is the owner of the given playlist
isPlaylistOwner = self.sp.checkIfUserIsOwner(playlistID)
if not (isPlaylistOwner):
self.showPopup(f"You are not the owner of playlist {playlistID}!")
return
# Setting the playlist in the SpotiPlus class
self.sp.setSelectedPlaylist(playlistID)
playlistName = self.sp.getCurrentPlaylistName()
self.showPopup(f"Playlist {playlistName} succesfully set!")
# Setting / updating the playlist name in gui
self.setPlaylistInGUI()
if (__name__ == "__main__"):
app = SpotiPlusApp()
app.run()