[Rhythmbox-devel] ArtPane



Hi. I've been following Rhythmbox CVS development for a while, and with all the renewed effort being put into plugins I'd like to offer my little effort. I have a few albums where the auto-search isn't coming up with the right album, and so therefore I wanted the option to be able to manually select a cover, but without having to go outside the Rhythmbox GUI. I've therefore taken a few hints from the Lyrics plugin and implemented a "Cover Art" pane for the Song info. You can type in some terms on a text entry box in this pane, press return and it'll show you what results those terms get from Amazon. If you see the right album, you can double click on the relevant row and it'll get set as the album for the current song. I've attached a patch to current Rhythmbox CVS to implement all of this as a patch to the artdisplay plugin.

Provisos: the UI sucks (really needs some buttons and hints in there) and its method of tying into AmazonCoverArtSearch and CoverArtDatabase is a lot of a hack right now, but it's a reasonable first effort.

Thoughts?

Tom Parker
--
palfrey tevp net - http://tevp.net
Illegitimus non carborundum
Index: plugins/artdisplay/artdisplay/__init__.py
===================================================================
RCS file: /cvs/gnome/rhythmbox/plugins/artdisplay/artdisplay/__init__.py,v
retrieving revision 1.2
diff -u -r1.2 __init__.py
--- plugins/artdisplay/artdisplay/__init__.py	20 May 2006 03:45:34 -0000	1.2
+++ plugins/artdisplay/artdisplay/__init__.py	22 May 2006 19:02:27 -0000
@@ -20,7 +20,8 @@
 import gtk, gobject
 
 from CoverArtDatabase import CoverArtDatabase
-
+from AmazonCoverArtSearch import AmazonCoverArtSearch
+from Loader import Loader
 
 FADE_STEPS = 10
 FADE_TOTAL_TIME = 1000
@@ -38,6 +39,7 @@
 		self.art_widget.set_padding (0, 5)
 		shell.add_widget (self.art_widget, rb.SHELL_UI_LOCATION_SIDEBAR)
 		self.sa_id = self.art_widget.connect ('size-allocate', self.size_allocated)
+		self.csi_id = shell.connect('create_song_info', self.create_song_info)
 		self.current_pixbuf = None
 		self.art_db = CoverArtDatabase ()
 		self.resize_id = 0
@@ -161,3 +163,100 @@
 				mode = gtk.gdk.INTERP_HYPER
 			self.art_widget.set_from_pixbuf (self.current_pixbuf.scale_simple (width, height, mode))
 			self.art_widget.show ()
+
+	def create_song_info (self, shell, song_info, is_multiple):
+		if is_multiple is False:
+			x = ArtPane(shell.get_property ("db"), song_info,self.on_get_pixbuf_completed)
+
+class ArtPane(object):
+	def __init__(self, db, song_info,callback):
+		self.loader = Loader()
+		
+		self.store = gtk.ListStore(gobject.TYPE_STRING,gobject.TYPE_STRING)
+		self.view = gtk.TreeView(self.store)
+		self.view.append_column(gtk.TreeViewColumn('Artist',gtk.CellRendererText(),text=0))
+		self.view.append_column(gtk.TreeViewColumn('Album',gtk.CellRendererText(),text=1))
+
+		self.entry = gtk.Entry()
+
+		vbox = gtk.VBox(spacing=12)
+		vbox.pack_start(self.entry, expand=False)
+		vbox.pack_start(self.view, expand=True)
+
+		self.entry.connect('key-press-event',self.search_art,song_info)
+
+		#self.buffer = self.view.get_buffer()
+		song = song_info.get_property("current-entry")
+		self.entry.set_text("%s %s"%(db.entry_get(song, rhythmdb.PROP_ARTIST),db.entry_get(song, rhythmdb.PROP_ALBUM)))
+
+		vbox.show_all()
+		self.page_num = song_info.append_page("Cover Art", vbox)
+		self.db = db
+		self.song_info = song_info
+		self.visible = 0
+		self.callback = callback
+		self.view.connect('row-activated',self.download_art,song)
+
+		self.entry_change_id = song_info.connect('notify::current-entry', self.entry_changed)
+		nb = vbox.get_parent()
+		self.switch_page_id = nb.connect('switch-page', self.switch_page_cb)
+
+	def entry_changed(self, pspec, duh):
+		self.song_info.get_property("current-entry")
+		if self.visible != 0:
+			self.get_art()
+
+	def switch_page_cb(self, notebook, page, page_num):
+		if page_num != self.page_num:
+			self.visible = 0
+			return
+
+		self.visible = 1
+
+	def search_art(self,widget,event,song_info):
+		if len(event.string)==0:
+			return
+		if ord(event.string[0])!=13:
+			#print "'%s' %d"%(event.string,ord(event.string[0]))
+			return
+		search = self.entry.get_text()
+		print "return was hit for %s"%search
+
+		#self.buffer.set_text("Searching for %s"%search)
+		se = AmazonCoverArtSearch (self.loader)
+		se.searching = True
+		se.db = self.db
+		se.args = []
+		se.keywords = search.split(" ")
+		se.on_search_completed_callback = self.on_search_engine_results
+		se.search_next()
+		self.se = se
+		#se.search (self.db, sp.get_playing_entry (), self.on_search_engine_results, self.on_get_pixbuf_completed)
+
+	def on_search_engine_results (self, search_engine, entry, results):
+		print "results",results
+		buff = ""
+		self.res = results
+		self.store.clear()
+		if results==None:
+			return
+		for r in results:
+			#print r,dir(r.Artists),r.ProductName
+			if type(r.Artists.Artist) == type([]):
+				self.store.append((r.Artists.Artist[0],r.ProductName))
+			else:
+				self.store.append((r.Artists.Artist,r.ProductName))
+	
+	def download_art(self, tv, path, column, song):
+		print path,column
+		id = path[0]
+		get = self.res[id]
+		print get.Artists.Artist,get.ProductName,get.ImageUrlLarge,dir(get)
+		art_db = CoverArtDatabase ()
+		#art_db.best_match = get
+		self.se.st_artist = self.db.entry_get (song, rhythmdb.PROP_ARTIST)
+		self.se.st_album = self.db.entry_get (song, rhythmdb.PROP_ALBUM)
+		self.se.entry = song
+		self.loader.get_url (str(get.ImageUrlLarge), art_db.on_image_data_received, self.se, "large", self.callback, get)
+		
+		


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]