Re: [Rhythmbox-devel] ArtPane



James "Doc" Livingston wrote:
Also, I get an error about the undefined method "get_art" when I use the
next/previous buttons.

This will still need quite some alterations to fit with the new album info framework, but attaching a version with a bugfix for that bug (plus random other bugs noted while fixing the album covers for a chunk of my library) anyways.


BTW, the reason why I didn't previously see the error with the next/previous buttons is that I've never used them before. Are they really needed?

Tom
--
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	24 May 2006 09:45:29 -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,131 @@
 				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:
+			song = self.song_info.get_property("current-entry")
+			self.entry.set_text("%s %s"%(self.db.entry_get(song, rhythmdb.PROP_ARTIST),self.db.entry_get(song, rhythmdb.PROP_ALBUM)))
+
+	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 = []
+		keys = [x for x in search.split(" ") if x!="Unknown"]
+		#new_keys = [x for x in keys]
+		#for k in keys:
+			
+		#return
+
+		se.keywords = keys
+		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
+		search_engine.on_search_completed_callback = None
+		self.store.clear()
+		if results==None:
+			return
+		for r in results:
+			#print r,dir(r.Artists),r.ProductName
+			try:
+				if "Artists" not in dir(r):
+					self.store.append(("Various Artists",r.ProductName))
+				elif type(r.Artists.Artist) == type([]):
+					self.store.append((r.Artists.Artist[0],r.ProductName))
+				else:
+					self.store.append((r.Artists.Artist,r.ProductName))
+			except AttributeError:
+				print r,dir(r)
+				raise
+	
+	def download_art(self, tv, path, column, song):
+		print path,column
+		id = path[0]
+		get = self.res[id]
+		if "Artists" not in dir(get):
+			print "Various Artists",
+		else:
+			print get.Artists.Artist,
+		print get.ProductName,get.ImageUrlLarge,dir(get)
+		self.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), self.on_image_data_received, self.se, "large", self.callback, get)
+		
+	def on_image_data_received (self, image_data, search_engine, image_version, callback, best_match):
+		if image_data is None or len (image_data) < 1000:
+			if image_version == "large" and best_match is not None:
+				# Fallback and try to load medium one
+				pic_url = str (best_match.ImageUrlMedium)
+				print "fallback",pic_url
+				self.loader.get_url (pic_url, self.on_image_data_received, search_engine, "medium", callback, best_match)
+				return
+			else:
+				print "we're on image size %s, and still failed... giving up"%image_version
+		else:
+			location = self.art_db._create_artwork (search_engine.st_artist, search_engine.st_album, image_data)
+			pixbuf = gtk.gdk.pixbuf_new_from_file (location)
+			callback (search_engine.entry, pixbuf)


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