def _window_response(self, window, response): if response == Gtk.ResponseType.CLOSE: self.last_tab = self.prefsnotebook.get_current_page() #XXX: These two are probably never triggered if self.config.show_lyrics and self.config.lyrics_location != consts.LYRICS_LOCATION_HOME: if not os.path.isdir(self.config.musicdir[self.config.profile_num]): ui.show_msg(self.window, _("To save lyrics to the music file's directory, you must specify a valid music directory."), _("Music Dir Verification"), 'musicdirVerificationError', Gtk.ButtonsType.CLOSE) # Set music_dir entry focused: self.prefsnotebook.set_current_page(0) self.direntry.grab_focus() return if self.config.show_covers and self.config.art_location != consts.ART_LOCATION_HOMECOVERS: if not os.path.isdir(self.config.musicdir[self.config.profile_num]): ui.show_msg(self.window, _("To save artwork to the music file's directory, you must specify a valid music directory."), _("Music Dir Verification"), 'musicdirVerificationError', Gtk.ButtonsType.CLOSE) # Set music_dir entry focused: self.prefsnotebook.set_current_page(0) self.direntry.grab_focus() return if not self.using_mpd_env_vars: if self.prev_host != self.config.host[self.config.profile_num] or self.prev_port != self.config.port[self.config.profile_num] or self.prev_password != self.config.password[self.config.profile_num]: # Try to connect if mpd connection info has been updated: ui.change_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH)) self.reconnect() self.settings_save() self.populate_profiles_for_menu() ui.change_cursor(None) window.destroy()
def _window_response(self, window, response): if response == Gtk.ResponseType.CLOSE: self.last_tab = self.prefsnotebook.get_current_page() #XXX: These two are probably never triggered if self.config.show_lyrics and self.config.lyrics_location != consts.LYRICS_LOCATION_HOME: if not os.path.isdir(misc.file_from_utf8(self.config.musicdir[self.config.profile_num])): ui.show_msg(self.window, _("To save lyrics to the music file's directory, you must specify a valid music directory."), _("Music Dir Verification"), 'musicdirVerificationError', Gtk.ButtonsType.CLOSE) # Set music_dir entry focused: self.prefsnotebook.set_current_page(0) self.direntry.grab_focus() return if self.config.show_covers and self.config.art_location != consts.ART_LOCATION_HOMECOVERS: if not os.path.isdir(misc.file_from_utf8(self.config.musicdir[self.config.profile_num])): ui.show_msg(self.window, _("To save artwork to the music file's directory, you must specify a valid music directory."), _("Music Dir Verification"), 'musicdirVerificationError', Gtk.ButtonsType.CLOSE) # Set music_dir entry focused: self.prefsnotebook.set_current_page(0) self.direntry.grab_focus() return if not self.using_mpd_env_vars: if self.prev_host != self.config.host[self.config.profile_num] or self.prev_port != self.config.port[self.config.profile_num] or self.prev_password != self.config.password[self.config.profile_num]: # Try to connect if mpd connection info has been updated: ui.change_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH)) self.reconnect() self.settings_save() self.populate_profiles_for_menu() ui.change_cursor(None) window.destroy()
def _prompt_replace(self): prompt = _( "A stream with this name already exists. Would you like to replace it?" ) return ui.show_msg(self.window, prompt, _("New Stream"), 'newStreamError', Gtk.ButtonsType.YES_NO) == Gtk.ResponseType.YES
def save_tag(self): filetag = tagpy.FileRef(self.tags[self.tagnum]['fullpath']) tag = filetag.tag() # Set tag fields according to entry text for field, entry in self.entries.items(): tag_value = entry.get_text().strip() if field in ('year', 'track'): if len(tag_value) == 0: tag_value = '0' tag_value = int(tag_value) if field is 'comment': if len(tag_value) == 0: tag_value = ' ' setattr(tag, field, tag_value) save_success = filetag.save() if not (save_success): # FIXME: was (save_success and self.conn and self.status): ui.show_msg(self.window, _("Unable to save tag to music file."), _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy)
def save_tag(self): filetag = tagpy.FileRef(self.tags[self.tagnum]['fullpath']) tag = filetag.tag() # Set tag fields according to entry text for field, entry in self.entries.items(): tag_value = entry.get_text().strip() if field in ('year', 'track'): if len(tag_value) == 0: tag_value = '0' tag_value = int(tag_value) if field is 'comment': if len(tag_value) == 0: tag_value = ' ' setattr(tag, field, tag_value) save_success = filetag.save() if not (save_success ): # FIXME: was (save_success and self.conn and self.status): ui.show_msg(self.window, _("Unable to save tag to music file."), _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy)
def on_playlist_menu_click(self, action): plname = misc.unescape_html(action.get_name().replace("Playlist: ", "")) text = ('Would you like to replace the existing playlist or append' 'these songs?') response = ui.show_msg(self.window, _(text), _("Existing Playlist"), "existingPlaylist", (_("Replace playlist"), 1, _("Append songs"), 2), default=self.config.existing_playlist_option) if response == 1: # Overwrite self.config.existing_playlist_option = response self.mpd.playlistclear(plname) self.add_selected_to_playlist(plname) elif response == 2: # Append songs: self.config.existing_playlist_option = response self.add_selected_to_playlist(plname)
def playlist_name_exists(self, title, role, plname, skip_plname=""): # If the playlist already exists, and the user does not want to # replace it, return True; In all other cases, return False playlists = self.mpd.listplaylists() if playlists is None: playlists = self.mpd.lsinfo() for item in playlists: if 'playlist' in item: if item['playlist'] == plname and \ plname != skip_plname: if ui.show_msg(self.window, _(('A playlist with this name already ' 'exists. Would you like to replace it?')), title, role, Gtk.ButtonsType.YES_NO) == \ Gtk.ResponseType.YES: return False else: return True return False
def on_playlist_menu_click(self, action): plname = misc.unescape_html(action.get_name().replace( "Playlist: ", "")) text = ('Would you like to replace the existing playlist or append' 'these songs?') response = ui.show_msg( self.window, _(text), _("Existing Playlist"), "existingPlaylist", (_("Replace playlist"), 1, _("Append songs"), 2), default=self.config.existing_playlist_option) if response == 1: # Overwrite self.config.existing_playlist_option = response self.mpd.playlistclear(plname) self.add_selected_to_playlist(plname) elif response == 2: # Append songs: self.config.existing_playlist_option = response self.add_selected_to_playlist(plname)
def plugin_configure(self, _widget): plugin = self.plugin_get_selected() ui.show_msg(self.prefswindow, "Nothing yet implemented.", "Configure", "pluginConfigure", Gtk.ButtonsType.CLOSE)
def _prompt_replace(self): prompt = _("A stream with this name already exists. Would you like to replace it?") return ui.show_msg(self.window, prompt, _("New Stream"), 'newStreamError', Gtk.ButtonsType.YES_NO) == Gtk.ResponseType.YES
def on_tags_edit(self, files, temp_mpdpaths, music_dir): """Display the editing dialog""" # Try loading module global tagpy if tagpy is None: try: import tagpy except ImportError: ui.show_msg( self.window, _("Taglib and/or tagpy not found, tag editing support disabled." ), _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy) ui.change_cursor(None) return # Set default tag encoding to utf8.. fixes some reported bugs. import tagpy.id3v2 as id3v2 id3v2.FrameFactory.instance().setDefaultTextEncoding( tagpy.StringType.UTF8) # Make sure tagpy is at least 0.91 if hasattr(tagpy.Tag.title, '__call__'): ui.show_msg( self.window, _("Tagpy version < 0.91. Please upgrade to a newer version, tag editing support disabled." ), _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy) ui.change_cursor(None) return if not os.path.isdir(music_dir): ui.show_msg( self.window, _("The path %s does not exist. Please specify a valid music directory in preferences." ) % music_dir, _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy) ui.change_cursor(None) return # XXX file list was created here if len(files) == 0: ui.change_cursor(None) return # Initialize: self.tagnum = -1 self.tags = [{ 'title': '', 'artist': '', 'album': '', 'year': '', 'track': '', 'genre': '', 'comment': '', 'title-changed': False, 'artist-changed': False, 'album-changed': False, 'year-changed': False, 'track-changed': False, 'genre-changed': False, 'comment-changed': False, 'fullpath': filename, 'mpdpath': path, } for filename, path in zip(files, temp_mpdpaths)] if not os.path.exists(self.tags[0]['fullpath']): ui.change_cursor(None) ui.show_msg( self.window, _("File '%s' not found. Please specify a valid music directory in preferences." ) % self.tags[0]['fullpath'], _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy) return if not self.tags_next_tag(): ui.change_cursor(None) ui.show_msg(self.window, _("No music files with editable tags found."), _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy) return if not self.edit_window: self._init_edit_window() saveall_button = self.builder.get_object('tags_saveall_button') if len(files) > 1: # Only show save all button if more than one song being edited. saveall_button.show() saveall_button.set_property("visible", True) else: saveall_button.hide() saveall_button.set_property("visible", False) self.tags_win_update() self.edit_window.show_all() SAVE_ALL = -12 done = False while not done: # Next file: self.tags_win_update() response = self.edit_window.run() if response == SAVE_ALL: self.save_tag() while self.tags_next_tag(): self.tags_win_update() self.save_tag() done = True elif response == Gtk.ResponseType.ACCEPT: self.save_tag() done = not self.tags_next_tag() if done: # To ensure we update the last file in tags_mpd_update self.tagnum = self.tagnum + 1 elif response == Gtk.ResponseType.REJECT: done = True tag_paths = (tag['mpdpath'] for tag in self.tags[:self.tagnum]) GLib.idle_add(self.tags_mpd_update, tag_paths) self.tags_set_use_mpdpath(self.use_mpdpaths) self.tags = None ui.change_cursor(None) self.edit_window.hide()
def on_tags_edit(self, files, temp_mpdpaths, music_dir): """Display the editing dialog""" # Try loading module global tagpy if tagpy is None: try: import tagpy except ImportError: ui.show_msg(self.window, _("Taglib and/or tagpy not found, tag editing support disabled."), _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy) ui.change_cursor(None) return # Set default tag encoding to utf8.. fixes some reported bugs. import tagpy.id3v2 as id3v2 id3v2.FrameFactory.instance().setDefaultTextEncoding(tagpy.StringType.UTF8) # Make sure tagpy is at least 0.91 if hasattr(tagpy.Tag.title, '__call__'): ui.show_msg(self.window, _("Tagpy version < 0.91. Please upgrade to a newer version, tag editing support disabled."), _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy) ui.change_cursor(None) return if not os.path.isdir(misc.file_from_utf8(music_dir)): ui.show_msg(self.window, _("The path %s does not exist. Please specify a valid music directory in preferences.") % music_dir, _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy) ui.change_cursor(None) return # XXX file list was created here if len(files) == 0: ui.change_cursor(None) return # Initialize: self.tagnum = -1 self.tags = [{ 'title': '', 'artist': '', 'album': '', 'year': '', 'track': '', 'genre': '', 'comment': '', 'title-changed': False, 'artist-changed': False, 'album-changed': False, 'year-changed': False, 'track-changed': False, 'genre-changed': False, 'comment-changed': False, 'fullpath': misc.file_from_utf8(filename), 'mpdpath': path,} for filename, path in zip(files, temp_mpdpaths)] if not os.path.exists(self.tags[0]['fullpath']): ui.change_cursor(None) ui.show_msg(self.window, _("File '%s' not found. Please specify a valid music directory in preferences.") % self.tags[0]['fullpath'], _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy) return if not self.tags_next_tag(): ui.change_cursor(None) ui.show_msg(self.window, _("No music files with editable tags found."), _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy) return if not self.edit_window: self._init_edit_window() saveall_button = self.builder.get_object('tags_saveall_button') if len(files) > 1: # Only show save all button if more than one song being edited. saveall_button.show() saveall_button.set_property("visible", True) else: saveall_button.hide() saveall_button.set_property("visible", False) self.tags_win_update() self.edit_window.show_all() SAVE_ALL = -12 done = False while not done: # Next file: self.tags_win_update() response = self.edit_window.run() if response == SAVE_ALL: self.save_tag() while self.tags_next_tag(): self.tags_win_update() self.save_tag() done = True elif response == Gtk.ResponseType.ACCEPT: self.save_tag() done = not self.tags_next_tag() if done: # To ensure we update the last file in tags_mpd_update self.tagnum = self.tagnum + 1 elif response == Gtk.ResponseType.REJECT: done = True tag_paths = (tag['mpdpath'] for tag in self.tags[:self.tagnum]) GLib.idle_add(self.tags_mpd_update, tag_paths) self.tags_set_use_mpdpath(self.use_mpdpaths) self.tags = None ui.change_cursor(None) self.edit_window.hide()