Esempio n. 1
0
            def do_scan():
                # Freeze user interface
                gldfile = join(self.functions.datadir, 'glade', 'loading.ui')
                win = gtk_builder()
                win.set_translation_domain('bluemindo')
                win.add_from_file(gldfile)
                box_content = win.get_object('box1')

                # Create an interface to help the user waiting for the job
                bluemindo = join(self.functions.datadir, 'image',
                                 'bluemindo.png')
                img = win.get_object('image')
                cover_px = Pixbuf.new_from_file(bluemindo)
                idle_add(img.set_from_pixbuf, cover_px)

                idle_add(
                    win.get_object('label').set_markup,
                    '<span size="x-large"><b>' +
                    _('Reloading music database.') + '</b></span>')

                idle_add(self.widgets[0][2].set_sensitive, False)
                idle_add(self.widgets[0][3].set_sensitive, False)
                idle_add(self.widgets[0][5].set_sensitive, False)
                idle_add(self.widgets[0][6].set_sensitive, False)
                idle_add(self.widgets[0][7].set_sensitive, False)
                idle_add(self.widgets[0][8].set_sensitive, False)

                idle_add(self.widgets[1].get_object('box1').add, box_content)

                lbl = win.get_object('label_info')
                idle_add(lbl.set_text,
                         _('Starting… Prepares to search for new files.'))

                # Update GUI
                box_content.show_all()
                self.widgets[1].get_object('box2').hide()

                # Do the scanning
                pb = win.get_object('progressbar')
                musicdb.scan(lbl, pb)

                # Show original GUI
                idle_add(self.widgets[0][2].set_sensitive, True)
                idle_add(self.widgets[0][3].set_sensitive, True)
                idle_add(box_content.hide)
                idle_add(self.widgets[1].get_object('box2').show_all)
                idle_add(self.create_view)
Esempio n. 2
0
    def __init__(self, widgets, aview):
        self.widgets = widgets

        self.functions = Functions()
        self.userconf = ConfigLoader()

        # GUI
        self.filter_button = self.widgets[1].get_object('tool-filter')
        self.filter_button.connect('clicked', self.on_button_clicked)

        gladefile = join(self.functions.datadir, 'glade', 'filterbar.ui')
        self.fbox = gtk_builder()
        self.fbox.set_translation_domain('bluemindo')
        self.fbox.add_from_file(gladefile)
        self.filter_box = self.fbox.get_object('infobar')

        wdg_place = self.widgets[1].get_object('filter-emplacement')
        wdg_place.add(self.filter_box)

        self.fbox.get_object('label_filter').set_text(_('Filter the results:'))

        # Create ComboBoxes
        self.genre_fstore = ListStore(int, str)
        self.genre_fcombo = self.fbox.get_object('combobox-genre')
        self.genre_fcombo.set_model(self.genre_fstore)
        renderer_text = CellRendererText()
        self.genre_fcombo.pack_start(renderer_text, True)
        self.genre_fcombo.set_entry_text_column(1)
        self.genre_fcombo.add_attribute(renderer_text, 'text', 1)

        self.year_fstore = ListStore(int, str)
        self.year_fcombo = self.fbox.get_object('combobox-year')
        self.year_fcombo.set_model(self.year_fstore)
        renderer_text = CellRendererText()
        self.year_fcombo.pack_start(renderer_text, True)
        self.year_fcombo.set_entry_text_column(1)
        self.year_fcombo.add_attribute(renderer_text, 'text', 1)
Esempio n. 3
0
        def start_playback(wdg):
            # Create GStreamer instance
            self.gst = GStreamer()
            self.gst.set_playback('gapless')
            self.gst.player.connect('about-to-finish', self.song_nearly_ended)
            self.gst.stop()

            self.current_song = False
            self.current_album = False

            # Prepare buttons
            self.btn_playpause = wdg[0][7]
            self.btn_previous = wdg[0][5]
            self.btn_next = wdg[0][8]
            self.btn_stop = wdg[0][6]

            self.btn_previous.connect('clicked', self.previous_pressed)
            self.btn_stop.connect('clicked', self.stop_pressed)
            self.btn_playpause.connect('clicked', self.play_pressed)
            self.btn_next.connect('clicked', self.next_pressed)

            self.btn_player = wdg[0][9]
            self.headerbar = wdg[0][0]

            # Create the player box and popover
            gtkpla = join(self.functions.datadir, 'glade', 'playerbar.ui')
            win = gtk_builder()
            win.set_translation_domain('bluemindo')
            win.add_from_file(gtkpla)
            basebox = win.get_object('playerbox')
            wdg[0][0].add(basebox)

            self.player_event = win.get_object('player_event')
            self.player_event.set_size_request(32, 32)
            self.player_button_img = win.get_object('image_cover')
            self.player_event.connect('button-press-event', self.show_player)
            default = join(self.functions.datadir, 'image', 'logo_head_big.png')
            cover_px = Pixbuf.new_from_file_at_scale(default, 20, 20, True)
            self.player_button_img.set_from_pixbuf(cover_px)
            self.player_event.set_sensitive(False)

            self.player_scalab = win.get_object('label_scale')
            self.player_scalab.set_markup('<span size="small">00:00</span>')
            self.player_sca = win.get_object('scale')
            self.player_sca.connect('change-value', self.on_change_value)
            self.player_sca.set_sensitive(False)

            # Create the player popover
            gtkpla = join(self.functions.datadir, 'glade', 'playerpopover.ui')
            win = gtk_builder()
            win.add_from_file(gtkpla)
            hbox = win.get_object('box-player')

            self.player_img = win.get_object('image')
            self.player_pop = Popover.new(self.player_event)
            self.player_pop.set_size_request(200, 200)
            self.player_pop.add(hbox)

            self.lyrics_button = wdg[1].get_object('tool-lyrics')
            self.lyrics_pop = Popover.new(self.lyrics_button)
            self.lyrics_pop.set_size_request(400, 600)
            box = Box(1, 0)
            self.lyrics_swin = ScrolledWindow()
            lyrics_tview = TextView()
            lyrics_tview.set_editable(False)
            self.lyrics_buffer = TextBuffer()
            lyrics_tview.set_buffer(self.lyrics_buffer)
            self.lyrics_swin.add(lyrics_tview)
            box.add(self.lyrics_swin)
            self.lyrics_wait = Spinner()
            self.lyrics_wait.props.active = True
            box.add(self.lyrics_wait)
            self.lyrics_pop.add(box)

            def show_lyrics(widget):
                if self.current_song:
                    title = self.current_song.title
                    artist = self.current_song.artist
                    album = self.current_song.album
                    filename = self.current_song.filename

                    sn = self.functions.get_hash(title, artist)
                    lyrics_file = join(self.userconf.datadir, '%s.lyrics' % sn)

                    lyrics = self.lyrics_downloader.get_lyrics(title,
                                                               artist,
                                                               True)

                    self.lyrics_pop.show_all()

                    if lyrics is not None:
                        self.lyrics_wait.hide()
                        self.lyrics_swin.show()
                        self.lyrics_buffer.set_text(lyrics)
                    else:
                        self.lyrics_swin.hide()
                        self.lyrics_wait.show()
                        self.lyrics_buffer.set_text('')

            self.lyrics_button.connect('clicked', show_lyrics)
            self.lyrics_button.set_sensitive(False)
Esempio n. 4
0
        def launch_playlist(wdg):
            self.widgets = wdg[1]

            self.playlist_label = self.widgets.get_object('label_playlist')
            self.playlist_repeat = self.widgets.get_object('tool-repeat')
            self.playlist_shuffle = self.widgets.get_object('tool-shuffle')
            self.playlist_clean = self.widgets.get_object('tool-clean')
            self.playlist_combo = self.widgets.get_object('combo-playlist')
            self.playlist_save = self.widgets.get_object('tool-saveplaylist')
            self.playlist_lyrics = self.widgets.get_object('tool-lyrics')

            self.playlist_tree = self.widgets.get_object('treeview_playlist')
            self.playlist_tree.set_headers_visible(False)
            self.playlist_tree.props.reorderable = True
            self.playlist_tree.connect('key_press_event', self.key_pressed)
            self.playlist_tree.connect('row_activated', self.row_activated)

            self.liststore = ListStore(str, str, str, str, int)
            self.playlist_tree.set_model(self.liststore)

            renderer_pix = CellRendererPixbuf()
            column_pixbuf = TreeViewColumn('1', renderer_pix, icon_name=0)
            column_pixbuf.set_fixed_width(18)
            self.playlist_tree.append_column(column_pixbuf)

            renderer_text = CellRendererText()
            column_text = TreeViewColumn('2', renderer_text, markup=1)
            column_text.props.expand = True
            column_text.props.max_width = 192
            self.playlist_tree.append_column(column_text)

            column_text = TreeViewColumn('3', renderer_text, markup=2)
            column_text.set_fixed_width(40)
            self.playlist_tree.append_column(column_text)

            self.repeat_btn = self.widgets.get_object('tool-repeat')
            if self.config['repeat']:
                self.repeat_btn.set_active(True)
            self.repeat_btn.connect('clicked', self.toggle, 'repeat')

            self.shuffle_btn = self.widgets.get_object('tool-shuffle')
            if self.config['shuffle']:
                self.shuffle_btn.set_active(True)
            self.shuffle_btn.connect('clicked', self.toggle, 'shuffle')

            def clean_wdg(widget):
                # Clean playlist
                self.clean()

                # Show popover
                if self.current_playlist_id > 3:
                    self.clean_btn.set_sensitive(True)
                    self.clean_pop.show_all()

            self.clean_btn = self.widgets.get_object('tool-clean')
            self.clean_btn.connect('clicked', clean_wdg)
            self.clean_pop = Popover.new(self.clean_btn)
            self.clean_pop.set_size_request(100, 30)

            gtkpla = join(self.functions.datadir, 'glade', 'plist-del-pop.ui')
            win = gtk_builder()
            win.set_translation_domain('bluemindo')
            win.add_from_file(gtkpla)
            hbox = win.get_object('box-playlist')
            lbl = win.get_object('label')
            lbl.set_text(_('Do you also want to remove the playlist?'))
            btn = win.get_object('del-btn')
            btn.set_label(_('Delete'))
            btn.connect('clicked', self.delete_playlist)
            self.clean_pop.add(hbox)

            # Populate combobox
            self.combolist = ListStore(int, str)

            self.combobox = self.widgets.get_object('combobox')
            self.combobox.set_model(self.combolist)
            self.combobox.set_popup_fixed_width(False)
            self.combobox.props.expand = False

            renderer_text = CellRendererText()
            renderer_text.props.ellipsize = EllipsizeMode.END
            self.combobox.pack_start(renderer_text, True)
            self.combobox.set_entry_text_column(1)
            self.combobox.add_attribute(renderer_text, 'text', 1)

            self.combolist.append([0, _('Current')])
            self.combolist.append([1, _('Top 50 songs')])
            self.combolist.append([2, _('Top 10 albums')])

            playlists = self.playlists_mgmnt.get_playlists()

            if len(playlists) > 0:
                self.combolist.append([3, ''])
                item_id = 3

                playlists.sort(key=lambda it: it[1])
                for item in playlists:
                    item_id += 1
                    self.combolist.append([item_id, item])
                    self.user_playlists[item_id] = item
                    self.last_user_playlist = item_id

            def combo_sep(model, iter):
                if model[iter][0] == 3:
                    return True
            self.combobox.set_row_separator_func(combo_sep)

            def on_combo_changed(widget):
                path = widget.get_active()
                item_id = self.combolist[path][0]

                # First, clean the playlist
                self.clean(None)

                # Second, populate the playlist
                if item_id > 0:
                    self.populate(item_id)

                # Then, update playlist identifier
                self.current_playlist_id = item_id

                # Show delete/remove button if the playlist is from the user
                if item_id > 3:
                    self.clean_btn.set_sensitive(True)

            self.combobox.set_active(0)
            self.combobox.connect('changed', on_combo_changed)
            
            self.tool_save = self.widgets.get_object('tool-saveplaylist')
            self.tool_save.connect('clicked', self.save_playlist)
            self.save_pop = Popover.new(self.tool_save)
            self.save_pop.set_size_request(100, 30)

            gtkpla = join(self.functions.datadir, 'glade', 'plist-add-pop.ui')
            win = gtk_builder()
            win.set_translation_domain('bluemindo')
            win.add_from_file(gtkpla)
            hbox = win.get_object('box-playlist')
            self.save_pop.add(hbox)

            self.save_entry = win.get_object('save-entry')
            self.save_entry.connect('key_press_event', self.save_playlist_key)
            self.save_btn = win.get_object('save-btn')
            self.save_btn.connect('clicked', self.save_playlist_button)
            self.save_btn.set_label(_('Save'))

            self.clean_btn.set_sensitive(False)
            self.tool_save.set_sensitive(False)
    def on_selection_changed(self, icon_view, album=None):
        popup = Popover.new(self.albumview)
        popup.set_size_request(810, 240)

        if album is None:
            selection = icon_view.get_selected_items()
            if len(selection) != 1:
                return

            path = selection[0]
            treeiter = self.albumfilter.get_iter(path)

            isset, path, cell = icon_view.get_cursor()
            isset, rect = icon_view.get_cell_rect(path, cell)
            popup.set_pointing_to(rect)

            album_id = self.albumfilter.get_value(treeiter, 4)
            album_obj = self.albums[album_id]
        else:
            album_obj = album
            popup.set_relative_to(self.search_entry)

        # Handle double clicks
        def empty_dblclick():
            self.dblclick = None

        if self.dblclick is None:
            self.dblclick = album_obj
            timeout_add(1000, empty_dblclick)
        elif self.dblclick == album_obj:
            self.play(album_obj)
            return

        album = album_obj.name
        artist = album_obj.artist

        glade_album = join(self.functions.datadir, 'glade', 'albumview.ui')
        box = gtk_builder()
        box.set_translation_domain('bluemindo')
        box.add_from_file(glade_album)
        popup.add(box.get_object('box1'))

        box.get_object('label_album').set_text(album)
        box.get_object('label_artist').set_text(artist)

        bdir = join(self.userconf.datadir, 'modules', 'player', 'covers')
        cover = join(bdir, self.functions.get_hash(album, artist))
        if isfile(cover):
            cover_px = Pixbuf.new_from_file_at_scale(cover, 180, 180, True)
        else:
            cover_px = Pixbuf.new_from_file(join(self.functions.datadir,
                                            'image', 'logo_head_big.png'))

        box.get_object('album_cover').set_from_pixbuf(cover_px)

        def play_album(wdg, album):
            self.play(album)

        def queue_album(wdg, album):
            self.queue(album)

        def change_cover(wdg, ka, album):
            artist_name = album.artist
            album_name = album.name

            fcdialog = FileChooserDialog(
                        title=_('Change the cover picture for this album'),
                        buttons=(_('Select'), ResponseType.OK))

            fcdialog.set_transient_for(self.widgets[0][11])
            response = fcdialog.run()
            if response == ResponseType.OK:
                filename = fcdialog.get_filename()

                datadir = self.userconf.datadir
                hash_a = self.functions.get_hash(album_name, artist_name)
                pictures_dir = join(datadir, 'modules', 'player', 'covers')
                album_file = join(pictures_dir, hash_a)

                copyfile(filename, album_file)

                new = Pixbuf.new_from_file_at_scale(album_file, 180, 180, True)
                box.get_object('album_cover').set_from_pixbuf(new)

            fcdialog.destroy()

        box.get_object('button_play').connect('clicked', play_album, album_obj)

        box.get_object('button_add').connect('clicked', queue_album, album_obj)

        box.get_object('coverevent').connect('button-press-event',
                                             change_cover, album_obj)

        i = 0
        a = -1
        previous_column = 0

        grid_songs = box.get_object('grid_songs')
        grid_songs.set_size_request(-1, 200)
        grid_songs.set_column_spacing(5)

        try:
            kids = grid_songs.get_children()
            for kid in kids:
                grid_songs.remove(kid)
        except IndexError:
            pass

        for song in album_obj.tracks:
            i += 1
            a += 1

            def queue(wdg, song):
                self.queue(song)

            def play(wdg, song):
                self.play(song)

            song_wdg = Box(spacing=0)
            song_btr = Button()
            song_btr.connect('clicked', play, song)
            song_btr.set_relief(ReliefStyle.NONE)
            song_btr_content = Box(spacing=0)
            song_btr.add(song_btr_content)

            song_tr = Label()
            song_tr.set_markup('<span foreground="grey">' + str(song.track)
                               + '</span>')
            song_tr.set_width_chars(3)
            song_btr_content.pack_start(song_tr, False, True, 0)
            song_ti = Label()
            song_ti.set_markup('<b>' + self.functions.view_encode(song.title, 22)
                               + '</b>')
            song_ti.set_alignment(0.0, 0.5)
            song_ti.set_size_request(190, -1)
            song_btr_content.pack_start(song_ti, False, False, 0)

            length = self.functions.human_length(song.length)
            song_le = Label()
            song_le.set_markup('<span foreground="grey">' + length
                               + '</span>')
            song_le.set_width_chars(5)
            song_btr_content.pack_start(song_le, False, True, 0)

            song_wdg.pack_start(song_btr, False, False, 0)

            song_add = Button.new_from_icon_name('list-add-symbolic', 0)
            song_add.set_property('relief', 2)
            song_add.set_size_request(14, 14)
            song_add.connect('clicked', queue, song)
            song_wdg.pack_start(song_add, False, False, 0)

            if i <= len(album_obj.tracks)/2:
                column = 0
                previous_column = 0
                row = a
            else:
                if previous_column == 0:
                    a = 0
                column = 1
                previous_column = 1
                row = a

            grid_songs.attach(song_wdg, column, row, 1, 1)
        popup.show_all()
    def __init__(self, extensions):
        # Start threads
        threads_init()

        self.extensions = extensions

        # Create the main Bluemindo window
        self.main_window = Window()
        functions.open_bluemindo(self.main_window)

        # Handling close button
        def close_window(wdg, ka):
            functions.close_bluemindo(self.main_window, True)

        self.main_window.connect('delete_event', close_window)

        # Create the whole Header Bar
        box = HeaderBar()
        box.set_show_close_button(True)
        box.props.title = 'Bluemindo'
        self.main_window.set_titlebar(box)

        # Add an icon to the window
        icon_file = join(functions.datadir, 'image', 'logo_head_small.png')
        pixbuf = Pixbuf.new_from_file(icon_file)
        self.main_window.set_icon(pixbuf)

        # Add the about button
        about_button = Button(relief=2)
        about_button.add(
            Image.new_from_gicon(ThemedIcon(name='help-about-symbolic'),
                                 IconSize.BUTTON))
        box.pack_end(about_button)

        # Add the reload button
        refresh_button = Button(relief=2)
        refresh_button.add(
            Image.new_from_gicon(ThemedIcon(name='view-refresh-symbolic'),
                                 IconSize.BUTTON))
        box.pack_end(refresh_button)

        # Add PREVIOUS/STOP/PLAYPAUSE/NEXT buttons
        player_box = Box(orientation=Orientation.HORIZONTAL)
        StyleContext.add_class(player_box.get_style_context(), 'linked')

        previous_b = Button()
        previous_b.set_size_request(42, -1)
        previous_b.add(
            Image.new_from_gicon(
                ThemedIcon(name='media-skip-backward-symbolic'),
                IconSize.BUTTON))
        player_box.add(previous_b)

        stop_b = Button()
        stop_b.set_size_request(42, -1)
        stop_b.add(
            Image.new_from_gicon(
                ThemedIcon(name='media-playback-stop-symbolic'),
                IconSize.BUTTON))
        player_box.add(stop_b)

        playpause_b = Button()
        playpause_b.set_size_request(55, -1)
        playpause_b.add(
            Image.new_from_gicon(
                ThemedIcon(name='media-playback-start-symbolic'),
                IconSize.BUTTON))
        player_box.add(playpause_b)

        next_b = Button()
        next_b.set_size_request(42, -1)
        next_b.add(
            Image.new_from_gicon(
                ThemedIcon(name='media-skip-forward-symbolic'),
                IconSize.BUTTON))
        player_box.add(next_b)

        box.pack_start(player_box)

        # Create the main window
        glade_main = join(functions.datadir, 'glade', 'mainwindow.ui')
        win = gtk_builder()
        win.set_translation_domain('bluemindo')
        win.add_from_file(glade_main)

        self.main_window.add(win.get_object('box1'))

        # Connect to the about button
        def show_dialog(wdg):
            dialog = AboutDialog()
            dialog.set_transient_for(self.main_window)

            dialog.set_artists(['Thomas Julien <*****@*****.**>'])
            dialog.set_authors([
                'Erwan Briand <*****@*****.**>',
                'Vincent Berset <*****@*****.**>',
                'Thibaut Girka <*****@*****.**>',
                'Ľubomír Remák <*****@*****.**>',
                'Anaël Verrier <*****@*****.**>'
            ])
            dialog.set_translator_credits(
                'Bruno Conde <*****@*****.**>\n' +
                'Niklas Grahn <*****@*****.**>\n' +
                'Ľubomír Remák <*****@*****.**>\n' +
                'Salvatore Tomarchio <*****@*****.**>\n' +
                'Shang Yuanchun <*****@*****.**>')

            dialog.set_copyright('Copyright © 2007-2016 Erwan Briand ' +
                                 '<*****@*****.**>')

            dialog.set_comments(
                _('Ergonomic and modern music player ' +
                  'designed for audiophiles.'))

            dialog.set_license('GNU General Public License (v3)')
            dialog.set_license_type(10)

            dialog.set_program_name('Bluemindo')
            dialog.set_version('1.0RC1')
            dialog.set_website('http://bluemindo.codingteam.net')

            pxbf = Pixbuf.new_from_file_at_scale(
                join(functions.datadir, 'image', 'logo_head_big.png'), 60, 60,
                True)
            dialog.set_logo(pxbf)

            dialog.show_all()

        about_button.connect('clicked', show_dialog)

        # Start main handler
        headerbar_wdg = [
            box, None, about_button, refresh_button, player_box, previous_b,
            stop_b, playpause_b, next_b, None,
            win.get_object('box1'), self.main_window
        ]
        self.wdg = [headerbar_wdg, win]