diff --git a/trunk/Makefile b/trunk/Makefile index 47cf1fcc..6911a79a 100644 --- a/trunk/Makefile +++ b/trunk/Makefile @@ -1,7 +1,7 @@ open: geany src/GuiObjects/*.py & - geany src/*.py & + geany src/*.py clean: rm -rf src/*.pyo diff --git a/trunk/src/GuiObjects/button.py b/trunk/src/GuiObjects/button.py index 7551b89a..8d05c6b5 100644 --- a/trunk/src/GuiObjects/button.py +++ b/trunk/src/GuiObjects/button.py @@ -7,6 +7,7 @@ from image import Image class Button(gtk.Button): def __init__(self,name,image,text,func): gtk.Button.__init__(self) + self.set_relief(gtk.RELIEF_NONE) box = gtk.HBox(True,0) if image!= None: box.pack_start(image,True,True,0) diff --git a/trunk/src/GuiObjects/infoView.py b/trunk/src/GuiObjects/infoView.py index 8b65dd68..4ffdfa77 100644 --- a/trunk/src/GuiObjects/infoView.py +++ b/trunk/src/GuiObjects/infoView.py @@ -23,11 +23,11 @@ class InfoView(gtk.VBox): artist = "" if self.data.song.info: title = self.data.song.info.title - album = self.data.song.info.album - artist = self.data.song.info.artist + album = "from "+self.data.song.info.album + artist = "by "+self.data.song.info.artist self.title.set_text(title) - self.album.set_text("from "+album) - self.artist.set_text("by "+artist) + self.album.set_text(album) + self.artist.set_text(artist) return True diff --git a/trunk/src/GuiObjects/plistView.py b/trunk/src/GuiObjects/plistView.py index c9e0eb91..1e622c6c 100644 --- a/trunk/src/GuiObjects/plistView.py +++ b/trunk/src/GuiObjects/plistView.py @@ -4,45 +4,111 @@ import pygtk pygtk.require('2.0') import gtk +from menuItem import MenuItem -class PlistView(gtk.ScrolledWindow): +CONTINUE = 0 +PAFTER = 1 + +# This is both the playlist and the queue +class PlistView(gtk.Notebook): def __init__(self,data): - gtk.ScrolledWindow.__init__(self) - self.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) + gtk.Notebook.__init__(self) + self.set_scrollable(True) self.data = data self.data.song.next = self.next self.controls = None - self.tree = None - self.label = gtk.Label("") - self.makeList() - #self.next(None,None) + self.status = CONTINUE + + self.ptree = None + self.pwin = gtk.ScrolledWindow() + self.pwin.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) + self.pwin.show() + + self.qtree = None + self.makePList() + self.makeQList() + self.qwin.show() self.loadSong(True) gobject.timeout_add(1000,self.checkUpdate) + self.append_page(self.pwin,gtk.Label("")) + self.append_page(self.qwin,gtk.Label("")) + self.setTabText("plist") + self.setTabText("queue") self.show() + def setStatus(self,status): + if status == "pafter": + self.status = PAFTER + + + def setTabText(self,tab): + if tab == "plist": + self.set_tab_label_text(self.pwin,"Playlist ("+str(len(self.data.curList))+")") + else: + self.set_tab_label_text(self.qwin,"Queue ("+str(len(self.data.curQ))+")") + + # Check if the playlist has been updated def checkUpdate(self): if self.data.updateList == True: + self.clearList(self.plist) self.data.updateList = False - self.makeList() + self.ptime = self.popList(self.data.curList,self.plist,self.plabel) + self.setTabText("plist") return True - # Make the playlist and show it - def makeList(self): - self.trackList= gtk.ListStore(int,str,str,str,str,int) - if self.tree: - self.remove(self.tree) + def makePList(self): + self.plist = gtk.ListStore(int,str,str,str,str,int) + if self.ptree: + self.pwin.remove(self.ptree) + self.plabel = gtk.Label("") + self.ptree,self.ptreesel = self.list2Tree(self.plist) + self.pwin.add(self.ptree) + self.prcmenu = gtk.Menu() + queue = MenuItem("Queue Song",self.enqueue,None,None,None,) + self.prcmenu.append(queue) + self.plist.set_sort_column_id(self.data.sortedCol,gtk.SORT_ASCENDING) + self.ptree.connect("button_release_event",self.clicked) + self.ptime = self.popList(self.data.curList,self.plist,self.plabel) + + + # Populate a list + def popList(self,src,dst,label): + time = self.generateList(src,dst) + label = self.makeTimeLabel(time) + return time + + + def makeQList(self): + self.qwin = gtk.ScrolledWindow() + self.qwin.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) + self.qlist = gtk.ListStore(int,str,str,str,str,int) + self.qlabel = gtk.Label("") + self.qtree,self.qtreesel = self.list2Tree(self.qlist) + self.qwin.add(self.qtree) + self.qtime = self.generateList(self.data.curQ,self.qlist) + self.qlabel = self.makeTimeLabel(self.qtime) + + + def generateList(self,src,dst): time = 0 - for index in self.data.curList: + i = len(dst) + for index in src: track = self.data.library.files[index] - self.trackList.append([track.id,track.title,track.length,track.artist,track.album,track.count]) + #dst.append([track.id,track.title,track.length,track.artist,track.album,track.count]) + dst.insert(i,[track.id,track.title,track.length,track.artist,track.album,track.count]) time+=track.duration - self.tree = gtk.TreeView(self.trackList) + i+=1 + return time + + + # Make the playlist and show it + def list2Tree(self,list): + tree = gtk.TreeView(list) cell = gtk.CellRendererText() cols = ["Id","Title","Length","Artist","Album","#"] - self.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) @@ -52,33 +118,44 @@ class PlistView(gtk.ScrolledWindow): col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) col.set_min_width(2) col.set_max_width(700) + col.set_sort_indicator(False) if cols[i] != "Id": - self.tree.append_column(col) - self.tree.set_rules_hint(True) - self.tree.set_enable_search(True) - self.tree.connect("row-activated",self.selectSong,"clicked",self.trackList) - self.treesel = self.tree.get_selection() - self.tree.show() - self.resizeCols() - self.add(self.tree) - self.makeTimeLabel(time) + tree.append_column(col) + tree.set_rules_hint(True) + tree.set_enable_search(True) + tree.connect("row-activated",self.selectSong,"clicked",list) + treesel = tree.get_selection() + tree.show() + self.resizeCols(tree) + return tree,treesel # Use to save column widths def saveCols(self): - cols = self.tree.get_columns() + cols = self.ptree.get_columns() self.data.colSizes = [] for col in cols: self.data.colSizes +=[col.get_width()] # Uses saved column settings - def resizeCols(self): - cols = self.tree.get_columns() + def resizeCols(self,tree): + cols = tree.get_columns() for i in range(len(self.data.colSizes)): cols[i].set_fixed_width(self.data.colSizes[i]) + # Erase the entire list + def clearList(self,list): + max = len(list) + if max == 0: + return + if max > 0: + iter = list.get_iter(0) + for i in range(0,max): + list.remove(iter) + + # Shows total running time of the playlist def makeTimeLabel(self,sec): day = 0 @@ -93,8 +170,9 @@ class PlistView(gtk.ScrolledWindow): string = "" string = self.toStr(day,"day")+self.toStr(hour,"hour") string += self.toStr(min,"minute")+self.toStr(sec,"second") - self.label.set_text(string) - self.label.show() + label = gtk.Label(string) + label.show() + return label # Make a string for the amount of time @@ -110,21 +188,38 @@ class PlistView(gtk.ScrolledWindow): # User selected a song with mouse click def selectSong(self,widgit,iter,path,data,list): - self.data.curSong = self.data.curList.index(list[iter][0]) + #self.data.curSong = self.data.curList.index(list[iter][0]) + self.data.curSong = self.plist[iter][0] self.loadSong(False) - self.controls.plause(None,None) + if self.data.song.playing == False: + self.controls.plause(None,None) # Go to the next song in the list def next(self,widgit,data): - if self.data.random == True: + self.data.playingQ = False + if len(self.data.curQ) > 0: + self.data.curSong = self.qlist[0][0] + self.data.curQ.pop(self.data.curQ.index(self.data.curSong)) + self.qlist.remove(self.qlist.get_iter(0)) + self.data.playingQ = True + self.setTabText("queue") + elif self.data.random == True: self.data.curSong = random.randint(0,len(self.data.curList)) else: - self.data.curSong+=1 + next = self.plist[0][0] + #self.data.curSong = self.plist[0][0] + for i in range(len(self.plist)-1): + if self.plist[i][0]==self.data.curSong: + next = self.plist[i+1][0] + break + self.data.curSong = next if self.data.curSong >= len(self.data.curList): self.data.curSong = 0 self.loadSong(True) - self.controls.plause(None,None) + if not((self.data.song.playing==False) ^ (self.status==PAFTER)): + self.controls.plause(None,None) + self.status = CONTINUE # Load a song and begin playback @@ -133,7 +228,7 @@ class PlistView(gtk.ScrolledWindow): return if self.data.song: self.data.song.close() - self.data.song.passInfo(self.data.library.files[self.data.curList[self.data.curSong]]) + self.data.song.passInfo(self.data.library.files[self.data.curSong]) if scroll == True: self.gotoCurSong() @@ -143,7 +238,25 @@ class PlistView(gtk.ScrolledWindow): if len(self.data.curList) == 0: return for i in range(len(self.data.curList)): - if self.trackList[i][0] == self.data.song.info.id: + if self.plist[i][0] == self.data.song.info.id: if i > 10: - self.tree.scroll_to_cell(i-10,None,True,0,0) - self.treesel.select_path(i) + self.ptree.scroll_to_cell(i-10,None,True,0,0) + else: + self.ptree.scroll_to_cell(0,None,True,0,0) + self.ptreesel.select_path(i) + + + + + def clicked(self,widget,data): + if data.button == 3: + self.prcmenu.popup(None,None,None,data.button,data.time) + + + def enqueue(self,widgit,func,data): + (model,pathlist) = self.ptreesel.get_selected_rows() + for path in pathlist: + q = self.plist[path] + self.data.curQ+=[q[0]] + self.qlist.append([q[0],q[1],q[2],q[3],q[4],q[5]]) + self.setTabText("queue") diff --git a/trunk/src/saveddata.py b/trunk/src/saveddata.py index 6f5b30cd..12ffd49b 100644 --- a/trunk/src/saveddata.py +++ b/trunk/src/saveddata.py @@ -12,6 +12,9 @@ class SavedData: self.divider = 150 self.library = Library() self.curList = [] + self.curQ = [] + self.updateQ = False + self.playingQ = False self.curSong = 0 self.colSizes = [110,110,110,110,110] self.sortedCol = 3 @@ -48,7 +51,7 @@ class SavedData: print "User data found, loading..." p = pickle.Unpickler(open(path)) data = p.load() - self.size = data.size + #self.size = data.size self.divider = data.divider self.library = data.library self.curList = data.curList @@ -57,3 +60,6 @@ class SavedData: self.path = data.path self.random = data.random self.curSong = data.curSong + self.curQ = data.curQ + self.playingQ = data.playingQ + diff --git a/trunk/src/song.py b/trunk/src/song.py index 32c717fa..1f164c15 100644 --- a/trunk/src/song.py +++ b/trunk/src/song.py @@ -4,7 +4,6 @@ import pygst pygst.require("0.10") import gst -from duration import Duration class Song(): #def __init__(self,info,exitFunc,prnt): diff --git a/trunk/src/songInfo.py b/trunk/src/songInfo.py index 5ee72e49..5bc2c8fd 100644 --- a/trunk/src/songInfo.py +++ b/trunk/src/songInfo.py @@ -1,5 +1,3 @@ -from duration import Duration - class SongInfo: def __init__(self): self.id = 0 diff --git a/trunk/src/window.py b/trunk/src/window.py index 61e5de47..28387132 100644 --- a/trunk/src/window.py +++ b/trunk/src/window.py @@ -1,10 +1,8 @@ import gobject -import pango import pygtk pygtk.require('2.0') import gtk import thread -from kiwi.ui.objectlist import Column, ObjectList from GuiObjects.menuItem import MenuItem from GuiObjects.libView import LibView @@ -14,7 +12,6 @@ from GuiObjects.infoView import InfoView class Window(gtk.Window): - #def __init__(self,onQuit,ops,song): def __init__(self,onQuit,options,data): gtk.Window.__init__(self,gtk.WINDOW_TOPLEVEL) self.data = data @@ -52,7 +49,7 @@ class Window(gtk.Window): bar.append(plist) # Replace first 'None' with after track functions - pafter = MenuItem("Pause After Current Track",None,"pafter",None,None) + pafter = MenuItem("Pause After Current Track",self.setPlayStatus,"pafter",None,None) qafter = MenuItem("Quit After Current Track",None,"qafter",None,None) playback = MenuItem("Playback",None,None,None,[pafter,qafter]) bar.append(playback) @@ -72,6 +69,10 @@ class Window(gtk.Window): self.data.updateList = True + def setPlayStatus(self,widgit,status,other): + self.plistview.setStatus(status) + + # Used to select a directory def selectDir(self,widgit,data,func): dirsel = gtk.FileChooserDialog(None,action=gtk.FILE_CHOOSER_ACTION_OPEN,buttons =(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) @@ -120,7 +121,7 @@ class Window(gtk.Window): controls = ControlPanel(self.data,self.plistview) self.plistview.controls = controls vbox.pack_start(controls,False,False,0) - box.pack_end(self.plistview.label) + box.pack_end(self.plistview.plabel) box.show() align = gtk.Alignment(1,1,0,0) align.add(box)