class CoverLyricsPanel(gtk.Frame): def __init__(self, controls): gtk.Frame.__init__(self) vbox = gtk.VBox(False, 5) self.controls = controls self.set_size_request(100, 200) self.album_title = gtk.Label(_("Album title")) image_size = FC().main_window_size[2] - (FC().hpaned_right + 16) self.image = ImageBase(ICON_BLANK_DISK, size=image_size) image_frame = gtk.Frame() image_frame.add(self.image) image_frame.set_label_widget(gtk.Label(_("Cover:"))) vbox.pack_start(image_frame, False) self.lyrics = TextArea() lyrics_frame = gtk.Frame() lyrics_frame.add(self.lyrics) lyrics_frame.set_label_widget(gtk.Label(_("Lyric:"))) vbox.pack_start(lyrics_frame, True) self.add(vbox) self.set_label_widget(self.album_title) self.show_all() def get_pixbuf(self): return self.controls.info_panel.image.pixbuf def set_cover(self): pixbuf = self.get_pixbuf() self.image.set_from_pixbuf(pixbuf) def adapt_image(self): if self.lyrics.get_property("visible"): self.image.size = self.lyrics.get_allocation().width self.image.set_from_pixbuf(self.controls.coverlyrics.get_pixbuf())
def __init__(self, controls): Gtk.Frame.__init__(self) self.controls = controls self.set_size_request(100, 200) self.album_title = Gtk.Label(_("Album title")) self.image = ImageBase(ICON_BLANK_DISK, size=FC().info_panel_image_size) self.image.set_from_pixbuf(self.get_pixbuf()) image_frame = Gtk.Frame() image_frame.add(self.image) image_frame.set_label_widget(Gtk.Label(_("Cover:"))) self.lyrics = TextArea() lyrics_frame = Gtk.Frame() lyrics_frame.add(self.lyrics) lyrics_frame.set_label_widget(Gtk.Label(_("Lyric:"))) vbox = Gtk.VBox(False, 5) vbox.pack_start(image_frame, False, False, 0) vbox.pack_start(lyrics_frame, True, True, 0) self.add(vbox) self.set_label_widget(self.album_title) self.show_all()
def __init__(self, controls): Gtk.Frame.__init__(self) self.controls = controls self.set_size_request(100, 200) self.album_title = Gtk.Label.new(_("Album title")) self.set_label_align(0.5, 0.5) self.image = ImageBase(ICON_BLANK_DISK, size=FC().info_panel_image_size) self.image.set_from_pixbuf(self.get_pixbuf()) image_frame = FrameDecorator(_("Cover"), self.image, 0.5, 0.5) self.lyrics = TextArea() lyrics_frame = FrameDecorator(_("Lyric"), self.lyrics, 0.5, 0.5) vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 5) vbox.pack_start(image_frame, False, False, 0) vbox.pack_start(lyrics_frame, True, True, 0) self.add(vbox) self.set_label_widget(self.album_title) self.show_all()
class CoverLyricsPanel(Gtk.Frame): def __init__(self, controls): Gtk.Frame.__init__(self) vbox = Gtk.VBox(False, 5) self.controls = controls self.set_size_request(100, 200) self.album_title = Gtk.Label(_("Album title")) image_size = FC().main_window_size[2] - (FC().hpaned_right + 16) self.image = ImageBase(ICON_BLANK_DISK, size=image_size) image_frame = Gtk.Frame() image_frame.add(self.image) image_frame.set_label_widget(Gtk.Label(_("Cover:"))) vbox.pack_start(image_frame, False, False, 0) self.lyrics = TextArea() self.lyrics.connect("size-allocate", self.adapt_image) lyrics_frame = Gtk.Frame() lyrics_frame.add(self.lyrics) lyrics_frame.set_label_widget(Gtk.Label(_("Lyric:"))) vbox.pack_start(lyrics_frame, True, True, 0) self.add(vbox) self.set_label_widget(self.album_title) self.show_all() def get_pixbuf(self): return self.controls.perspectives.get_perspective('info').get_widget().image.pixbuf def set_cover(self): pixbuf = self.get_pixbuf() self.image.size = FC().info_panel_image_size self.image.set_from_pixbuf(pixbuf) def adapt_image(self, *a): dif = self.lyrics.get_allocation().width - self.image.get_allocation().width if self.lyrics.get_property("visible") and dif < 2: self.image.size = self.lyrics.get_allocation().width - 20 self.image.set_from_pixbuf(self.controls.coverlyrics.get_pixbuf())
def __init__(self, controls): gtk.Frame.__init__(self) vbox = gtk.VBox(False, 5) self.controls = controls self.set_size_request(100, 200) self.album_title = gtk.Label(_("Album title")) image_size = FC().main_window_size[2] - (FC().hpaned_right + 16) self.image = ImageBase(ICON_BLANK_DISK, size=image_size) image_frame = gtk.Frame() image_frame.add(self.image) image_frame.set_label_widget(gtk.Label(_("Cover:"))) vbox.pack_start(image_frame, False) self.lyrics = TextArea() lyrics_frame = gtk.Frame() lyrics_frame.add(self.lyrics) lyrics_frame.set_label_widget(gtk.Label(_("Lyric:"))) vbox.pack_start(lyrics_frame, True) self.add(vbox) self.set_label_widget(self.album_title) self.show_all()
def __init__(self, controls): Gtk.Frame.__init__(self) vbox = Gtk.VBox(False, 5) self.controls = controls self.set_size_request(100, 200) self.album_title = Gtk.Label(_("Album title")) image_size = FC().main_window_size[2] - (FC().hpaned_right + 16) self.image = ImageBase(ICON_BLANK_DISK, size=image_size) image_frame = Gtk.Frame() image_frame.add(self.image) image_frame.set_label_widget(Gtk.Label(_("Cover:"))) vbox.pack_start(image_frame, False, False, 0) self.lyrics = TextArea() self.lyrics.connect("size-allocate", self.adapt_image) lyrics_frame = Gtk.Frame() lyrics_frame.add(self.lyrics) lyrics_frame.set_label_widget(Gtk.Label(_("Lyric:"))) vbox.pack_start(lyrics_frame, True, True, 0) self.add(vbox) self.set_label_widget(self.album_title) self.show_all()
def __init__(self, controls): Gtk.Frame.__init__(self) FControl.__init__(self, controls) self.album_label = Gtk.Label() self.album_label.set_line_wrap(True) self.album_label.set_markup("<b></b>") self.set_label_widget(self.album_label) self.empty = TextArea() self.best_songs = SimpleTreeControl(_("Best Songs"), controls) self.best_songs.line_title = EventLabel(self.best_songs.get_title(), func=self.show_current, arg=self.best_songs, func1=self.show_best_songs) self.artists = SimpleTreeControl(_("Similar Artists"), controls) self.artists.line_title = EventLabel(self.artists.get_title(), func=self.show_current, arg=self.artists, func1=self.show_similar_artists) self.tracks = SimpleTreeControl(_("Similar Songs"), controls) self.tracks.line_title = EventLabel(self.tracks.get_title(), func=self.show_current, arg=self.tracks, func1=self.show_similar_tracks) self.tags = SimpleTreeControl(_("Similar Tags"), controls) self.tags.line_title = EventLabel(self.tags.get_title(), func=self.show_current, arg=self.tags, func1=self.show_similar_tags) self.lyrics = TextArea() lyric_title = _("Lyrics") self.lyrics.set_text("", lyric_title) self.lyrics.line_title = EventLabel(lyric_title, func=self.show_current, arg=self.lyrics, func1=self.show_similar_lyrics) """wiki""" wBox = Gtk.VBox() wiki_title = _("About Artist") self.wiki = TextArea() wBox.line_title = EventLabel(wiki_title, func=self.show_current, arg=wBox, func1=self.show_wiki_info) """info""" self.last_fm_label = Gtk.LinkButton("http://www.last.fm", "Last.Fm") self.wiki_label = Gtk.LinkButton("http://www.wikipedia.org", "Wikipedia") info_line = HBoxDecoratorTrue(self.last_fm_label, self.wiki_label) info_frame = FrameDecorator(_("Info"), info_line, 0.5, 0.5) """downloads""" self.exua_label = Gtk.LinkButton("http://www.ex.ua", "EX.ua") self.rutracker_label = Gtk.LinkButton("http://rutracker.org", "Rutracker") dm_line = HBoxDecoratorTrue(self.exua_label, self.rutracker_label) dm_frame = FrameDecorator(_("Downloads"), dm_line, 0.5, 0.5) self.wiki = TextArea() self.wiki.set_text("", wiki_title) wBox.pack_start(HBoxDecoratorTrue(info_frame, dm_frame), False, False, 0) wBox.pack_start(self.wiki, True, True, 0) wBox.scroll = wBox self.vpaned_small = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) """image and similar artists""" ibox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0) self.image = ImageBase(ICON_BLANK_DISK, FC().info_panel_image_size) lbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) self.left_widget = [wBox, self.artists, self.tracks, self.tags, self.lyrics, self.best_songs] for l_widget in self.left_widget: lbox.pack_start(l_widget.line_title, True, True, 0) ibox.pack_start(self.image, False, False, 0) ibox.pack_start(lbox, True, True, 0) """image and similar artists""" sbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) for l_widget in self.left_widget: sbox.pack_start(l_widget.scroll, True, True, 0) sbox.pack_end(self.empty.scroll, True, True, 0) self.vpaned_small.pack_start(ibox, False, False, 0) self.vpaned_small.pack_start(sbox, True, True, 0) self.add(self.vpaned_small) self.bean = None self.info_cache = InfoCache() self.update_lock = threading.Lock() self.clear()
class InfoPanelWidget(Gtk.Frame, LoadSave, FControl): def __init__(self, controls): Gtk.Frame.__init__(self) FControl.__init__(self, controls) self.album_label = Gtk.Label() self.album_label.set_line_wrap(True) self.album_label.set_markup("<b></b>") self.set_label_widget(self.album_label) self.empty = TextArea() self.best_songs = SimpleTreeControl(_("Best Songs"), controls) self.best_songs.line_title = EventLabel(self.best_songs.get_title(), func=self.show_current, arg=self.best_songs, func1=self.show_best_songs) self.artists = SimpleTreeControl(_("Similar Artists"), controls) self.artists.line_title = EventLabel(self.artists.get_title(), func=self.show_current, arg=self.artists, func1=self.show_similar_artists) self.tracks = SimpleTreeControl(_("Similar Songs"), controls) self.tracks.line_title = EventLabel(self.tracks.get_title(), func=self.show_current, arg=self.tracks, func1=self.show_similar_tracks) self.tags = SimpleTreeControl(_("Similar Tags"), controls) self.tags.line_title = EventLabel(self.tags.get_title(), func=self.show_current, arg=self.tags, func1=self.show_similar_tags) self.lyrics = TextArea() lyric_title = _("Lyrics") self.lyrics.set_text("", lyric_title) self.lyrics.line_title = EventLabel(lyric_title, func=self.show_current, arg=self.lyrics, func1=self.show_similar_lyrics) """wiki""" wBox = Gtk.VBox() wiki_title = _("About Artist") self.wiki = TextArea() wBox.line_title = EventLabel(wiki_title, func=self.show_current, arg=wBox, func1=self.show_wiki_info) """info""" self.last_fm_label = Gtk.LinkButton("http://www.last.fm", "Last.Fm") self.wiki_label = Gtk.LinkButton("http://www.wikipedia.org", "Wikipedia") info_line = HBoxDecoratorTrue(self.last_fm_label, self.wiki_label) info_frame = FrameDecorator(_("Info"), info_line, 0.5, 0.5) """downloads""" self.exua_label = Gtk.LinkButton("http://www.ex.ua", "EX.ua") self.rutracker_label = Gtk.LinkButton("http://rutracker.org", "Rutracker") dm_line = HBoxDecoratorTrue(self.exua_label, self.rutracker_label) dm_frame = FrameDecorator(_("Downloads"), dm_line, 0.5, 0.5) self.wiki = TextArea() self.wiki.set_text("", wiki_title) wBox.pack_start(HBoxDecoratorTrue(info_frame, dm_frame), False, False, 0) wBox.pack_start(self.wiki, True, True, 0) wBox.scroll = wBox self.vpaned_small = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) """image and similar artists""" ibox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0) self.image = ImageBase(ICON_BLANK_DISK, FC().info_panel_image_size) lbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) self.left_widget = [wBox, self.artists, self.tracks, self.tags, self.lyrics, self.best_songs] for l_widget in self.left_widget: lbox.pack_start(l_widget.line_title, True, True, 0) ibox.pack_start(self.image, False, False, 0) ibox.pack_start(lbox, True, True, 0) """image and similar artists""" sbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) for l_widget in self.left_widget: sbox.pack_start(l_widget.scroll, True, True, 0) sbox.pack_end(self.empty.scroll, True, True, 0) self.vpaned_small.pack_start(ibox, False, False, 0) self.vpaned_small.pack_start(sbox, True, True, 0) self.add(self.vpaned_small) self.bean = None self.info_cache = InfoCache() self.update_lock = threading.Lock() self.clear() @idle_task def show_current(self, widget): if not self.controls.net_wrapper.is_internet(): return self.empty.hide() if widget.line_title.selected: widget.scroll.hide() self.empty.show() widget.line_title.set_not_active() return for w in self.left_widget: w.scroll.hide() w.line_title.set_not_active() widget.scroll.show_all() widget.line_title.set_active() self.info_cache.active_method = widget.line_title.func1 self.controls.in_thread.run_with_spinner(widget.line_title.func1) def clear(self): self.image.set_no_image() self.tracks.clear_tree() self.tags.clear_tree() self.artists.clear_tree() self.lyrics.set_text("", _("Lyrics")) def update_info_panel(self): if not self.controls.net_wrapper.is_internet() or not self.bean: return bean = copy.copy(self.bean) def update_info_panel_task(): self.update_lock.acquire() try: self.show_album_title(bean) self.show_disc_cover(bean) if self.controls.coverlyrics.get_property("visible"): try: self.show_similar_lyrics(bean) except Exception, e: logging.error("Can't get lyrics. " + type(e).__name__ + ": " + e.message) if self.info_cache.active_method: self.info_cache.active_method() except:
def __init__(self, controls): gtk.Frame.__init__(self) FControl.__init__(self, controls) self.album_label = gtk.Label() self.album_label.set_line_wrap(True) self.album_label.set_markup("<b></b>") self.set_label_widget(self.album_label) self.best_songs = SimpleTreeControl(_("Best Songs"), controls) self.best_songs.line_title = EventLabel(self.best_songs.get_title(), func=self.show_current, arg=self.best_songs, func1=self.show_best_songs) self.artists = SimpleTreeControl(_("Similar Artists"), controls) self.artists.line_title = EventLabel(self.artists.get_title(), func=self.show_current, arg=self.artists, func1=self.show_similar_artists) self.tracks = SimpleTreeControl(_("Similar Songs"), controls) self.tracks.line_title = EventLabel(self.tracks.get_title(), func=self.show_current, arg=self.tracks, func1=self.show_similar_tracks) self.tags = SimpleTreeControl(_("Similar Tags"), controls) self.tags.line_title = EventLabel(self.tags.get_title(), func=self.show_current, arg=self.tags, func1=self.show_similar_tags) self.lyrics = TextArea() lyric_title = _("Lyrics") self.lyrics.set_text("", lyric_title) self.lyrics.line_title = EventLabel(lyric_title, func=self.show_current, arg=self.lyrics, func1=self.show_similar_lyrics) """wiki""" wBox = gtk.VBox() wiki_title = _("Biography") self.wiki = TextArea() wBox.line_title = EventLabel(wiki_title, func=self.show_current, arg=wBox, func1=self.show_wiki_info) self.last_fm_label = gtk.LinkButton("http://www.last.fm", "last.fm") self.wiki_label = gtk.LinkButton("http://www.wikipedia.org", "wikipedia") self.wiki = TextArea() self.wiki.set_text("", wiki_title) wBox.pack_start(HBoxDecorator(self.last_fm_label, self.wiki_label), False, False) wBox.pack_start(self.wiki, True, True) wBox.scroll = wBox self.vpaned_small = gtk.VBox(False, 0) """image and similar artists""" ibox = gtk.HBox(False, 0) self.image = ImageBase(ICON_BLANK_DISK, FC().info_panel_image_size) lbox = gtk.VBox(False, 0) self.left_widget = [wBox, self.artists, self.tracks, self.tags, self.lyrics, self.best_songs] for l_widget in self.left_widget: lbox.pack_start(l_widget.line_title) ibox.pack_start(self.image, False, False) ibox.pack_start(lbox, True, True) """image and similar artists""" sbox = gtk.VBox(False, 0) for l_widget in self.left_widget: sbox.pack_start(l_widget.scroll, True, True) self.vpaned_small.pack_start(ibox, False, False) self.vpaned_small.pack_start(sbox, True, True) self.add(self.vpaned_small) self.hide_all() self.bean = None self.info_cache = InfoCache()
class InfoPanelWidget(gtk.Frame, LoadSave, FControl): def __init__(self, controls): gtk.Frame.__init__(self) FControl.__init__(self, controls) self.album_label = gtk.Label() self.album_label.set_line_wrap(True) self.album_label.set_markup("<b></b>") self.set_label_widget(self.album_label) self.best_songs = SimpleTreeControl(_("Best Songs"), controls) self.best_songs.line_title = EventLabel(self.best_songs.get_title(), func=self.show_current, arg=self.best_songs, func1=self.show_best_songs) self.artists = SimpleTreeControl(_("Similar Artists"), controls) self.artists.line_title = EventLabel(self.artists.get_title(), func=self.show_current, arg=self.artists, func1=self.show_similar_artists) self.tracks = SimpleTreeControl(_("Similar Songs"), controls) self.tracks.line_title = EventLabel(self.tracks.get_title(), func=self.show_current, arg=self.tracks, func1=self.show_similar_tracks) self.tags = SimpleTreeControl(_("Similar Tags"), controls) self.tags.line_title = EventLabel(self.tags.get_title(), func=self.show_current, arg=self.tags, func1=self.show_similar_tags) self.lyrics = TextArea() lyric_title = _("Lyrics") self.lyrics.set_text("", lyric_title) self.lyrics.line_title = EventLabel(lyric_title, func=self.show_current, arg=self.lyrics, func1=self.show_similar_lyrics) """wiki""" wBox = gtk.VBox() wiki_title = _("Biography") self.wiki = TextArea() wBox.line_title = EventLabel(wiki_title, func=self.show_current, arg=wBox, func1=self.show_wiki_info) self.last_fm_label = gtk.LinkButton("http://www.last.fm", "last.fm") self.wiki_label = gtk.LinkButton("http://www.wikipedia.org", "wikipedia") self.wiki = TextArea() self.wiki.set_text("", wiki_title) wBox.pack_start(HBoxDecorator(self.last_fm_label, self.wiki_label), False, False) wBox.pack_start(self.wiki, True, True) wBox.scroll = wBox self.vpaned_small = gtk.VBox(False, 0) """image and similar artists""" ibox = gtk.HBox(False, 0) self.image = ImageBase(ICON_BLANK_DISK, FC().info_panel_image_size) lbox = gtk.VBox(False, 0) self.left_widget = [wBox, self.artists, self.tracks, self.tags, self.lyrics, self.best_songs] for l_widget in self.left_widget: lbox.pack_start(l_widget.line_title) ibox.pack_start(self.image, False, False) ibox.pack_start(lbox, True, True) """image and similar artists""" sbox = gtk.VBox(False, 0) for l_widget in self.left_widget: sbox.pack_start(l_widget.scroll, True, True) self.vpaned_small.pack_start(ibox, False, False) self.vpaned_small.pack_start(sbox, True, True) self.add(self.vpaned_small) self.hide_all() self.bean = None self.info_cache = InfoCache() def activate_perspective(self): FC().left_perspective = LEFT_PERSPECTIVE_INFO def show_current(self, widget): for w in self.left_widget: w.scroll.hide() w.line_title.set_not_active() widget.scroll.show_all() widget.line_title.set_active() self.info_cache.active_method = widget.line_title.func1 self.controls.in_thread.run_with_progressbar(widget.line_title.func1) def clear(self): self.image.set_no_image() self.tracks.clear_tree() self.tags.clear_tree() self.artists.clear_tree() def update_info_panel(self): if not self.bean: return None def task(): self.show_disc_cover() if FC().left_perspective == LEFT_PERSPECTIVE_INFO: self.show_album_title() self.info_cache.active_method() self.controls.in_thread.run_with_progressbar(task) def update(self, bean): #self.bean = bean if bean.type == FTYPE_NOT_UPDATE_INFO_PANEL: return False self.clear() if not FC().is_view_info_panel: logging.debug("Info panel disabled") return """check connection""" if not self.controls.lastfm.connect(): return """update bean info form text if possible""" bean = update_bean_from_normalized_text(bean) if not bean.artist or not bean.title: logging.debug("Artist and title not defined") self.bean = bean self.update_info_panel() def show_album_title(self): bean = self.bean """update info album and year""" album_name = self.controls.lastfm.get_album_name(bean.artist, bean.title) album_year = self.controls.lastfm.get_album_year(bean.artist, bean.title) info_line = bean.artist if album_name: info_line = album_name if album_name and album_year: info_line = album_name + "(" + album_year + ")" self.album_label.set_markup("<b>%s</b>" % info_line) def show_disc_cover(self): bean = self.bean """update image""" if not bean.image: bean.image = self.controls.lastfm.get_album_image_url(bean.artist, bean.title) self.image.update_info_from(bean) self.controls.trayicon.update_info_from(bean) def show_similar_lyrics(self): if self.info_cache.lyric_bean == self.bean: return None self.info_cache.lyric_bean = self.bean """lyrics""" text = get_lyrics(self.bean.artist, self.bean.title) lyrics_title = "*** %s - %s *** \n" % (self.bean.artist, self.bean.title) self.lyrics.set_text(text, lyrics_title) def show_wiki_info(self): if self.info_cache.wiki_artist == self.bean.artist: return None self.info_cache.wiki_artist = self.bean.artist if "ru" in locale.getlocale()[0]: self.wiki_label.set_uri("http://ru.wikipedia.org/w/index.php?&search=%s" % self.bean.artist) else: self.wiki_label.set_uri("http://en.wikipedia.org/w/index.php?&search=%s" % self.bean.artist) self.last_fm_label.set_uri("http://www.last.fm/search?q=%s" % self.bean.artist) artist = self.controls.lastfm.get_network().get_artist(self.bean.artist) self.wiki.set_text(artist.get_bio_content(), self.bean.artist) images = artist.get_images(limit=5) for image in images: try: url = image.sizes.large except AttributeError: url = image.sizes["large"] self.wiki.append_image(url) def show_similar_tags(self): if self.info_cache.similar_tags_bean == self.bean: return None self.info_cache.similar_tags_bean = self.bean """similar tags""" similar_tags = self.controls.lastfm.search_top_similar_tags(self.bean.artist, self.bean.title) parent = FModel("Similar Tags: " + self.bean.title) update_parent_for_beans(similar_tags, parent) self.tags.populate_all([parent] + similar_tags) def show_similar_tracks(self): if self.info_cache.similar_tracks_bean == self.bean: return None self.info_cache.similar_tracks_bean = self.bean """similar songs""" similar_tracks = self.controls.lastfm.search_top_similar_tracks(self.bean.artist, self.bean.title) parent = FModel("Similar Tracks: " + self.bean.title) update_parent_for_beans(similar_tracks, parent) self.tracks.populate_all([parent] + similar_tracks) def show_similar_artists(self): if self.info_cache.similar_artists_bean == self.bean: return None self.info_cache.similar_artists_bean = self.bean """similar artists""" similar_artists = self.controls.lastfm.search_top_similar_artist(self.bean.artist) parent = FModel("Similar Artists: " + self.bean.artist) update_parent_for_beans(similar_artists, parent) self.artists.populate_all([parent] + similar_artists) def show_best_songs(self): if self.info_cache.best_songs_bean == self.bean: return None self.info_cache.best_songs_bean = self.bean best_songs = self.controls.lastfm.search_top_tracks(self.bean.artist) parent = FModel("Best Songs: " + self.bean.artist) update_parent_for_beans(best_songs, parent) self.best_songs.populate_all([parent] + best_songs) def on_load(self): self.show_current(self.left_widget[0]) def on_save(self): pass
class InfoPanelWidget(gtk.Frame, LoadSave, FControl): def __init__(self, controls): gtk.Frame.__init__(self) FControl.__init__(self, controls) self.album_label = gtk.Label() self.album_label.set_line_wrap(True) self.album_label.set_markup("<b></b>") self.set_label_widget(self.album_label) self.empty = TextArea() self.best_songs = SimpleTreeControl(_("Best Songs"), controls) self.best_songs.line_title = EventLabel(self.best_songs.get_title(), func=self.show_current, arg=self.best_songs, func1=self.show_best_songs) self.artists = SimpleTreeControl(_("Similar Artists"), controls) self.artists.line_title = EventLabel(self.artists.get_title(), func=self.show_current, arg=self.artists, func1=self.show_similar_artists) self.tracks = SimpleTreeControl(_("Similar Songs"), controls) self.tracks.line_title = EventLabel(self.tracks.get_title(), func=self.show_current, arg=self.tracks, func1=self.show_similar_tracks) self.tags = SimpleTreeControl(_("Similar Tags"), controls) self.tags.line_title = EventLabel(self.tags.get_title(), func=self.show_current, arg=self.tags, func1=self.show_similar_tags) self.lyrics = TextArea() lyric_title = _("Lyrics") self.lyrics.set_text("", lyric_title) self.lyrics.line_title = EventLabel(lyric_title, func=self.show_current, arg=self.lyrics, func1=self.show_similar_lyrics) """wiki""" wBox = gtk.VBox() wiki_title = _("About Artist") self.wiki = TextArea() wBox.line_title = EventLabel(wiki_title, func=self.show_current, arg=wBox, func1=self.show_wiki_info) self.last_fm_label = gtk.LinkButton("http://www.last.fm", "last.fm") self.wiki_label = gtk.LinkButton("http://www.wikipedia.org", "wikipedia") self.wiki = TextArea() self.wiki.set_text("", wiki_title) wBox.pack_start(HBoxDecorator(self.last_fm_label, self.wiki_label), False, False) wBox.pack_start(self.wiki, True, True) wBox.scroll = wBox self.vpaned_small = gtk.VBox(False, 0) """image and similar artists""" ibox = gtk.HBox(False, 0) self.image = ImageBase(ICON_BLANK_DISK, FC().info_panel_image_size) lbox = gtk.VBox(False, 0) self.left_widget = [wBox, self.artists, self.tracks, self.tags, self.lyrics, self.best_songs] for l_widget in self.left_widget: lbox.pack_start(l_widget.line_title) ibox.pack_start(self.image, False, False) ibox.pack_start(lbox, True, True) """image and similar artists""" sbox = gtk.VBox(False, 0) for l_widget in self.left_widget: sbox.pack_start(l_widget.scroll, True, True) sbox.pack_end(self.empty.scroll, True, True) self.vpaned_small.pack_start(ibox, False, False) self.vpaned_small.pack_start(sbox, True, True) self.add(self.vpaned_small) self.hide_all() self.bean = None self.info_cache = InfoCache() def activate_perspective(self): FC().left_perspective = LEFT_PERSPECTIVE_INFO def show_current(self, widget): self.empty.hide() if widget.line_title.selected: widget.scroll.hide() self.empty.show() widget.line_title.set_not_active() self.info_cache.active_method return for w in self.left_widget: w.scroll.hide() w.line_title.set_not_active() widget.scroll.show_all() widget.line_title.set_active() self.info_cache.active_method = widget.line_title.func1 self.controls.in_thread.run_with_progressbar(widget.line_title.func1) def clear(self): self.image.set_no_image() self.tracks.clear_tree() self.tags.clear_tree() self.artists.clear_tree() def update_info_panel(self): if not self.bean: return None def task(): self.show_disc_cover() self.show_album_title() if self.controls.coverlyrics.get_property("visible"): self.show_similar_lyrics() if self.info_cache.active_method: self.info_cache.active_method() self.controls.in_thread.run_with_progressbar(task) def update(self, bean): if bean.type == FTYPE_NOT_UPDATE_INFO_PANEL: return False self.clear() if not FC().is_view_info_panel: logging.debug("Info panel disabled") return """check connection""" if not self.controls.lastfm_service.connect(): return """update bean info form text if possible""" bean = update_bean_from_normalized_text(bean) if not bean.artist or not bean.title: logging.debug("Artist and title not defined") self.bean = bean self.update_info_panel() def show_album_title(self): bean = self.bean """update info album and year""" info_line = bean.artist if FCache().album_titles.has_key(bean.text): info_line = FCache().album_titles[bean.text] else: album_name = self.controls.lastfm_service.get_album_name(bean.artist, bean.title) album_year = self.controls.lastfm_service.get_album_year(bean.artist, bean.title) if album_name: info_line = album_name if album_name and album_year: info_line = album_name + "(" + album_year + ")" if isinstance(info_line, unicode) or isinstance(info_line, str) : FCache().album_titles[bean.text] = info_line info_line.replace('&', '&') self.album_label.set_markup("<b>%s</b>" % info_line) self.controls.coverlyrics.album_title.set_markup("<b>%s</b>" % info_line) def show_disc_cover(self): bean = self.bean dict = FCache().covers """update image""" if not bean.image: if not os.path.isdir(COVERS_DIR): os.mkdir(COVERS_DIR) list_images = os.listdir(COVERS_DIR) '''remove extra keys''' for key in dict.keys(): if (key+'.jpg') not in list_images: del dict[key] '''remove extra files''' for file in list_images: if os.path.splitext(file)[0] not in dict.keys(): os.remove(os.path.join(COVERS_DIR, file)) for list, key in zip(dict.values(), dict.keys()): if bean.text in list: bean.image = os.path.join(COVERS_DIR, key + ".jpg") break if not bean.image: '''get image url''' bean.image = self.controls.lastfm_service.get_album_image_url(bean.artist, bean.title) self.image.update_info_from(bean) if not bean.image: logging.warning("""""Can't get cover image. Check the correctness of the artist's name and track title""""") '''make .jpg image and store it in cache''' if bean.image and bean.image.startswith("http://"): url_basename = os.path.splitext(os.path.basename(bean.image))[0] if dict.has_key(url_basename): dict[url_basename].append(bean.text) else: dict[url_basename] = [bean.text] self.image.get_pixbuf().save(os.path.join(COVERS_DIR, url_basename + '.jpg'), "jpeg", {"quality":"90"}) self.controls.trayicon.update_info_from(bean) self.controls.coverlyrics.set_cover() def show_similar_lyrics(self): if self.info_cache.lyric_bean == self.bean: return None self.info_cache.lyric_bean = self.bean """lyrics""" if not os.path.isdir(LYRICS_DIR): os.mkdir(LYRICS_DIR) lyrics_list = os.listdir(LYRICS_DIR) lyrics_title = "*** %s - %s *** \n" % (self.bean.artist, self.bean.title) if lyrics_title in lyrics_list: text = "".join(open(os.path.join(LYRICS_DIR, lyrics_title), 'r').readlines()) else: text = get_lyrics(self.bean.artist, self.bean.title) if text: open(os.path.join(LYRICS_DIR, lyrics_title), 'w').write(text) else: text = "The text not found" self.lyrics.set_text(text, lyrics_title) self.controls.coverlyrics.lyrics.set_text(text, lyrics_title) def show_wiki_info(self): if not self.bean: return if self.info_cache.wiki_artist == self.bean.artist: return None self.info_cache.wiki_artist = self.bean.artist self.wiki_label.set_uri("http://%s.wikipedia.org/w/index.php?&search=%s" %(SITE_LOCALE, self.bean.artist)) self.last_fm_label.set_uri("http://www.last.fm/search?q=%s" % self.bean.artist) artist = self.controls.lastfm_service.get_network().get_artist(self.bean.artist) self.wiki.set_text(artist.get_bio_content(), self.bean.artist) images = artist.get_images(limit=5) for image in images: try: url = image.sizes.large except AttributeError: url = image.sizes["large"] self.wiki.append_image(url) def show_similar_tags(self): if self.info_cache.similar_tags_bean == self.bean: return None self.info_cache.similar_tags_bean = self.bean """similar tags""" similar_tags = self.controls.lastfm_service.search_top_similar_tags(self.bean.artist, self.bean.title) parent = FModel("Similar Tags: " + self.bean.title) update_parent_for_beans(similar_tags, parent) self.tags.populate_all([parent] + similar_tags) def show_similar_tracks(self): if self.info_cache.similar_tracks_bean == self.bean: return None self.info_cache.similar_tracks_bean = self.bean """similar songs""" similar_tracks = self.controls.lastfm_service.search_top_similar_tracks(self.bean.artist, self.bean.title) parent = FModel("Similar Tracks: " + self.bean.title) update_parent_for_beans(similar_tracks, parent) self.tracks.populate_all([parent] + similar_tracks) def show_similar_artists(self): if self.info_cache.similar_artists_bean == self.bean: return None self.info_cache.similar_artists_bean = self.bean """similar artists""" similar_artists = self.controls.lastfm_service.search_top_similar_artist(self.bean.artist) parent = FModel("Similar Artists: " + self.bean.artist) update_parent_for_beans(similar_artists, parent) self.artists.populate_all([parent] + similar_artists) def show_best_songs(self): if self.info_cache.best_songs_bean == self.bean: return None self.info_cache.best_songs_bean = self.bean best_songs = self.controls.lastfm_service.search_top_tracks(self.bean.artist) parent = FModel("Best Songs: " + self.bean.artist) update_parent_for_beans(best_songs, parent) self.best_songs.populate_all([parent] + best_songs) def on_load(self): for w in self.left_widget: w.scroll.hide() w.line_title.set_not_active() self.empty.show() FCache().on_load() def on_save(self): pass def on_quit(self): FCache().on_quit()
def __init__(self, controls): gtk.Frame.__init__(self) FControl.__init__(self, controls) self.album_label = gtk.Label() self.album_label.set_line_wrap(True) self.album_label.set_markup("<b></b>") self.set_label_widget(self.album_label) self.empty = TextArea() self.best_songs = SimpleTreeControl(_("Best Songs"), controls) self.best_songs.line_title = EventLabel(self.best_songs.get_title(), func=self.show_current, arg=self.best_songs, func1=self.show_best_songs) self.artists = SimpleTreeControl(_("Similar Artists"), controls) self.artists.line_title = EventLabel(self.artists.get_title(), func=self.show_current, arg=self.artists, func1=self.show_similar_artists) self.tracks = SimpleTreeControl(_("Similar Songs"), controls) self.tracks.line_title = EventLabel(self.tracks.get_title(), func=self.show_current, arg=self.tracks, func1=self.show_similar_tracks) self.tags = SimpleTreeControl(_("Similar Tags"), controls) self.tags.line_title = EventLabel(self.tags.get_title(), func=self.show_current, arg=self.tags, func1=self.show_similar_tags) self.lyrics = TextArea() lyric_title = _("Lyrics") self.lyrics.set_text("", lyric_title) self.lyrics.line_title = EventLabel(lyric_title, func=self.show_current, arg=self.lyrics, func1=self.show_similar_lyrics) """wiki""" wBox = gtk.VBox() wiki_title = _("About Artist") self.wiki = TextArea() wBox.line_title = EventLabel(wiki_title, func=self.show_current, arg=wBox, func1=self.show_wiki_info) self.last_fm_label = gtk.LinkButton("http://www.last.fm", "last.fm") self.wiki_label = gtk.LinkButton("http://www.wikipedia.org", "wikipedia") self.wiki = TextArea() self.wiki.set_text("", wiki_title) wBox.pack_start(HBoxDecorator(self.last_fm_label, self.wiki_label), False, False) wBox.pack_start(self.wiki, True, True) wBox.scroll = wBox self.vpaned_small = gtk.VBox(False, 0) """image and similar artists""" ibox = gtk.HBox(False, 0) self.image = ImageBase(ICON_BLANK_DISK, FC().info_panel_image_size) lbox = gtk.VBox(False, 0) self.left_widget = [ wBox, self.artists, self.tracks, self.tags, self.lyrics, self.best_songs ] for l_widget in self.left_widget: lbox.pack_start(l_widget.line_title) ibox.pack_start(self.image, False, False) ibox.pack_start(lbox, True, True) """image and similar artists""" sbox = gtk.VBox(False, 0) for l_widget in self.left_widget: sbox.pack_start(l_widget.scroll, True, True) sbox.pack_end(self.empty.scroll, True, True) self.vpaned_small.pack_start(ibox, False, False) self.vpaned_small.pack_start(sbox, True, True) self.add(self.vpaned_small) self.hide_all() self.bean = None self.info_cache = InfoCache()
class InfoPanelWidget(gtk.Frame, LoadSave, FControl): def __init__(self, controls): gtk.Frame.__init__(self) FControl.__init__(self, controls) self.album_label = gtk.Label() self.album_label.set_line_wrap(True) self.album_label.set_markup("<b></b>") self.set_label_widget(self.album_label) self.empty = TextArea() self.best_songs = SimpleTreeControl(_("Best Songs"), controls) self.best_songs.line_title = EventLabel(self.best_songs.get_title(), func=self.show_current, arg=self.best_songs, func1=self.show_best_songs) self.artists = SimpleTreeControl(_("Similar Artists"), controls) self.artists.line_title = EventLabel(self.artists.get_title(), func=self.show_current, arg=self.artists, func1=self.show_similar_artists) self.tracks = SimpleTreeControl(_("Similar Songs"), controls) self.tracks.line_title = EventLabel(self.tracks.get_title(), func=self.show_current, arg=self.tracks, func1=self.show_similar_tracks) self.tags = SimpleTreeControl(_("Similar Tags"), controls) self.tags.line_title = EventLabel(self.tags.get_title(), func=self.show_current, arg=self.tags, func1=self.show_similar_tags) self.lyrics = TextArea() lyric_title = _("Lyrics") self.lyrics.set_text("", lyric_title) self.lyrics.line_title = EventLabel(lyric_title, func=self.show_current, arg=self.lyrics, func1=self.show_similar_lyrics) """wiki""" wBox = gtk.VBox() wiki_title = _("About Artist") self.wiki = TextArea() wBox.line_title = EventLabel(wiki_title, func=self.show_current, arg=wBox, func1=self.show_wiki_info) self.last_fm_label = gtk.LinkButton("http://www.last.fm", "last.fm") self.wiki_label = gtk.LinkButton("http://www.wikipedia.org", "wikipedia") self.wiki = TextArea() self.wiki.set_text("", wiki_title) wBox.pack_start(HBoxDecorator(self.last_fm_label, self.wiki_label), False, False) wBox.pack_start(self.wiki, True, True) wBox.scroll = wBox self.vpaned_small = gtk.VBox(False, 0) """image and similar artists""" ibox = gtk.HBox(False, 0) self.image = ImageBase(ICON_BLANK_DISK, FC().info_panel_image_size) lbox = gtk.VBox(False, 0) self.left_widget = [ wBox, self.artists, self.tracks, self.tags, self.lyrics, self.best_songs ] for l_widget in self.left_widget: lbox.pack_start(l_widget.line_title) ibox.pack_start(self.image, False, False) ibox.pack_start(lbox, True, True) """image and similar artists""" sbox = gtk.VBox(False, 0) for l_widget in self.left_widget: sbox.pack_start(l_widget.scroll, True, True) sbox.pack_end(self.empty.scroll, True, True) self.vpaned_small.pack_start(ibox, False, False) self.vpaned_small.pack_start(sbox, True, True) self.add(self.vpaned_small) self.hide_all() self.bean = None self.info_cache = InfoCache() def activate_perspective(self): FC().left_perspective = LEFT_PERSPECTIVE_INFO def show_current(self, widget): self.empty.hide() if widget.line_title.selected: widget.scroll.hide() self.empty.show() widget.line_title.set_not_active() self.info_cache.active_method return for w in self.left_widget: w.scroll.hide() w.line_title.set_not_active() widget.scroll.show_all() widget.line_title.set_active() self.info_cache.active_method = widget.line_title.func1 self.controls.in_thread.run_with_progressbar(widget.line_title.func1) def clear(self): self.image.set_no_image() self.tracks.clear_tree() self.tags.clear_tree() self.artists.clear_tree() def update_info_panel(self): if not self.bean: return None def task(): self.show_disc_cover() self.show_album_title() if self.controls.coverlyrics.get_property("visible"): self.show_similar_lyrics() if self.info_cache.active_method: self.info_cache.active_method() self.controls.in_thread.run_with_progressbar(task) def update(self, bean): if bean.type == FTYPE_NOT_UPDATE_INFO_PANEL: return False self.clear() if not FC().is_view_info_panel: logging.debug("Info panel disabled") return """check connection""" if not self.controls.lastfm_service.connect(): return """update bean info form text if possible""" bean = update_bean_from_normalized_text(bean) if not bean.artist or not bean.title: logging.debug("Artist and title not defined") self.bean = bean self.update_info_panel() def show_album_title(self): bean = self.bean """update info album and year""" info_line = bean.artist if FCache().album_titles.has_key(bean.text): info_line = FCache().album_titles[bean.text] else: album_name = self.controls.lastfm_service.get_album_name( bean.artist, bean.title) album_year = self.controls.lastfm_service.get_album_year( bean.artist, bean.title) if album_name: info_line = album_name if album_name and album_year: info_line = album_name + "(" + album_year + ")" if isinstance(info_line, unicode) or isinstance(info_line, str): FCache().album_titles[bean.text] = info_line info_line.replace('&', '&') self.album_label.set_markup("<b>%s</b>" % info_line) self.controls.coverlyrics.album_title.set_markup("<b>%s</b>" % info_line) def show_disc_cover(self): bean = self.bean dict = FCache().covers """update image""" if not bean.image: if not os.path.isdir(COVERS_DIR): os.mkdir(COVERS_DIR) list_images = os.listdir(COVERS_DIR) '''remove extra keys''' for key in dict.keys(): if (key + '.jpg') not in list_images: del dict[key] '''remove extra files''' for file in list_images: if os.path.splitext(file)[0] not in dict.keys(): os.remove(os.path.join(COVERS_DIR, file)) for list, key in zip(dict.values(), dict.keys()): if bean.text in list: bean.image = os.path.join(COVERS_DIR, key + ".jpg") break if not bean.image: '''get image url''' bean.image = self.controls.lastfm_service.get_album_image_url( bean.artist, bean.title) self.image.update_info_from(bean) if not bean.image: logging.warning( """""Can't get cover image. Check the correctness of the artist's name and track title""" "") '''make .jpg image and store it in cache''' if bean.image and bean.image.startswith("http://"): url_basename = os.path.splitext(os.path.basename(bean.image))[0] if dict.has_key(url_basename): dict[url_basename].append(bean.text) else: dict[url_basename] = [bean.text] self.image.get_pixbuf().save( os.path.join(COVERS_DIR, url_basename + '.jpg'), "jpeg", {"quality": "90"}) self.controls.trayicon.update_info_from(bean) self.controls.coverlyrics.set_cover() def show_similar_lyrics(self): if self.info_cache.lyric_bean == self.bean: return None self.info_cache.lyric_bean = self.bean """lyrics""" if not os.path.isdir(LYRICS_DIR): os.mkdir(LYRICS_DIR) lyrics_list = os.listdir(LYRICS_DIR) lyrics_title = "*** %s - %s *** \n" % (self.bean.artist, self.bean.title) if lyrics_title in lyrics_list: text = "".join( open(os.path.join(LYRICS_DIR, lyrics_title), 'r').readlines()) else: text = get_lyrics(self.bean.artist, self.bean.title) if text: open(os.path.join(LYRICS_DIR, lyrics_title), 'w').write(text) else: text = "The text not found" self.lyrics.set_text(text, lyrics_title) self.controls.coverlyrics.lyrics.set_text(text, lyrics_title) def show_wiki_info(self): if not self.bean: return if self.info_cache.wiki_artist == self.bean.artist: return None self.info_cache.wiki_artist = self.bean.artist self.wiki_label.set_uri( "http://%s.wikipedia.org/w/index.php?&search=%s" % (SITE_LOCALE, self.bean.artist)) self.last_fm_label.set_uri("http://www.last.fm/search?q=%s" % self.bean.artist) artist = self.controls.lastfm_service.get_network().get_artist( self.bean.artist) self.wiki.set_text(artist.get_bio_content(), self.bean.artist) images = artist.get_images(limit=5) for image in images: try: url = image.sizes.large except AttributeError: url = image.sizes["large"] self.wiki.append_image(url) def show_similar_tags(self): if self.info_cache.similar_tags_bean == self.bean: return None self.info_cache.similar_tags_bean = self.bean """similar tags""" similar_tags = self.controls.lastfm_service.search_top_similar_tags( self.bean.artist, self.bean.title) parent = FModel("Similar Tags: " + self.bean.title) update_parent_for_beans(similar_tags, parent) self.tags.populate_all([parent] + similar_tags) def show_similar_tracks(self): if self.info_cache.similar_tracks_bean == self.bean: return None self.info_cache.similar_tracks_bean = self.bean """similar songs""" similar_tracks = self.controls.lastfm_service.search_top_similar_tracks( self.bean.artist, self.bean.title) parent = FModel("Similar Tracks: " + self.bean.title) update_parent_for_beans(similar_tracks, parent) self.tracks.populate_all([parent] + similar_tracks) def show_similar_artists(self): if self.info_cache.similar_artists_bean == self.bean: return None self.info_cache.similar_artists_bean = self.bean """similar artists""" similar_artists = self.controls.lastfm_service.search_top_similar_artist( self.bean.artist) parent = FModel("Similar Artists: " + self.bean.artist) update_parent_for_beans(similar_artists, parent) self.artists.populate_all([parent] + similar_artists) def show_best_songs(self): if self.info_cache.best_songs_bean == self.bean: return None self.info_cache.best_songs_bean = self.bean best_songs = self.controls.lastfm_service.search_top_tracks( self.bean.artist) parent = FModel("Best Songs: " + self.bean.artist) update_parent_for_beans(best_songs, parent) self.best_songs.populate_all([parent] + best_songs) def on_load(self): for w in self.left_widget: w.scroll.hide() w.line_title.set_not_active() self.empty.show() FCache().on_load() def on_save(self): pass def on_quit(self): FCache().on_quit()
def __init__(self, controls): Gtk.Frame.__init__(self) FControl.__init__(self, controls) self.album_label = Gtk.Label() self.album_label.set_line_wrap(True) self.album_label.set_markup("<b></b>") self.set_label_widget(self.album_label) self.empty = TextArea() self.best_songs = SimpleTreeControl(_("Best Songs"), controls) self.best_songs.line_title = EventLabel(self.best_songs.get_title(), func=self.show_current, arg=self.best_songs, func1=self.show_best_songs) self.artists = SimpleTreeControl(_("Similar Artists"), controls) self.artists.line_title = EventLabel(self.artists.get_title(), func=self.show_current, arg=self.artists, func1=self.show_similar_artists) self.tracks = SimpleTreeControl(_("Similar Songs"), controls) self.tracks.line_title = EventLabel(self.tracks.get_title(), func=self.show_current, arg=self.tracks, func1=self.show_similar_tracks) self.tags = SimpleTreeControl(_("Similar Tags"), controls) self.tags.line_title = EventLabel(self.tags.get_title(), func=self.show_current, arg=self.tags, func1=self.show_similar_tags) self.lyrics = TextArea() lyric_title = _("Lyrics") self.lyrics.set_text("", lyric_title) self.lyrics.line_title = EventLabel(lyric_title, func=self.show_current, arg=self.lyrics, func1=self.show_similar_lyrics) """wiki""" wBox = Gtk.VBox() wiki_title = _("About Artist") self.wiki = TextArea() wBox.line_title = EventLabel(wiki_title, func=self.show_current, arg=wBox, func1=self.show_wiki_info) """info""" info_frame = Gtk.Frame(label=_("Info")) self.last_fm_label = Gtk.LinkButton("http://www.last.fm", "Last.Fm") self.wiki_label = Gtk.LinkButton("http://www.wikipedia.org", "Wikipedia") info_line = HBoxDecoratorTrue(self.last_fm_label, self.wiki_label) info_frame.add(info_line) """downloads""" dm_frame = Gtk.Frame(label=_("Downloads")) self.exua_label = Gtk.LinkButton("http://www.ex.ua", "EX.ua") self.rutracker_label = Gtk.LinkButton("http://rutracker.org", "Rutracker") dm_line = HBoxDecoratorTrue(self.exua_label, self.rutracker_label) dm_frame.add(dm_line) self.wiki = TextArea() self.wiki.set_text("", wiki_title) wBox.pack_start(HBoxDecoratorTrue(info_frame, dm_frame), False, False, 0) wBox.pack_start(self.wiki, True, True, 0) wBox.scroll = wBox self.vpaned_small = Gtk.VBox(False, 0) """image and similar artists""" ibox = Gtk.HBox(False, 0) self.image = ImageBase(ICON_BLANK_DISK, FC().info_panel_image_size) lbox = Gtk.VBox(False, 0) self.left_widget = [wBox, self.artists, self.tracks, self.tags, self.lyrics, self.best_songs] for l_widget in self.left_widget: lbox.pack_start(l_widget.line_title, True, True, 0) ibox.pack_start(self.image, False, False, 0) ibox.pack_start(lbox, True, True, 0) """image and similar artists""" sbox = Gtk.VBox(False, 0) for l_widget in self.left_widget: sbox.pack_start(l_widget.scroll, True, True, 0) sbox.pack_end(self.empty.scroll, True, True, 0) self.vpaned_small.pack_start(ibox, False, False, 0) self.vpaned_small.pack_start(sbox, True, True, 0) self.add(self.vpaned_small) self.bean = None self.info_cache = InfoCache() self.update_lock = threading.Lock() self.clear()
class InfoPanelWidget(Gtk.Frame, LoadSave, FControl): def __init__(self, controls): Gtk.Frame.__init__(self) FControl.__init__(self, controls) self.album_label = Gtk.Label() self.album_label.set_line_wrap(True) self.album_label.set_markup("<b></b>") self.set_label_widget(self.album_label) self.empty = TextArea() self.best_songs = SimpleTreeControl(_("Best Songs"), controls) self.best_songs.line_title = EventLabel(self.best_songs.get_title(), func=self.show_current, arg=self.best_songs, func1=self.show_best_songs) self.artists = SimpleTreeControl(_("Similar Artists"), controls) self.artists.line_title = EventLabel(self.artists.get_title(), func=self.show_current, arg=self.artists, func1=self.show_similar_artists) self.tracks = SimpleTreeControl(_("Similar Songs"), controls) self.tracks.line_title = EventLabel(self.tracks.get_title(), func=self.show_current, arg=self.tracks, func1=self.show_similar_tracks) self.tags = SimpleTreeControl(_("Similar Tags"), controls) self.tags.line_title = EventLabel(self.tags.get_title(), func=self.show_current, arg=self.tags, func1=self.show_similar_tags) self.lyrics = TextArea() lyric_title = _("Lyrics") self.lyrics.set_text("", lyric_title) self.lyrics.line_title = EventLabel(lyric_title, func=self.show_current, arg=self.lyrics, func1=self.show_similar_lyrics) """wiki""" wBox = Gtk.VBox() wiki_title = _("About Artist") self.wiki = TextArea() wBox.line_title = EventLabel(wiki_title, func=self.show_current, arg=wBox, func1=self.show_wiki_info) """info""" info_frame = Gtk.Frame(label=_("Info")) self.last_fm_label = Gtk.LinkButton("http://www.last.fm", "Last.Fm") self.wiki_label = Gtk.LinkButton("http://www.wikipedia.org", "Wikipedia") info_line = HBoxDecoratorTrue(self.last_fm_label, self.wiki_label) info_frame.add(info_line) """downloads""" dm_frame = Gtk.Frame(label=_("Downloads")) self.exua_label = Gtk.LinkButton("http://www.ex.ua", "EX.ua") self.rutracker_label = Gtk.LinkButton("http://rutracker.org", "Rutracker") dm_line = HBoxDecoratorTrue(self.exua_label, self.rutracker_label) dm_frame.add(dm_line) self.wiki = TextArea() self.wiki.set_text("", wiki_title) wBox.pack_start(HBoxDecoratorTrue(info_frame, dm_frame), False, False, 0) wBox.pack_start(self.wiki, True, True, 0) wBox.scroll = wBox self.vpaned_small = Gtk.VBox(False, 0) """image and similar artists""" ibox = Gtk.HBox(False, 0) self.image = ImageBase(ICON_BLANK_DISK, FC().info_panel_image_size) lbox = Gtk.VBox(False, 0) self.left_widget = [wBox, self.artists, self.tracks, self.tags, self.lyrics, self.best_songs] for l_widget in self.left_widget: lbox.pack_start(l_widget.line_title, True, True, 0) ibox.pack_start(self.image, False, False, 0) ibox.pack_start(lbox, True, True, 0) """image and similar artists""" sbox = Gtk.VBox(False, 0) for l_widget in self.left_widget: sbox.pack_start(l_widget.scroll, True, True, 0) sbox.pack_end(self.empty.scroll, True, True, 0) self.vpaned_small.pack_start(ibox, False, False, 0) self.vpaned_small.pack_start(sbox, True, True, 0) self.add(self.vpaned_small) self.bean = None self.info_cache = InfoCache() self.update_lock = threading.Lock() self.clear() @idle_task def show_current(self, widget): if not self.controls.net_wrapper.is_internet(): return self.empty.hide() if widget.line_title.selected: widget.scroll.hide() self.empty.show() widget.line_title.set_not_active() return for w in self.left_widget: w.scroll.hide() w.line_title.set_not_active() widget.scroll.show_all() widget.line_title.set_active() self.info_cache.active_method = widget.line_title.func1 self.controls.in_thread.run_with_progressbar(widget.line_title.func1) def clear(self): self.image.set_no_image() self.tracks.clear_tree() self.tags.clear_tree() self.artists.clear_tree() self.lyrics.set_text("", _("Lyrics")) def update_info_panel(self): if not self.controls.net_wrapper.is_internet() or not self.bean: return bean = copy.copy(self.bean) def update_info_panel_task(): self.update_lock.acquire() try: self.show_album_title(bean) self.show_disc_cover(bean) if self.controls.coverlyrics.get_property("visible"): try: self.show_similar_lyrics(bean) except Exception, e: logging.error("Can't get lyrics. " + type(e).__name__ + ": " + e.message) if self.info_cache.active_method: self.info_cache.active_method() except: pass self.update_lock.release() self.controls.in_thread.run_with_progressbar(update_info_panel_task, with_lock=False)
class InfoPanelWidget(Gtk.Frame, LoadSave, FControl): def __init__(self, controls): Gtk.Frame.__init__(self) FControl.__init__(self, controls) self.album_label = Gtk.Label.new(None) self.album_label.set_line_wrap(True) self.album_label.set_markup("<b></b>") self.set_label_widget(self.album_label) self.empty = TextArea() self.best_songs = SimpleTreeControl(_("Best Songs"), controls) self.best_songs.line_title = EventLabel(self.best_songs.get_title(), func=self.show_current, arg=self.best_songs, func1=self.show_best_songs) self.artists = SimpleTreeControl(_("Similar Artists"), controls) self.artists.line_title = EventLabel(self.artists.get_title(), func=self.show_current, arg=self.artists, func1=self.show_similar_artists) self.tracks = SimpleTreeControl(_("Similar Songs"), controls) self.tracks.line_title = EventLabel(self.tracks.get_title(), func=self.show_current, arg=self.tracks, func1=self.show_similar_tracks) self.tags = SimpleTreeControl(_("Similar Tags"), controls) self.tags.line_title = EventLabel(self.tags.get_title(), func=self.show_current, arg=self.tags, func1=self.show_similar_tags) self.lyrics = TextArea() lyric_title = _("Lyrics") self.lyrics.set_text("", lyric_title) self.lyrics.line_title = EventLabel(lyric_title, func=self.show_current, arg=self.lyrics, func1=self.show_similar_lyrics) """wiki""" wBox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) wiki_title = _("About Artist") self.wiki = TextArea() wBox.line_title = EventLabel(wiki_title, func=self.show_current, arg=wBox, func1=self.show_wiki_info) """info""" self.last_fm_label = Gtk.LinkButton.new_with_label( "http://www.last.fm", "Last.Fm") self.wiki_label = Gtk.LinkButton.new_with_label( "http://www.wikipedia.org", "Wikipedia") info_line = HBoxDecoratorTrue(self.last_fm_label, self.wiki_label) info_frame = FrameDecorator(_("Info"), info_line, 0.5, 0.5) """downloads""" self.exua_label = Gtk.LinkButton.new_with_label( "http://www.ex.ua", "EX.ua") self.rutracker_label = Gtk.LinkButton.new_with_label( "http://rutracker.org", "Rutracker") dm_line = HBoxDecoratorTrue(self.exua_label, self.rutracker_label) dm_frame = FrameDecorator(_("Downloads"), dm_line, 0.5, 0.5) self.wiki = TextArea() self.wiki.set_text("", wiki_title) wBox.pack_start(HBoxDecoratorTrue(info_frame, dm_frame), False, False, 0) wBox.pack_start(self.wiki, True, True, 0) wBox.scroll = wBox self.vpaned_small = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) """image and similar artists""" ibox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0) self.image = ImageBase(ICON_BLANK_DISK, FC().info_panel_image_size) lbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) self.left_widget = [ wBox, self.artists, self.tracks, self.tags, self.lyrics, self.best_songs ] for l_widget in self.left_widget: lbox.pack_start(l_widget.line_title, True, True, 0) ibox.pack_start(self.image, False, False, 0) ibox.pack_start(lbox, True, True, 0) """image and similar artists""" sbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) for l_widget in self.left_widget: sbox.pack_start(l_widget.scroll, True, True, 0) sbox.pack_end(self.empty.scroll, True, True, 0) self.vpaned_small.pack_start(ibox, False, False, 0) self.vpaned_small.pack_start(sbox, True, True, 0) self.add(self.vpaned_small) self.bean = None self.info_cache = InfoCache() self.update_lock = threading.Lock() self.clear() @idle_task def show_current(self, widget): if not self.controls.net_wrapper.is_internet(): return self.empty.hide() if widget.line_title.selected: widget.scroll.hide() self.empty.show() widget.line_title.set_not_active() return for w in self.left_widget: w.scroll.hide() w.line_title.set_not_active() widget.scroll.show_all() widget.line_title.set_active() self.info_cache.active_method = widget.line_title.func1 self.controls.in_thread.run_with_spinner(widget.line_title.func1) def clear(self): self.image.set_no_image() self.tracks.clear_tree() self.tags.clear_tree() self.artists.clear_tree() self.lyrics.set_text("", _("Lyrics")) def update_info_panel(self): if not self.controls.net_wrapper.is_internet() or not self.bean: return bean = copy.copy(self.bean) def update_info_panel_task(): self.update_lock.acquire() try: self.show_album_title(bean) self.show_disc_cover(bean) if self.controls.coverlyrics.get_property("visible"): try: self.show_similar_lyrics(bean) except Exception as e: logging.error("Can't get lyrics. " + type(e).__name__ + ": " + e.message) if self.info_cache.active_method: self.info_cache.active_method() except: pass self.update_lock.release() threading.Thread(target=update_info_panel_task).start() def update(self, bean): if bean.type == FTYPE_NOT_UPDATE_INFO_PANEL: return False self.clear() if not self.controls.net_wrapper.is_internet(): return if not FC().is_view_info_panel: logging.debug("Info panel disabled") return """check connection""" if not self.controls.lastfm_service.connect(): return """update bean info form text if possible""" bean = update_bean_from_normalized_text(bean) if not bean.artist or not bean.title: logging.debug("Artist and title not defined") self.bean = bean self.update_info_panel() def show_album_title(self, bean=None): if not bean: bean = self.bean if bean.UUID != self.bean.UUID: return """update info album and year""" info_line = bean.artist if bean.text in FCache().album_titles: info_line = FCache().album_titles[bean.text] else: album_name = self.controls.lastfm_service.get_album_name( bean.artist, bean.title) album_year = self.controls.lastfm_service.get_album_year( bean.artist, bean.title) if album_name: info_line = album_name if album_name and album_year: info_line = album_name + " (" + album_year + ")" if isinstance(info_line, str): FCache().album_titles[bean.text] = info_line if info_line and bean.UUID == self.bean.UUID: info_line = info_line.replace('&', '&') GLib.idle_add(self.album_label.set_markup, "<b>%s</b>" % info_line) GLib.idle_add(self.controls.coverlyrics.album_title.set_markup, "<b>%s</b>" % info_line) def show_disc_cover(self, bean=None): if not bean: bean = self.bean if bean.UUID != self.bean.UUID: return """update image""" if not bean.image: if not os.path.isdir(COVERS_DIR): os.mkdir(COVERS_DIR) bean.image = get_image_for_bean(bean, self.controls) if not bean.image: logging.warning( """""Can't get cover image. Check the correctness of the artist's name and track title""" "") if bean.UUID == self.bean.UUID: self.image.update_info_from(bean) self.controls.trayicon.update_info_from(bean) self.controls.coverlyrics.set_cover() def show_similar_lyrics(self, bean=None): if not bean: bean = self.bean if not bean: return if bean.UUID != self.bean.UUID: return """lyrics""" if not os.path.isdir(LYRICS_DIR): os.mkdir(LYRICS_DIR) cache_name = lyrics_title = "%s - %s" % (bean.artist, bean.title) illegal_chars = ["/", "#", ";", ":", "%", "*", "&", "\\"] for char in illegal_chars: cache_name = cache_name.replace(char, "_") cache_name = cache_name.lower().strip() text = None if os.path.exists(os.path.join(LYRICS_DIR, cache_name)): with open(os.path.join(LYRICS_DIR, cache_name), 'r') as cache_file: text = "".join(cache_file.readlines()) else: self.lyrics.set_text(_("Loading..."), lyrics_title) try: logging.debug("Try to get lyrics from lyrics.wikia.com") text = get_lyrics(bean.artist, bean.title) except: logging.info( "Error occurred when getting lyrics from lyrics.wikia.com") if not text: text = get_lyrics_by_parsing(bean.artist, bean.title) if text: with open(os.path.join(LYRICS_DIR, cache_name), 'w') as cache_file: cache_file.write(text) else: logging.info("The text not found") text = _("The text not found") if bean.UUID == self.bean.UUID: self.set_lyrics(text, lyrics_title) def show_wiki_info(self): if not self.bean: return if self.info_cache.wiki_artist == self.bean.artist: return None self.info_cache.wiki_artist = self.bean.artist self.wiki_label.set_uri( "http://%s.wikipedia.org/w/index.php?&search=%s" % (SITE_LOCALE, self.bean.artist)) self.last_fm_label.set_uri("http://www.last.fm/search?q=%s" % self.bean.artist) self.exua_label.set_uri("http://www.ex.ua/search?s=%s" % self.bean.artist) self.rutracker_label.set_uri( "http://rutracker.org/forum/tracker.php?nm=%s" % self.bean.artist) artist = self.controls.lastfm_service.get_network().get_artist( self.bean.artist) self.wiki.set_text(artist.get_bio_summary(), self.bean.artist) # Deprecated # images = artist.get_images(limit=6) # # for image in images: # try: # url = image.sizes.large # except AttributeError: # url = image.sizes["large"] # self.wiki.append_image(url) def show_similar_tags(self): if self.info_cache.similar_tags_bean == self.bean: return None self.info_cache.similar_tags_bean = self.bean """similar tags""" similar_tags = self.controls.lastfm_service.search_top_similar_tags( self.bean.artist, self.bean.title) parent = FModel(_("Similar Tags:") + " " + self.bean.title) update_parent_for_beans(similar_tags, parent) self.tags.populate_all([parent] + similar_tags) def show_similar_tracks(self): if self.info_cache.similar_tracks_bean == self.bean: return None self.info_cache.similar_tracks_bean = self.bean """similar songs""" similar_tracks = self.controls.lastfm_service.search_top_similar_tracks( self.bean.artist, self.bean.title) parent = FModel(_("Similar Tracks:") + " " + self.bean.title) update_parent_for_beans(similar_tracks, parent) self.tracks.populate_all([parent] + similar_tracks) def show_similar_artists(self): if self.info_cache.similar_artists_bean == self.bean: return None self.info_cache.similar_artists_bean = self.bean """similar artists""" if self.bean.artist: similar_artists = self.controls.lastfm_service.search_top_similar_artist( self.bean.artist) parent = FModel(_("Similar Artists:") + " " + self.bean.artist) update_parent_for_beans(similar_artists, parent) self.artists.populate_all([parent] + similar_artists) def show_best_songs(self): if self.info_cache.best_songs_bean == self.bean: return None self.info_cache.best_songs_bean = self.bean best_songs = self.controls.lastfm_service.search_top_tracks( self.bean.artist) parent = FModel(_("Best Songs:") + " " + self.bean.artist) update_parent_for_beans(best_songs, parent) self.best_songs.populate_all([parent] + best_songs) @idle_task def set_lyrics(self, text, title): self.lyrics.set_text(text, title) self.controls.coverlyrics.lyrics.set_text(text, title) def on_load(self): for w in self.left_widget: w.scroll.hide() w.line_title.set_not_active() self.empty.show() FCache().on_load() def on_save(self): pass def on_quit(self): FCache().on_quit()