Various clean ups:

- refactor method argument
- some variable name fixes
- converted dict to list
- added missing lines

bzr-revno: 1996
This commit is contained in:
Andreas Preikschat 2012-06-17 09:16:34 +01:00 committed by Tim Bentley
commit f542ebf94d
10 changed files with 44 additions and 48 deletions

View File

@ -234,10 +234,10 @@ class Renderer(object):
serviceItem = ServiceItem()
if self.force_page:
# make big page for theme edit dialog to get line count
serviceItem.add_from_text(u'', VERSE_FOR_LINE_COUNT)
serviceItem.add_from_text(VERSE_FOR_LINE_COUNT)
else:
self.image_manager.deleteImage(theme_data.theme_name)
serviceItem.add_from_text(u'', VERSE)
serviceItem.add_from_text(VERSE)
serviceItem.renderer = self
serviceItem.raw_footer = FOOTER
# if No file do not update cache

View File

@ -220,20 +220,17 @@ class ServiceItem(object):
self.image_border)
self._new_item()
def add_from_text(self, title, raw_slide, verse_tag=None):
def add_from_text(self, raw_slide, verse_tag=None):
"""
Add a text slide to the service item.
``frame_title``
The title of the slide in the service item.
``raw_slide``
The raw text of the slide.
"""
if verse_tag:
verse_tag = verse_tag.upper()
self.service_item_type = ServiceItemType.Text
title = title.split(u'\n')[0]
title = raw_slide[:30].split(u'\n')[0]
self._raw_frames.append(
{u'title': title, u'raw_slide': raw_slide, u'verseTag': verse_tag})
self._new_item()

View File

@ -63,8 +63,7 @@ class BiblePlugin(Plugin):
# unicode(UiStrings().Export))
# Set to invisible until we can export bibles
self.exportBibleItem.setVisible(False)
if self.manager.old_bible_databases:
self.toolsUpgradeItem.setVisible(True)
self.toolsUpgradeItem.setVisible(bool(self.manager.old_bible_databases))
def finalise(self):
"""

View File

@ -63,6 +63,7 @@ class Verse(BaseModel):
"""
pass
def init_schema(url):
"""
Setup a bible database connection and initialise the database schema.

View File

@ -418,7 +418,7 @@ class BibleMediaItem(MediaManagerItem):
``bible``
The bible to initialise (unicode).
``last_book_id``
The "book reference id" of the book which is choosen at the moment.
(int)
@ -976,7 +976,7 @@ class BibleMediaItem(MediaManagerItem):
else:
service_item.theme = self.settings.bible_theme
for slide in raw_slides:
service_item.add_from_text(slide[:30], slide)
service_item.add_from_text(slide)
return True
def formatTitle(self, start_bitem, old_bitem):

View File

@ -210,12 +210,12 @@ class CustomMediaItem(MediaManagerItem):
theme = customSlide.theme_name
if theme:
service_item.theme = theme
customXML = CustomXMLParser(customSlide.text)
verseList = customXML.get_verses()
raw_slides = [verse[1] for verse in verseList]
custom_xml = CustomXMLParser(customSlide.text)
verse_list = custom_xml.get_verses()
raw_slides = [verse[1] for verse in verse_list]
service_item.title = title
for slide in raw_slides:
service_item.add_from_text(slide[:30], slide)
service_item.add_from_text(slide)
if Settings().value(self.settingsSection + u'/display footer',
QtCore.QVariant(True)).toBool() or credit:
service_item.raw_footer.append(u' '.join([title, credit]))

View File

@ -57,19 +57,17 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
self.firstNameEdit.setFocus()
return QtGui.QDialog.exec_(self)
def onFirstNameEditTextEdited(self, text):
def onFirstNameEditTextEdited(self, display_name):
if not self._autoDisplayName:
return
display_name = text
if self.lastNameEdit.text() != u'':
if not self.lastNameEdit.text():
display_name = display_name + u' ' + self.lastNameEdit.text()
self.displayEdit.setText(display_name)
def onLastNameEditTextEdited(self, text):
def onLastNameEditTextEdited(self, display_name):
if not self._autoDisplayName:
return
display_name = text
if self.firstNameEdit.text() != u'':
if not self.firstNameEdit.text():
display_name = self.firstNameEdit.text() + u' ' + display_name
self.displayEdit.setText(display_name)

View File

@ -256,8 +256,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
verse_tags_translated = False
if self.song.lyrics.startswith(u'<?xml version='):
songXML = SongXML()
verseList = songXML.get_verses(self.song.lyrics)
for count, verse in enumerate(verseList):
verse_list = songXML.get_verses(self.song.lyrics)
for count, verse in enumerate(verse_list):
self.verseListWidget.setRowCount(
self.verseListWidget.rowCount() + 1)
# This silently migrates from localized verse type markup.
@ -479,27 +479,26 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
def onVerseEditButtonClicked(self):
item = self.verseListWidget.currentItem()
if item:
tempText = item.text()
verseId = unicode(item.data(QtCore.Qt.UserRole).toString())
self.verseForm.setVerse(tempText, True, verseId)
temp_text = item.text()
verse_id = unicode(item.data(QtCore.Qt.UserRole).toString())
self.verseForm.setVerse(temp_text, True, verse_id)
if self.verseForm.exec_():
after_text, verse_tag, verse_num = self.verseForm.getVerse()
verse_def = u'%s%s' % (verse_tag, verse_num)
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(verse_def))
item.setText(after_text)
# number of lines has changed, repaint the list moving the data
if len(tempText.split(u'\n')) != len(after_text.split(u'\n')):
tempList = {}
tempId = {}
if len(temp_text.split(u'\n')) != len(after_text.split(u'\n')):
temp_list = []
temp_ids = []
for row in range(self.verseListWidget.rowCount()):
tempList[row] = self.verseListWidget.item(row, 0)\
.text()
tempId[row] = self.verseListWidget.item(row, 0)\
.data(QtCore.Qt.UserRole)
item = self.verseListWidget.item(row, 0)
temp_list.append(item.text())
temp_ids.append(item.data(QtCore.Qt.UserRole))
self.verseListWidget.clear()
for row in range (0, len(tempList)):
item = QtGui.QTableWidgetItem(tempList[row], 0)
item.setData(QtCore.Qt.UserRole, tempId[row])
for row, entry in enumerate(temp_list):
item = QtGui.QTableWidgetItem(entry, 0)
item.setData(QtCore.Qt.UserRole, temp_ids[row])
self.verseListWidget.setItem(row, 0, item)
self.tagRows()
# Check if all verse tags are used.
@ -923,9 +922,9 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
multiple = []
for i in range(self.verseListWidget.rowCount()):
item = self.verseListWidget.item(i, 0)
verseId = unicode(item.data(QtCore.Qt.UserRole).toString())
verse_tag = verseId[0]
verse_num = verseId[1:]
verse_id = unicode(item.data(QtCore.Qt.UserRole).toString())
verse_tag = verse_id[0]
verse_num = verse_id[1:]
sxml.add_verse_to_lyrics(verse_tag, verse_num,
unicode(item.text()))
if verse_num > u'1' and verse_tag not in multiple:

View File

@ -193,6 +193,7 @@ class VerseType(object):
return default
return verse_index
def retrieve_windows_encoding(recommendation=None):
"""
Determines which encoding to use on an information source. The process uses
@ -252,12 +253,14 @@ def retrieve_windows_encoding(recommendation=None):
return None
return filter(lambda item: item[1] == choice[0], encodings)[0][0]
def clean_string(string):
"""
Strips punctuation from the passed string to assist searching
"""
return WHITESPACE.sub(u' ', APOSTROPHE.sub(u'', string)).lower()
def clean_title(title):
"""
Cleans the song title by removing Unicode control chars groups C0 & C1,
@ -265,6 +268,7 @@ def clean_title(title):
"""
return CONTROL_CHARS.sub(u'', title).rstrip()
def clean_song(manager, song):
"""
Cleans the search title, rebuilds the search lyrics, adds a default author

View File

@ -465,14 +465,14 @@ class SongMediaItem(MediaManagerItem):
service_item.theme = song.theme_name
service_item.edit_id = item_id
if song.lyrics.startswith(u'<?xml version='):
verseList = SongXML().get_verses(song.lyrics)
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(
verseList[0][0][u'type'])) is not None:
verse_list[0][0][u'type'])) is not None:
verse_tags_translated = True
if not song.verse_order.strip():
for verse in verseList:
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']
@ -486,14 +486,13 @@ class SongMediaItem(MediaManagerItem):
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(
verse[1][:30], unicode(verse[1]), verse_def)
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 verseList:
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:]):
@ -506,12 +505,11 @@ class SongMediaItem(MediaManagerItem):
verse_tag = VerseType.TranslatedTags[verse_index]
verse_def = u'%s%s' % (verse_tag,
verse[0][u'label'])
service_item.add_from_text(
verse[1][:30], verse[1], verse_def)
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(slide[:30], unicode(slide))
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)