Playlist shows in main window
git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@24 1daee41c-8060-4895-b1f0-2197c00d777a
This commit is contained in:
parent
2f946a6d71
commit
a687c14a14
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import tagpy
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
from libdata import LibData
|
from libdata import LibData
|
||||||
from songInfo import SongInfo
|
from songInfo import SongInfo
|
||||||
|
@ -71,21 +72,32 @@ class Library():
|
||||||
index = len(self.data.files)
|
index = len(self.data.files)
|
||||||
info = SongInfo()
|
info = SongInfo()
|
||||||
info.filename = os.path.join(self.data.path,file)
|
info.filename = os.path.join(self.data.path,file)
|
||||||
|
f = tagpy.FileRef(info.filename)
|
||||||
|
t = f.tag()
|
||||||
|
info.title = t.title
|
||||||
|
info.album = t.album
|
||||||
|
info.artist = t.artist
|
||||||
|
|
||||||
|
#use later for length
|
||||||
|
# a = f.audioProperties()
|
||||||
|
# info.length = a.length
|
||||||
|
|
||||||
#print file
|
#print file
|
||||||
split = file.rsplit(os.sep)
|
#split = file.rsplit(os.sep)
|
||||||
max = 3
|
#max = 3
|
||||||
if len(split) < 3:
|
#if len(split) < 3:
|
||||||
max = len(split)
|
# max = len(split)
|
||||||
for i in range(max):
|
#for i in range(max):
|
||||||
if i==0:
|
# if i==0:
|
||||||
info.title = split[len(split)-1]
|
# info.title = split[len(split)-1]
|
||||||
elif i==1:
|
# elif i==1:
|
||||||
info.album = split[len(split)-2]
|
# info.album = split[len(split)-2]
|
||||||
else:
|
# else:
|
||||||
info.artist = split[len(split)-3]
|
# info.artist = split[len(split)-3]
|
||||||
#print info.artist,",", info.title,",", info.album
|
#print info.artist,",", info.title,",", info.album
|
||||||
#print s1,s2,s3
|
#print s1,s2,s3
|
||||||
self.data.files+=[info]
|
self.data.files+=[info]
|
||||||
|
print len(self.data.files)
|
||||||
for word in words:
|
for word in words:
|
||||||
if (word in self.data.map.keys()) == True:
|
if (word in self.data.map.keys()) == True:
|
||||||
self.data.map[word]+=[index]
|
self.data.map[word]+=[index]
|
||||||
|
|
|
@ -34,6 +34,7 @@ class main:
|
||||||
window = Window(self.quit,self.ops)
|
window = Window(self.quit,self.ops)
|
||||||
self.ops.setInfo = window.changeInfo
|
self.ops.setInfo = window.changeInfo
|
||||||
self.ops.resetInfo = window.resetInfo
|
self.ops.resetInfo = window.resetInfo
|
||||||
|
self.ops.scrollSong = window.gotoCurSong
|
||||||
|
|
||||||
song = None
|
song = None
|
||||||
# If we were given a song as input, check that it exists and begin playback
|
# If we were given a song as input, check that it exists and begin playback
|
||||||
|
|
|
@ -12,6 +12,7 @@ class Operations:
|
||||||
self.library = None
|
self.library = None
|
||||||
self.setInfo = None
|
self.setInfo = None
|
||||||
self.resetInfo = None
|
self.resetInfo = None
|
||||||
|
self.scrollSong = None
|
||||||
self.exit = exit
|
self.exit = exit
|
||||||
self.after = CONTINUE
|
self.after = CONTINUE
|
||||||
|
|
||||||
|
@ -50,10 +51,12 @@ class Operations:
|
||||||
str += " After "
|
str += " After "
|
||||||
changeFrame(str)
|
changeFrame(str)
|
||||||
|
|
||||||
|
|
||||||
# Advance to the next song
|
# Advance to the next song
|
||||||
def next(self,widget,data):
|
def next(self,widget,data):
|
||||||
# Close open songs
|
# Close open songs
|
||||||
if self.song != None:
|
if self.song != None:
|
||||||
|
self.song.info.playCount+=1
|
||||||
self.song.close()
|
self.song.close()
|
||||||
# Are we exiting?
|
# Are we exiting?
|
||||||
if self.after == QUIT:
|
if self.after == QUIT:
|
||||||
|
@ -74,6 +77,7 @@ class Operations:
|
||||||
self.song.pause()
|
self.song.pause()
|
||||||
self.after = CONTINUE
|
self.after = CONTINUE
|
||||||
self.library.dump()
|
self.library.dump()
|
||||||
|
self.scrollSong()
|
||||||
|
|
||||||
|
|
||||||
# Mark progress on the progress bar
|
# Mark progress on the progress bar
|
||||||
|
|
|
@ -51,63 +51,63 @@ class Playlist:
|
||||||
def selectSong(self,module,iter,path,data,list):
|
def selectSong(self,module,iter,path,data,list):
|
||||||
self.queueSong(list[iter][0])
|
self.queueSong(list[iter][0])
|
||||||
self.opsNext(None,None)
|
self.opsNext(None,None)
|
||||||
self.hideWindow(None,None)
|
#self.hideWindow(None,None)
|
||||||
|
|
||||||
|
|
||||||
# Make the playlist window
|
# Make the playlist window
|
||||||
def makeWindow(self):
|
#def makeWindow(self):
|
||||||
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
# self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||||
self.window.connect("delete_event",self.hideWindow)
|
# self.window.connect("delete_event",self.hideWindow)
|
||||||
self.window.set_size_request(200,300)
|
# self.window.set_size_request(200,300)
|
||||||
self.scroll = gtk.ScrolledWindow()
|
# self.scroll = gtk.ScrolledWindow()
|
||||||
self.scroll.set_border_width(0)
|
# self.scroll.set_border_width(0)
|
||||||
self.scroll.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
|
# self.scroll.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
|
||||||
self.window.add(self.scroll)
|
# self.window.add(self.scroll)
|
||||||
self.populateList()
|
# self.populateList()
|
||||||
|
|
||||||
|
|
||||||
# Fill in rows in the playlist
|
# Fill in rows in the playlist
|
||||||
def populateList(self):
|
#def populateList(self):
|
||||||
liststore = gtk.ListStore(int,str,str,str,int)
|
# liststore = gtk.ListStore(int,str,str,str,int)
|
||||||
#liststore = gtk.ListStore(str,str)
|
#liststore = gtk.ListStore(str,str)
|
||||||
for num in self.list:
|
# for num in self.list:
|
||||||
liststore.append(self.translate(num))
|
# liststore.append(self.translate(num))
|
||||||
treeview = gtk.TreeView(liststore)
|
# treeview = gtk.TreeView(liststore)
|
||||||
cell = gtk.CellRendererText()
|
# cell = gtk.CellRendererText()
|
||||||
cols = ["Id","Title","Artist","Album","Count"]
|
# cols = ["Id","Title","Artist","Album","Count"]
|
||||||
for i in range(len(cols)):
|
# for i in range(len(cols)):
|
||||||
col = gtk.TreeViewColumn(cols[i],cell)
|
# col = gtk.TreeViewColumn(cols[i],cell)
|
||||||
col.add_attribute(cell,'text',i)
|
# col.add_attribute(cell,'text',i)
|
||||||
col.set_resizable(True)
|
# col.set_resizable(True)
|
||||||
col.set_sort_column_id(i)
|
# col.set_sort_column_id(i)
|
||||||
treeview.append_column(col)
|
# treeview.append_column(col)
|
||||||
|
|
||||||
treeview.set_search_column(1)
|
# treeview.set_search_column(1)
|
||||||
treeview.connect("row-activated",self.selectSong,"clicked",liststore)
|
# treeview.connect("row-activated",self.selectSong,"clicked",liststore)
|
||||||
treeview.show()
|
# treeview.show()
|
||||||
treeview.columns_autosize()
|
# treeview.columns_autosize()
|
||||||
self.scroll.add(treeview)
|
# self.scroll.add(treeview)
|
||||||
self.scroll.show()
|
# self.scroll.show()
|
||||||
# Go to current song, enable grid lines
|
# Go to current song, enable grid lines
|
||||||
selrow = self.curSong-10
|
# selrowthe golden sun rises = self.curSong-10
|
||||||
if selrow < 0:
|
# if selrow < 0:
|
||||||
selrow = 0
|
# selrow = 0
|
||||||
treeview.scroll_to_cell(selrow,None,False,0,0)
|
# treeview.scroll_to_cell(selrow,None,False,0,0)
|
||||||
treeview.set_grid_lines(True)
|
# treeview.set_grid_lines(True)
|
||||||
treesel = treeview.get_selection()
|
# treesel = treeview.get_selection()
|
||||||
treesel.select_path(self.curSong)
|
# treesel.select_path(self.curSong)
|
||||||
|
|
||||||
|
|
||||||
# Hide the playlist
|
# Hide the playlist
|
||||||
def hideWindow(self,widget,data):
|
#def hideWindow(self,widget,data):
|
||||||
#self.scroll.hide()
|
#self.scroll.hide()
|
||||||
self.window.hide()
|
# self.window.hide()
|
||||||
self.window = None
|
# self.window = None
|
||||||
|
|
||||||
|
|
||||||
# Show the playlist
|
# Show the playlist
|
||||||
def showWindow(self,widget,data):
|
#def showWindow(self,widget,data):
|
||||||
#self.populateList()
|
#self.populateList()
|
||||||
self.makeWindow()
|
# self.makeWindow()
|
||||||
self.window.show()
|
# self.window.show()
|
||||||
self.window.maximize()
|
# self.window.maximize()
|
||||||
|
|
|
@ -82,12 +82,14 @@ class Song():
|
||||||
self.player.set_state(gst.STATE_PAUSED)
|
self.player.set_state(gst.STATE_PAUSED)
|
||||||
|
|
||||||
|
|
||||||
|
# Stop playback
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.player.set_state(gst.STATE_PAUSED)
|
self.player.set_state(gst.STATE_PAUSED)
|
||||||
self.current = 0
|
self.current = 0
|
||||||
self.player.seek_simple(self.time_format,gst.SEEK_FLAG_FLUSH,self.current)
|
self.player.seek_simple(self.time_format,gst.SEEK_FLAG_FLUSH,self.current)
|
||||||
|
|
||||||
|
|
||||||
|
# Close the song
|
||||||
def close(self):
|
def close(self):
|
||||||
self.player.set_state(gst.STATE_NULL)
|
self.player.set_state(gst.STATE_NULL)
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ class Window(gtk.Window):
|
||||||
gtk.Window.__init__(self,gtk.WINDOW_TOPLEVEL)
|
gtk.Window.__init__(self,gtk.WINDOW_TOPLEVEL)
|
||||||
print "Making window!"
|
print "Making window!"
|
||||||
self.ops = ops
|
self.ops = ops
|
||||||
|
self.tree = None
|
||||||
self.tooltip = gtk.Tooltips()
|
self.tooltip = gtk.Tooltips()
|
||||||
self.tagLabels = dict()
|
self.tagLabels = dict()
|
||||||
self.set_title("Ocarina")
|
self.set_title("Ocarina")
|
||||||
|
@ -22,7 +23,9 @@ class Window(gtk.Window):
|
||||||
|
|
||||||
self.makeMenuBar()
|
self.makeMenuBar()
|
||||||
self.makeInfoPane()
|
self.makeInfoPane()
|
||||||
|
self.makeList()
|
||||||
self.makeControls()
|
self.makeControls()
|
||||||
|
self.maximize()
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +39,8 @@ class Window(gtk.Window):
|
||||||
self.tagLabels["album"] = self.makeLabel("Album: ?",box)
|
self.tagLabels["album"] = self.makeLabel("Album: ?",box)
|
||||||
box.show()
|
box.show()
|
||||||
self.infoFrame.show()
|
self.infoFrame.show()
|
||||||
self.mainLayout.add(self.infoFrame)
|
#self.mainLayout.add(self.infoFrame)
|
||||||
|
self.mainLayout.pack_start(self.infoFrame,False,False,0)
|
||||||
|
|
||||||
|
|
||||||
# Set up a new label, add to container
|
# Set up a new label, add to container
|
||||||
|
@ -44,6 +48,7 @@ class Window(gtk.Window):
|
||||||
def makeLabel(self,text,container):
|
def makeLabel(self,text,container):
|
||||||
box = gtk.HBox(False,0)
|
box = gtk.HBox(False,0)
|
||||||
label = gtk.Label(text)
|
label = gtk.Label(text)
|
||||||
|
s = label.get_style().copy()
|
||||||
self.tooltip.set_tip(label,text,tip_private=None)
|
self.tooltip.set_tip(label,text,tip_private=None)
|
||||||
#label.set_max_width_chars(35)
|
#label.set_max_width_chars(35)
|
||||||
label.show()
|
label.show()
|
||||||
|
@ -77,9 +82,64 @@ class Window(gtk.Window):
|
||||||
self.tooltip.set_tip(self.tagLabels[key],key.title()+": ?")
|
self.tooltip.set_tip(self.tagLabels[key],key.title()+": ?")
|
||||||
self.tagLabels[key].show()
|
self.tagLabels[key].show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def makeList(self):
|
||||||
|
# Make scrolled window, add to window
|
||||||
|
scroll = gtk.ScrolledWindow()
|
||||||
|
scroll.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
|
||||||
|
#self.mainLayout.pack_start(scroll,False,False,0)
|
||||||
|
self.mainLayout.add(scroll)
|
||||||
|
# Make and populate list
|
||||||
|
self.list = gtk.ListStore(int,str,str,str,int)
|
||||||
|
for num in self.ops.plist.list:
|
||||||
|
self.list.append(self.ops.plist.translate(num))
|
||||||
|
# Make treeview from list
|
||||||
|
if self.tree:
|
||||||
|
self.tree = None
|
||||||
|
self.tree = gtk.TreeView(self.list)
|
||||||
|
cell = gtk.CellRendererText()
|
||||||
|
cols = ["Id","Title","Artist","Album","Count"]
|
||||||
|
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)
|
||||||
|
self.tree.append_column(col)
|
||||||
|
self.tree.connect("row-activated",self.ops.plist.selectSong,"clicked",self.list)
|
||||||
|
self.tree.set_grid_lines(True)
|
||||||
|
scroll.add(self.tree)
|
||||||
|
self.tree.columns_autosize()
|
||||||
|
self.tree.show()
|
||||||
|
scroll.show()
|
||||||
|
#self.gotoCurSong()
|
||||||
|
|
||||||
|
|
||||||
|
def gotoCurSong(self):
|
||||||
|
print self.list[0][0]
|
||||||
|
print len(self.list)
|
||||||
|
selrow = 0
|
||||||
|
row = 0
|
||||||
|
for i in range(len(self.list)):
|
||||||
|
#print i
|
||||||
|
if self.list[i][0] == self.ops.plist.curSong:
|
||||||
|
if i > 10:
|
||||||
|
selrow = i - 10
|
||||||
|
row = i
|
||||||
|
break
|
||||||
|
#selrow = self.ops.plist.curSong - 10
|
||||||
|
#if selrow < 0:
|
||||||
|
# selrow = 0
|
||||||
|
print selrow,row
|
||||||
|
self.tree.scroll_to_cell(selrow,None,True,0,0)
|
||||||
|
treesel = self.tree.get_selection()
|
||||||
|
treesel.select_path(row)
|
||||||
|
|
||||||
|
|
||||||
# Use to make play/pause/next/etc buttons
|
# Use to make play/pause/next/etc buttons
|
||||||
def makeControls(self):
|
def makeControls(self):
|
||||||
#controls = gtk.VBox(False,0)
|
#controls = gtk.VBox(False,0)
|
||||||
|
row = gtk.HBox(False,0)
|
||||||
topRow = gtk.HBox(False,0)
|
topRow = gtk.HBox(False,0)
|
||||||
# Make top row buttons
|
# Make top row buttons
|
||||||
self.makeButton("play","images/play.png",None,self.ops.play,topRow)
|
self.makeButton("play","images/play.png",None,self.ops.play,topRow)
|
||||||
|
@ -87,12 +147,15 @@ class Window(gtk.Window):
|
||||||
self.makeButton("stop","images/stop.png",None,self.ops.stop,topRow)
|
self.makeButton("stop","images/stop.png",None,self.ops.stop,topRow)
|
||||||
self.makeButton("next","images/next.png",None,self.ops.next,topRow)
|
self.makeButton("next","images/next.png",None,self.ops.next,topRow)
|
||||||
self.makeButton("info",None,"Info",self.ops.info,topRow)
|
self.makeButton("info",None,"Info",self.ops.info,topRow)
|
||||||
self.makeButton("plist",None,"Plist",self.ops.plist.showWindow,topRow)
|
#self.makeButton("plist",None,"Plist",self.ops.plist.showWindow,topRow)
|
||||||
|
|
||||||
test = gtk.VBox(False,0)
|
test = gtk.VBox(False,0)
|
||||||
self.makeCheck("Random",self.ops.random,self.ops.plist.random,True,topRow)
|
self.makeCheck("Random",self.ops.random,self.ops.plist.random,True,topRow)
|
||||||
topRow.show()
|
topRow.show()
|
||||||
self.mainLayout.pack_start(topRow,False,False,0)
|
row.pack_end(topRow,False,False,0)
|
||||||
|
row.show()
|
||||||
|
#self.mainLayout.pack_start(topRow,False,False,0)
|
||||||
|
self.mainLayout.pack_start(row,False,False,0)
|
||||||
# Make progress bar, add below top row
|
# Make progress bar, add below top row
|
||||||
pbar = gtk.ProgressBar()
|
pbar = gtk.ProgressBar()
|
||||||
pbar.set_fraction(0)
|
pbar.set_fraction(0)
|
||||||
|
@ -183,14 +246,17 @@ class Window(gtk.Window):
|
||||||
dirsel = gtk.FileChooserDialog(None,action=gtk.FILE_CHOOSER_ACTION_OPEN,buttons =(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
|
dirsel = gtk.FileChooserDialog(None,action=gtk.FILE_CHOOSER_ACTION_OPEN,buttons =(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
|
||||||
dirsel.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
dirsel.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
||||||
response = dirsel.run()
|
response = dirsel.run()
|
||||||
|
file = ""
|
||||||
#dirsel = None
|
#dirsel = None
|
||||||
if response == gtk.RESPONSE_OK:
|
if response == gtk.RESPONSE_OK:
|
||||||
#print dirsel.get_filename(),'selected'
|
#print dirsel.get_filename(),'selected'
|
||||||
#dirsel.hide()
|
#dirsel.hide()
|
||||||
file = dirsel.get_filename()
|
file = dirsel.get_filename()
|
||||||
dirsel.hide()
|
#dirsel.hide()
|
||||||
dirsel = None
|
#dirsel = None
|
||||||
func(file)
|
#func(file)
|
||||||
else:
|
#else:
|
||||||
dirsel.hide()
|
dirsel.hide()
|
||||||
dirsel = None
|
dirsel.destroy()
|
||||||
|
#dirsel = None
|
||||||
|
func(file)
|
||||||
|
|
Loading…
Reference in New Issue