update functions that were previously methods to drop the '_'

rename _child to to_str because of name conflicts
This commit is contained in:
Simon Hanna 2016-01-07 14:10:31 +01:00
parent 5bc13e45e3
commit d5780b9f78
5 changed files with 38 additions and 38 deletions

View File

@ -273,7 +273,7 @@ class Renderer(OpenLPMixin, RegistryMixin, RegistryProperties):
except ValueError:
text_to_render = text.split('\n[---]\n')[0]
text = ''
text_to_render, raw_tags, html_tags = Renderer._get_start_tags(text_to_render)
text_to_render, raw_tags, html_tags = get_start_tags(text_to_render)
if text:
text = raw_tags + text
else:
@ -441,7 +441,7 @@ class Renderer(OpenLPMixin, RegistryMixin, RegistryProperties):
previous_raw = line + line_end
continue
# Figure out how many words of the line will fit on screen as the line will not fit as a whole.
raw_words = Renderer._words_split(line)
raw_words = Renderer.words_split(line)
html_words = list(map(expand_tags, raw_words))
previous_html, previous_raw = \
self._binary_chop(formatted, previous_html, previous_raw, html_words, raw_words, ' ', line_end)
@ -485,7 +485,7 @@ class Renderer(OpenLPMixin, RegistryMixin, RegistryProperties):
if smallest_index == index or highest_index == index:
index = smallest_index
text = previous_raw.rstrip('<br>') + separator.join(raw_list[:index + 1])
text, raw_tags, html_tags = _get_start_tags(text)
text, raw_tags, html_tags = get_start_tags(text)
formatted.append(text)
previous_html = ''
previous_raw = ''
@ -521,7 +521,7 @@ class Renderer(OpenLPMixin, RegistryMixin, RegistryProperties):
return self.web_frame.contentsSize().height() <= self.empty_height
def _words_split(line):
def words_split(line):
"""
Split the slide up by word so can wrap better
@ -531,7 +531,7 @@ def _words_split(line):
line = line.replace('\n', ' ')
return line.split(' ')
def _get_start_tags(raw_text):
def get_start_tags(raw_text):
"""
Tests the given text for not closed formatting tags and returns a tuple consisting of three unicode strings::

View File

@ -1577,7 +1577,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa
if item is None:
end_pos = len(self.service_items)
else:
end_pos = _get_parent_item_data(item) - 1
end_pos = get_parent_item_data(item) - 1
service_item = self.service_items[start_pos]
self.service_items.remove(service_item)
self.service_items.insert(end_pos, service_item)
@ -1590,21 +1590,21 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa
self.drop_position = len(self.service_items)
else:
# we are over something so lets investigate
pos = _get_parent_item_data(item) - 1
pos = get_parent_item_data(item) - 1
service_item = self.service_items[pos]
if (plugin == service_item['service_item'].name and
service_item['service_item'].is_capable(ItemCapabilities.CanAppend)):
action = self.dnd_menu.exec(QtGui.QCursor.pos())
# New action required
if action == self.new_action:
self.drop_position = _get_parent_item_data(item)
self.drop_position = get_parent_item_data(item)
# Append to existing action
if action == self.add_to_action:
self.drop_position = _get_parent_item_data(item)
self.drop_position = get_parent_item_data(item)
item.setSelected(True)
replace = True
else:
self.drop_position = _get_parent_item_data(item) - 1
self.drop_position = get_parent_item_data(item) - 1
Registry().execute('%s_add_service_item' % plugin, replace)
def update_theme_list(self, theme_list):
@ -1655,7 +1655,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa
return self.drop_position
def _get_parent_item_data(item):
def get_parent_item_data(item):
"""
Finds and returns the parent item for any item

View File

@ -72,7 +72,7 @@ class SongExportForm(OpenLPWizard):
"""
Song wizard specific signals.
"""
self.available_list_widget.itemActivated.connect(_on_item_activated)
self.available_list_widget.itemActivated.connect(on_item_activated)
self.search_line_edit.textEdited.connect(self.on_search_line_edit_changed)
self.uncheck_button.clicked.connect(self.on_uncheck_button_clicked)
self.check_button.clicked.connect(self.on_check_button_clicked)
@ -172,7 +172,7 @@ class SongExportForm(OpenLPWizard):
return True
elif self.currentPage() == self.available_songs_page:
items = [
item for item in _find_list_widget_items(self.available_list_widget) if item.checkState()
item for item in find_list_widget_items(self.available_list_widget) if item.checkState()
]
if not items:
critical_error_message_box(
@ -241,7 +241,7 @@ class SongExportForm(OpenLPWizard):
"""
songs = [
song.data(QtCore.Qt.UserRole)
for song in _find_list_widget_items(self.selected_list_widget)
for song in find_list_widget_items(self.selected_list_widget)
]
exporter = OpenLyricsExport(self, songs, self.directory_line_edit.text())
try:
@ -264,9 +264,9 @@ class SongExportForm(OpenLPWizard):
:param text: The text of the *search_line_edit*.
"""
search_result = [
song for song in _find_list_widget_items(self.available_list_widget, text)
song for song in find_list_widget_items(self.available_list_widget, text)
]
for item in _find_list_widget_items(self.available_list_widget):
for item in find_list_widget_items(self.available_list_widget):
item.setHidden(item not in search_result)
def on_uncheck_button_clicked(self):
@ -297,7 +297,7 @@ class SongExportForm(OpenLPWizard):
self.directory_line_edit, 'last directory export')
def _find_list_widget_items(list_widget, text=''):
def find_list_widget_items(list_widget, text=''):
"""
Returns a list of *QListWidgetItem*s of the ``list_widget``. Note, that hidden items are included.
@ -308,7 +308,7 @@ def _find_list_widget_items(list_widget, text=''):
item for item in list_widget.findItems(text, QtCore.Qt.MatchContains)
]
def _on_item_activated(item):
def on_item_activated(item):
"""
Called, when an item in the *available_list_widget* has been triggered.
The item is check if it was not checked, whereas it is unchecked when it

View File

@ -243,7 +243,7 @@ class FoilPresenter(object):
"""
authors = []
try:
copyright = _child(foilpresenterfolie.copyright.text_)
copyright = to_str(foilpresenterfolie.copyright.text_)
except AttributeError:
copyright = None
if copyright:
@ -336,7 +336,7 @@ class FoilPresenter(object):
:param song: The song object.
"""
try:
song.ccli_number = _child(foilpresenterfolie.ccliid)
song.ccli_number = to_str(foilpresenterfolie.ccliid)
except AttributeError:
song.ccli_number = ''
@ -348,7 +348,7 @@ class FoilPresenter(object):
:param song: The song object.
"""
try:
song.comments = _child(foilpresenterfolie.notiz)
song.comments = to_str(foilpresenterfolie.notiz)
except AttributeError:
song.comments = ''
@ -360,7 +360,7 @@ class FoilPresenter(object):
:param song: The song object.
"""
try:
song.copyright = _child(foilpresenterfolie.copyright.text_)
song.copyright = to_str(foilpresenterfolie.copyright.text_)
except AttributeError:
song.copyright = ''
@ -386,19 +386,19 @@ class FoilPresenter(object):
VerseType.tags[VerseType.PreChorus]: 1
}
if not hasattr(foilpresenterfolie.strophen, 'strophe'):
self.importer.log_error(_child(foilpresenterfolie.titel),
self.importer.log_error(to_str(foilpresenterfolie.titel),
str(translate('SongsPlugin.FoilPresenterSongImport',
'Invalid Foilpresenter song file. No verses found.')))
self.save_song = False
return
for strophe in foilpresenterfolie.strophen.strophe:
text = _child(strophe.text_) if hasattr(strophe, 'text_') else ''
verse_name = _child(strophe.key)
text = to_str(strophe.text_) if hasattr(strophe, 'text_') else ''
verse_name = to_str(strophe.key)
children = strophe.getchildren()
sortnr = False
for child in children:
if child.tag == 'sortnr':
verse_sortnr = _child(strophe.sortnr)
verse_sortnr = to_str(strophe.sortnr)
sortnr = True
# In older Version there is no sortnr, but we need one
if not sortnr:
@ -474,7 +474,7 @@ class FoilPresenter(object):
song.song_number = ''
try:
for bucheintrag in foilpresenterfolie.buch.bucheintrag:
book_name = _child(bucheintrag.name)
book_name = to_str(bucheintrag.name)
if book_name:
book = self.manager.get_object_filtered(Book, Book.name == book_name)
if book is None:
@ -483,8 +483,8 @@ class FoilPresenter(object):
self.manager.save_object(book)
song.song_book_id = book.id
try:
if _child(bucheintrag.nummer):
song.song_number = _child(bucheintrag.nummer)
if to_str(bucheintrag.nummer):
song.song_number = to_str(bucheintrag.nummer)
except AttributeError:
pass
# We only support one song book, so take the first one.
@ -502,13 +502,13 @@ class FoilPresenter(object):
try:
for title_string in foilpresenterfolie.titel.titelstring:
if not song.title:
song.title = _child(title_string)
song.title = to_str(title_string)
song.alternate_title = ''
else:
song.alternate_title = _child(title_string)
song.alternate_title = to_str(title_string)
except AttributeError:
# Use first line of first verse
first_line = _child(foilpresenterfolie.strophen.strophe.text_)
first_line = to_str(foilpresenterfolie.strophen.strophe.text_)
song.title = first_line.split('\n')[0]
def _process_topics(self, foilpresenterfolie, song):
@ -520,7 +520,7 @@ class FoilPresenter(object):
"""
try:
for name in foilpresenterfolie.kategorien.name:
topic_text = _child(name)
topic_text = to_str(name)
if topic_text:
topic = self.manager.get_object_filtered(Topic, Topic.name == topic_text)
if topic is None:
@ -532,7 +532,7 @@ class FoilPresenter(object):
pass
def _child(element):
def to_str(element):
"""
This returns the text of an element as unicode string.

View File

@ -39,7 +39,7 @@ class TestFoilPresenter(TestCase):
"""
# TODO: The following modules still need tests written for
# xml_to_song
# _child
# to_str
# _process_authors
# _process_cclinumber
# _process_comments
@ -50,7 +50,7 @@ class TestFoilPresenter(TestCase):
# _process_topics
def setUp(self):
self.child_patcher = patch('openlp.plugins.songs.lib.importers.foilpresenter._child')
self.to_str_patcher = patch('openlp.plugins.songs.lib.importers.foilpresenter.to_str')
self.clean_song_patcher = patch('openlp.plugins.songs.lib.importers.foilpresenter.clean_song')
self.objectify_patcher = patch('openlp.plugins.songs.lib.importers.foilpresenter.objectify')
self.process_authors_patcher = \
@ -72,7 +72,7 @@ class TestFoilPresenter(TestCase):
self.song_xml_patcher = patch('openlp.plugins.songs.lib.importers.foilpresenter.SongXML')
self.translate_patcher = patch('openlp.plugins.songs.lib.importers.foilpresenter.translate')
self.mocked_child = self.child_patcher.start()
self.mocked_child = self.to_str_patcher.start()
self.mocked_clean_song = self.clean_song_patcher.start()
self.mocked_objectify = self.objectify_patcher.start()
self.mocked_process_authors = self.process_authors_patcher.start()
@ -92,7 +92,7 @@ class TestFoilPresenter(TestCase):
self.mocked_song_import = MagicMock()
def tearDown(self):
self.child_patcher.stop()
self.to_str_patcher.stop()
self.clean_song_patcher.stop()
self.objectify_patcher.stop()
self.process_authors_patcher.stop()