def generate_footer(self, item, song): """ Generates the song footer based on a song and adds details to a service item. :param item: The service item to be amended :param song: The song to be used to generate the footer :return: List of all authors (only required for initial song generation) """ authors_words = [] authors_music = [] authors_words_music = [] authors_translation = [] authors_none = [] for author_song in song.authors_songs: if author_song.author_type == AuthorType.Words: authors_words.append(author_song.author.display_name) elif author_song.author_type == AuthorType.Music: authors_music.append(author_song.author.display_name) elif author_song.author_type == AuthorType.WordsAndMusic: authors_words_music.append(author_song.author.display_name) elif author_song.author_type == AuthorType.Translation: authors_translation.append(author_song.author.display_name) else: authors_none.append(author_song.author.display_name) authors_all = authors_words_music + authors_words + authors_music + authors_translation + authors_none item.audit = [ song.title, authors_all, song.copyright, str(song.ccli_number) ] item.raw_footer = [] item.raw_footer.append(song.title) if authors_none: item.raw_footer.append("{text}: {authors}".format(text=translate('OpenLP.Ui', 'Written by'), authors=create_separated_list(authors_none))) if authors_words_music: item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.WordsAndMusic], authors=create_separated_list(authors_words_music))) if authors_words: item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.Words], authors=create_separated_list(authors_words))) if authors_music: item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.Music], authors=create_separated_list(authors_music))) if authors_translation: item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.Translation], authors=create_separated_list(authors_translation))) if song.copyright: if self.display_copyright_symbol: item.raw_footer.append("{symbol} {song}".format(symbol=SongStrings.CopyrightSymbol, song=song.copyright)) else: item.raw_footer.append(song.copyright) if self.display_songbook and song.songbook_entries: songbooks = [str(songbook_entry) for songbook_entry in song.songbook_entries] item.raw_footer.append(", ".join(songbooks)) if Settings().value('core/ccli number'): item.raw_footer.append(translate('SongsPlugin.MediaItem', 'CCLI License: ') + Settings().value('core/ccli number')) return authors_all
def generate_footer(self, item, song): """ Generates the song footer based on a song and adds details to a service item. :param item: The service item to be amended :param song: The song to be used to generate the footer :return: List of all authors (only required for initial song generation) """ authors_words = [] authors_music = [] authors_words_music = [] authors_translation = [] authors_none = [] for author_song in song.authors_songs: if author_song.author_type == AuthorType.Words: authors_words.append(author_song.author.display_name) elif author_song.author_type == AuthorType.Music: authors_music.append(author_song.author.display_name) elif author_song.author_type == AuthorType.WordsAndMusic: authors_words_music.append(author_song.author.display_name) elif author_song.author_type == AuthorType.Translation: authors_translation.append(author_song.author.display_name) else: authors_none.append(author_song.author.display_name) authors_all = authors_words_music + authors_words + authors_music + authors_translation + authors_none item.audit = [ song.title, authors_all, song.copyright, str(song.ccli_number) ] item.raw_footer = [] item.raw_footer.append(song.title) if authors_none: item.raw_footer.append("%s: %s" % (translate('OpenLP.Ui', 'Written by'), create_separated_list(authors_none))) if authors_words_music: item.raw_footer.append("%s: %s" % (AuthorType.Types[AuthorType.WordsAndMusic], create_separated_list(authors_words_music))) if authors_words: item.raw_footer.append("%s: %s" % (AuthorType.Types[AuthorType.Words], create_separated_list(authors_words))) if authors_music: item.raw_footer.append("%s: %s" % (AuthorType.Types[AuthorType.Music], create_separated_list(authors_music))) if authors_translation: item.raw_footer.append("%s: %s" % (AuthorType.Types[AuthorType.Translation], create_separated_list(authors_translation))) if song.copyright: if self.display_copyright_symbol: item.raw_footer.append("%s %s" % (SongStrings.CopyrightSymbol, song.copyright)) else: item.raw_footer.append(song.copyright) if self.display_songbook and song.book: item.raw_footer.append("%s #%s" % (song.book.name, song.song_number)) if Settings().value('core/ccli number'): item.raw_footer.append(translate('SongsPlugin.MediaItem', 'CCLI License: ') + Settings().value('core/ccli number')) return authors_all
def set_defaults(self): """ Set default form values for the song export wizard. """ self.restart() self.finish_button.setVisible(False) self.cancel_button.setVisible(True) self.available_list_widget.clear() self.selected_list_widget.clear() self.directory_line_edit.clear() self.search_line_edit.clear() # Load the list of songs. self.application.set_busy_cursor() songs = self.plugin.manager.get_all_objects(Song) songs.sort(key=lambda song: song.sort_key) for song in songs: # No need to export temporary songs. if song.temporary: continue authors = create_separated_list([author.display_name for author in song.authors]) title = '%s (%s)' % (str(song.title), authors) item = QtGui.QListWidgetItem(title) item.setData(QtCore.Qt.UserRole, song) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled) item.setCheckState(QtCore.Qt.Unchecked) self.available_list_widget.addItem(item) self.application.set_normal_cursor()
def display_results_song(self, search_results): """ Display the song search results in the media manager list :param search_results: A list of db Song objects :return: None """ def get_song_key(song): """Get the key to sort by""" return song.sort_key log.debug('display results Song') self.save_auto_select_id() self.list_view.clear() search_results.sort(key=get_song_key) for song in search_results: # Do not display temporary songs if song.temporary: continue author_list = [author.display_name for author in song.authors] text = create_separated_list(author_list) if author_list else song.title song_detail = '{title} ({author})'.format(title=song.title, author=text) song_name = QtWidgets.QListWidgetItem(song_detail) song_name.setData(QtCore.Qt.UserRole, song.id) self.list_view.addItem(song_name) # Auto-select the item if name has been set if song.id == self.auto_select_id: self.list_view.setCurrentItem(song_name) self.auto_select_id = -1
def set_defaults(self): """ Set default form values for the song export wizard. """ def get_song_key(song): """Get the key to sort by""" return song.sort_key self.restart() self.finish_button.setVisible(False) self.cancel_button.setVisible(True) self.available_list_widget.clear() self.selected_list_widget.clear() self.directory_line_edit.clear() self.search_line_edit.clear() # Load the list of songs. self.application.set_busy_cursor() songs = self.plugin.manager.get_all_objects(Song) songs.sort(key=get_song_key) for song in songs: # No need to export temporary songs. if song.temporary: continue authors = create_separated_list([author.display_name for author in song.authors]) title = '{title} ({author})'.format(title=song.title, author=authors) item = QtWidgets.QListWidgetItem(title) item.setData(QtCore.Qt.UserRole, song) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled) item.setCheckState(QtCore.Qt.Unchecked) self.available_list_widget.addItem(item) self.application.set_normal_cursor()
def _validate_verse_list(self, verse_order, verse_count): verses = [] invalid_verses = [] verse_names = [] order_names = str(verse_order).split() order = self._extract_verse_order(verse_order) for index in range(verse_count): verse = self.verse_list_widget.item(index, 0) verse = verse.data(QtCore.Qt.UserRole) if verse not in verse_names: verses.append(verse) verse_names.append('%s%s' % (VerseType.translated_tag(verse[0]), verse[1:])) for count, item in enumerate(order): if item not in verses: invalid_verses.append(order_names[count]) if invalid_verses: valid = create_separated_list(verse_names) if len(invalid_verses) > 1: msg = translate('SongsPlugin.EditSongForm', 'There are no verses corresponding to "%(invalid)s".' 'Valid entries are %(valid)s.\nPlease enter the verses seperated by spaces.') \ % {'invalid' : ', '.join(invalid_verses), 'valid' : valid} else: msg = translate('SongsPlugin.EditSongForm', 'There is no verse corresponding to "%(invalid)s".' 'Valid entries are %(valid)s.\nPlease enter the verses seperated by spaces.') \ % {'invalid' : invalid_verses[0], 'valid' : valid} critical_error_message_box(title=translate('SongsPlugin.EditSongForm', 'Invalid Verse Order'), message=msg) return len(invalid_verses) == 0
def test_create_separated_list_with_two_items(self): """ Test the create_separated_list function with a list of two entries """ # GIVEN: A list with two strings. string_list = ['Author 1', 'Author 2'] # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) # THEN: We should have "Author 1 and Author 2" self.assertEqual(string_result, 'Author 1 and Author 2', 'The string should be "Author 1 and Author 2".')
def test_create_separated_list_with_one_item(self): """ Test the create_separated_list function with a list consisting of only one entry """ # GIVEN: A list with a string. string_list = ['Author 1'] # WHEN: We get a string build from the entries it the list and a separator. string_result = create_separated_list(string_list) # THEN: We should have "Author 1" self.assertEqual(string_result, 'Author 1', 'The string should be "Author 1".')
def test_create_separated_list_empty_list(self): """ Test the create_separated_list function with an empty list """ # GIVEN: An empty list and the mocked Qt module. string_list = [] # WHEN: We get a string build from the entries it the list and a separator. string_result = create_separated_list(string_list) # THEN: We shoud have an emptry string. assert string_result == '', 'The string sould be empty.'
def test_create_separated_list_with_two_items(self): """ Test the create_separated_list function with a list of two entries """ # GIVEN: A list with two strings. string_list = ['Author 1', 'Author 2'] # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) # THEN: We should have "Author 1 and Author 2" assert string_result == 'Author 1 and Author 2', 'The string should be "Author 1 and Author 2".'
def test_create_separated_list_with_one_item(self): """ Test the create_separated_list function with a list consisting of only one entry """ # GIVEN: A list with a string. string_list = ['Author 1'] # WHEN: We get a string build from the entries it the list and a separator. string_result = create_separated_list(string_list) # THEN: We should have "Author 1" assert string_result == 'Author 1', 'The string should be "Author 1".'
def test_create_separated_list_qlocate(self, mocked_createSeparatedList): """ Test the create_separated_list function using the Qt provided method """ # GIVEN: A list of strings and the mocked Qt module. mocked_createSeparatedList.return_value = 'Author 1, Author 2, and Author 3' string_list = ['Author 1', 'Author 2', 'Author 3'] # WHEN: We get a string build from the entries it the list and a separator. string_result = create_separated_list(string_list) # THEN: We should have "Author 1, Author 2, and Author 3" assert string_result == 'Author 1, Author 2 and Author 3', \ 'The string should be "Author 1, Author 2, and Author 3".'
def test_create_separated_list_with_one_item(self): """ Test the create_separated_list function with a list consisting of only one entry """ with patch('openlp.core.lib.Qt') as mocked_qt: # GIVEN: A list with a string and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = '4.8' mocked_qt.qVersion.return_value = '4.7' string_list = ['Author 1'] # WHEN: We get a string build from the entries it the list and a separator. string_result = create_separated_list(string_list) # THEN: We should have "Author 1" assert string_result == 'Author 1', 'The string should be u\'Author 1\'.'
def test_create_separated_list_empty_list(self): """ Test the create_separated_list function with an empty list """ with patch('openlp.core.lib.Qt') as mocked_qt: # GIVEN: An empty list and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = '4.8' mocked_qt.qVersion.return_value = '4.7' string_list = [] # WHEN: We get a string build from the entries it the list and a separator. string_result = create_separated_list(string_list) # THEN: We shoud have an emptry string. assert string_result == '', 'The string sould be empty.'
def test_create_separated_list_empty_list(self): """ Test the create_separated_list function with an empty list """ with patch('openlp.core.lib.Qt') as mocked_qt: # GIVEN: An empty list and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = '4.8' mocked_qt.qVersion.return_value = '4.7' string_list = [] # WHEN: We get a string build from the entries it the list and a separator. string_result = create_separated_list(string_list) # THEN: We shoud have an emptry string. self.assertEqual(string_result, '', 'The string sould be empty.')
def create_separated_list_with_one_item_test(self): """ Test the create_separated_list function with a list consisting of only one entry """ with patch('openlp.core.lib.Qt') as mocked_qt: # GIVEN: A list with a string and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = '4.8' mocked_qt.qVersion.return_value = '4.7' string_list = ['Author 1'] # WHEN: We get a string build from the entries it the list and a separator. string_result = create_separated_list(string_list) # THEN: We should have "Author 1" assert string_result == 'Author 1', 'The string should be u\'Author 1\'.'
def create_separated_list_with_two_items_test(self): """ Test the create_separated_list function with a list of two entries """ with patch('openlp.core.lib.Qt') as mocked_qt, patch('openlp.core.lib.translate') as mocked_translate: # GIVEN: A list of strings and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = '4.8' mocked_qt.qVersion.return_value = '4.7' mocked_translate.return_value = '%s and %s' string_list = ['Author 1', 'Author 2'] # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) # THEN: We should have "Author 1 and Author 2" assert string_result == 'Author 1 and Author 2', 'The string should be u\'Author 1 and Author 2\'.'
def test_create_separated_list_qlocate(self): """ Test the create_separated_list function using the Qt provided method """ with patch('openlp.core.lib.Qt') as mocked_qt, \ patch('openlp.core.lib.QtCore.QLocale.createSeparatedList') as mocked_createSeparatedList: # GIVEN: A list of strings and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = '4.9' mocked_qt.qVersion.return_value = '4.8' mocked_createSeparatedList.return_value = 'Author 1, Author 2, and Author 3' string_list = ['Author 1', 'Author 2', 'Author 3'] # WHEN: We get a string build from the entries it the list and a separator. string_result = create_separated_list(string_list) # THEN: We should have "Author 1, Author 2, and Author 3" self.assertEqual(string_result, 'Author 1, Author 2 and Author 3', 'The string should be "Author 1, ' 'Author 2, and Author 3".')
def create_separated_list_with_three_items_test(self): """ Test the create_separated_list function with a list of three items """ with patch('openlp.core.lib.Qt') as mocked_qt, patch('openlp.core.lib.translate') as mocked_translate: # GIVEN: A list with a string and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = '4.8' mocked_qt.qVersion.return_value = '4.7' # Always return the untranslated string. mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate string_list = ['Author 1', 'Author 2', 'Author 3'] # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) # THEN: We should have "Author 1, Author 2, and Author 3" assert string_result == 'Author 1, Author 2, and Author 3', 'The string should be u\'Author 1, ' \ 'Author 2, and Author 3\'.'
def test_create_separated_list_qlocate(self): """ Test the create_separated_list function using the Qt provided method """ with patch('openlp.core.lib.Qt') as mocked_qt, \ patch('openlp.core.lib.QtCore.QLocale.createSeparatedList') as mocked_createSeparatedList: # GIVEN: A list of strings and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = '4.9' mocked_qt.qVersion.return_value = '4.8' mocked_createSeparatedList.return_value = 'Author 1, Author 2, and Author 3' string_list = ['Author 1', 'Author 2', 'Author 3'] # WHEN: We get a string build from the entries it the list and a separator. string_result = create_separated_list(string_list) # THEN: We should have "Author 1, Author 2, and Author 3" assert string_result == 'Author 1, Author 2, and Author 3', 'The string should be u\'Author 1, ' \ 'Author 2, and Author 3\'.'
def display_results_song(self, search_results): log.debug('display results Song') self.save_auto_select_id() self.list_view.clear() search_results.sort(key=lambda song: song.sort_key) for song in search_results: # Do not display temporary songs if song.temporary: continue author_list = [author.display_name for author in song.authors] song_detail = '%s (%s)' % (song.title, create_separated_list(author_list)) if author_list else song.title song_name = QtGui.QListWidgetItem(song_detail) song_name.setData(QtCore.Qt.UserRole, song.id) self.list_view.addItem(song_name) # Auto-select the item if name has been set if song.id == self.auto_select_id: self.list_view.setCurrentItem(song_name) self.auto_select_id = -1
def displayResultsSong(self, searchresults): log.debug(u'display results Song') self.saveAutoSelectId() self.listView.clear() searchresults.sort(cmp=natcmp, key=lambda song: song.sort_key) for song in searchresults: # Do not display temporary songs if song.temporary: continue author_list = [author.display_name for author in song.authors] song_title = unicode(song.title) song_detail = u'%s (%s)' % (song_title, create_separated_list(author_list)) song_name = QtGui.QListWidgetItem(song_detail) song_name.setData(QtCore.Qt.UserRole, song.id) self.listView.addItem(song_name) # Auto-select the item if name has been set if song.id == self.autoSelectId: self.listView.setCurrentItem(song_name) self.autoSelectId = -1
def generate_footer(self, item, song): """ Generates the song footer based on a song and adds details to a service item. author_list is only required for initial song generation. ``item`` The service item to be amended ``song`` The song to be used to generate the footer """ author_list = [str(author.display_name) for author in song.authors] item.audit = [ song.title, author_list, song.copyright, str(song.ccli_number) ] item.raw_footer = [] item.raw_footer.append(song.title) item.raw_footer.append(create_separated_list(author_list)) item.raw_footer.append(song.copyright) if Settings().value('core/ccli number'): item.raw_footer.append(translate('SongsPlugin.MediaItem', 'CCLI License: ') + Settings().value('core/ccli number')) return author_list
def generateSlideData(self, service_item, item=None, xmlVersion=False, remote=False, context=ServiceItemContext.Service): log.debug(u'generateSlideData: %s, %s, %s' % (service_item, item, self.remoteSong)) item_id = self._getIdOfItemToGenerate(item, self.remoteSong) service_item.add_capability(ItemCapabilities.CanEdit) service_item.add_capability(ItemCapabilities.CanPreview) service_item.add_capability(ItemCapabilities.CanLoop) service_item.add_capability(ItemCapabilities.OnLoadUpdate) service_item.add_capability(ItemCapabilities.AddIfNewItem) service_item.add_capability(ItemCapabilities.CanSoftBreak) song = self.plugin.manager.get_object(Song, item_id) service_item.theme = song.theme_name service_item.edit_id = item_id if song.lyrics.startswith(u'<?xml version='): verse_list = SongXML().get_verses(song.lyrics) # no verse list or only 1 space (in error) verse_tags_translated = False if VerseType.from_translated_string(unicode(verse_list[0][0][u'type'])) is not None: verse_tags_translated = True if not song.verse_order.strip(): for verse in verse_list: # We cannot use from_loose_input() here, because database # is supposed to contain English lowercase singlechar tags. verse_tag = verse[0][u'type'] verse_index = None if len(verse_tag) > 1: verse_index = VerseType.from_translated_string(verse_tag) if verse_index is None: verse_index = VerseType.from_string(verse_tag, None) if verse_index is None: verse_index = VerseType.from_tag(verse_tag) verse_tag = VerseType.TranslatedTags[verse_index].upper() verse_def = u'%s%s' % (verse_tag, verse[0][u'label']) service_item.add_from_text(unicode(verse[1]), verse_def) else: # Loop through the verse list and expand the song accordingly. for order in song.verse_order.lower().split(): if not order: break for verse in verse_list: if verse[0][u'type'][0].lower() == order[0] and (verse[0][u'label'].lower() == order[1:] or \ not order[1:]): if verse_tags_translated: verse_index = VerseType.from_translated_tag(verse[0][u'type']) else: verse_index = VerseType.from_tag(verse[0][u'type']) verse_tag = VerseType.TranslatedTags[verse_index] verse_def = u'%s%s' % (verse_tag, verse[0][u'label']) service_item.add_from_text(verse[1], verse_def) else: verses = song.lyrics.split(u'\n\n') for slide in verses: service_item.add_from_text(unicode(slide)) service_item.title = song.title author_list = [unicode(author.display_name) for author in song.authors] service_item.raw_footer.append(song.title) service_item.raw_footer.append(create_separated_list(author_list)) service_item.raw_footer.append(song.copyright) if Settings().value(u'general/ccli number'): service_item.raw_footer.append(translate('SongsPlugin.MediaItem', 'CCLI License: ') + Settings().value(u'general/ccli number')) service_item.audit = [ song.title, author_list, song.copyright, unicode(song.ccli_number) ] service_item.data_string = {u'title': song.search_title, u'authors': u', '.join(author_list)} service_item.xml_version = self.openLyrics.song_to_xml(song) # Add the audio file to the service item. if song.media_files: service_item.add_capability(ItemCapabilities.HasBackgroundAudio) service_item.background_audio = [m.file_name for m in song.media_files] return True
def generate_slide_data(self, service_item, item=None, xmlVersion=False, remote=False, context=ServiceItemContext.Service): """ Generates and formats the slides for the service item as well as the service item's title. """ log.debug('generating slide data') if item: items = item else: items = self.list_view.selectedItems() if not items: return False bible_text = '' old_item = None old_chapter = -1 raw_slides = [] raw_title = [] verses = VerseReferenceList() for bitem in items: book = self._decode_qt_object(bitem, 'book') chapter = int(self._decode_qt_object(bitem, 'chapter')) verse = int(self._decode_qt_object(bitem, 'verse')) bible = self._decode_qt_object(bitem, 'bible') version = self._decode_qt_object(bitem, 'version') copyright = self._decode_qt_object(bitem, 'copyright') permissions = self._decode_qt_object(bitem, 'permissions') text = self._decode_qt_object(bitem, 'text') second_bible = self._decode_qt_object(bitem, 'second_bible') second_version = self._decode_qt_object(bitem, 'second_version') second_copyright = self._decode_qt_object(bitem, 'second_copyright') second_permissions = self._decode_qt_object(bitem, 'second_permissions') second_text = self._decode_qt_object(bitem, 'second_text') verses.add(book, chapter, verse, version, copyright, permissions) verse_text = self.formatVerse(old_chapter, chapter, verse) if second_bible: bible_text = '%s %s\n\n%s %s' % (verse_text, text, verse_text, second_text) raw_slides.append(bible_text.rstrip()) bible_text = '' # If we are 'Verse Per Slide' then create a new slide. elif self.settings.layout_style == LayoutStyle.VersePerSlide: bible_text = '%s %s' % (verse_text, text) raw_slides.append(bible_text.rstrip()) bible_text = '' # If we are 'Verse Per Line' then force a new line. elif self.settings.layout_style == LayoutStyle.VersePerLine: bible_text = '%s%s %s\n' % (bible_text, verse_text, text) # We have to be 'Continuous'. else: bible_text = '%s %s %s\n' % (bible_text, verse_text, text) bible_text = bible_text.strip(' ') if not old_item: start_item = bitem elif self.checkTitle(bitem, old_item): raw_title.append(self.formatTitle(start_item, old_item)) start_item = bitem old_item = bitem old_chapter = chapter # Add footer service_item.raw_footer.append(verses.format_verses()) if second_bible: verses.add_version(second_version, second_copyright, second_permissions) service_item.raw_footer.append(verses.format_versions()) raw_title.append(self.formatTitle(start_item, bitem)) # If there are no more items we check whether we have to add bible_text. if bible_text: raw_slides.append(bible_text.lstrip()) bible_text = '' # Service Item: Capabilities if self.settings.layout_style == LayoutStyle.Continuous and not second_bible: # Split the line but do not replace line breaks in renderer. service_item.add_capability(ItemCapabilities.NoLineBreaks) service_item.add_capability(ItemCapabilities.CanPreview) service_item.add_capability(ItemCapabilities.CanLoop) service_item.add_capability(ItemCapabilities.CanWordSplit) service_item.add_capability(ItemCapabilities.CanEditTitle) # Service Item: Title service_item.title = create_separated_list(raw_title) # Service Item: Theme if not self.settings.bible_theme: service_item.theme = None else: service_item.theme = self.settings.bible_theme for slide in raw_slides: service_item.add_from_text(slide) return True
def generate_footer(self, item, song): """ Generates the song footer based on a song and adds details to a service item. :param item: The service item to be amended :param song: The song to be used to generate the footer :return: List of all authors (only required for initial song generation) """ authors_words = [] authors_music = [] authors_words_music = [] authors_translation = [] authors_none = [] for author_song in song.authors_songs: if author_song.author_type == AuthorType.Words: authors_words.append(author_song.author.display_name) elif author_song.author_type == AuthorType.Music: authors_music.append(author_song.author.display_name) elif author_song.author_type == AuthorType.WordsAndMusic: authors_words_music.append(author_song.author.display_name) elif author_song.author_type == AuthorType.Translation: authors_translation.append(author_song.author.display_name) else: authors_none.append(author_song.author.display_name) authors_all = authors_words_music + authors_words + authors_music + authors_translation + authors_none item.audit = [ song.title, authors_all, song.copyright, str(song.ccli_number) ] item.raw_footer = [] item.raw_footer.append(song.title) if authors_none: # If the setting for showing "Written by:" is enabled, show it before unspecified authors. if Settings().value('songs/display written by'): item.raw_footer.append("{text}: {authors}".format(text=translate('OpenLP.Ui', 'Written by'), authors=create_separated_list(authors_none))) else: item.raw_footer.append("{authors}".format(authors=create_separated_list(authors_none))) if authors_words_music: item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.WordsAndMusic], authors=create_separated_list(authors_words_music))) if authors_words: item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.Words], authors=create_separated_list(authors_words))) if authors_music: item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.Music], authors=create_separated_list(authors_music))) if authors_translation: item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.Translation], authors=create_separated_list(authors_translation))) if song.copyright: if self.display_copyright_symbol: item.raw_footer.append("{symbol} {song}".format(symbol=SongStrings.CopyrightSymbol, song=song.copyright)) else: item.raw_footer.append(song.copyright) if self.display_songbook and song.songbook_entries: songbooks = [str(songbook_entry) for songbook_entry in song.songbook_entries] item.raw_footer.append(", ".join(songbooks)) if Settings().value('core/ccli number'): item.raw_footer.append(translate('SongsPlugin.MediaItem', 'CCLI License: ') + Settings().value('core/ccli number')) return authors_all
def generate_footer(self, item, song): """ Generates the song footer based on a song and adds details to a service item. :param item: The service item to be amended :param song: The song to be used to generate the footer :return: List of all authors (only required for initial song generation) """ authors_words = [] authors_music = [] authors_words_music = [] authors_translation = [] authors_none = [] for author_song in song.authors_songs: if author_song.author_type == AuthorType.Words: authors_words.append(author_song.author.display_name) elif author_song.author_type == AuthorType.Music: authors_music.append(author_song.author.display_name) elif author_song.author_type == AuthorType.WordsAndMusic: authors_words_music.append(author_song.author.display_name) elif author_song.author_type == AuthorType.Translation: authors_translation.append(author_song.author.display_name) else: authors_none.append(author_song.author.display_name) authors_all = authors_words_music + authors_words + authors_music + authors_translation + authors_none item.audit = [ song.title, authors_all, song.copyright, str(song.ccli_number) ] item.raw_footer = [] item.raw_footer.append(song.title) if authors_none: # If the setting for showing "Written by:" is enabled, show it before unspecified authors. if Settings().value('songs/display written by'): item.raw_footer.append("{text}: {authors}".format(text=translate('OpenLP.Ui', 'Written by'), authors=create_separated_list(authors_none))) else: item.raw_footer.append("{authors}".format(authors=create_separated_list(authors_none))) if authors_words_music: item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.WordsAndMusic], authors=create_separated_list(authors_words_music))) if authors_words: item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.Words], authors=create_separated_list(authors_words))) if authors_music: item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.Music], authors=create_separated_list(authors_music))) if authors_translation: item.raw_footer.append("{text}: {authors}".format(text=AuthorType.Types[AuthorType.Translation], authors=create_separated_list(authors_translation))) if song.copyright: if self.display_copyright_symbol: item.raw_footer.append("{symbol} {song}".format(symbol=SongStrings.CopyrightSymbol, song=song.copyright)) else: item.raw_footer.append(song.copyright) if self.display_songbook and song.songbook_entries: songbooks = [str(songbook_entry) for songbook_entry in song.songbook_entries] item.raw_footer.append(", ".join(songbooks)) if Settings().value('core/ccli number'): item.raw_footer.append(translate('SongsPlugin.MediaItem', 'CCLI License: ') + Settings().value('core/ccli number')) item.metadata.append('<em>{label}:</em> {title}'.format(label=translate('SongsPlugin.MediaItem', 'Title'), title=song.title)) if song.alternate_title: item.metadata.append('<em>{label}:</em> {title}'. format(label=translate('SongsPlugin.MediaItem', 'Alt Title'), title=song.alternate_title)) if song.songbook_entries: for songbook_entry in song.songbook_entries: item.metadata.append('<em>{label}:</em> {book}/{num}/{pub}'. format(label=translate('SongsPlugin.MediaItem', 'Songbook'), book=songbook_entry.songbook.name, num=songbook_entry.entry, pub=songbook_entry.songbook.publisher)) if song.topics: for topics in song.topics: item.metadata.append('<em>{label}:</em> {topic}'. format(label=translate('SongsPlugin.MediaItem', 'Topic'), topic=topics.name)) return authors_all
def generate_footer(self, item, song): """ Generates the song footer based on a song and adds details to a service item. :param item: The service item to be amended :param song: The song to be used to generate the footer :return: List of all authors (only required for initial song generation) """ authors_words = [] authors_music = [] authors_words_music = [] authors_translation = [] authors_none = [] for author_song in song.authors_songs: if author_song.author_type == AuthorType.Words: authors_words.append(author_song.author.display_name) elif author_song.author_type == AuthorType.Music: authors_music.append(author_song.author.display_name) elif author_song.author_type == AuthorType.WordsAndMusic: authors_words_music.append(author_song.author.display_name) elif author_song.author_type == AuthorType.Translation: authors_translation.append(author_song.author.display_name) else: authors_none.append(author_song.author.display_name) authors_all = authors_words_music + authors_words + authors_music + authors_translation + authors_none item.audit = [ song.title, authors_all, song.copyright, str(song.ccli_number) ] item.raw_footer = [] item.raw_footer.append(song.title) if authors_none: item.raw_footer.append("{text}: {authors}".format( text=translate('OpenLP.Ui', 'Written by'), authors=create_separated_list(authors_none))) if authors_words_music: item.raw_footer.append("{text}: {authors}".format( text=AuthorType.Types[AuthorType.WordsAndMusic], authors=create_separated_list(authors_words_music))) if authors_words: item.raw_footer.append("{text}: {authors}".format( text=AuthorType.Types[AuthorType.Words], authors=create_separated_list(authors_words))) if authors_music: item.raw_footer.append("{text}: {authors}".format( text=AuthorType.Types[AuthorType.Music], authors=create_separated_list(authors_music))) if authors_translation: item.raw_footer.append("{text}: {authors}".format( text=AuthorType.Types[AuthorType.Translation], authors=create_separated_list(authors_translation))) if song.copyright: item.raw_footer.append("{symbol} {song}".format( symbol=SongStrings.CopyrightSymbol, song=song.copyright)) songbooks = [ str(songbook_entry) for songbook_entry in song.songbook_entries ] if song.songbook_entries: item.raw_footer.append(", ".join(songbooks)) if self.settings.value('core/ccli number'): item.raw_footer.append( translate('SongsPlugin.MediaItem', 'CCLI License: ') + self.settings.value('core/ccli number')) footer_template = self.settings.value('songs/footer template') # Keep this in sync with the list in songstab.py vars = { 'title': song.title, 'alternate_title': song.alternate_title, 'authors_none_label': translate('OpenLP.Ui', 'Written by'), 'authors_none': authors_none, 'authors_words_label': AuthorType.Types[AuthorType.Words], 'authors_words': authors_words, 'authors_music_label': AuthorType.Types[AuthorType.Music], 'authors_music': authors_music, 'authors_words_music_label': AuthorType.Types[AuthorType.WordsAndMusic], 'authors_words_music': authors_words_music, 'authors_translation_label': AuthorType.Types[AuthorType.Translation], 'authors_translation': authors_translation, 'authors_words_all': authors_words + authors_words_music, 'authors_music_all': authors_music + authors_words_music, 'copyright': song.copyright, 'songbook_entries': songbooks, 'ccli_license': self.settings.value('core/ccli number'), 'ccli_license_label': translate('SongsPlugin.MediaItem', 'CCLI License'), 'ccli_number': song.ccli_number, 'topics': [topic.name for topic in song.topics] } try: item.footer_html = mako.template.Template( footer_template).render_unicode(**vars).replace('\n', '') except mako.exceptions.SyntaxException: log.error('Failed to render Song footer html:\n' + mako.exceptions.text_error_template().render()) critical_error_message_box(message=translate( 'SongsPlugin.MediaItem', 'Failed to render Song footer html.\nSee log for details')) return authors_all