diff --git a/trunk/src/GuiObjects/libView.py b/trunk/src/GuiObjects/libView.py index fdd2e5e6..50daf277 100644 --- a/trunk/src/GuiObjects/libView.py +++ b/trunk/src/GuiObjects/libView.py @@ -3,6 +3,8 @@ import pygtk pygtk.require('2.0') import gtk +from menuItem import MenuItem + #class LibView(gtk.ScrolledWindow): class LibView(gtk.VBox): @@ -17,6 +19,7 @@ class LibView(gtk.VBox): self.pbar = gtk.ProgressBar() self.pack_start(self.win) self.pack_start(self.pbar,False,False,0) + self.makeRCMenu() self.update() self.win.show() @@ -31,14 +34,17 @@ class LibView(gtk.VBox): self.treeview.remove_column(self.col) self.pbar.pulse() self.pbar.set_text("Found "+str(self.library.count)+" files.") - tree = gtk.TreeStore(str) + tree = gtk.TreeStore(str,int) for artist in self.library.artAlb.keys(): - ariter = tree.append(None,[artist]) + ariter = tree.append(None,[artist.title(),-1]) for album in self.library.artAlb[artist]: - aliter = tree.append(ariter,[album]) - for track in self.library.albTrk[album]: - tree.append(aliter,[track]) + aliter = tree.append(ariter,[album.title(),-1]) + for track in self.library.albTrk[(artist,album)]: + #if rval == False: + # print artist,album,self.library.files[track].title + tree.append(aliter,[self.library.files[track].title,self.library.files[track].id]) self.treeview = gtk.TreeView(tree) + self.treeview.connect("button_release_event",self.clicked) self.col = gtk.TreeViewColumn('Library') self.treeview.append_column(self.col) cell = gtk.CellRendererText() @@ -47,12 +53,46 @@ class LibView(gtk.VBox): self.col.set_sort_column_id(0) self.treeview.set_rules_hint(True) self.treeview.show() + self.selection = self.treeview.get_selection() + self.selection.set_mode(gtk.SELECTION_MULTIPLE) self.win.add(self.treeview) if rval==False: self.pbar.hide() return rval + # Begin updating the library def updates(self): self.pbar.show() - gobject.timeout_add(500,self.update) + gobject.timeout_add(1000,self.update) + + + # Right click menu + def makeRCMenu(self): + self.rcmenu = gtk.Menu() + add = MenuItem("Add to Playlist",self.populatePlaylist,None,None,None) + self.rcmenu.append(add) + + + # Show the right click menu on a right click + def clicked(self,widget,data): + if data.button == 3: + self.rcmenu.popup(None,None,None,data.button,data.time) + + + def populatePlaylist(self,widgit,func,data): + (model,pathlist) = self.selection.get_selected_rows() + for path in pathlist: + iter = model.get_iter(path) + self.popHelper(model,iter,model.iter_n_children(iter)) + + + def popHelper(self,model,iter,count): + if count == 0: + print model[iter][0],count + return + + child = model.iter_children(iter) + for i in range(count): + self.popHelper(model,child,model.iter_n_children(child)) + child = model.iter_next(child) diff --git a/trunk/src/library.py b/trunk/src/library.py index 0609ed1d..05297b28 100644 --- a/trunk/src/library.py +++ b/trunk/src/library.py @@ -4,55 +4,38 @@ import tagpy import cPickle as pickle from libdata import LibData from songInfo import SongInfo +import thread class Library: #def __init__(self,prnt): def __init__(self): - #self.prnt = prnt - #self.data = LibData() self.goodTypes = ["ogg","mp3"]#,"wma"] - self.files = [] - self.count = 0 - self.path = "" + self.reset() self.scanning = False - self.artAlb = dict() - self.albTrk = dict() - # Build up directory if library save - #self.save = os.path.expanduser("~") - #self.save = os.path.join(self.save,".ocarina") - #self.save = os.path.join(self.save,"library.pickle") - # Load existing library - #if os.path.exists(self.save): - #self.prnt(["Library found, loading..."]) - # print "Library found, loading..." - # p = pickle.Unpickler(open(self.save)) - # self.data = p.load() # Begin a scan on dir def scan(self,thread,dir): - #self.data = LibData() - #self.data.path = os.path.expanduser(dir) self.scanning = True + self.reset() + + self.path = os.path.expanduser(dir) + if os.path.exists(self.path) == False: + #print "Directory not found: %s" % dir + return + #print "Scanning: "+self.path + self.traverse("") + self.scanning = False + #print "Found %s files!" % str(self.count) + + + def reset(self): self.files = [] self.count = 0 self.artAlb = dict() self.albTrk = dict() - - self.path = os.path.expanduser(dir) - if os.path.exists(self.path) == False: - #self.prnt(["Directory not found: "+dir]) - print "Directory not found: %s" % dir - return - print "Scanning: "+self.path - #self.scanning = True - self.traverse("") - self.scanning = False - #num = len(self.data.files) - #self.prnt(["Found "+str(num)+" files!"]) - print "Found %s files!" % str(self.count) - #self.dump() + self.path = "" # Traverse directorys @@ -71,11 +54,14 @@ class Library: tSplit = entry.rsplit('.') type = tSplit[len(tSplit)-1].lower() if (type in self.goodTypes) == True: - self.add(self.hash(joined),joined) + self.count += 1 + thread.start_new_thread(self.add,(self.hash(joined),joined,self.count-1)) + #self.add(self.hash(joined),joined) # Hash a file and return list of words def hash(self,file): + return file = file.lower() # Only keep letters and numbers words = re.sub('[^a-z0-9]',' ',file).split() @@ -83,12 +69,12 @@ class Library: # Add song to library - def add(self,words,file): - index = len(self.files) - info = SongInfo() + def add(self,words,file,index): + self.files+=[SongInfo()] + info = self.files[index] info.filename = os.path.join(self.path,file) - self.files += [info.filename] info.count = 0 + info.id = index split = info.filename.rsplit(os.sep) max = 3 if len(split) < 3: @@ -100,32 +86,6 @@ class Library: info.album = split[len(split)-2] else: info.artist = split[len(split)-3] - self.files+=[info] - - if (info.artist in self.artAlb.keys()) == False: - self.artAlb[info.artist] = [info.album] - elif (info.album in self.artAlb[info.artist]) == False: - self.artAlb[info.artist] += [info.album] - - if (info.album in self.albTrk.keys()) == False: - self.albTrk[info.album] = [info.title] - #elif (info.title in self.albTrk[self.info.album]) == False: - else: - self.albTrk[info.album] += [info.title] - - self.count += 1 - #print self.count - - return - - #use later for length - #a = f.audioProperties() - #info.length = a.length - - #print file - - #print info.artist,",", info.title,",", info.album - #print s1,s2,s3 f = tagpy.FileRef(info.filename) t = f.tag() @@ -137,16 +97,22 @@ class Library: info.artist = t.artist a = f.audioProperties() - info.length = a.length - info.id = len(self.data.files) - - self.data.files+=[info] - print info.id - for word in words: - if (word in self.data.map.keys()) == True: - self.data.map[word]+=[index] - else: - self.data.map[word] = [index] + info.duration = a.length + info.fixTime() + + artist = info.artist.lower() + album = info.album.lower() + + + if (artist in self.artAlb.keys()) == False: + self.artAlb[artist] = [album] + elif (album in self.artAlb[artist]) == False: + self.artAlb[artist] += [album] + + if ((artist,album) in self.albTrk.keys()) == False: + self.albTrk[(artist,album)] = [index] + else: + self.albTrk[(artist,album)] += [index] # Dump to file diff --git a/trunk/src/song.py b/trunk/src/song.py index f2f3287a..8825ccb7 100644 --- a/trunk/src/song.py +++ b/trunk/src/song.py @@ -54,19 +54,19 @@ class Song(): self.getNext(None,None) #if self.quit != None: # self.quit("") - elif t == gst.MESSAGE_TAG: - tags = message.parse_tag() - for tag in tags.keys(): - self.info.tags[tag] = tags[tag] - if tag=="title": - self.info.title = tags[tag] - elif tag=="album": - self.info.album = tags[tag] - elif tag=="artist": - self.info.artist = tags[tag] - self.setInfo(tags) + #elif t == gst.MESSAGE_TAG: + # tags = message.parse_tag() + # for tag in tags.keys(): + # self.info.tags[tag] = tags[tag] + # if tag=="title": + # self.info.title = tags[tag] + # elif tag=="album": + # self.info.album = tags[tag] + # elif tag=="artist": + # self.info.artist = tags[tag] + # self.setInfo(tags) #self.taglist = message.parse_tag() - return + # return # Change state to "playing" @@ -95,15 +95,15 @@ class Song(): # Find the duration of the pipeline - def duration(self): - try: - self.info.length = Duration() - length = self.player.query_duration(self.time_format,None)[0] - self.total = length - self.info.length.setTime(length) - return True - except: - return False + #def duration(self): + # try: + # self.info.length = Duration() + # length = self.player.query_duration(self.time_format,None)[0] + # self.total = length + # self.info.length.setTime(length) + # return True + #except: + # return False #self.length.disp(self.prnt) diff --git a/trunk/src/songInfo.py b/trunk/src/songInfo.py index 6c8082d5..0b81220f 100644 --- a/trunk/src/songInfo.py +++ b/trunk/src/songInfo.py @@ -4,11 +4,34 @@ class SongInfo: def __init__(self): self.id = 0 self.filename = "" - #self.tags = dict() self.count = 0 - #self.banned = False - self.length = None - self.duration = None + # Length is a string, duration is an int + self.length = "" + self.duration = 0 self.title = "" self.album = "" self.artist = "" + + + def fixTime(self): + time = self.duration + # Find hour + if time >= 3600: + hour = time/3600 + time = time - (self.hour * 3600) + if hour > 0: + self.length=str(hour)+":" + # Find minute + if time >= 60: + min = time/60 + time = time - (min * 60) + if min < 10: + self.length+="0" + self.length+=str(min)+":" + else: + self.length+="00:" + # Remainder is seconds + sec = time + if sec < 10: + self.length+="0" + self.length+=str(sec) diff --git a/trunk/src/window.py b/trunk/src/window.py index c0146438..3ac587fc 100644 --- a/trunk/src/window.py +++ b/trunk/src/window.py @@ -273,8 +273,8 @@ class Window(gtk.Window): # This is the dropdown selections # Make a new library option newLib = MenuItem("New Library",self.selectDir,"ScanLib",self.data.library.scan,None) - #update = MenuItem("Update",self.libview.update,"Update",None,None) - library = MenuItem("Library",None,None,None,[newLib]) + delete = MenuItem("Delete Library",self.deleteLib,"Delete",None,None) + library = MenuItem("Library",None,None,None,[newLib,delete]) bar.append(library) # Replace first 'None' with after track functions @@ -287,6 +287,11 @@ class Window(gtk.Window): self.mainLayout.pack_start(bar,False,False,0) + def deleteLib(self,widgit,data,other=None): + self.data.library.reset() + self.libview.update() + + # 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)) @@ -332,6 +337,7 @@ class Window(gtk.Window): trackview.set_rules_hint(True) trackview.show() trackscroll = gtk.ScrolledWindow() + trackscroll.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) trackscroll.add(trackview) trackscroll.show() self.divider.add2(trackscroll)