def __init__(self, parent, treeview, export_all=True): super().__init__(_('Export Songs'), parent.app.window, Gtk.DialogFlags.MODAL, ( Gtk.STOCK_CLOSE, Gtk.ResponseType.OK, )) self.parent = parent self.treeview = treeview self.export_all = export_all self.app = parent.app self.set_border_width(15) box = self.get_content_area() box.set_size_request(540, 260) box.set_spacing = 5 folder_label = Widgets.BoldLabel(_('Choose export folder:')) box.pack_start(folder_label, False, True, 2) self.folder_chooser = Widgets.FolderChooser(self.app.window) self.folder_chooser.props.margin_left = 20 box.pack_start(self.folder_chooser, False, True, 0) self.including_lrc = Gtk.CheckButton(_('Including lyrics')) self.including_lrc.set_tooltip_text( _('Export lyrics to the same folder')) self.including_lrc.props.margin_top = 20 box.pack_start(self.including_lrc, False, False, 0) export_box = Gtk.Box(spacing=5) export_box.props.margin_top = 20 box.pack_start(export_box, False, True, 0) self.export_prog = Gtk.ProgressBar() self.export_prog.props.show_text = True self.export_prog.props.text = '' export_box.pack_start(self.export_prog, True, True, 0) self.export_btn = Gtk.Button(_('Export')) self.export_btn.connect('clicked', self.do_export) export_box.pack_start(self.export_btn, False, False, 0) infobar = Gtk.InfoBar() infobar.props.margin_top = 20 box.pack_start(infobar, False, True, 0) info_content = infobar.get_content_area() info_label = Gtk.Label(_('Only cached songs will be exported')) info_content.pack_start(info_label, False, False, 0) box.show_all()
def on_export_playlist_button_clicked(self, button): def do_export(button): num_songs = len(liststore) export_dir = folder_chooser.get_filename() export_lrc = with_lrc.get_active() for i, item in enumerate(liststore): song = Widgets.song_row_to_dict(item, start=0) song_link, song_path = Net.get_song_link( song, self.app.conf) if song_link is not True: continue shutil.copy(song_path, export_dir) if export_lrc: (lrc_path, lrc_cached) = Net.get_lrc_path(song) if lrc_cached: shutil.copy(lrc_path, export_dir) export_prog.set_fraction(i / num_songs) Gdk.Window.process_all_updates() dialog.destroy() selection = self.treeview_left.get_selection() model, _iter = selection.get_selected() if not _iter: return path = model.get_path(_iter) index = path.get_indices()[0] disname, list_name, editable = model[path] liststore = self.tabs[list_name].liststore dialog = Gtk.Dialog( _('Export Songs'), self.app.window, Gtk.DialogFlags.MODAL, (Gtk.STOCK_CLOSE, Gtk.ResponseType.OK,)) box = dialog.get_content_area() box.set_size_request(600, 320) box.set_border_width(5) folder_label = Widgets.BoldLabel(_('Choose export folder')) box.pack_start(folder_label, False, True, 0) folder_chooser = Widgets.FolderChooser(self.app.window) folder_chooser.props.margin_left = 20 box.pack_start(folder_chooser, False, True, 0) with_lrc = Gtk.CheckButton(_('With lyrics')) with_lrc.set_tooltip_text(_('Export lyrics to the same folder')) with_lrc.props.margin_top = 20 box.pack_start(with_lrc, False, False, 0) export_box = Gtk.Box(spacing=5) export_box.props.margin_top = 20 box.pack_start(export_box, False, True, 0) export_prog = Gtk.ProgressBar() export_box.pack_start(export_prog, True, True, 0) export_btn = Gtk.Button(_('Export')) export_btn.connect('clicked', do_export) export_box.pack_start(export_btn, False, False, 0) infobar = Gtk.InfoBar() infobar.props.margin_top = 20 box.pack_start(infobar, False, True, 0) info_content = infobar.get_content_area() info_label = Gtk.Label(_('Only cached songs will be exported')) info_content.pack_start(info_label, False, False, 0) box.show_all() dialog.run() dialog.destroy()