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: except ValueError:
text_to_render = text.split('\n[---]\n')[0] text_to_render = text.split('\n[---]\n')[0]
text = '' 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: if text:
text = raw_tags + text text = raw_tags + text
else: else:
@ -441,7 +441,7 @@ class Renderer(OpenLPMixin, RegistryMixin, RegistryProperties):
previous_raw = line + line_end previous_raw = line + line_end
continue continue
# Figure out how many words of the line will fit on screen as the line will not fit as a whole. # 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)) html_words = list(map(expand_tags, raw_words))
previous_html, previous_raw = \ previous_html, previous_raw = \
self._binary_chop(formatted, previous_html, previous_raw, html_words, raw_words, ' ', line_end) 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: if smallest_index == index or highest_index == index:
index = smallest_index index = smallest_index
text = previous_raw.rstrip('<br>') + separator.join(raw_list[:index + 1]) 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) formatted.append(text)
previous_html = '' previous_html = ''
previous_raw = '' previous_raw = ''
@ -521,7 +521,7 @@ class Renderer(OpenLPMixin, RegistryMixin, RegistryProperties):
return self.web_frame.contentsSize().height() <= self.empty_height 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 Split the slide up by word so can wrap better
@ -531,7 +531,7 @@ def _words_split(line):
line = line.replace('\n', ' ') line = line.replace('\n', ' ')
return line.split(' ') 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:: 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: if item is None:
end_pos = len(self.service_items) end_pos = len(self.service_items)
else: else:
end_pos = _get_parent_item_data(item) - 1 end_pos = get_parent_item_data(item) - 1
service_item = self.service_items[start_pos] service_item = self.service_items[start_pos]
self.service_items.remove(service_item) self.service_items.remove(service_item)
self.service_items.insert(end_pos, 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) self.drop_position = len(self.service_items)
else: else:
# we are over something so lets investigate # 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] service_item = self.service_items[pos]
if (plugin == service_item['service_item'].name and if (plugin == service_item['service_item'].name and
service_item['service_item'].is_capable(ItemCapabilities.CanAppend)): service_item['service_item'].is_capable(ItemCapabilities.CanAppend)):
action = self.dnd_menu.exec(QtGui.QCursor.pos()) action = self.dnd_menu.exec(QtGui.QCursor.pos())
# New action required # New action required
if action == self.new_action: 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 # Append to existing action
if action == self.add_to_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) item.setSelected(True)
replace = True replace = True
else: 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) Registry().execute('%s_add_service_item' % plugin, replace)
def update_theme_list(self, theme_list): def update_theme_list(self, theme_list):
@ -1655,7 +1655,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa
return self.drop_position 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 Finds and returns the parent item for any item

View File

@ -72,7 +72,7 @@ class SongExportForm(OpenLPWizard):
""" """
Song wizard specific signals. 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.search_line_edit.textEdited.connect(self.on_search_line_edit_changed)
self.uncheck_button.clicked.connect(self.on_uncheck_button_clicked) self.uncheck_button.clicked.connect(self.on_uncheck_button_clicked)
self.check_button.clicked.connect(self.on_check_button_clicked) self.check_button.clicked.connect(self.on_check_button_clicked)
@ -172,7 +172,7 @@ class SongExportForm(OpenLPWizard):
return True return True
elif self.currentPage() == self.available_songs_page: elif self.currentPage() == self.available_songs_page:
items = [ 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: if not items:
critical_error_message_box( critical_error_message_box(
@ -241,7 +241,7 @@ class SongExportForm(OpenLPWizard):
""" """
songs = [ songs = [
song.data(QtCore.Qt.UserRole) 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()) exporter = OpenLyricsExport(self, songs, self.directory_line_edit.text())
try: try:
@ -264,9 +264,9 @@ class SongExportForm(OpenLPWizard):
:param text: The text of the *search_line_edit*. :param text: The text of the *search_line_edit*.
""" """
search_result = [ 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) item.setHidden(item not in search_result)
def on_uncheck_button_clicked(self): def on_uncheck_button_clicked(self):
@ -297,7 +297,7 @@ class SongExportForm(OpenLPWizard):
self.directory_line_edit, 'last directory export') 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. 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) 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. 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 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 = [] authors = []
try: try:
copyright = _child(foilpresenterfolie.copyright.text_) copyright = to_str(foilpresenterfolie.copyright.text_)
except AttributeError: except AttributeError:
copyright = None copyright = None
if copyright: if copyright:
@ -336,7 +336,7 @@ class FoilPresenter(object):
:param song: The song object. :param song: The song object.
""" """
try: try:
song.ccli_number = _child(foilpresenterfolie.ccliid) song.ccli_number = to_str(foilpresenterfolie.ccliid)
except AttributeError: except AttributeError:
song.ccli_number = '' song.ccli_number = ''
@ -348,7 +348,7 @@ class FoilPresenter(object):
:param song: The song object. :param song: The song object.
""" """
try: try:
song.comments = _child(foilpresenterfolie.notiz) song.comments = to_str(foilpresenterfolie.notiz)
except AttributeError: except AttributeError:
song.comments = '' song.comments = ''
@ -360,7 +360,7 @@ class FoilPresenter(object):
:param song: The song object. :param song: The song object.
""" """
try: try:
song.copyright = _child(foilpresenterfolie.copyright.text_) song.copyright = to_str(foilpresenterfolie.copyright.text_)
except AttributeError: except AttributeError:
song.copyright = '' song.copyright = ''
@ -386,19 +386,19 @@ class FoilPresenter(object):
VerseType.tags[VerseType.PreChorus]: 1 VerseType.tags[VerseType.PreChorus]: 1
} }
if not hasattr(foilpresenterfolie.strophen, 'strophe'): 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', str(translate('SongsPlugin.FoilPresenterSongImport',
'Invalid Foilpresenter song file. No verses found.'))) 'Invalid Foilpresenter song file. No verses found.')))
self.save_song = False self.save_song = False
return return
for strophe in foilpresenterfolie.strophen.strophe: for strophe in foilpresenterfolie.strophen.strophe:
text = _child(strophe.text_) if hasattr(strophe, 'text_') else '' text = to_str(strophe.text_) if hasattr(strophe, 'text_') else ''
verse_name = _child(strophe.key) verse_name = to_str(strophe.key)
children = strophe.getchildren() children = strophe.getchildren()
sortnr = False sortnr = False
for child in children: for child in children:
if child.tag == 'sortnr': if child.tag == 'sortnr':
verse_sortnr = _child(strophe.sortnr) verse_sortnr = to_str(strophe.sortnr)
sortnr = True sortnr = True
# In older Version there is no sortnr, but we need one # In older Version there is no sortnr, but we need one
if not sortnr: if not sortnr:
@ -474,7 +474,7 @@ class FoilPresenter(object):
song.song_number = '' song.song_number = ''
try: try:
for bucheintrag in foilpresenterfolie.buch.bucheintrag: for bucheintrag in foilpresenterfolie.buch.bucheintrag:
book_name = _child(bucheintrag.name) book_name = to_str(bucheintrag.name)
if book_name: if book_name:
book = self.manager.get_object_filtered(Book, Book.name == book_name) book = self.manager.get_object_filtered(Book, Book.name == book_name)
if book is None: if book is None:
@ -483,8 +483,8 @@ class FoilPresenter(object):
self.manager.save_object(book) self.manager.save_object(book)
song.song_book_id = book.id song.song_book_id = book.id
try: try:
if _child(bucheintrag.nummer): if to_str(bucheintrag.nummer):
song.song_number = _child(bucheintrag.nummer) song.song_number = to_str(bucheintrag.nummer)
except AttributeError: except AttributeError:
pass pass
# We only support one song book, so take the first one. # We only support one song book, so take the first one.
@ -502,13 +502,13 @@ class FoilPresenter(object):
try: try:
for title_string in foilpresenterfolie.titel.titelstring: for title_string in foilpresenterfolie.titel.titelstring:
if not song.title: if not song.title:
song.title = _child(title_string) song.title = to_str(title_string)
song.alternate_title = '' song.alternate_title = ''
else: else:
song.alternate_title = _child(title_string) song.alternate_title = to_str(title_string)
except AttributeError: except AttributeError:
# Use first line of first verse # 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] song.title = first_line.split('\n')[0]
def _process_topics(self, foilpresenterfolie, song): def _process_topics(self, foilpresenterfolie, song):
@ -520,7 +520,7 @@ class FoilPresenter(object):
""" """
try: try:
for name in foilpresenterfolie.kategorien.name: for name in foilpresenterfolie.kategorien.name:
topic_text = _child(name) topic_text = to_str(name)
if topic_text: if topic_text:
topic = self.manager.get_object_filtered(Topic, Topic.name == topic_text) topic = self.manager.get_object_filtered(Topic, Topic.name == topic_text)
if topic is None: if topic is None:
@ -532,7 +532,7 @@ class FoilPresenter(object):
pass pass
def _child(element): def to_str(element):
""" """
This returns the text of an element as unicode string. 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 # TODO: The following modules still need tests written for
# xml_to_song # xml_to_song
# _child # to_str
# _process_authors # _process_authors
# _process_cclinumber # _process_cclinumber
# _process_comments # _process_comments
@ -50,7 +50,7 @@ class TestFoilPresenter(TestCase):
# _process_topics # _process_topics
def setUp(self): 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.clean_song_patcher = patch('openlp.plugins.songs.lib.importers.foilpresenter.clean_song')
self.objectify_patcher = patch('openlp.plugins.songs.lib.importers.foilpresenter.objectify') self.objectify_patcher = patch('openlp.plugins.songs.lib.importers.foilpresenter.objectify')
self.process_authors_patcher = \ self.process_authors_patcher = \
@ -72,7 +72,7 @@ class TestFoilPresenter(TestCase):
self.song_xml_patcher = patch('openlp.plugins.songs.lib.importers.foilpresenter.SongXML') self.song_xml_patcher = patch('openlp.plugins.songs.lib.importers.foilpresenter.SongXML')
self.translate_patcher = patch('openlp.plugins.songs.lib.importers.foilpresenter.translate') 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_clean_song = self.clean_song_patcher.start()
self.mocked_objectify = self.objectify_patcher.start() self.mocked_objectify = self.objectify_patcher.start()
self.mocked_process_authors = self.process_authors_patcher.start() self.mocked_process_authors = self.process_authors_patcher.start()
@ -92,7 +92,7 @@ class TestFoilPresenter(TestCase):
self.mocked_song_import = MagicMock() self.mocked_song_import = MagicMock()
def tearDown(self): def tearDown(self):
self.child_patcher.stop() self.to_str_patcher.stop()
self.clean_song_patcher.stop() self.clean_song_patcher.stop()
self.objectify_patcher.stop() self.objectify_patcher.stop()
self.process_authors_patcher.stop() self.process_authors_patcher.stop()