Exemple #1
0
 def _save_images(self, data: CoverData, img: Gtk.Image):
     paths = self._filenames(self.config.save_pattern, img.extension,
                             full_path=True)
     first_path = paths.pop()
     print_d(f"Saving {data} to {first_path}")
     img.save_image(first_path)
     # Copying faster than potentially resizing
     for path in paths:
         shutil.copy(first_path, path)
Exemple #2
0
    def stop_pressed(self, wdg=None):
        # Aborting playback
        cur = self.gst.getnow()
        self.gst.stop()

        # Update global vars
        self.current_song = False
        self.current_album = False

        # Update file
        current_playing = join(self.userconf.datadir, 'current-playing')
        if exists(current_playing):
            os_remove(current_playing)

        # Update user interface
        self.btn_playpause.set_image(Image.new_from_gicon(ThemedIcon(
             name='media-playback-start-symbolic'), IconSize.BUTTON))

        self.headerbar.props.subtitle = ''

        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.lyrics_button.set_sensitive(False)
        self.player_sca.set_sensitive(False)

        # Do we have to send the signal?
        if wdg is not None:
            self.extensions.load_event('OnStopPressed')
Exemple #3
0
    def play_pressed(self, wdg=None):
        # Get GStreamer status, don't do anything if playser is stopped
        first_state = self.gst.getstatus()
        if first_state == 'STOP':
            return

        # Toggles play/pause
        self.gst.playpause(None)
        new_state = self.gst.getstatus()

        # Update user interface
        if new_state == 'PAUSED':
            self.btn_playpause.set_image(Image.new_from_gicon(ThemedIcon(
                 name='media-playback-start-symbolic'), IconSize.BUTTON))
        else:
            self.btn_playpause.set_image(Image.new_from_gicon(ThemedIcon(
                 name='media-playback-pause-symbolic'), IconSize.BUTTON))        
Exemple #4
0
    def __init__(self, parent: Window):
        super().__init__(title='Warning - Anki is open', transient_for=parent)

        self.set_default_size(width=250, height=100)
        self.set_modal(True)
        self.set_keep_above(True)
        self.set_decorated(False)
        self.set_urgency_hint(True)

        lbl: Label = Label(
            label=
            'Warning: your anki is probably opened, please close it before trying again.'
        )

        box: Box = self.get_content_area()

        setMargin(box, 20)

        # box.pack_(child, expand, fill, padding)
        box.pack_start(lbl, False, True, 0)

        img_path: Filepath = path.abspath('asts/Icons/alert.png')

        try:
            warn_pixbuf: Pixbuf = Pixbuf().new_from_file_at_scale(
                img_path, 50, 50, True)

            warn_img: Image = Image().new_from_pixbuf(warn_pixbuf)

            box.pack_start(warn_img, False, True, 0)

            setMargin(warn_img, 20)

        except GLib_Error:
            exit(f'{img_path} file not found. Failed to create pixbuf.')

        self.add_buttons(STOCK_OK, ResponseType.OK)
Exemple #5
0
    def on_play_new_song(self, song):
        # Guess ReplayGain mode
        if hasattr(song, 'rg_mode_guess') and song.rg_mode_guess == 'album':
            self.gst.change_rg_mode('album')
        else:
            if not self.current_album:
                self.gst.change_rg_mode('track')
            else:
                if song in self.current_album.tracks:
                    self.gst.change_rg_mode('album')
                else:
                    self.current_album = False
                    self.gst.change_rg_mode('track')

        # Play the song
        cur = self.gst.getnow()
        self.gst.playpause(song.filename)

        # Update global vars
        self.current_song = song

        # Update user interface
        self.btn_playpause.set_image(Image.new_from_gicon(ThemedIcon(
             name='media-playback-pause-symbolic'), IconSize.BUTTON))

        title = song.title
        artist = song.artist
        album = song.album
        filename = song.filename

        self.headerbar.props.subtitle = title + ' - ' + artist

        default = join(self.functions.datadir, 'image', 'logo_head_big.png')
        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, 32, 32, True)
        else:
            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(True)
        self.lyrics_button.set_sensitive(True)

        # Update file
        current_playing = join(self.userconf.datadir, 'current-playing')
        file_ = open(current_playing, 'w')
        file_.write(title + ' - ' + artist + ' (from: ' + album + ')')
        file_.close()

        # Update player informations
        if isfile(cover):
            cover_px = Pixbuf.new_from_file_at_scale(cover, 200, 200, True)
        else:
            cover_px = Pixbuf.new_from_file_at_scale(default, 120, 120, True)
        self.player_img.set_from_pixbuf(cover_px)

        # Create the scale
        self.player_sca.set_sensitive(True)
        self.player_sca.set_range(0, float(song.length))
        timeout_add(500, self.scale_timer)

        # Download lyrics
        thread = Thread(group=None, target=self.lyrics_downloader.get_lyrics,
                        name='lyrics', args=(title, artist))
        thread.start()

        # Send notification to extensions about this new song
        self.extensions.load_event('HasStartedSong', song)
Exemple #6
0
 def __init__(self, *args, label="", **kwargs):
     Image.__init__(self, *args, **kwargs)
    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]
Exemple #8
0
    def _setButtonsSignals(self) -> None:
        """
        Set up the buttons and their respective signals for both grids.

        :param win: A window.
        :param fst_grid: The first grid container where the buttons goes in.
        :param box: The box container where the first grid goes in.
        :param fc_s: A list with file choosers.
        :return:
        """

        del_img: Optional[Pixbuf]

        img_path: str = path.abspath('asts/Icons/delete.png')

        try:
            del_img = Pixbuf().new_from_file_at_scale(img_path, 20, 20, False)
        except GLib_Error:
            exit(f'{img_path} file not found. Failed to create pixbuf.')

        icons: List[Optional[Image]] = [
            Image().new_from_pixbuf(del_img) for _ in range(4)
        ]

        btns: List[Button] = [Button() for _ in range(4)]

        for (idx, btn) in enumerate(btns):
            btn.set_image(icons[idx])
            setMargin(btn, 0, 5, 0, 5)
            btn.set_halign(Align.END)

            self._fst_grid.attach(btn, 2, idx, 1, 1)

        btns[FileType.ANKI2_COLLECTION].connect(
            'clicked',
            lambda _: self._fc_s[FileType.ANKI2_COLLECTION].unselect_all())

        btns[FileType.VIDEO].connect(
            'clicked', lambda _: self._fc_s[FileType.VIDEO].unselect_all())

        btns[FileType.SUBTITLE].connect(
            'clicked', lambda _: self._fc_s[FileType.SUBTITLE].unselect_all())

        btns[FileType.O_SUBTITLE].connect(
            'clicked',
            lambda _: self._fc_s[FileType.O_SUBTITLE].unselect_all())

        box: Box = Box()

        self._box.pack_end(box, False, True, 0)

        box.set_orientation(Orientation.HORIZONTAL)
        box.set_halign(Align.CENTER)

        cancel_btn: Button = Button(label='Cancel')

        box.pack_start(cancel_btn, False, True, 0)

        cancel_btn.set_margin_bottom(10)
        cancel_btn.connect('clicked', lambda _: self.close())

        self._next_btn = Button(label='Next')

        box.pack_end(self._next_btn, False, True, 0)

        setMargin(self._next_btn, 200, 10, 0, 0)
        self._next_btn.connect('clicked', self._onNextBtnClicked)

        timeout_add(300, self._setSensitiveNextBtn)
        timeout_add(300, self._checkInvalidSelection)