105 lines
2.6 KiB
Python
105 lines
2.6 KiB
Python
import gobject
|
|
import pygtk
|
|
pygtk.require('2.0')
|
|
import gtk
|
|
|
|
|
|
class PlistView(gtk.ScrolledWindow):
|
|
def __init__(self,data):
|
|
gtk.ScrolledWindow.__init__(self)
|
|
self.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
|
|
self.data = data
|
|
self.data.song.next = self.next
|
|
self.tree = None
|
|
self.label = gtk.Label("")
|
|
self.makeList()
|
|
gobject.timeout_add(1000,self.checkUpdate)
|
|
|
|
|
|
def checkUpdate(self):
|
|
if self.data.updateList == True:
|
|
self.data.updateList = False
|
|
self.makeList()
|
|
return True
|
|
|
|
|
|
def makeList(self):
|
|
trackList= gtk.ListStore(int,str,str,str,str,int)
|
|
if self.tree:
|
|
self.remove(self.tree)
|
|
time = 0
|
|
for index in self.data.curList:
|
|
track = self.data.library.files[index]
|
|
trackList.append([track.id,track.title,track.length,track.artist,track.album,track.count])
|
|
time+=track.duration
|
|
self.tree = gtk.TreeView(trackList)
|
|
cell = gtk.CellRendererText()
|
|
cols = ["Id","Title","Length","Artist","Album","#"]
|
|
trackList.set_sort_column_id(self.data.sortedCol,gtk.SORT_ASCENDING)
|
|
lenSaved = len(self.data.colSizes)
|
|
for i in range(len(cols)):
|
|
col = gtk.TreeViewColumn(cols[i],cell)
|
|
col.add_attribute(cell,'text',i)
|
|
col.set_resizable(True)
|
|
col.set_sort_column_id(i)
|
|
col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
|
col.set_min_width(2)
|
|
col.set_max_width(700)
|
|
if cols[i] != "Id":
|
|
self.tree.append_column(col)
|
|
self.tree.set_rules_hint(True)
|
|
self.tree.connect("row-activated",self.selectSong,"clicked",trackList)
|
|
self.tree.show()
|
|
self.resizeCols()
|
|
self.add(self.tree)
|
|
self.makeTimeLabel(time)
|
|
|
|
|
|
# Use to save column widths
|
|
def saveCols(self):
|
|
cols = self.tree.get_columns()
|
|
self.data.colSizes = []
|
|
for col in cols:
|
|
self.data.colSizes +=[col.get_width()]
|
|
|
|
|
|
def resizeCols(self):
|
|
cols = self.tree.get_columns()
|
|
for i in range(len(self.data.colSizes)):
|
|
cols[i].set_fixed_width(self.data.colSizes[i])
|
|
|
|
|
|
def makeTimeLabel(self,time):
|
|
day = time/86500
|
|
time = time-(day*86500)
|
|
hour = time/3600
|
|
time = time-(hour*3600)
|
|
min = time/60
|
|
time = time-(min*60)
|
|
|
|
string = self.toStr(day,"day")+self.toStr(hour,"hour")
|
|
string += self.toStr(min,"minute")+self.toStr(time,"second")
|
|
self.label.set_text(string)
|
|
self.label.show()
|
|
|
|
|
|
def toStr(self,time,label):
|
|
if time > 0:
|
|
string=str(time) + " "+label
|
|
if time > 1:
|
|
string+="s"
|
|
string += " "
|
|
return string
|
|
|
|
|
|
def selectSong(self,widgit,iter,path,data,list):
|
|
print list[iter][0]
|
|
if self.data.song:
|
|
self.data.song.close()
|
|
self.data.song.passInfo(self.data.library.files[list[iter][0]])
|
|
self.data.song.play(None,None)
|
|
|
|
|
|
def next(self):
|
|
self.song.close()
|