From a687c14a147027892ea125978be32829b839d094 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Mon, 15 Jun 2009 03:54:59 +0000 Subject: [PATCH] Playlist shows in main window git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@24 1daee41c-8060-4895-b1f0-2197c00d777a --- trunk/library.py | 34 ++++++++++++------ trunk/ocarina.py | 1 + trunk/operations.py | 4 +++ trunk/playlist.py | 86 ++++++++++++++++++++++----------------------- trunk/song.py | 2 ++ trunk/window.py | 84 ++++++++++++++++++++++++++++++++++++++----- 6 files changed, 148 insertions(+), 63 deletions(-) diff --git a/trunk/library.py b/trunk/library.py index f9f94c0a..05ebe9d0 100644 --- a/trunk/library.py +++ b/trunk/library.py @@ -1,5 +1,6 @@ import os import re +import tagpy import cPickle as pickle from libdata import LibData from songInfo import SongInfo @@ -71,21 +72,32 @@ class Library(): index = len(self.data.files) info = SongInfo() 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 - split = file.rsplit(os.sep) - max = 3 - if len(split) < 3: - max = len(split) - for i in range(max): - if i==0: - info.title = split[len(split)-1] - elif i==1: - info.album = split[len(split)-2] - else: - info.artist = split[len(split)-3] + #split = file.rsplit(os.sep) + #max = 3 + #if len(split) < 3: + # max = len(split) + #for i in range(max): + # if i==0: + # info.title = split[len(split)-1] + # elif i==1: + # info.album = split[len(split)-2] + # else: + # info.artist = split[len(split)-3] #print info.artist,",", info.title,",", info.album #print s1,s2,s3 self.data.files+=[info] + print len(self.data.files) for word in words: if (word in self.data.map.keys()) == True: self.data.map[word]+=[index] diff --git a/trunk/ocarina.py b/trunk/ocarina.py index 6587c60e..cd2347b9 100644 --- a/trunk/ocarina.py +++ b/trunk/ocarina.py @@ -34,6 +34,7 @@ class main: window = Window(self.quit,self.ops) self.ops.setInfo = window.changeInfo self.ops.resetInfo = window.resetInfo + self.ops.scrollSong = window.gotoCurSong song = None # If we were given a song as input, check that it exists and begin playback diff --git a/trunk/operations.py b/trunk/operations.py index d86374a5..0ec3df1c 100644 --- a/trunk/operations.py +++ b/trunk/operations.py @@ -12,6 +12,7 @@ class Operations: self.library = None self.setInfo = None self.resetInfo = None + self.scrollSong = None self.exit = exit self.after = CONTINUE @@ -50,10 +51,12 @@ class Operations: str += " After " changeFrame(str) + # Advance to the next song def next(self,widget,data): # Close open songs if self.song != None: + self.song.info.playCount+=1 self.song.close() # Are we exiting? if self.after == QUIT: @@ -74,6 +77,7 @@ class Operations: self.song.pause() self.after = CONTINUE self.library.dump() + self.scrollSong() # Mark progress on the progress bar diff --git a/trunk/playlist.py b/trunk/playlist.py index 998ccf56..80de46ff 100644 --- a/trunk/playlist.py +++ b/trunk/playlist.py @@ -51,63 +51,63 @@ class Playlist: def selectSong(self,module,iter,path,data,list): self.queueSong(list[iter][0]) self.opsNext(None,None) - self.hideWindow(None,None) + #self.hideWindow(None,None) # Make the playlist window - def makeWindow(self): - self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) - self.window.connect("delete_event",self.hideWindow) - self.window.set_size_request(200,300) - self.scroll = gtk.ScrolledWindow() - self.scroll.set_border_width(0) - self.scroll.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) - self.window.add(self.scroll) - self.populateList() + #def makeWindow(self): + # self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) + # self.window.connect("delete_event",self.hideWindow) + # self.window.set_size_request(200,300) + # self.scroll = gtk.ScrolledWindow() + # self.scroll.set_border_width(0) + # self.scroll.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) + # self.window.add(self.scroll) + # self.populateList() # Fill in rows in the playlist - def populateList(self): - liststore = gtk.ListStore(int,str,str,str,int) + #def populateList(self): + # liststore = gtk.ListStore(int,str,str,str,int) #liststore = gtk.ListStore(str,str) - for num in self.list: - liststore.append(self.translate(num)) - treeview = gtk.TreeView(liststore) - 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) - treeview.append_column(col) + # for num in self.list: + # liststore.append(self.translate(num)) + # treeview = gtk.TreeView(liststore) + # 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) + # treeview.append_column(col) - treeview.set_search_column(1) - treeview.connect("row-activated",self.selectSong,"clicked",liststore) - treeview.show() - treeview.columns_autosize() - self.scroll.add(treeview) - self.scroll.show() + # treeview.set_search_column(1) + # treeview.connect("row-activated",self.selectSong,"clicked",liststore) + # treeview.show() + # treeview.columns_autosize() + # self.scroll.add(treeview) + # self.scroll.show() # Go to current song, enable grid lines - selrow = self.curSong-10 - if selrow < 0: - selrow = 0 - treeview.scroll_to_cell(selrow,None,False,0,0) - treeview.set_grid_lines(True) - treesel = treeview.get_selection() - treesel.select_path(self.curSong) + # selrowthe golden sun rises = self.curSong-10 + # if selrow < 0: + # selrow = 0 + # treeview.scroll_to_cell(selrow,None,False,0,0) + # treeview.set_grid_lines(True) + # treesel = treeview.get_selection() + # treesel.select_path(self.curSong) # Hide the playlist - def hideWindow(self,widget,data): + #def hideWindow(self,widget,data): #self.scroll.hide() - self.window.hide() - self.window = None + # self.window.hide() + # self.window = None # Show the playlist - def showWindow(self,widget,data): + #def showWindow(self,widget,data): #self.populateList() - self.makeWindow() - self.window.show() - self.window.maximize() + # self.makeWindow() + # self.window.show() + # self.window.maximize() diff --git a/trunk/song.py b/trunk/song.py index a398cedb..b2ea9e7d 100644 --- a/trunk/song.py +++ b/trunk/song.py @@ -82,12 +82,14 @@ class Song(): self.player.set_state(gst.STATE_PAUSED) + # Stop playback def stop(self): self.player.set_state(gst.STATE_PAUSED) self.current = 0 self.player.seek_simple(self.time_format,gst.SEEK_FLAG_FLUSH,self.current) + # Close the song def close(self): self.player.set_state(gst.STATE_NULL) diff --git a/trunk/window.py b/trunk/window.py index 3334292c..b045903d 100644 --- a/trunk/window.py +++ b/trunk/window.py @@ -9,6 +9,7 @@ class Window(gtk.Window): gtk.Window.__init__(self,gtk.WINDOW_TOPLEVEL) print "Making window!" self.ops = ops + self.tree = None self.tooltip = gtk.Tooltips() self.tagLabels = dict() self.set_title("Ocarina") @@ -22,7 +23,9 @@ class Window(gtk.Window): self.makeMenuBar() self.makeInfoPane() + self.makeList() self.makeControls() + self.maximize() self.show() @@ -36,7 +39,8 @@ class Window(gtk.Window): self.tagLabels["album"] = self.makeLabel("Album: ?",box) box.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 @@ -44,6 +48,7 @@ class Window(gtk.Window): def makeLabel(self,text,container): box = gtk.HBox(False,0) label = gtk.Label(text) + s = label.get_style().copy() self.tooltip.set_tip(label,text,tip_private=None) #label.set_max_width_chars(35) label.show() @@ -77,9 +82,64 @@ class Window(gtk.Window): self.tooltip.set_tip(self.tagLabels[key],key.title()+": ?") 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 def makeControls(self): #controls = gtk.VBox(False,0) + row = gtk.HBox(False,0) topRow = gtk.HBox(False,0) # Make top row buttons 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("next","images/next.png",None,self.ops.next,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) self.makeCheck("Random",self.ops.random,self.ops.plist.random,True,topRow) 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 pbar = gtk.ProgressBar() 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.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER) response = dirsel.run() + file = "" #dirsel = None if response == gtk.RESPONSE_OK: #print dirsel.get_filename(),'selected' #dirsel.hide() file = dirsel.get_filename() - dirsel.hide() - dirsel = None - func(file) - else: - dirsel.hide() - dirsel = None + #dirsel.hide() + #dirsel = None + #func(file) + #else: + dirsel.hide() + dirsel.destroy() + #dirsel = None + func(file)