本文整理汇总了Python中openlp.plugins.songs.lib.VerseType.from_string方法的典型用法代码示例。如果您正苦于以下问题:Python VerseType.from_string方法的具体用法?Python VerseType.from_string怎么用?Python VerseType.from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openlp.plugins.songs.lib.VerseType
的用法示例。
在下文中一共展示了VerseType.from_string方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: song_to_line_dict
# 需要导入模块: from openlp.plugins.songs.lib import VerseType [as 别名]
# 或者: from openlp.plugins.songs.lib.VerseType import from_string [as 别名]
def song_to_line_dict(self, song):
song_xml = SongXML()
if song.chords:
verse_chords_xml = song_xml.get_verses(song.chords)
else:
verse_chords_xml = song_xml.get_verses(song.lyrics)
section_line_dict = {}
for count, verse in enumerate(verse_chords_xml):
# This silently migrates from localized verse type markup.
# If we trusted the database, this would be unnecessary.
verse_tag = verse[0]['type']
index = None
if len(verse_tag) > 1:
index = VerseType.from_translated_string(verse_tag)
if index is None:
index = VerseType.from_string(verse_tag, None)
else:
verse_tags_translated = True
if index is None:
index = VerseType.from_tag(verse_tag)
verse[0]['type'] = VerseType.tags[index]
if verse[0]['label'] == '':
verse[0]['label'] = '1'
section_header = '%s%s' % (verse[0]['type'], verse[0]['label'])
line_list = []
for line in verse[1].split('\n'):
line_list.append(line)
section_line_dict[section_header] = line_list
return section_line_dict
示例2: setupUi
# 需要导入模块: from openlp.plugins.songs.lib import VerseType [as 别名]
# 或者: from openlp.plugins.songs.lib.VerseType import from_string [as 别名]
#.........这里部分代码省略.........
self.song_alternate_title_content.setText(self.song.alternate_title)
self.song_alternate_title_content.setWordWrap(True)
self.song_info_form_layout.setWidget(1, QtGui.QFormLayout.FieldRole, self.song_alternate_title_content)
# Add CCLI number widget.
self.song_ccli_number_label = QtGui.QLabel(self)
self.song_ccli_number_label.setObjectName('song_ccli_number_label')
self.song_info_form_layout.setWidget(2, QtGui.QFormLayout.LabelRole, self.song_ccli_number_label)
self.song_ccli_number_content = QtGui.QLabel(self)
self.song_ccli_number_content.setObjectName('song_ccli_number_content')
self.song_ccli_number_content.setText(self.song.ccli_number)
self.song_ccli_number_content.setWordWrap(True)
self.song_info_form_layout.setWidget(2, QtGui.QFormLayout.FieldRole, self.song_ccli_number_content)
# Add copyright widget.
self.song_copyright_label = QtGui.QLabel(self)
self.song_copyright_label.setObjectName('song_copyright_label')
self.song_info_form_layout.setWidget(3, QtGui.QFormLayout.LabelRole, self.song_copyright_label)
self.song_copyright_content = QtGui.QLabel(self)
self.song_copyright_content.setObjectName('song_copyright_content')
self.song_copyright_content.setWordWrap(True)
self.song_copyright_content.setText(self.song.copyright)
self.song_info_form_layout.setWidget(3, QtGui.QFormLayout.FieldRole, self.song_copyright_content)
# Add comments widget.
self.song_comments_label = QtGui.QLabel(self)
self.song_comments_label.setObjectName('song_comments_label')
self.song_info_form_layout.setWidget(4, QtGui.QFormLayout.LabelRole, self.song_comments_label)
self.song_comments_content = QtGui.QLabel(self)
self.song_comments_content.setObjectName('song_comments_content')
self.song_comments_content.setText(self.song.comments)
self.song_comments_content.setWordWrap(True)
self.song_info_form_layout.setWidget(4, QtGui.QFormLayout.FieldRole, self.song_comments_content)
# Add authors widget.
self.song_authors_label = QtGui.QLabel(self)
self.song_authors_label.setObjectName('song_authors_label')
self.song_info_form_layout.setWidget(5, QtGui.QFormLayout.LabelRole, self.song_authors_label)
self.song_authors_content = QtGui.QLabel(self)
self.song_authors_content.setObjectName('song_authors_content')
self.song_authors_content.setWordWrap(True)
authors_text = ', '.join([author.display_name for author in self.song.authors])
self.song_authors_content.setText(authors_text)
self.song_info_form_layout.setWidget(5, QtGui.QFormLayout.FieldRole, self.song_authors_content)
# Add verse order widget.
self.song_verse_order_label = QtGui.QLabel(self)
self.song_verse_order_label.setObjectName('song_verse_order_label')
self.song_info_form_layout.setWidget(6, QtGui.QFormLayout.LabelRole, self.song_verse_order_label)
self.song_verse_order_content = QtGui.QLabel(self)
self.song_verse_order_content.setObjectName('song_verse_order_content')
self.song_verse_order_content.setText(self.song.verse_order)
self.song_verse_order_content.setWordWrap(True)
self.song_info_form_layout.setWidget(6, QtGui.QFormLayout.FieldRole, self.song_verse_order_content)
self.song_group_box_layout.addLayout(self.song_info_form_layout)
# Add verses widget.
self.song_info_verse_list_widget = QtGui.QTableWidget(self.song_group_box)
self.song_info_verse_list_widget.setColumnCount(1)
self.song_info_verse_list_widget.horizontalHeader().setVisible(False)
self.song_info_verse_list_widget.setObjectName('song_info_verse_list_widget')
self.song_info_verse_list_widget.setSelectionMode(QtGui.QAbstractItemView.NoSelection)
self.song_info_verse_list_widget.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.song_info_verse_list_widget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.song_info_verse_list_widget.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.song_info_verse_list_widget.setAlternatingRowColors(True)
song_xml = SongXML()
verses = song_xml.get_verses(self.song.lyrics)
self.song_info_verse_list_widget.setRowCount(len(verses))
song_tags = []
for verse_number, verse in enumerate(verses):
item = QtGui.QTableWidgetItem()
item.setText(verse[1])
self.song_info_verse_list_widget.setItem(verse_number, 0, item)
# We cannot use from_loose_input() here, because database
# is supposed to contain English lowercase singlechar tags.
verse_tag = verse[0]['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.translated_tags[verse_index].upper()
song_tags.append(str(verse_tag + verse[0]['label']))
self.song_info_verse_list_widget.setVerticalHeaderLabels(song_tags)
# Resize table fields to content and table to columns
self.song_info_verse_list_widget.setColumnWidth(0, self.song_group_box.width())
self.song_info_verse_list_widget.resizeRowsToContents()
# The 6 is a trial and error value since verticalHeader().length() + offset() is a little bit to small.
# It seems there is no clean way to determine the real height of the table contents.
# The "correct" value slightly fluctuates depending on the theme used, in the worst case
# Some pixels are missing at the bottom of the table, but all themes I tried still allowed
# to read the last verse line, so I'll just leave it at that.
self.song_info_verse_list_widget.setFixedHeight(self.song_info_verse_list_widget.verticalHeader().length() +
self.song_info_verse_list_widget.verticalHeader().offset() + 6)
self.song_group_box_layout.addWidget(self.song_info_verse_list_widget)
self.song_group_box_layout.addStretch()
self.song_vertical_layout.addWidget(self.song_group_box)
self.song_remove_button = QtGui.QPushButton(self)
self.song_remove_button.setObjectName('song_remove_button')
self.song_remove_button.setIcon(build_icon(':/songs/song_delete.png'))
self.song_remove_button.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
self.song_vertical_layout.addWidget(self.song_remove_button, alignment=QtCore.Qt.AlignHCenter)
示例3: generate_slide_data
# 需要导入模块: from openlp.plugins.songs.lib import VerseType [as 别名]
# 或者: from openlp.plugins.songs.lib.VerseType import from_string [as 别名]
def generate_slide_data(self, service_item, item=None, xml_version=False, remote=False,
context=ServiceItemContext.Service):
"""
Generate the slide data. Needs to be implemented by the plugin.
:param service_item: The service item to be built on
:param item: The Song item to be used
:param xml_version: The xml version (not used)
:param remote: Triggered from remote
:param context: Why is it being generated
"""
log.debug('generate_slide_data: %s, %s, %s' % (service_item, item, self.remote_song))
item_id = self._get_id_of_item_to_generate(item, self.remote_song)
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
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(str(verse_list[0][0]['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]['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.translated_tags[verse_index].upper()
verse_def = '%s%s' % (verse_tag, verse[0]['label'])
service_item.add_from_text(str(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]['type'][0].lower() == \
order[0] and (verse[0]['label'].lower() == order[1:] or not order[1:]):
if verse_tags_translated:
verse_index = VerseType.from_translated_tag(verse[0]['type'])
else:
verse_index = VerseType.from_tag(verse[0]['type'])
verse_tag = VerseType.translated_tags[verse_index]
verse_def = '%s%s' % (verse_tag, verse[0]['label'])
service_item.add_from_text(verse[1], verse_def)
service_item.title = song.title
author_list = self.generate_footer(service_item, song)
service_item.data_string = {'title': song.search_title, 'authors': ', '.join(author_list)}
service_item.set_extra_data_dict(self.open_lyrics.song_to_line_dict(song))
service_item.xml_version = self.open_lyrics.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
示例4: load_song
# 需要导入模块: from openlp.plugins.songs.lib import VerseType [as 别名]
# 或者: from openlp.plugins.songs.lib.VerseType import from_string [as 别名]
def load_song(self, song_id, preview=False):
"""
Loads a song.
``song_id``
The song id (int).
``preview``
Should be ``True`` if the song is also previewed (boolean).
"""
log.debug('Load Song')
self.initialise()
self.song_tab_widget.setCurrentIndex(0)
self.load_authors()
self.load_topics()
self.load_books()
self.load_media_files()
self.song = self.manager.get_object(Song, song_id)
self.title_edit.setText(self.song.title)
self.alternative_edit.setText(
self.song.alternate_title if self.song.alternate_title else '')
if self.song.song_book_id != 0:
book_name = self.manager.get_object(Book, self.song.song_book_id)
find_and_set_in_combo_box(self.song_book_combo_box, str(book_name.name))
else:
self.song_book_combo_box.setEditText('')
self.song_book_combo_box.setCurrentIndex(0)
if self.song.theme_name:
find_and_set_in_combo_box(self.theme_combo_box, str(self.song.theme_name))
else:
# Clear the theme combo box in case it was previously set (bug #1212801)
self.theme_combo_box.setEditText('')
self.theme_combo_box.setCurrentIndex(0)
self.copyright_edit.setText(self.song.copyright if self.song.copyright else '')
self.comments_edit.setPlainText(self.song.comments if self.song.comments else '')
self.ccli_number_edit.setText(self.song.ccli_number if self.song.ccli_number else '')
self.song_book_number_edit.setText(self.song.song_number if self.song.song_number else '')
# lazy xml migration for now
self.verse_list_widget.clear()
self.verse_list_widget.setRowCount(0)
verse_tags_translated = False
if self.song.lyrics.startswith('<?xml version='):
songXML = SongXML()
verse_list = songXML.get_verses(self.song.lyrics)
for count, verse in enumerate(verse_list):
self.verse_list_widget.setRowCount(self.verse_list_widget.rowCount() + 1)
# This silently migrates from localized verse type markup.
# If we trusted the database, this would be unnecessary.
verse_tag = verse[0]['type']
index = None
if len(verse_tag) > 1:
index = VerseType.from_translated_string(verse_tag)
if index is None:
index = VerseType.from_string(verse_tag, None)
else:
verse_tags_translated = True
if index is None:
index = VerseType.from_tag(verse_tag)
verse[0]['type'] = VerseType.tags[index]
if verse[0]['label'] == '':
verse[0]['label'] = '1'
verse_def = '%s%s' % (verse[0]['type'], verse[0]['label'])
item = QtGui.QTableWidgetItem(verse[1])
item.setData(QtCore.Qt.UserRole, verse_def)
self.verse_list_widget.setItem(count, 0, item)
else:
verses = self.song.lyrics.split('\n\n')
for count, verse in enumerate(verses):
self.verse_list_widget.setRowCount(self.verse_list_widget.rowCount() + 1)
item = QtGui.QTableWidgetItem(verse)
verse_def = '%s%s' % (VerseType.tags[VerseType.Verse], str(count + 1))
item.setData(QtCore.Qt.UserRole, verse_def)
self.verse_list_widget.setItem(count, 0, item)
if self.song.verse_order:
# we translate verse order
translated = []
for verse_def in self.song.verse_order.split():
verse_index = None
if verse_tags_translated:
verse_index = VerseType.from_translated_tag(verse_def[0], None)
if verse_index is None:
verse_index = VerseType.from_tag(verse_def[0])
verse_tag = VerseType.translated_tags[verse_index].upper()
translated.append('%s%s' % (verse_tag, verse_def[1:]))
self.verse_order_edit.setText(' '.join(translated))
else:
self.verse_order_edit.setText('')
self.tag_rows()
# clear the results
self.authors_list_view.clear()
for author in self.song.authors:
author_name = QtGui.QListWidgetItem(str(author.display_name))
author_name.setData(QtCore.Qt.UserRole, author.id)
self.authors_list_view.addItem(author_name)
# clear the results
self.topics_list_view.clear()
for topic in self.song.topics:
topic_name = QtGui.QListWidgetItem(str(topic.name))
topic_name.setData(QtCore.Qt.UserRole, topic.id)
self.topics_list_view.addItem(topic_name)
#.........这里部分代码省略.........
示例5: generateSlideData
# 需要导入模块: from openlp.plugins.songs.lib import VerseType [as 别名]
# 或者: from openlp.plugins.songs.lib.VerseType import from_string [as 别名]
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