forked from openlp/openlp
Bug #875286
use VerseType.Other if it is not recogniced during OpenSong import. bzr-revno: 1805
This commit is contained in:
commit
fee0f79a73
@ -278,13 +278,11 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
if len(verse_tag) > 1:
|
if len(verse_tag) > 1:
|
||||||
index = VerseType.from_translated_string(verse_tag)
|
index = VerseType.from_translated_string(verse_tag)
|
||||||
if index is None:
|
if index is None:
|
||||||
index = VerseType.from_string(verse_tag)
|
index = VerseType.from_string(verse_tag, None)
|
||||||
else:
|
else:
|
||||||
verse_tags_translated = True
|
verse_tags_translated = True
|
||||||
if index is None:
|
if index is None:
|
||||||
index = VerseType.from_tag(verse_tag)
|
index = VerseType.from_tag(verse_tag)
|
||||||
if index is None:
|
|
||||||
index = VerseType.Other
|
|
||||||
verse[0][u'type'] = VerseType.Tags[index]
|
verse[0][u'type'] = VerseType.Tags[index]
|
||||||
if verse[0][u'label'] == u'':
|
if verse[0][u'label'] == u'':
|
||||||
verse[0][u'label'] = u'1'
|
verse[0][u'label'] = u'1'
|
||||||
@ -308,7 +306,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
for verse_def in self.song.verse_order.split():
|
for verse_def in self.song.verse_order.split():
|
||||||
verse_index = None
|
verse_index = None
|
||||||
if verse_tags_translated:
|
if verse_tags_translated:
|
||||||
verse_index = VerseType.from_translated_tag(verse_def[0])
|
verse_index = VerseType.from_translated_tag(verse_def[0],
|
||||||
|
None)
|
||||||
if verse_index is None:
|
if verse_index is None:
|
||||||
verse_index = VerseType.from_tag(verse_def[0])
|
verse_index = VerseType.from_tag(verse_def[0])
|
||||||
verse_tag = VerseType.TranslatedTags[verse_index].upper()
|
verse_tag = VerseType.TranslatedTags[verse_index].upper()
|
||||||
@ -606,14 +605,14 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
order_names = unicode(self.verseOrderEdit.text()).split()
|
order_names = unicode(self.verseOrderEdit.text()).split()
|
||||||
for item in order_names:
|
for item in order_names:
|
||||||
if len(item) == 1:
|
if len(item) == 1:
|
||||||
verse_index = VerseType.from_translated_tag(item)
|
verse_index = VerseType.from_translated_tag(item, None)
|
||||||
if verse_index is not None:
|
if verse_index is not None:
|
||||||
order.append(VerseType.Tags[verse_index] + u'1')
|
order.append(VerseType.Tags[verse_index] + u'1')
|
||||||
else:
|
else:
|
||||||
# it matches no verses anyway
|
# it matches no verses anyway
|
||||||
order.append(u'')
|
order.append(u'')
|
||||||
else:
|
else:
|
||||||
verse_index = VerseType.from_translated_tag(item[0])
|
verse_index = VerseType.from_translated_tag(item[0], None)
|
||||||
if verse_index is None:
|
if verse_index is None:
|
||||||
# it matches no verses anyway
|
# it matches no verses anyway
|
||||||
order.append(u'')
|
order.append(u'')
|
||||||
|
@ -113,7 +113,7 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
|
|||||||
verse_num = int(match.group(2))
|
verse_num = int(match.group(2))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
verse_num = 1
|
verse_num = 1
|
||||||
verse_type_index = VerseType.from_loose_input(verse_tag)
|
verse_type_index = VerseType.from_loose_input(verse_tag, None)
|
||||||
if verse_type_index is not None:
|
if verse_type_index is not None:
|
||||||
self.verseNumberBox.setValue(verse_num)
|
self.verseNumberBox.setValue(verse_num)
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
|
|||||||
match = VERSE_REGEX.match(text)
|
match = VERSE_REGEX.match(text)
|
||||||
if match:
|
if match:
|
||||||
verse_type = match.group(1)
|
verse_type = match.group(1)
|
||||||
verse_type_index = VerseType.from_loose_input(verse_type)
|
verse_type_index = VerseType.from_loose_input(verse_type, None)
|
||||||
try:
|
try:
|
||||||
verse_number = int(match.group(2))
|
verse_number = int(match.group(2))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -153,7 +153,7 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
|
|||||||
tag=u'%s1' % VerseType.Tags[VerseType.Verse]):
|
tag=u'%s1' % VerseType.Tags[VerseType.Verse]):
|
||||||
self.hasSingleVerse = single
|
self.hasSingleVerse = single
|
||||||
if single:
|
if single:
|
||||||
verse_type_index = VerseType.from_tag(tag[0])
|
verse_type_index = VerseType.from_tag(tag[0], None)
|
||||||
verse_number = tag[1:]
|
verse_number = tag[1:]
|
||||||
if verse_type_index is not None:
|
if verse_type_index is not None:
|
||||||
self.verseTypeComboBox.setCurrentIndex(verse_type_index)
|
self.verseTypeComboBox.setCurrentIndex(verse_type_index)
|
||||||
|
@ -69,7 +69,7 @@ class VerseType(object):
|
|||||||
TranslatedTags = [name[0].lower() for name in TranslatedNames]
|
TranslatedTags = [name[0].lower() for name in TranslatedNames]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def translated_tag(verse_tag, strict=False):
|
def translated_tag(verse_tag, default=Other):
|
||||||
"""
|
"""
|
||||||
Return the translated UPPERCASE tag for a given tag,
|
Return the translated UPPERCASE tag for a given tag,
|
||||||
used to show translated verse tags in UI
|
used to show translated verse tags in UI
|
||||||
@ -77,86 +77,84 @@ class VerseType(object):
|
|||||||
``verse_tag``
|
``verse_tag``
|
||||||
The string to return a VerseType for
|
The string to return a VerseType for
|
||||||
|
|
||||||
``strict``
|
``default``
|
||||||
Determines if the default Other or None should be returned
|
Default return value if no matching tag is found
|
||||||
"""
|
"""
|
||||||
if strict:
|
|
||||||
not_found_value = None
|
|
||||||
else:
|
|
||||||
not_found_value = VerseType.TranslatedTags[VerseType.Other].upper()
|
|
||||||
verse_tag = verse_tag[0].lower()
|
verse_tag = verse_tag[0].lower()
|
||||||
for num, tag in enumerate(VerseType.Tags):
|
for num, tag in enumerate(VerseType.Tags):
|
||||||
if verse_tag == tag:
|
if verse_tag == tag:
|
||||||
return VerseType.TranslatedTags[num].upper()
|
return VerseType.TranslatedTags[num].upper()
|
||||||
return not_found_value
|
if default in VerseType.TranslatedTags:
|
||||||
|
return VerseType.TranslatedTags[default].upper()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def translated_name(verse_tag, strict=False):
|
def translated_name(verse_tag, default=Other):
|
||||||
"""
|
"""
|
||||||
Return the translated name for a given tag
|
Return the translated name for a given tag
|
||||||
|
|
||||||
``verse_tag``
|
``verse_tag``
|
||||||
The string to return a VerseType for
|
The string to return a VerseType for
|
||||||
|
|
||||||
``strict``
|
``default``
|
||||||
Determines if the default Other or None should be returned
|
Default return value if no matching tag is found
|
||||||
"""
|
"""
|
||||||
if strict:
|
|
||||||
not_found_value = None
|
|
||||||
else:
|
|
||||||
not_found_value = VerseType.TranslatedNames[VerseType.Other]
|
|
||||||
verse_tag = verse_tag[0].lower()
|
verse_tag = verse_tag[0].lower()
|
||||||
for num, tag in enumerate(VerseType.Tags):
|
for num, tag in enumerate(VerseType.Tags):
|
||||||
if verse_tag == tag:
|
if verse_tag == tag:
|
||||||
return VerseType.TranslatedNames[num]
|
return VerseType.TranslatedNames[num]
|
||||||
return not_found_value
|
if default in VerseType.TranslatedNames:
|
||||||
|
return VerseType.TranslatedNames[default]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_tag(verse_tag, strict=False):
|
def from_tag(verse_tag, default=Other):
|
||||||
"""
|
"""
|
||||||
Return the VerseType for a given tag
|
Return the VerseType for a given tag
|
||||||
|
|
||||||
``verse_tag``
|
``verse_tag``
|
||||||
The string to return a VerseType for
|
The string to return a VerseType for
|
||||||
|
|
||||||
``strict``
|
``default``
|
||||||
Determines if the default Other or None should be returned
|
Default return value if no matching tag is found
|
||||||
"""
|
"""
|
||||||
if strict:
|
|
||||||
no_return_value = None
|
|
||||||
else:
|
|
||||||
no_return_value = VerseType.Other
|
|
||||||
verse_tag = verse_tag[0].lower()
|
verse_tag = verse_tag[0].lower()
|
||||||
for num, tag in enumerate(VerseType.Tags):
|
for num, tag in enumerate(VerseType.Tags):
|
||||||
if verse_tag == tag:
|
if verse_tag == tag:
|
||||||
return num
|
return num
|
||||||
return no_return_value
|
return default
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_translated_tag(verse_tag):
|
def from_translated_tag(verse_tag, default=Other):
|
||||||
"""
|
"""
|
||||||
Return the VerseType for a given tag
|
Return the VerseType for a given tag
|
||||||
|
|
||||||
``verse_tag``
|
``verse_tag``
|
||||||
The string to return a VerseType for
|
The string to return a VerseType for
|
||||||
|
|
||||||
|
``default``
|
||||||
|
Default return value if no matching tag is found
|
||||||
"""
|
"""
|
||||||
verse_tag = verse_tag[0].lower()
|
verse_tag = verse_tag[0].lower()
|
||||||
for num, tag in enumerate(VerseType.TranslatedTags):
|
for num, tag in enumerate(VerseType.TranslatedTags):
|
||||||
if verse_tag == tag:
|
if verse_tag == tag:
|
||||||
return num
|
return num
|
||||||
|
return default
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_string(verse_name):
|
def from_string(verse_name, default=Other):
|
||||||
"""
|
"""
|
||||||
Return the VerseType for a given string
|
Return the VerseType for a given string
|
||||||
|
|
||||||
``verse_name``
|
``verse_name``
|
||||||
The string to return a VerseType for
|
The string to return a VerseType for
|
||||||
|
|
||||||
|
``default``
|
||||||
|
Default return value if no matching tag is found
|
||||||
"""
|
"""
|
||||||
verse_name = verse_name.lower()
|
verse_name = verse_name.lower()
|
||||||
for num, name in enumerate(VerseType.Names):
|
for num, name in enumerate(VerseType.Names):
|
||||||
if verse_name == name.lower():
|
if verse_name == name.lower():
|
||||||
return num
|
return num
|
||||||
|
return default
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_translated_string(verse_name):
|
def from_translated_string(verse_name):
|
||||||
@ -172,23 +170,26 @@ class VerseType(object):
|
|||||||
return num
|
return num
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_loose_input(verse_name):
|
def from_loose_input(verse_name, default=Other):
|
||||||
"""
|
"""
|
||||||
Return the VerseType for a given string, Other if not found
|
Return the VerseType for a given string
|
||||||
|
|
||||||
``verse_name``
|
``verse_name``
|
||||||
The string to return a VerseType for
|
The string to return a VerseType for
|
||||||
|
|
||||||
|
``default``
|
||||||
|
Default return value if no matching tag is found
|
||||||
"""
|
"""
|
||||||
verse_index = None
|
|
||||||
if len(verse_name) > 1:
|
if len(verse_name) > 1:
|
||||||
verse_index = VerseType.from_translated_string(verse_name)
|
verse_index = VerseType.from_translated_string(verse_name)
|
||||||
if verse_index is None:
|
if verse_index is None:
|
||||||
verse_index = VerseType.from_string(verse_name)
|
verse_index = VerseType.from_string(verse_name, default)
|
||||||
elif len(verse_name) == 1:
|
elif len(verse_name) == 1:
|
||||||
|
verse_index = VerseType.from_translated_tag(verse_name, None)
|
||||||
if verse_index is None:
|
if verse_index is None:
|
||||||
verse_index = VerseType.from_translated_tag(verse_name)
|
verse_index = VerseType.from_tag(verse_name, default)
|
||||||
if verse_index is None:
|
else:
|
||||||
verse_index = VerseType.from_tag(verse_name)
|
return default
|
||||||
return verse_index
|
return verse_index
|
||||||
|
|
||||||
def retrieve_windows_encoding(recommendation=None):
|
def retrieve_windows_encoding(recommendation=None):
|
||||||
|
@ -457,7 +457,7 @@ class SongMediaItem(MediaManagerItem):
|
|||||||
verse_index = \
|
verse_index = \
|
||||||
VerseType.from_translated_string(verse_tag)
|
VerseType.from_translated_string(verse_tag)
|
||||||
if verse_index is None:
|
if verse_index is None:
|
||||||
verse_index = VerseType.from_string(verse_tag)
|
verse_index = VerseType.from_string(verse_tag, None)
|
||||||
if verse_index is None:
|
if verse_index is None:
|
||||||
verse_index = VerseType.from_tag(verse_tag)
|
verse_index = VerseType.from_tag(verse_tag)
|
||||||
verse_tag = VerseType.TranslatedTags[verse_index].upper()
|
verse_tag = VerseType.TranslatedTags[verse_index].upper()
|
||||||
@ -479,8 +479,6 @@ class SongMediaItem(MediaManagerItem):
|
|||||||
else:
|
else:
|
||||||
verse_index = VerseType.from_tag(
|
verse_index = VerseType.from_tag(
|
||||||
verse[0][u'type'])
|
verse[0][u'type'])
|
||||||
if verse_index is None:
|
|
||||||
verse_index = VerseType.Other
|
|
||||||
verse_tag = VerseType.TranslatedTags[verse_index]
|
verse_tag = VerseType.TranslatedTags[verse_index]
|
||||||
verse_def = u'%s%s' % (verse_tag,
|
verse_def = u'%s%s' % (verse_tag,
|
||||||
verse[0][u'label'])
|
verse[0][u'label'])
|
||||||
|
Loading…
Reference in New Issue
Block a user