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 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 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 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)
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()