def export_current_playlist(self, *e): pl = self.main.get_current_playlist().playlist name = pl.get_name() + ".m3u" dialog = dialogs.FileOperationDialog( _("Export Current Playlist"), None, gtk.FILE_CHOOSER_ACTION_SAVE, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) extensions = { 'm3u': _('M3U Playlist'), 'pls': _('PLS Playlist'), 'asx': _('ASX Playlist'), 'xspf': _('XSPF Playlist') } dialog.add_extensions(extensions) dialog.set_current_name(name) result = dialog.run() if result == gtk.RESPONSE_OK: path = unicode(dialog.get_filename(), 'utf-8') try: _xpl.export_playlist(pl, path) except _xpl.InvalidPlaylistTypeException: path = path + ".m3u" try: _xpl.export_playlist(pl, path) except _xpl.InvalidPlaylistTypeException: dialogs.error(None, _('Invalid file extension, file not saved')) dialog.destroy()
def _on_button_clicked(self, button): """ Allows setting the cover image using a file selection dialog """ dialog = dialogs.FileOperationDialog( title=_('Select image to set as cover'), parent=self.get_toplevel(), buttons=( Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK, ), ) dialog.set_select_multiple(False) filefilter = Gtk.FileFilter() # Not using Gtk.FileFilter.add_pixbuf_formats since # not all image formats are supported in tags filefilter.set_name(_('Supported image formats')) filefilter.add_pattern('*.[jJ][pP][gG]') filefilter.add_pattern('*.[jJ][pP][eE][gG]') filefilter.add_pattern('*.[pP][nN][gG]') dialog.add_filter(filefilter) if dialog.run() == Gtk.ResponseType.OK: filename = dialog.get_filename() try: pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename) info = GdkPixbuf.Pixbuf.get_file_info(filename)[0] except TypeError: pass else: self.batch_update = True self.set_pixbuf(pixbuf, info.get_mime_types()[0]) self.type_selection.set_active(self.default_type) self.type_selection.set_sensitive(True) self.description_entry.set_text( os.path.basename(filename).rsplit('.', 1)[0] ) self.description_entry.set_sensitive(True) self.batch_update = False self.call_update_func() dialog.destroy()