forked from kanishkarj/Rave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playlist.py
85 lines (72 loc) · 4.12 KB
/
playlist.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
'''code for playlist functionalities.
The VlcPlayer.py contains mediaPlayer instance and media instance
which is connected to medialist here'''
import sys
import os.path
from packages.libvlc import vlc
from PyQt4 import QtCore, QtGui
from Qt_Designer_files.playlist_design import Ui_playlist #import playlist UI
class Playlist(QtGui.QDialog):
def __init__(self):
super(Playlist,self).__init__()
self.window=Ui_playlist()
self.window.setupUi(self)
self.mediaList=vlc.Instance().media_list_new() #create medialist instance
self.window.listAdd.setIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__),'icons/svg/IconSet2/addMedia.svg')))
self.window.listAdd.setIconSize(QtCore.QSize(40,40))
self.window.listAdd.setStyleSheet ('background-color:transparent; border-radius:5em;')
self.window.listRemove.setIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__),'icons/svg/IconSet2/removeMedia.svg')))
self.window.listRemove.setIconSize(QtCore.QSize(30,30))
self.window.listRemove.setStyleSheet ('background-color:transparent; border-radius:5em;')
self.window.listRearrange.setIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__),'icons/svg/IconSet2/rearrange.svg')))
self.window.listRearrange.setIconSize(QtCore.QSize(30,30))
self.window.listRearrange.setStyleSheet ('background-color:transparent; border-radius:5em;')
self.window.mediaList.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
self.connect(self.window.listRearrange,QtCore.SIGNAL("clicked()"),self.rearrangePlaylist)
#Add single item to medialist
def setSingleFile(self,filename):
self.mediaList.add_media(filename)
self.updatePlaylistUi()
return self.mediaList[len(self.mediaList)-1]
#add multiple items to medialist
def setMultipleFiles(self,filenames):
for file in filenames:
self.mediaList.add_media(file)
self.updatePlaylistUi()
return self.mediaList[len(self.mediaList)-len(filenames)]
def itemToMedia(self,item):
for media in self.mediaList:
if media.get_meta(0)==item.text():
return media
def mediaToItem(self,media):
i=self.mediaList.index_of_item(media)
return self.window.mediaList.item(i)
#show medialist items in playlist UI window
def updatePlaylistUi(self):
self.window.mediaList.clear()
for media in self.mediaList:
self.window.mediaList.addItem(media.get_meta(0))
#show playing icon against cuurently playing item
def setNowPlaying(self,media):
item=self.mediaToItem(media)
for i in range(self.window.mediaList.count()):
if item==self.window.mediaList.item(i):
self.window.mediaList.item(i).setIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__),'icons/svg/IconSet2/nowPlaying.svg')))
else:
self.window.mediaList.item(i).setIcon(QtGui.QIcon(''))
#rearrange playlist and medialist using drag and drop
def rearrangePlaylist(self):
if self.window.mediaList.dragDropMode()!= QtGui.QAbstractItemView.InternalMove:
self.window.mediaList.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
self.window.listRearrange.setIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__),'icons/svg/IconSet2/done.svg')))
self.window.listRearrange.setIconSize(QtCore.QSize(30,30))
self.window.listRearrange.setStyleSheet ('background-color:transparent;')
else:
self.window.mediaList.setDragDropMode(QtGui.QAbstractItemView.NoDragDrop)
self.window.listRearrange.setIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__),'icons/svg/IconSet2/rearrange.svg')))
self.window.listRearrange.setIconSize(QtCore.QSize(30,30))
self.window.listRearrange.setStyleSheet ('background-color:transparent;')
mList=vlc.Instance().media_list_new()
for i in range(self.window.mediaList.count()):
mList.add_media(self.itemToMedia(self.window.mediaList.item(i)))
self.mediaList=mList