4 from album_art import MussorgskyAlbumArt
6 class AlbumArtSelectionDialog (gtk.Dialog):
8 def __init__ (self, parent, artist, album, size, downloader=None):
10 parent window, amount of images to offer
11 Optionally downloader (for testing porpouses)
13 gtk.Dialog.__init__ (self,
14 "Select album art", parent,
15 gtk.DIALOG_DESTROY_WITH_PARENT,
16 (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT))
21 self.__create_view (size)
23 self.connect ("response", self.handle_response)
26 self.downloader = downloader
28 self.downloader = MussorgskyAlbumArt ()
30 gobject.idle_add (self.__get_alternatives_async)
31 self.selection_img = None
32 self.selection_thumb = None
33 hildon.hildon_gtk_window_set_progress_indicator (self, 1)
36 def __create_view (self, size):
37 hbox = gtk.HBox (homogeneous=True)
41 for i in range (0, size):
43 img.set_size_request (124, 124)
44 self.images.append (img)
46 event_box = gtk.EventBox ()
48 event_box.connect ("button-release-event", self.click_on_img, i)
49 event_box.set_sensitive (False)
50 self.event_boxes.append (event_box)
52 hbox.pack_start (event_box, expand=False, fill=True)
56 def __get_alternatives_async (self):
58 for (path, thumb) in self.downloader.get_alternatives (self.album, self.artist, self.size):
61 self.paths.insert (counter, (path, thumb))
62 print "Setting", thumb, "as image"
63 self.images[counter].set_from_file (thumb)
64 self.event_boxes [counter].set_sensitive (True)
66 while (gtk.events_pending()):
69 while (counter < self.size):
70 self.images[counter].set_from_stock (gtk.STOCK_CDROM, gtk.ICON_SIZE_DIALOG)
73 hildon.hildon_gtk_window_set_progress_indicator (self, 0)
76 def click_on_img (self, widget, event, position):
77 img, thumb = self.paths[position]
78 self.selection_img, self.selection_thumb = self.downloader.save_alternative (self.artist,
81 self.response (position)
83 def get_selection (self):
84 return (self.selection_img, self.selection_thumb)
87 def handle_response (self, widget, response_id):
89 # Return False to continue propagating the signal
92 if __name__ == "__main__":
97 self.alt = [("../hendrix.jpeg", "../hendrix-thumb.jpeg"),
98 ("../hoover.jpeg", "../hoover-thumb.jpeg"),
99 ("../backbeat.jpeg", "../backbeat-thumb.jpeg"),
100 ("../dylan.jpeg", "../dylan-thumb.jpeg")]
101 def get_alternatives (self, album, artist, amount):
105 def save_alternative (self, artist, album, img, thumb):
106 return ("/home/user/.cache/media-art/" + img, "/home/user/.thumbnails/normal/" + thumb)
109 def clicked_button (self):
110 aadd = AlbumArtSelectionDialog (w, "rory gallagher", "irish tour", 4, MockDownloader ())
112 response = aadd.run ()
113 if response == gtk.RESPONSE_CLOSE or response == gtk.RESPONSE_DELETE_EVENT or response == gtk.RESPONSE_REJECT:
116 print "Selected", aadd.get_selection ()
120 w.connect ("destroy", gtk.main_quit)
123 button = gtk.Button ("click")
124 button.connect ("clicked", clicked_button)