4 from album_art_thread 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):
62 self.paths.insert (counter, (path, thumb))
64 print "Setting", thumb, "as image"
65 self.images[counter].set_from_file (thumb)
66 self.event_boxes [counter].set_sensitive (True)
70 while (gtk.events_pending()):
73 while (counter < self.size):
74 self.images[counter].set_from_stock (gtk.STOCK_CDROM, gtk.ICON_SIZE_DIALOG)
77 hildon.hildon_gtk_window_set_progress_indicator (self, 0)
80 def click_on_img (self, widget, event, position):
81 img, thumb = self.paths[position]
82 self.selection_img, self.selection_thumb = self.downloader.save_alternative (self.artist,
85 self.response (position)
87 def get_selection (self):
88 return (self.selection_img, self.selection_thumb)
91 def handle_response (self, widget, response_id):
93 # Return False to continue propagating the signal
96 if __name__ == "__main__":
101 self.alt = [("../hendrix.jpeg", "../hendrix-thumb.jpeg"),
102 ("../hoover.jpeg", "../hoover-thumb.jpeg"),
103 ("../backbeat.jpeg", "../backbeat-thumb.jpeg"),
104 ("../dylan.jpeg", "../dylan-thumb.jpeg")]
105 def get_alternatives (self, album, artist, amount):
109 def save_alternative (self, artist, album, img, thumb):
110 return ("/home/user/.cache/media-art/" + img, "/home/user/.thumbnails/normal/" + thumb)
113 def clicked_button (self):
114 aadd = AlbumArtSelectionDialog (w, "rory gallagher", "irish tour", 4, MockDownloader ())
116 response = aadd.run ()
117 if response == gtk.RESPONSE_CLOSE or response == gtk.RESPONSE_DELETE_EVENT or response == gtk.RESPONSE_REJECT:
120 print "Selected", aadd.get_selection ()
124 w.connect ("destroy", gtk.main_quit)
127 button = gtk.Button ("click")
128 button.connect ("clicked", clicked_button)