From 1314d613e7aa233826eae1b35f78054f21f1ce80 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Sun, 28 Jun 2009 22:14:27 +0000 Subject: [PATCH] Can play songs again git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@35 1daee41c-8060-4895-b1f0-2197c00d777a --- trunk/src/GuiObjects/libView.py | 8 +-- trunk/src/GuiObjects/plistView.py | 71 ++++++++++++++++++++++-- trunk/src/library.py | 3 +- trunk/src/ocarina.py | 3 ++ trunk/src/saveddata.py | 11 ++++ trunk/src/song.py | 33 +++++++----- trunk/src/window.py | 90 +++++-------------------------- 7 files changed, 121 insertions(+), 98 deletions(-) diff --git a/trunk/src/GuiObjects/libView.py b/trunk/src/GuiObjects/libView.py index ad916f67..4aa6452f 100644 --- a/trunk/src/GuiObjects/libView.py +++ b/trunk/src/GuiObjects/libView.py @@ -45,6 +45,7 @@ class LibView(gtk.VBox): #if rval == False: # print artist,album,self.data.library.files[track].title tree.append(aliter,[self.data.library.files[track].title,self.data.library.files[track].id]) + tree.set_sort_column_id(0,gtk.SORT_ASCENDING) self.treeview = gtk.TreeView(tree) self.treeview.connect("button_release_event",self.clicked) self.col = gtk.TreeViewColumn('Library') @@ -65,12 +66,13 @@ class LibView(gtk.VBox): def makeLabel(self): - self.label = gtk.Label(str(self.data.library.count)+" tracks in collection") - self.label.show() + self.label = gtk.Label("")#str(self.data.library.count)+" tracks in collection") + self.updateLabel() + #self.label.show() def updateLabel(self): - self.label.set_text(str(self.data.library.count)+" tracks in collection") + self.label.set_text(str(self.data.library.count)+" collected") self.label.show() diff --git a/trunk/src/GuiObjects/plistView.py b/trunk/src/GuiObjects/plistView.py index 40fcb208..a5294b0f 100644 --- a/trunk/src/GuiObjects/plistView.py +++ b/trunk/src/GuiObjects/plistView.py @@ -9,7 +9,9 @@ class PlistView(gtk.ScrolledWindow): 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) @@ -22,20 +24,81 @@ class PlistView(gtk.ScrolledWindow): def makeList(self): - trackList= gtk.ListStore(int,str,str,str,str) + 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.artist,track.album,track.length]) + 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","Artist","Album","Length"] + 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) - self.tree.append_column(col) + 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() diff --git a/trunk/src/library.py b/trunk/src/library.py index 05297b28..21498429 100644 --- a/trunk/src/library.py +++ b/trunk/src/library.py @@ -70,7 +70,8 @@ class Library: # Add song to library def add(self,words,file,index): - self.files+=[SongInfo()] + #self.files+=[SongInfo()] + self.files.insert(index,SongInfo()) info = self.files[index] info.filename = os.path.join(self.path,file) info.count = 0 diff --git a/trunk/src/ocarina.py b/trunk/src/ocarina.py index 72947713..53ea088b 100644 --- a/trunk/src/ocarina.py +++ b/trunk/src/ocarina.py @@ -30,6 +30,7 @@ class main: self.options.verbose = True # Load saved data (or create new data) self.data = SavedData(self.options) + self.data.song = Song(self.quit) self.window = Window(self.quit,self.options,self.data) gtk.main() @@ -79,6 +80,8 @@ class main: #print self.window.get_size() self.data.size = self.window.get_size() self.data.divider = self.window.divider.get_position() + self.window.plistview.saveCols() + self.data.clearSong() self.data.dump() #self.library.dump() gtk.main_quit() diff --git a/trunk/src/saveddata.py b/trunk/src/saveddata.py index e2128685..26a7b991 100644 --- a/trunk/src/saveddata.py +++ b/trunk/src/saveddata.py @@ -2,6 +2,7 @@ import os import cPickle as pickle from library import Library +from song import Song class SavedData: def __init__(self,options): @@ -11,8 +12,11 @@ class SavedData: self.divider = 150 self.library = Library() self.curList = [] + self.colSizes = [110,110,110,110,110] + self.sortedCol = 3 self.updateList = False self.path = path + self.song = None if os.path.exists(path): try: @@ -30,6 +34,12 @@ class SavedData: out.close() + def clearSong(self): + self.song.close() + self.song = None + return + + # Read user data from the file def load(self,path,options): if options.verbose == True: @@ -40,3 +50,4 @@ class SavedData: self.library = data.library self.divider = data.divider self.curList = data.curList + self.colSizes = data.colSizes diff --git a/trunk/src/song.py b/trunk/src/song.py index 8825ccb7..373b62d7 100644 --- a/trunk/src/song.py +++ b/trunk/src/song.py @@ -8,19 +8,20 @@ from duration import Duration class Song(): #def __init__(self,info,exitFunc,prnt): - def __init__(self,info,exitFunc): + def __init__(self,exitFunc): self.quit=exitFunc #self.prnt=prnt - self.info = info - self.info.tags = dict() - self.setInfo = None - self.getNext = None - self.current = 0 + #self.info = info + #self.info.tags = dict() + #self.setInfo = None + #self.getNext = None + #self.current = 0 # initialize player pipeline + self.next = None self.player = gst.Pipeline("player") - bin = gst.element_factory_make("playbin",None) - bin.set_property("uri","file://"+self.info.filename) - self.player.add(bin) + self.bin = gst.element_factory_make("playbin",None) + #bin.set_property("uri","file://"+self.info.filename) + self.player.add(self.bin) # initialize bus bus = self.player.get_bus() @@ -28,7 +29,7 @@ class Song(): bus.connect("message",self.onMessage) # Pause song - self.pause() + #self.pause() # Initialize stuff for finding duration self.time_format = gst.Format(gst.FORMAT_TIME) @@ -51,7 +52,8 @@ class Song(): self.close() print "Error: %s" % err, debug print "Trying next song" - self.getNext(None,None) + self.next() + #self.getNext(None,None) #if self.quit != None: # self.quit("") #elif t == gst.MESSAGE_TAG: @@ -73,8 +75,8 @@ class Song(): def play(self,widgit,data): self.player.set_state(gst.STATE_PLAYING) # Start main loop and find duration (if this hasn't been done yet) - while self.duration() == False: - time.sleep(0.1) + #while self.duration() == False: + # time.sleep(0.1) # Change state to "paused" @@ -117,3 +119,8 @@ class Song(): return (True,dur) except: return (False,None) + + + def passInfo(self,info): + self.info = info + self.bin.set_property("uri","file://"+self.info.filename) diff --git a/trunk/src/window.py b/trunk/src/window.py index e12fe624..f379e109 100644 --- a/trunk/src/window.py +++ b/trunk/src/window.py @@ -111,65 +111,6 @@ class Window(gtk.Window): self.tagLabels[key].show() - - def makeList(self): - title = Column('title') - title.expand = True - title.searchable = True - artist = Column('artist') - artist.expand = True - artist.searchable = True - album = Column('album') - album.expand = True - album.searchable = True - count = Column('count') - count.expand = True - #count.searchable = True - length = Column('length') - length.expand = True - #length.searchable = True - self.list = ObjectList([title,artist,album,count,length]) - for num in self.ops.plist.list: - #print self.ops.plist.translate(num) - self.list.append(self.ops.plist.translate(num)) - #self.list.append(num) - self.list.sort_by_attribute('artist') - self.list.connect("row-activated",self.ops.plist.selectSong,"clicked",self.list) - self.list.show() - self.mainLayout.add(self.list) - ''' - # 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.connect("button_press_event",self.ops.click,"clicked",self.list,self.tree.get_selection()) - self.tree.set_grid_lines(True) - scroll.add(self.tree) - self.tree.columns_autosize() - self.tree.show() - scroll.show() - #self.gotoCurSong() - ''' - - def gotoCurSong(self): #return if len(self.list) == 0: @@ -278,6 +219,10 @@ class Window(gtk.Window): library = MenuItem("Library",None,None,None,[newLib,delete]) bar.append(library) + clear = MenuItem("Clear Playlist",self.clearPlist,"Clear",None,None) + plist = MenuItem("Playlist",None,None,None,[clear]) + bar.append(plist) + # Replace first 'None' with after track functions pafter = MenuItem("Pause After Current Track",None,"pafter",self.changeFrameTitle,None) qafter = MenuItem("Quit After Current Track",None,"qafter",self.changeFrameTitle,None) @@ -291,6 +236,13 @@ class Window(gtk.Window): def deleteLib(self,widgit,data,other=None): self.data.library.reset() self.libview.update() + self.data.curList = [] + self.data.updateList = True + + + def clearPlist(self,widgit,data,other=None): + self.data.curList = [] + self.data.updateList = True # Used to select a directory @@ -327,23 +279,6 @@ class Window(gtk.Window): rightPane=gtk.VBox(False,0) - #tracks = gtk.TreeStore(str) - #for file in self.data.library.files: - # tracks.append(None,[file.title]) - - #trackview = gtk.TreeView(tracks) - #title = gtk.TreeViewColumn('filename') - #trackview.append_column(title) - #cell = gtk.CellRendererText() - #title.pack_start(cell,True) - #title.add_attribute(cell,'text',0) - #trackview.set_rules_hint(True) - #trackview.show() - #trackscroll = gtk.ScrolledWindow() - #trackscroll.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) - #trackscroll.add(trackview) - #trackscroll.show() - #rightPane.pack_start(trackscroll,False,False,0) self.plistview = PlistView(self.data) self.plistview.show() rightPane.add(self.plistview) @@ -358,7 +293,8 @@ class Window(gtk.Window): def makeBottomRow(self,vbox): box = gtk.HBox(False,0) - box.pack_end(self.libview.label) + box.pack_end(self.libview.label,False,False,10) + box.pack_end(self.plistview.label) box.show() align = gtk.Alignment(1,0.5,0,0) align.add(box)