コード例 #1
0
    def setup_custom_sounds(self):
        # Setup user custom sounds
        self.custom_sounds = SoundsGroup(_('Custom'), self.sounds_settings)
        self.box.pack_start(self.custom_sounds, False, True, 0)

        # Add sound button row
        add_row = Gtk.ListBoxRow()
        add_row.set_selectable(False)
        add_row_box = Gtk.Box(height_request=34)
        add_row.add(add_row_box)
        add_row_icon = Gtk.Image.new_from_icon_name('list-add-symbolic',
                                                    Gtk.IconSize.MENU)
        add_row_box.pack_start(add_row_icon, True, True, 0)
        self.custom_sounds.listbox.add(add_row)
        self.custom_sounds.listbox.connect('row-activated', self.open_audio)

        # Load saved custom audios
        # Get saved audios from settings
        saved = self.sounds_settings.get_custom_audios()
        # Iterate audios
        for name, uri in saved.items():
            # Create a new SoundObject
            sound = SoundObject(name,
                                uri=uri,
                                mainplayer=self.mainplayer,
                                settings=self.sounds_settings,
                                custom=True)
            # Add SoundObject to SoundsGroup
            self.custom_sounds.add(sound)
コード例 #2
0
    def setup_custom_sounds(self):
        # Setup user custom sounds
        self.custom_sounds = SoundsGroup(_('Custom'), True)
        self.custom_sounds.connect('add-clicked', self._on_add_sound_clicked)
        self.box.pack_start(self.custom_sounds, False, True, 0)

        # Load saved custom audios
        for name, uri in Settings.get().custom_audios.items():
            # Create a new SoundObject
            sound = SoundObject(
                name, uri=uri, mainplayer=self.mainplayer, custom=True
            )
            # Add SoundObject to SoundsGroup
            self.custom_sounds.add(sound)
コード例 #3
0
    def setup_sounds(self):
        # Setup default sounds
        for g in SOUNDS:
            # Create a new SoundsGroup
            group = SoundsGroup(g['name'])
            # Iterate sounds
            for s in g['sounds']:
                # Create a new SoundObject
                sound = SoundObject(s['name'], title=s['title'],
                                    mainplayer=self.mainplayer)
                # Add SoundObject to SoundsGroup
                group.add(sound)

            # Add SoundsGroup to the window's main box
            self.box.pack_start(group, False, True, 0)
コード例 #4
0
class BlanketWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'BlanketWindow'

    headerbar = Gtk.Template.Child()
    scrolled_window = Gtk.Template.Child()
    box = Gtk.Template.Child()

    playpause_btn: PlayPauseButton = Gtk.Template.Child()

    menu = Gtk.Template.Child()
    volume = Gtk.Template.Child()
    presets_chooser: PresetChooser = Gtk.Template.Child()

    name_binding = None

    def __init__(self, mainplayer, mpris, **kwargs):
        super().__init__(**kwargs)

        # Set default window icon for window managers
        self.set_default_icon_name('com.rafaelmardojai.Blanket')

        # Main player & MPRIS server object
        self.mainplayer = mainplayer
        self.mpris = mpris

        # Setup widgets
        self.setup()

    def setup(self):
        # Get volume scale adjustment
        vol_adjustment = self.volume.get_adjustment()
        # Bind volume scale value with main player volume
        vol_adjustment.bind_property('value', self.mainplayer, 'volume',
                                     GObject.BindingFlags.BIDIRECTIONAL)
        # Set volume scale value on first run
        self.volume.set_value(self.mainplayer.volume)

        # Wire playpause button
        self.mainplayer.bind_property('playing', self.playpause_btn, 'playing',
                                      GObject.BindingFlags.SYNC_CREATE)

        # Setup presets widgets
        self.setup_presets()
        # Setup included/saved sounds
        self.setup_sounds()
        self.setup_custom_sounds()

        # Get saved scroll position
        saved_scroll = Settings.get().scroll_position
        # Get scrolled window vertical adjustment
        self.vscroll = self.scrolled_window.get_vadjustment()
        # Set saved scroll to vertical adjustment
        self.vscroll.set_value(saved_scroll)

    def setup_presets(self):
        self.presets_chooser.connect('selected', self._on_preset_selected)
        self.update_title(self.presets_chooser.selected)
        self.mpris.update_title(self.presets_chooser.selected.name)

        items = self.presets_chooser.model.get_n_items()

    def setup_sounds(self):
        # Setup default sounds
        for g in SOUNDS:
            # Create a new SoundsGroup
            group = SoundsGroup(g['name'])
            # Iterate sounds
            for s in g['sounds']:
                # Create a new SoundObject
                sound = SoundObject(s['name'],
                                    title=s['title'],
                                    mainplayer=self.mainplayer)
                # Add SoundObject to SoundsGroup
                group.add(sound)

            # Add SoundsGroup to the window's main box
            self.box.append(group)

    def setup_custom_sounds(self):
        # Setup user custom sounds
        self.custom_sounds = SoundsGroup(_('Custom'), True)
        self.custom_sounds.connect('add-clicked', self._on_add_sound_clicked)
        self.box.append(self.custom_sounds)

        # Load saved custom audios
        for name, uri in Settings.get().custom_audios.items():
            # Create a new SoundObject
            sound = SoundObject(name,
                                uri=uri,
                                mainplayer=self.mainplayer,
                                custom=True)
            # Add SoundObject to SoundsGroup
            self.custom_sounds.add(sound)

    def open_audio(self):
        def on_response(_filechooser, _id):
            gfile = self.filechooser.get_file()
            if gfile:
                filename = gfile.get_path()
                name = os.path.basename(filename).split('.')[0]
                uri = gfile.get_uri()

                # Create a new SoundObject
                sound = SoundObject(name,
                                    uri=uri,
                                    mainplayer=self.mainplayer,
                                    custom=True)
                # Save to settings
                GLib.idle_add(Settings.get().add_custom_audio, sound.name,
                              sound.uri)
                # Add SoundObject to SoundsGroup
                self.custom_sounds.add(sound)

        filters = {
            'Ogg': ['audio/ogg'],
            'FLAC': ['audio/flac'],
            'WAV': ['audio/x-wav', 'audio/wav'],
            'MP3': ['audio/mpeg'],
        }

        self.filechooser = Gtk.FileChooserNative.new(
            _('Open audio'), self, Gtk.FileChooserAction.OPEN, None, None)
        self.filechooser.connect('response', on_response)

        for f, mts in filters.items():
            audio_filter = Gtk.FileFilter()
            audio_filter.set_name(f)
            for mt in mts:
                audio_filter.add_mime_type(mt)
            self.filechooser.add_filter(audio_filter)

        response = self.filechooser.show()

    def update_title(self, preset):
        if self.name_binding is not None:
            self.name_binding.unbind()

        if preset.id != Settings.get().default_preset:
            self.name_binding = preset.bind_property(
                'name', self, 'title', GObject.BindingFlags.SYNC_CREATE)
        else:
            self.set_title(_('Blanket'))

    def _on_preset_selected(self, _chooser, preset):
        self.mainplayer.preset_changed()
        self.update_title(preset)
        self.mpris.update_title(preset.name)

    def _on_reset_volumes(self, _control, _preset):
        self.mainplayer.reset_volumes()

    def _on_add_sound_clicked(self, _group):
        self.open_audio()
コード例 #5
0
class BlanketWindow(Handy.ApplicationWindow):
    __gtype_name__ = 'BlanketWindow'

    headerbar = Gtk.Template.Child()
    scrolled_window = Gtk.Template.Child()
    box = Gtk.Template.Child()

    playpause_btn: PlayPauseButton = Gtk.Template.Child()

    menu = Gtk.Template.Child()
    volume = Gtk.Template.Child()
    quit_revealer = Gtk.Template.Child()
    presets_btn = Gtk.Template.Child()
    new_preset_btn = Gtk.Template.Child()
    presets_chooser: PresetChooser = Gtk.Template.Child()

    name_binding = None

    def __init__(self, mainplayer, **kwargs):
        super().__init__(**kwargs)

        # Set default window icon for window managers
        self.set_default_icon_name('com.rafaelmardojai.Blanket')

        # Main player
        self.mainplayer = mainplayer

        # Setup widgets
        self.setup()

    def setup(self):
        # Load dark theme
        gtk_settings = Gtk.Settings.get_default()
        gtk_settings.set_property(
            'gtk-application-prefer-dark-theme', Settings.get().dark_mode
        )

        # Get volume scale adjustment
        vol_adjustment = self.volume.get_adjustment()
        # Bind volume scale value with main player volume
        vol_adjustment.bind_property('value', self.mainplayer,
                                     'volume',
                                     GObject.BindingFlags.BIDIRECTIONAL)
        # Set volume scale value on first run
        self.volume.set_value(self.mainplayer.volume)

        # Wire playpause button
        self.mainplayer.bind_property(
            'playing', self.playpause_btn, 'playing',
            GObject.BindingFlags.SYNC_CREATE
        )

        # If background-playback enabled show quit action on menu
        self.quit_revealer.set_reveal_child(Settings.get().background)

        # Setup presets widgets
        self.setup_presets()
        # Setup included/saved sounds
        self.setup_sounds()
        self.setup_custom_sounds()

        # Show all widgets added to window
        self.show_all()

        # Get saved scroll position
        saved_scroll = Settings.get().scroll_position
        # Get scrolled window vertical adjustment
        self.vscroll = self.scrolled_window.get_vadjustment()
        # Set saved scroll to vertical adjustment
        self.vscroll.set_value(saved_scroll)

    def setup_presets(self):
        self.presets_chooser.connect('selected', self._on_preset_selected)
        self.update_title(self.presets_chooser.selected)

        self.presets_chooser.model.connect(
            'items-changed',
            self._on_presets_changed
        )
        items = self.presets_chooser.model.get_n_items()
        self.presets_btn.set_visible(items > 1)
        self.new_preset_btn.set_visible(items == 1)

    def setup_sounds(self):
        # Setup default sounds
        for g in SOUNDS:
            # Create a new SoundsGroup
            group = SoundsGroup(g['name'])
            # Iterate sounds
            for s in g['sounds']:
                # Create a new SoundObject
                sound = SoundObject(s['name'], title=s['title'],
                                    mainplayer=self.mainplayer)
                # Add SoundObject to SoundsGroup
                group.add(sound)

            # Add SoundsGroup to the window's main box
            self.box.pack_start(group, False, True, 0)

    def setup_custom_sounds(self):
        # Setup user custom sounds
        self.custom_sounds = SoundsGroup(_('Custom'), True)
        self.custom_sounds.connect('add-clicked', self._on_add_sound_clicked)
        self.box.pack_start(self.custom_sounds, False, True, 0)

        # Load saved custom audios
        for name, uri in Settings.get().custom_audios.items():
            # Create a new SoundObject
            sound = SoundObject(
                name, uri=uri, mainplayer=self.mainplayer, custom=True
            )
            # Add SoundObject to SoundsGroup
            self.custom_sounds.add(sound)

    def open_audio(self):
        filters = {
            'Ogg': ['audio/ogg'],
            'FLAC': ['audio/flac'],
            'WAV': ['audio/x-wav', 'audio/wav'],
            'MP3': ['audio/mpeg'],
        }

        self.filechooser = Gtk.FileChooserNative.new(
            _('Open audio'),
            self,
            Gtk.FileChooserAction.OPEN,
            None,
            None)

        for f, mts in filters.items():
            audio_filter = Gtk.FileFilter()
            audio_filter.set_name(f)
            for mt in mts:
                audio_filter.add_mime_type(mt)
            self.filechooser.add_filter(audio_filter)

        response = self.filechooser.run()

        if response == Gtk.ResponseType.ACCEPT:
            filename = self.filechooser.get_filename()
            if filename:
                name = os.path.basename(filename).split('.')[0]
                uri = self.filechooser.get_uri()

                # Create a new SoundObject
                sound = SoundObject(
                    name, uri=uri, mainplayer=self.mainplayer, custom=True
                )
                # Save to settings
                GLib.idle_add(Settings.get().add_custom_audio,
                              sound.name, sound.uri)
                # Add SoundObject to SoundsGroup
                self.custom_sounds.add(sound)
                self.custom_sounds.show_all()

    def update_title(self, preset):
        if self.name_binding is not None:
            self.name_binding.unbind()

        if preset.id != Settings.get().default_preset:
            self.name_binding = preset.bind_property(
                'name', self.headerbar, 'title',
                GObject.BindingFlags.SYNC_CREATE
            )
        else:
            self.headerbar.set_title(_('Blanket'))

    def _on_preset_selected(self, _chooser, preset):
        self.mainplayer.preset_changed()
        self.update_title(preset)

    def _on_reset_volumes(self, _control, _preset):
        self.mainplayer.reset_volumes()

    def _on_presets_changed(self, model, _position, _removed, _added):
        items = model.get_n_items()
        self.presets_btn.set_visible(items > 1)
        self.new_preset_btn.set_visible(items == 1)

        if items == 1:
            self.menu.open_submenu('main')

    def _on_add_sound_clicked(self, _group):
        self.open_audio()
コード例 #6
0
class BlanketWindow(Handy.ApplicationWindow):
    __gtype_name__ = 'BlanketWindow'

    scrolled_window = Gtk.Template.Child()
    box = Gtk.Template.Child()

    playpause_btn = Gtk.Template.Child()
    playpause_icon = Gtk.Template.Child()

    volume = Gtk.Template.Child()

    quit_revealer = Gtk.Template.Child()

    def __init__(self, mainplayer, settings, sounds_settings, **kwargs):
        super().__init__(**kwargs)

        # Set default window icon for window managers
        self.set_default_icon_name('com.rafaelmardojai.Blanket')

        # Main player
        self.mainplayer = mainplayer

        # Settings
        self.settings = settings
        self.sounds_settings = sounds_settings

        # Setup widgets
        self.setup()

    def setup(self):
        # Get volume scale adjustment
        vol_adjustment = self.volume.get_adjustment()
        # Bind volume scale value with main player volume
        vol_adjustment.bind_property('value', self.mainplayer, 'volume',
                                     GObject.BindingFlags.BIDIRECTIONAL)
        # Set volume scale value on first run
        self.volume.set_value(self.mainplayer.get_property('volume'))

        # If background-playback enabled show quit action on menu
        if self.settings.get_value('background-playback'):
            self.quit_revealer.set_reveal_child(True)

        # Setup included/saved sounds
        self.setup_sounds()
        self.setup_custom_sounds()

        # Show all widgets added to window
        self.show_all()

        # Get saved scroll position
        saved_scroll = self.settings.get_double('scroll-position')
        # Get scrolled window vertical adjustment
        self.vscroll = self.scrolled_window.get_vadjustment()
        # Set saved scroll to vertical adjustment
        self.vscroll.set_value(saved_scroll)

    def setup_sounds(self):
        # Setup default sounds
        for g in SOUNDS:
            # Create a new SoundsGroup
            group = SoundsGroup(g['name'], self.sounds_settings)
            # Iterate sounds
            for s in g['sounds']:
                # Create a new SoundObject
                sound = SoundObject(s['name'],
                                    title=s['title'],
                                    mainplayer=self.mainplayer,
                                    settings=self.sounds_settings)
                # Add SoundObject to SoundsGroup
                group.add(sound)

            # Add SoundsGroup to the window's main box
            self.box.pack_start(group, False, True, 0)

    def setup_custom_sounds(self):
        # Setup user custom sounds
        self.custom_sounds = SoundsGroup(_('Custom'), self.sounds_settings)
        self.box.pack_start(self.custom_sounds, False, True, 0)

        # Add sound button row
        add_row = Gtk.ListBoxRow()
        add_row.set_selectable(False)
        add_row_box = Gtk.Box(height_request=34)
        add_row.add(add_row_box)
        add_row_icon = Gtk.Image.new_from_icon_name('list-add-symbolic',
                                                    Gtk.IconSize.MENU)
        add_row_box.pack_start(add_row_icon, True, True, 0)
        self.custom_sounds.listbox.add(add_row)
        self.custom_sounds.listbox.connect('row-activated', self.open_audio)

        # Load saved custom audios
        # Get saved audios from settings
        saved = self.sounds_settings.get_custom_audios()
        # Iterate audios
        for name, uri in saved.items():
            # Create a new SoundObject
            sound = SoundObject(name,
                                uri=uri,
                                mainplayer=self.mainplayer,
                                settings=self.sounds_settings,
                                custom=True)
            # Add SoundObject to SoundsGroup
            self.custom_sounds.add(sound)

    def update_playing_ui(self, playing):
        # Change widgets states
        if playing:
            self.playpause_icon.set_from_icon_name(
                'media-playback-pause-symbolic', Gtk.IconSize.MENU)
        else:
            self.playpause_icon.set_from_icon_name(
                'media-playback-start-symbolic', Gtk.IconSize.MENU)

    def open_audio(self, _widget=None, _row=None):

        filters = {
            'OGG': ['audio/ogg'],
            'FLAC': ['audio/x-flac'],
            'WAV': ['audio/x-wav', 'audio/wav'],
            'MP3': ['audio/mpeg'],
        }

        self.filechooser = Gtk.FileChooserNative.new(
            _('Open audio'), self, Gtk.FileChooserAction.OPEN, None, None)

        for f, mts in filters.items():
            audio_filter = Gtk.FileFilter()
            audio_filter.set_name(f)
            for mt in mts:
                audio_filter.add_mime_type(mt)
            self.filechooser.add_filter(audio_filter)

        response = self.filechooser.run()

        if response == Gtk.ResponseType.ACCEPT:
            filename = self.filechooser.get_filename()
            if filename:
                name = os.path.basename(filename).split('.')[0]
                uri = self.filechooser.get_uri()

                # Create a new SoundObject
                sound = SoundObject(name,
                                    uri=uri,
                                    mainplayer=self.mainplayer,
                                    settings=self.sounds_settings,
                                    custom=True)
                # Save to settings
                GLib.idle_add(self.sounds_settings.add_custom_audio,
                              sound.name, sound.uri)
                # Add SoundObject to SoundsGroup
                self.custom_sounds.add(sound)
                self.custom_sounds.show_all()