import gobject import pygtk pygtk.require('2.0') import gtk from menuItem import MenuItem #class LibView(gtk.ScrolledWindow): class LibView(gtk.VBox): def __init__(self,library): #gtk.ScrolledWindow.__init__(self) gtk.VBox.__init__(self,False,0) self.win = gtk.ScrolledWindow() self.win.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) self.library = library self.treeview = None self.col = None self.pbar = gtk.ProgressBar() self.pack_start(self.win) self.pack_start(self.pbar,False,False,0) self.makeRCMenu() self.makeLabel() self.update() self.win.show() # Use to update the library pane def update(self): rval = self.library.scanning #if self.library.count == 0: # return False if self.treeview: self.win.remove(self.treeview) self.treeview.remove_column(self.col) self.pbar.pulse() self.pbar.set_text("Found "+str(self.library.count)+" files.") tree = gtk.TreeStore(str,int) for artist in self.library.artAlb.keys(): ariter = tree.append(None,[artist.title(),-1]) for album in self.library.artAlb[artist]: 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() self.col.pack_start(cell,True) self.col.add_attribute(cell,'text',0) 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) self.updateLabel() if rval==False: self.pbar.hide() return rval def makeLabel(self): self.label = gtk.Label(str(self.library.count)+" tracks in collection") self.label.show() def updateLabel(self): self.label.set_text(str(self.library.count)+" tracks in collection") self.label.show() # Begin updating the library def updates(self): self.pbar.show() 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)