本文整理汇总了Python中openlp.plugins.songs.lib.VerseType.translated_name方法的典型用法代码示例。如果您正苦于以下问题:Python VerseType.translated_name方法的具体用法?Python VerseType.translated_name怎么用?Python VerseType.translated_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openlp.plugins.songs.lib.VerseType
的用法示例。
在下文中一共展示了VerseType.translated_name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_verse_edit_all_button_clicked
# 需要导入模块: from openlp.plugins.songs.lib import VerseType [as 别名]
# 或者: from openlp.plugins.songs.lib.VerseType import translated_name [as 别名]
def on_verse_edit_all_button_clicked(self):
verse_list = ''
if self.verse_list_widget.rowCount() > 0:
for row in range(self.verse_list_widget.rowCount()):
item = self.verse_list_widget.item(row, 0)
field = item.data(QtCore.Qt.UserRole)
verse_tag = VerseType.translated_name(field[0])
verse_num = field[1:]
verse_list += '---[%s:%s]---\n' % (verse_tag, verse_num)
verse_list += item.text()
verse_list += '\n'
self.verse_form.set_verse(verse_list)
else:
self.verse_form.set_verse('')
if not self.verse_form.exec_():
return
verse_list = self.verse_form.get_all_verses()
verse_list = str(verse_list.replace('\r\n', '\n'))
self.verse_list_widget.clear()
self.verse_list_widget.setRowCount(0)
for row in self.find_verse_split.split(verse_list):
for match in row.split('---['):
for count, parts in enumerate(match.split(']---\n')):
if count == 0:
if len(parts) == 0:
continue
# handling carefully user inputted versetags
separator = parts.find(':')
if separator >= 0:
verse_name = parts[0:separator].strip()
verse_num = parts[separator+1:].strip()
else:
verse_name = parts
verse_num = '1'
verse_index = VerseType.from_loose_input(verse_name)
verse_tag = VerseType.tags[verse_index]
# Later we need to handle v1a as well.
#regex = re.compile(r'(\d+\w.)')
regex = re.compile(r'\D*(\d+)\D*')
match = regex.match(verse_num)
if match:
verse_num = match.group(1)
else:
verse_num = '1'
verse_def = '%s%s' % (verse_tag, verse_num)
else:
if parts.endswith('\n'):
parts = parts.rstrip('\n')
item = QtGui.QTableWidgetItem(parts)
item.setData(QtCore.Qt.UserRole, verse_def)
self.verse_list_widget.setRowCount(self.verse_list_widget.rowCount() + 1)
self.verse_list_widget.setItem(self.verse_list_widget.rowCount() - 1, 0, item)
self.tag_rows()
self.verse_edit_button.setEnabled(False)
self.verse_delete_button.setEnabled(False)
# Check if all verse tags are used.
self.on_verse_order_text_changed(self.verse_order_edit.text())
示例2: translated_name_test
# 需要导入模块: from openlp.plugins.songs.lib import VerseType [as 别名]
# 或者: from openlp.plugins.songs.lib.VerseType import translated_name [as 别名]
def translated_name_test(self):
"""
Test that the translated_name() method returns the correct name
"""
# GIVEN: A mocked out translate() function that just returns what it was given
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
mocked_translate.side_effect = lambda x, y: y
# WHEN: We run the translated_name() method with a "verse"
result = VerseType.translated_name('v')
# THEN: The result should be "Verse"
self.assertEqual(result, 'Verse', 'The result should be "Verse"')
# WHEN: We run the translated_name() method with a "chorus"
result = VerseType.translated_name('c')
# THEN: The result should be "Chorus"
self.assertEqual(result, 'Chorus', 'The result should be "Chorus"')
示例3: insert_verse
# 需要导入模块: from openlp.plugins.songs.lib import VerseType [as 别名]
# 或者: from openlp.plugins.songs.lib.VerseType import translated_name [as 别名]
def insert_verse(self, verse_tag, verse_num=1):
"""
Insert a verse
:param verse_tag: The verse tag
:param verse_num: The verse number
"""
if self.verse_text_edit.textCursor().columnNumber() != 0:
self.verse_text_edit.insertPlainText('\n')
verse_tag = VerseType.translated_name(verse_tag)
self.verse_text_edit.insertPlainText('---[%s:%s]---\n' % (verse_tag, verse_num))
self.verse_text_edit.setFocus()
示例4: translated_invalid_name_with_invalid_default_test
# 需要导入模块: from openlp.plugins.songs.lib import VerseType [as 别名]
# 或者: from openlp.plugins.songs.lib.VerseType import translated_name [as 别名]
def translated_invalid_name_with_invalid_default_test(self):
"""
Test that the translated_name() method returns the specified default tag when passed an invalid tag
"""
# GIVEN: A mocked out translate() function that just returns what it was given
with patch('openlp.plugins.songs.lib.translate') as mocked_translate:
mocked_translate.side_effect = lambda x, y: y
# WHEN: We run the translated_name() method with an invalid verse type and specify an invalid default
result = VerseType.translated_name('q', 29)
# THEN: The result should be "Other"
self.assertEqual(result, 'Other', 'The result should be "Other", but was "%s"' % result)