ocarina/trunk/src/playlist.py

64 lines
1.5 KiB
Python

from list import List
import random
from menuItem import MenuItem
class Playlist(List):
def __init__(self,data,queue,nextFunc,labelFunc,plause):
List.__init__(self,data,"Playlist",nextFunc,labelFunc,plause)
self.queue = queue
#for file in self.data.curList:
# List.insert(self,file)
self.populated = False
self.makeRCMenu()
def visible(self,func):
List.visible(self,func)
if (func == "show") and (self.populated == False):
for file in self.data.curList:
List.insert(self,file)
self.populated = True
self.makeLabel()
def insert(self,file):
if self.populated == False:
self.visible("show")
List.insert(self,file)
self.data.curList+=[file]
#self.populated = True
def drop(self):
List.drop(self)
self.data.curList = []
def getNext(self):
# If random is true, give back a random song
max = len(self.filter) - 1
if max == -1:
return False
if self.data.random == True:
self.data.curSong = self.filter[random.randint(0,max)][0]
# Otherwise, give back next non-filtered song
else:
next = self.filter[0][0]
for i in range(max):
if self.filter[i][0]==self.data.curSong:
next = self.filter[i+1][0]
break
self.data.curSong = next
self.loadSong(self.data.library.files[self.data.curSong])
return True
def makeRCMenu(self):
List.makeRCMenu(self)
toQ = MenuItem("Add to queue",self.addToQ,None,None,None)
self.rcmenu.prepend(toQ)
def addToQ(self,widgit,func,data):
self.selection(self.queue.insert)
self.queue.filterRows("")