Exemple #1
0
 def append_image(self, url):
     if not url:
         return None
     enditer = self.buffer.get_end_iter()
     image = ImageBase(None)
     image.set_image_from_url(url)
     self.buffer.insert_pixbuf(enditer, image.get_pixbuf())
Exemple #2
0
    def __init__(self, controls):
        FControl.__init__(self, controls)
        Gtk.StatusIcon.__init__(self)
        self.hide()
        ImageBase.__init__(self, ICON_FOOBNIX, 150)

        self.popup_menu = PopupMenuWindow(self.controls)
        self.popup_volume_contol = PopupVolumeWindow(self.controls, self.popup_menu)

        self.connect("activate", self.on_activate)
        self.connect("popup-menu", self.on_popup_menu)

        try:
            self.set_has_tooltip(True)
            #self.set_tooltip("Foobnix music player")
            self.connect("query-tooltip", self.on_query_tooltip)
            self.connect("button-press-event", self.on_button_press)
            self.connect("scroll-event", self.on_scroll)
        except Exception as e:
            logging.warn("Tooltip doesn't work " + str(e))

        self.current_bean = FModel().add_artist("Artist").add_title("Title")
        self.tooltip_image = ImageBase(ICON_FOOBNIX, 75)

        self._previous_notify = None
Exemple #3
0
class CoverLyricsPanel(gtk.Frame):
    def __init__(self, controls):
        gtk.Frame.__init__(self)
        vbox = gtk.VBox(False, 5)
        self.controls = controls

        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)
Exemple #4
0
 def append_image(self, url):
     if not url:
         return None
     enditer = self.buffer.get_end_iter()
     image = ImageBase(None)
     image.set_image_from_url(url)
     self.buffer.insert_pixbuf(enditer, image.get_pixbuf())
Exemple #5
0
    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()
Exemple #6
0
class CoverLyricsPanel(Gtk.Frame):
    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.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()

    def get_pixbuf(self):
        return self.controls.perspectives.get_perspective('info').get_widget().image.pixbuf

    def set_cover(self):
        self.image.size = FC().info_panel_image_size
        self.image.set_from_pixbuf(self.get_pixbuf())
Exemple #7
0
class CoverLyricsPanel(gtk.Frame):
    def __init__(self, controls):
        gtk.Frame.__init__(self)
        vbox = gtk.VBox(False, 5)
        self.controls = controls
        
        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)
Exemple #8
0
    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()
Exemple #9
0
class TrayIconControls(gtk.StatusIcon, ImageBase, FControl, LoadSave):
    def __init__(self, controls):
        FControl.__init__(self, controls)
        gtk.StatusIcon.__init__(self)
        self.hide()

        ImageBase.__init__(self, ICON_FOOBNIX, 150)

        self.popup_menu = PopupWindowMenu(self.controls)

        self.connect("activate", self.on_activate)
        self.connect("popup-menu", self.on_popup_menu)

        try:
            self.set_has_tooltip(True)
            self.tooltip = gtk.Tooltip()
            self.set_tooltip("Foobnix music player")
            self.connect("query-tooltip", self.on_query_tooltip)
            self.connect("button-press-event", self.on_button_press)
            self.connect("scroll-event", self.controls.volume.on_scroll_event)
        except Exception, e:
            logging.warn("On debian it doesn't work" + str(e))

        self.current_bean = FModel().add_artist("Artist").add_title("Title")
        self.tooltip_image = ImageBase(ICON_FOOBNIX, 75)
Exemple #10
0
        def dialog_token():
            self.set_keep_above(True)
            self.token = gtk.Entry()
            self.set_size_request(550, -1)
            self.user_id = gtk.Entry()
            if FC().user_id:
                self.user_id.set_text(FC().user_id)

            edit = gtk.Entry()
            edit.set_text(self.API_URL)
            link = gtk.LinkButton(self.API_URL, _("Open"))

            line = gtk.HBox(False, 0)
            line.pack_start(edit, True, True)
            line.pack_start(link, False, False)

            apply = gtk.Button(_("2: Apply Token"))
            apply.connect("clicked", self.on_apply)

            self.info_line = gtk.Label(_("Please generate token..."))

            vbox.pack_start(ImageBase("vk.png"), False, False)
            vbox.pack_start(line, False, False)

            vbox.pack_start(HBoxLableEntry(gtk.Label(_("Token:")), self.token))
            vbox.pack_start(
                HBoxLableEntry(gtk.Label(_("User ID:")), self.user_id))

            vbox.pack_start(apply, False, False)
            vbox.pack_start(self.info_line, False, False)
Exemple #11
0
    def __init__(self, controls):
        self.controls = controls
        box = Gtk.VBox(False, 0)
        box.hide()

        '''static_icon'''
        self.static_icon = IconBlock(_("Icon"), controls, FC().static_icon_entry)

        """dynamic icons"""
        self.play_icon = IconBlock(_("Play"), controls, FC().play_icon_entry)
        self.pause_icon = IconBlock(_("Pause"), controls, FC().pause_icon_entry)
        self.stop_icon = IconBlock(_("Stop"), controls, FC().stop_icon_entry)
        self.radio_icon = IconBlock(_("Radio"), controls, FC().radio_icon_entry)

        self.tray_icon_button = Gtk.CheckButton(label=_("Show tray icon"), use_underline=True)
        self.hide_in_tray_on_start = Gtk.CheckButton(label=_("Hide player in tray on start"), use_underline=True)
        #self.tray_icon_button.connect("clicked", self.on_show_tray_icon)

        self.close_button = Gtk.RadioButton(group=None, label=_("On close window - close player"))

        self.hide_button = Gtk.RadioButton(group=self.close_button, label=_("On close window - hide player"))
        self.hide_button.connect("toggled", self.on_show_tray_icon)

        self.minimize_button = Gtk.RadioButton(group=self.close_button, label=_("On close window - minimize player"))

        """system icon"""
        self.static_tray_icon = ChooseDecorator(None, FrameDecorator(_("System Icon Static"), self.static_icon))

        """dynamic icons"""
        line = VBoxDecorator(self.play_icon,
                             self.pause_icon,
                             self.stop_icon,
                             self.radio_icon)

        self.icon_controls = ChooseDecorator(self.static_tray_icon.get_radio_button(), FrameDecorator(_("System Icons Dynamic"), line))

        """disc image icon"""
        image = ImageBase(ICON_BLANK_DISK, 30)
        self.change_tray_icon = ChooseDecorator(self.static_tray_icon.get_radio_button(), FrameDecorator(_("Disc cover image"), image))

        self.notifier = Gtk.CheckButton(_("Notification pop-up"))
        self.notifier.connect("toggled", self.on_toggle)

        self.n_time = self.notify_time()

        box.pack_start(self.hide_in_tray_on_start, False, True, 0)
        box.pack_start(self.tray_icon_button, False, True, 0)
        box.pack_start(self.close_button, False, True, 0)
        box.pack_start(self.hide_button, False, True, 0)
        box.pack_start(self.minimize_button, False, True, 0)

        box.pack_start(self.static_tray_icon, True, True, 0)
        box.pack_start(self.icon_controls, True, True, 0)
        box.pack_start(self.change_tray_icon, False, False, 0)

        notifier_box = Gtk.VBox()
        notifier_box.pack_start(self.notifier, False, False, 0)
        notifier_box.pack_start(self.n_time, False, False, 0)
        box.pack_start(FrameDecorator(_("Notification"), notifier_box), False, False, 0)
        self.widget = box
Exemple #12
0
    def __init__(self, controls):
        FControl.__init__(self, controls)
        Gtk.StatusIcon.__init__(self)
        self.hide()
        ImageBase.__init__(self, ICON_FOOBNIX, 150)

        self.popup_menu = PopupMenuWindow(self.controls)
        self.popup_volume_contol = PopupVolumeWindow(self.controls, self.popup_menu)

        self.connect("activate", self.on_activate)
        self.connect("popup-menu", self.on_popup_menu)

        try:
            self.set_has_tooltip(True)
            #self.set_tooltip("Foobnix music player")
            self.connect("query-tooltip", self.on_query_tooltip)
            self.connect("button-press-event", self.on_button_press)
            self.connect("scroll-event", self.on_scroll)
        except Exception, e:
            logging.warn("Tooltip doesn't work " + str(e))
Exemple #13
0
    def __init__(self, controls):
        FControl.__init__(self, controls)
        gtk.StatusIcon.__init__(self)
        self.hide()

        ImageBase.__init__(self, ICON_FOOBNIX, 150)

        self.popup_menu = PopupWindowMenu(self.controls)

        self.connect("activate", self.on_activate)
        self.connect("popup-menu", self.on_popup_menu)

        try:
            self.set_has_tooltip(True)
            self.tooltip = gtk.Tooltip()
            self.set_tooltip("Foobnix music player")
            self.connect("query-tooltip", self.on_query_tooltip)
            self.connect("button-press-event", self.on_button_press)
            self.connect("scroll-event", self.controls.volume.on_scroll_event)
        except Exception, e:
            logging.warn("On debian it doesn't work" + str(e))
Exemple #14
0
    def __init__(self, controls):
        FControl.__init__(self, controls)
        gtk.StatusIcon.__init__(self)
        self.hide()
        
        ImageBase.__init__(self, ICON_FOOBNIX, 150)
        
        self.popup_menu = PopupWindowMenu(self.controls)
        
        self.connect("activate", self.on_activate)
        self.connect("popup-menu", self.on_popup_menu)

        try:
            self.set_has_tooltip(True)        
            self.tooltip = gtk.Tooltip()
            self.set_tooltip("Foobnix music player")
            self.connect("query-tooltip", self.on_query_tooltip)
            self.connect("button-press-event", self.on_button_press)
            self.connect("scroll-event", self.controls.volume.on_scroll_event)
        except Exception, e:
            logging.warn("On debian it doesn't work" + str(e))
Exemple #15
0
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())
Exemple #16
0
    def __init__(self, controls):
        gtk.Frame.__init__(self)
        vbox = gtk.VBox(False, 5)
        self.controls = controls

        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()
Exemple #17
0
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())
Exemple #18
0
def info_dialog_with_link_and_donate(version):
    dialog = Gtk.MessageDialog(
        None, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
        Gtk.MessageType.INFO, Gtk.ButtonsType.OK, None)
    dialog.set_icon_from_file(get_foobnix_resourse_path_by_name(ICON_FOOBNIX))
    dialog.set_title(_("New foobnix release avaliable"))
    dialog.set_markup(_("New foobnix release avaliable"))
    dialog.format_secondary_markup("<b>" + version + "</b>")

    card = Gtk.LinkButton(
        "http://www.foobnix.com/support?lang=%s" % SITE_LOCALE,
        _("Download and Donate"))
    #terminal = Gtk.LinkButton("http://www.foobnix.com/donate/eng#terminal", _("Download and Donate by Webmoney or Payment Terminal"))
    link = Gtk.LinkButton(
        "http://www.foobnix.com/support?lang=%s" % SITE_LOCALE, _("Download"))

    frame = Gtk.Frame(label="Please donate and download")
    vbox = Gtk.VBox(True, 0)
    vbox.pack_start(card, True, True)
    #vbox.pack_start(terminal, True, True)
    vbox.pack_start(link, True, True)
    frame.add(vbox)

    image = ImageBase("images/foobnix-slogan.jpg")

    dialog.vbox.pack_start(image, True, True)
    dialog.vbox.pack_start(frame, True, True)
    dialog.vbox.pack_start(
        Gtk.Label(
            _("We hope you like the player. We will make it even better.")),
        True, True)
    version_check = Gtk.CheckButton(
        _("Check for new foobnix release on start"))
    version_check.set_active(FC().check_new_version)
    dialog.vbox.pack_start(version_check, True, True)

    dialog.show_all()
    dialog.run()

    FC().check_new_version = version_check.get_active()
    FC().save()
    dialog.destroy()
Exemple #19
0
def info_dialog_with_link_and_donate(version):
    dialog = gtk.MessageDialog(
        None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
        gtk.MESSAGE_INFO, gtk.BUTTONS_OK, None)
    dialog.set_title(_("New foobnix release avaliable"))
    dialog.set_markup(_("New foobnix release avaliable"))
    dialog.format_secondary_markup("<b>" + version + "</b>")

    card = gtk.LinkButton(
        "http://www.foobnix.com/support?lang=%s" % SITE_LOCALE,
        _("Download and Donate"))
    #terminal = gtk.LinkButton("http://www.foobnix.com/donate/eng#terminal", _("Download and Donate by Webmoney or Payment Terminal"))
    link = gtk.LinkButton(
        "http://www.foobnix.com/support?lang=%s" % SITE_LOCALE, _("Download"))

    frame = gtk.Frame("Please donate and download")
    vbox = gtk.VBox(True, 0)
    vbox.pack_start(card, True, True)
    #vbox.pack_start(terminal, True, True)
    vbox.pack_start(link, True, True)
    frame.add(vbox)

    image = ImageBase("foobnix-slogan.jpg")

    dialog.vbox.pack_start(image, True, True)
    dialog.vbox.pack_start(frame, True, True)
    dialog.vbox.pack_start(
        gtk.Label(
            _("We hope you like the player. We will make it even better.")),
        True, True)
    version_check = gtk.CheckButton(
        _("Check for new foobnix release on start"))
    version_check.set_active(FC().check_new_version)
    dialog.vbox.pack_start(version_check, True, True)

    dialog.show_all()
    dialog.run()

    FC().check_new_version = version_check.get_active()
    FC().save()
    dialog.destroy()
Exemple #20
0
 def __init__(self, controls):
     gtk.Frame.__init__(self)
     vbox = gtk.VBox(False, 5)
     self.controls = controls
     
     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()
Exemple #21
0
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('&', '&amp;')
        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()
Exemple #22
0
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    
Exemple #23
0
    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()
Exemple #24
0
    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()
Exemple #25
0
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:
Exemple #26
0
    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()
Exemple #27
0
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('&', '&amp;')
            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()
Exemple #28
0
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)
Exemple #29
0
class TrayIconControls(Gtk.StatusIcon, ImageBase, FControl, LoadSave):
    def __init__(self, controls):
        FControl.__init__(self, controls)
        Gtk.StatusIcon.__init__(self)
        self.hide()
        ImageBase.__init__(self, ICON_FOOBNIX, 150)

        self.popup_menu = PopupMenuWindow(self.controls)
        self.popup_volume_contol = PopupVolumeWindow(self.controls, self.popup_menu)

        self.connect("activate", self.on_activate)
        self.connect("popup-menu", self.on_popup_menu)

        try:
            self.set_has_tooltip(True)
            #self.set_tooltip("Foobnix music player")
            self.connect("query-tooltip", self.on_query_tooltip)
            self.connect("button-press-event", self.on_button_press)
            self.connect("scroll-event", self.on_scroll)
        except Exception as e:
            logging.warn("Tooltip doesn't work " + str(e))

        self.current_bean = FModel().add_artist("Artist").add_title("Title")
        self.tooltip_image = ImageBase(ICON_FOOBNIX, 75)

        self._previous_notify = None

    def on_save(self):
        pass

    def on_scroll(self, button, event):
        self.controls.volume.on_scroll_event(button, event)
        self.popup_volume_contol.show()

    def on_load(self):
        if FC().show_tray_icon:
            self.set_from_file(get_foobnix_resourse_path_by_name(ICON_FOOBNIX))
            self.show()

    def update_info_from(self, bean):
        self.current_bean = bean
        if bean.artist:
            artist = bean.artist
            self.tooltip_image.size = 150
        else:
            artist = 'Unknown artist'
            self.tooltip_image.size = 75
            self.tooltip_image.resource = ICON_FOOBNIX
        self.tooltip_image.update_info_from(bean)

        if bean.title:
            title = bean.title
        else:
            title = bean.text
        if FC().change_tray_icon:
            super(TrayIconControls, self).update_info_from(bean)

        if FC().notifier:
            self.to_notify(artist, title)

    @idle_task
    def to_notify(self, artist, title):
            message = "%s%s" % (artist, title)
            if self._previous_notify == message:
                return
            self._previous_notify = message
            notification = Notify.Notification.new(artist, title, "")
            notification.set_urgency(Notify.Urgency.LOW)
            notification.set_timeout(FC().notify_time)
            if self.tooltip_image.get_pixbuf() != None:
                notification.set_icon_from_pixbuf(self.tooltip_image.get_pixbuf())
            notification.show()

    def on_query_tooltip(self, widget, x, y, keyboard_tip, tooltip):
        artist = "Artist"
        title = "Title"
        if self.current_bean:
            if self.current_bean.artist and self.current_bean.title:
                artist = self.current_bean.artist
                #artist = string.join(["&amp;" if x == '&' else x for x in artist], '')
                artist = artist.replace('&', '&amp;')
                title = self.current_bean.title
            else:
                artist = "Unknown artist"
                title = self.current_bean.text

        max_str_len = 40
        if len(title) > max_str_len:
            title = split_string(title, max_str_len)

        alabel = Gtk.Label.new(None)
        alabel.set_markup("<b>%s</b>" % artist)
        hbox1 = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
        hbox1.pack_start(alabel, False, False, 0)
        hbox2 = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
        hbox2.pack_start(Gtk.Label.new(title), False, False, 0)
        vbox = VBoxDecorator(Gtk.Label.new(None), hbox1, Gtk.Label.new(None), hbox2)
        """if self.tooltip_image.size == 150:
            alignment = Gtk.Alignment(0, 0.4)
        else:
            alignment = Gtk.Alignment()
        alignment.set_padding(padding_top=0, padding_bottom=0, padding_left=10, padding_right=10)
        alignment.add(vbox)"""
        vbox.set_halign(Gtk.Align.CENTER)
        tooltip.set_icon(self.tooltip_image.get_pixbuf())
        tooltip.set_custom(vbox)
        return True

    def on_activate(self, *a):
        self.controls.windows_visibility()

    def on_button_press(self, w, e):
        if is_middle_click(e):
            self.controls.play_pause()

    def hide(self):
        self.set_visible(False)

    def show(self):
        self.set_visible(True)

    def show_window(self, *a):
        #self.popup_menu.reshow_with_initial_size()
        self.popup_menu.show()

    def hide_window(self, *a):
        self.popup_menu.hide()

    def on_popup_menu(self, *a):
        self.show_window()

    @idle_task
    def set_text(self, text):
        self.popup_menu.set_text(text)
        self.set_tooltip_text(text)
Exemple #30
0
    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()
Exemple #31
0
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('&', '&amp;')
        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()