Even more variables adapted to PEP8. Sentencify lots of comments.

This commit is contained in:
Patrick Zimmermann 2013-02-18 19:46:50 +01:00
parent 8a19e75be3
commit 10d9b506a6
6 changed files with 65 additions and 66 deletions

View File

@ -93,16 +93,16 @@ class OpenLPWizard(QtGui.QWizard):
``image``
The image to display on the "welcome" page of the wizard. Should be 163x350.
``addProgressPage``
``add_progress_page``
Whether to add a progress page with a progressbar at the end of the wizard.
"""
def __init__(self, parent, plugin, name, image, addProgressPage=True):
def __init__(self, parent, plugin, name, image, add_progress_page=True):
"""
Constructor
"""
QtGui.QWizard.__init__(self, parent)
self.plugin = plugin
self.withProgressPage = addProgressPage
self.with_progress_page = add_progress_page
self.setObjectName(name)
self.openIcon = build_icon(u':/general/general_open.png')
self.deleteIcon = build_icon(u':/general/general_delete.png')
@ -113,7 +113,7 @@ class OpenLPWizard(QtGui.QWizard):
self.customInit()
self.customSignals()
QtCore.QObject.connect(self, QtCore.SIGNAL(u'currentIdChanged(int)'), self.onCurrentIdChanged)
if self.withProgressPage:
if self.with_progress_page:
QtCore.QObject.connect(self.errorCopyToButton, QtCore.SIGNAL(u'clicked()'), self.onErrorCopyToButtonClicked)
QtCore.QObject.connect(self.errorSaveToButton, QtCore.SIGNAL(u'clicked()'), self.onErrorSaveToButtonClicked)
@ -128,7 +128,7 @@ class OpenLPWizard(QtGui.QWizard):
QtGui.QWizard.NoBackButtonOnLastPage)
add_welcome_page(self, image)
self.addCustomPages()
if self.withProgressPage:
if self.with_progress_page:
self.addProgressPage()
self.retranslateUi()
@ -191,7 +191,7 @@ class OpenLPWizard(QtGui.QWizard):
Stop the wizard on cancel button, close button or ESC key.
"""
log.debug(u'Wizard cancelled by user.')
if self.withProgressPage and self.currentPage() == self.progressPage:
if self.with_progress_page and self.currentPage() == self.progressPage:
Registry().execute(u'openlp_stop_wizard')
self.done(QtGui.QDialog.Rejected)
@ -199,7 +199,7 @@ class OpenLPWizard(QtGui.QWizard):
"""
Perform necessary functions depending on which wizard page is active.
"""
if self.withProgressPage and self.page(pageId) == self.progressPage:
if self.with_progress_page and self.page(pageId) == self.progressPage:
self.preWizard()
self.performWizard()
self.postWizard()

View File

@ -80,7 +80,7 @@ class DuplicateSongRemovalForm(OpenLPWizard):
"""
Add song wizard specific pages.
"""
#add custom pages
# Add custom pages.
self.searching_page = QtGui.QWizardPage()
self.searching_page.setObjectName(u'searching_page')
self.searching_vertical_layout = QtGui.QVBoxLayout(self.searching_page)
@ -117,8 +117,8 @@ class DuplicateSongRemovalForm(OpenLPWizard):
self.songs_horizontal_scroll_area.setWidget(self.songs_horizontal_songs_widget)
self.review_layout.addWidget(self.songs_horizontal_scroll_area)
self.review_page_id = self.addPage(self.review_page)
#add a dummy page to the end, to prevent the finish button to appear and the next button do disappear on the
#review page
# Add a dummy page to the end, to prevent the finish button to appear and the next button do disappear on the
#review page.
self.dummy_page = QtGui.QWizardPage()
self.dummy_page_id = self.addPage(self.dummy_page)
@ -153,17 +153,17 @@ class DuplicateSongRemovalForm(OpenLPWizard):
``page_id``
ID of the page the wizard changed to.
"""
#hide back button
# Hide back button.
self.button(QtGui.QWizard.BackButton).hide()
if page_id == self.searching_page_id:
#search duplicate songs
# Search duplicate songs.
max_songs = self.plugin.manager.get_object_count(Song)
if max_songs == 0 or max_songs == 1:
self.duplicate_search_progress_bar.setMaximum(1)
self.duplicate_search_progress_bar.setValue(1)
self.notify_no_duplicates()
return
# with x songs we have x*(x - 1) / 2 comparisons
# With x songs we have x*(x - 1) / 2 comparisons.
max_progress_count = max_songs * (max_songs - 1) / 2
self.duplicate_search_progress_bar.setMaximum(max_progress_count)
songs = self.plugin.manager.get_all_objects(Song)
@ -212,7 +212,7 @@ class DuplicateSongRemovalForm(OpenLPWizard):
duplicate_group_found = False
duplicate_added = False
for duplicate_group in self.duplicate_song_list:
#skip the first song in the duplicate lists, since the first one has to be an earlier song
# Skip the first song in the duplicate lists, since the first one has to be an earlier song.
if search_song in duplicate_group and not duplicate_song in duplicate_group:
duplicate_group.append(duplicate_song)
duplicate_group_found = True
@ -253,7 +253,7 @@ class DuplicateSongRemovalForm(OpenLPWizard):
on the review page as long as there are more song duplicates to review.
"""
if self.currentId() == self.review_page_id:
#as long as it's not the last duplicate list entry we revisit the review page
# As long as it's not the last duplicate list entry we revisit the review page.
if len(self.duplicate_song_list) == 1:
return True
else:
@ -270,9 +270,9 @@ class DuplicateSongRemovalForm(OpenLPWizard):
``song_review_widget``
The SongReviewWidget whose song we should delete.
"""
#remove song from duplicate song list
# Remove song from duplicate song list.
self.duplicate_song_list[-1].remove(song_review_widget.song)
#remove song
# Remove song from the database.
item_id = song_review_widget.song.id
media_files = self.plugin.manager.get_all_objects(MediaFile,
MediaFile.song_id == item_id)
@ -290,12 +290,12 @@ class DuplicateSongRemovalForm(OpenLPWizard):
except OSError:
log.exception(u'Could not remove directory: %s', save_path)
self.plugin.manager.delete_object(Song, item_id)
# remove GUI elements
# Remove GUI elements for the song.
self.songs_horizontal_layout.removeWidget(song_review_widget)
song_review_widget.setParent(None)
# check if we only have one duplicate left
# Check if we only have one duplicate left:
# 4 stretches + 1 SongReviewWidget = 5
# the SongReviewWidget is then at position 2
# The SongReviewWidget is then at position 2.
if len(self.duplicate_song_list[-1]) == 1:
self.songs_horizontal_layout.itemAt(2).widget().song_remove_button.setEnabled(False)
@ -303,9 +303,9 @@ class DuplicateSongRemovalForm(OpenLPWizard):
"""
Removes the previous review UI elements and calls process_current_duplicate_entry.
"""
#remove last duplicate group
# Remove last duplicate group.
self.duplicate_song_list.pop()
# remove all previous elements
# Remove all previous elements.
for i in reversed(range(self.songs_horizontal_layout.count())):
item = self.songs_horizontal_layout.itemAt(i)
if isinstance(item, QtGui.QWidgetItem):
@ -316,7 +316,7 @@ class DuplicateSongRemovalForm(OpenLPWizard):
widget.setParent(None)
else:
self.songs_horizontal_layout.removeItem(item)
#process next set of duplicates
# Process next set of duplicates.
self.process_current_duplicate_entry()
def process_current_duplicate_entry(self):
@ -325,12 +325,12 @@ class DuplicateSongRemovalForm(OpenLPWizard):
the current duplicate group to review, if it's the last
duplicate song group, hide the "next" button and show the "finish" button.
"""
# update counter
# Update the counter.
self.review_current_count = self.review_total_count - (len(self.duplicate_song_list) - 1)
self.update_review_counter_text()
# add song elements to the UI
# Add song elements to the UI.
if len(self.duplicate_song_list) > 0:
# a stretch doesn't seem to stretch endlessly, so I add two to get enough stetch for 1400x1050
# A stretch doesn't seem to stretch endlessly, so I add two to get enough stetch for 1400x1050.
self.songs_horizontal_layout.addStretch()
self.songs_horizontal_layout.addStretch()
for duplicate in self.duplicate_song_list[-1]:
@ -341,7 +341,7 @@ class DuplicateSongRemovalForm(OpenLPWizard):
self.songs_horizontal_layout.addWidget(song_review_widget)
self.songs_horizontal_layout.addStretch()
self.songs_horizontal_layout.addStretch()
#change next button to finish button on last review
# Change next button to finish button on last review.
if len(self.duplicate_song_list) == 1:
self.button(QtGui.QWizard.FinishButton).show()
self.button(QtGui.QWizard.FinishButton).setEnabled(True)
@ -349,7 +349,7 @@ class DuplicateSongRemovalForm(OpenLPWizard):
def _get_main_window(self):
"""
Adds the main window to the class dynamically
Adds the main window to the class dynamically.
"""
if not hasattr(self, u'_main_window'):
self._main_window = Registry().get(u'main_window')

View File

@ -67,7 +67,7 @@ class SongReviewWidget(QtGui.QWidget):
self.song_group_box_layout.setObjectName(u'song_group_box_layout')
self.song_info_form_layout = QtGui.QFormLayout()
self.song_info_form_layout.setObjectName(u'song_info_form_layout')
#title
# Add title widget.
self.song_title_label = QtGui.QLabel(self)
self.song_title_label.setObjectName(u'song_title_label')
self.song_info_form_layout.setWidget(0, QtGui.QFormLayout.LabelRole, self.song_title_label)
@ -76,7 +76,7 @@ class SongReviewWidget(QtGui.QWidget):
self.song_title_content.setText(self.song.title)
self.song_title_content.setWordWrap(True)
self.song_info_form_layout.setWidget(0, QtGui.QFormLayout.FieldRole, self.song_title_content)
#alternate title
# Add alternate title widget.
self.song_alternate_title_label = QtGui.QLabel(self)
self.song_alternate_title_label.setObjectName(u'song_alternate_title_label')
self.song_info_form_layout.setWidget(1, QtGui.QFormLayout.LabelRole, self.song_alternate_title_label)
@ -85,7 +85,7 @@ class SongReviewWidget(QtGui.QWidget):
self.song_alternate_title_content.setText(self.song.alternate_title)
self.song_alternate_title_content.setWordWrap(True)
self.song_info_form_layout.setWidget(1, QtGui.QFormLayout.FieldRole, self.song_alternate_title_content)
#CCLI number
# Add CCLI number widget.
self.song_ccli_number_label = QtGui.QLabel(self)
self.song_ccli_number_label.setObjectName(u'song_ccli_number_label')
self.song_info_form_layout.setWidget(2, QtGui.QFormLayout.LabelRole, self.song_ccli_number_label)
@ -94,7 +94,7 @@ class SongReviewWidget(QtGui.QWidget):
self.song_ccli_number_content.setText(self.song.ccli_number)
self.song_ccli_number_content.setWordWrap(True)
self.song_info_form_layout.setWidget(2, QtGui.QFormLayout.FieldRole, self.song_ccli_number_content)
#copyright
# Add copyright widget.
self.song_copyright_label = QtGui.QLabel(self)
self.song_copyright_label.setObjectName(u'song_copyright_label')
self.song_info_form_layout.setWidget(3, QtGui.QFormLayout.LabelRole, self.song_copyright_label)
@ -103,7 +103,7 @@ class SongReviewWidget(QtGui.QWidget):
self.song_copyright_content.setWordWrap(True)
self.song_copyright_content.setText(self.song.copyright)
self.song_info_form_layout.setWidget(3, QtGui.QFormLayout.FieldRole, self.song_copyright_content)
#comments
# Add comments widget.
self.song_comments_label = QtGui.QLabel(self)
self.song_comments_label.setObjectName(u'song_comments_label')
self.song_info_form_layout.setWidget(4, QtGui.QFormLayout.LabelRole, self.song_comments_label)
@ -112,7 +112,7 @@ class SongReviewWidget(QtGui.QWidget):
self.song_comments_content.setText(self.song.comments)
self.song_comments_content.setWordWrap(True)
self.song_info_form_layout.setWidget(4, QtGui.QFormLayout.FieldRole, self.song_comments_content)
#authors
# Add authors widget.
self.song_authors_label = QtGui.QLabel(self)
self.song_authors_label.setObjectName(u'song_authors_label')
self.song_info_form_layout.setWidget(5, QtGui.QFormLayout.LabelRole, self.song_authors_label)
@ -126,7 +126,7 @@ class SongReviewWidget(QtGui.QWidget):
authors_text = authors_text[:-2]
self.song_authors_content.setText(authors_text)
self.song_info_form_layout.setWidget(5, QtGui.QFormLayout.FieldRole, self.song_authors_content)
#verse order
# Add verse order widget.
self.song_verse_order_label = QtGui.QLabel(self)
self.song_verse_order_label.setObjectName(u'song_verse_order_label')
self.song_info_form_layout.setWidget(6, QtGui.QFormLayout.LabelRole, self.song_verse_order_label)
@ -135,7 +135,7 @@ class SongReviewWidget(QtGui.QWidget):
self.song_verse_order_content.setText(self.song.verse_order)
self.song_verse_order_content.setWordWrap(True)
self.song_info_form_layout.setWidget(6, QtGui.QFormLayout.FieldRole, self.song_verse_order_content)
#verses
# Add verses widget.
self.song_group_box_layout.addLayout(self.song_info_form_layout)
self.song_info_verse_group_box = QtGui.QGroupBox(self.song_group_box)
self.song_info_verse_group_box.setObjectName(u'song_info_verse_group_box')

View File

@ -73,7 +73,6 @@ class DuplicateSongFinder(object):
differ = difflib.SequenceMatcher(a=large, b=small)
diff_tuples = differ.get_opcodes()
diff_no_typos = self.__remove_typos(diff_tuples)
#print(diff_no_typos)
if self.__length_of_equal_blocks(diff_no_typos) >= self.min_block_size or \
self.__length_of_longest_equal_block(diff_no_typos) > len(small) * 2 / 3:
return True
@ -97,25 +96,25 @@ class DuplicateSongFinder(object):
``diff``
The diff set to remove the typos from.
"""
#remove typo at beginning of string
# Remove typo at beginning of the string.
if len(diff) >= 2:
if diff[0][0] != "equal" and self.__op_length(diff[0]) <= self.max_typo_size and \
self.__op_length(diff[1]) >= self.min_fragment_size:
del diff[0]
#remove typos in the middle of string
# Remove typos in the middle of the string.
if len(diff) >= 3:
for index in range(len(diff) - 3, -1, -1):
if self.__op_length(diff[index]) >= self.min_fragment_size and \
diff[index + 1][0] != "equal" and self.__op_length(diff[index + 1]) <= self.max_typo_size and \
self.__op_length(diff[index + 2]) >= self.min_fragment_size:
del diff[index + 1]
#remove typo at the end of string
# Remove typo at the end of the string.
if len(diff) >= 2:
if self.__op_length(diff[-2]) >= self.min_fragment_size and \
diff[-1][0] != "equal" and self.__op_length(diff[-1]) <= self.max_typo_size:
del diff[-1]
#merge fragments
# Merge the bordering equal passages that occured by removing differences.
for index in range(len(diff) - 2, -1, -1):
if diff[index][0] == "equal" and self.__op_length(diff[index]) >= self.min_fragment_size and \
diff[index + 1][0] == "equal" and self.__op_length(diff[index + 1]) >= self.min_fragment_size:

View File

@ -94,12 +94,12 @@ class SongsPlugin(Plugin):
self.songImportItem.setVisible(True)
self.songExportItem.setVisible(True)
self.toolsReindexItem.setVisible(True)
self.toolsFindDuplicates.setVisible(True)
self.tools_find_duplicates.setVisible(True)
action_list = ActionList.get_instance()
action_list.add_action(self.songImportItem, UiStrings().Import)
action_list.add_action(self.songExportItem, UiStrings().Export)
action_list.add_action(self.toolsReindexItem, UiStrings().Tools)
action_list.add_action(self.toolsFindDuplicates, UiStrings().Tools)
action_list.add_action(self.tools_find_duplicates, UiStrings().Tools)
def addImportMenuItem(self, import_menu):
"""
@ -149,12 +149,12 @@ class SongsPlugin(Plugin):
statustip=translate('SongsPlugin', 'Re-index the songs database to improve searching and ordering.'),
visible=False, triggers=self.onToolsReindexItemTriggered)
tools_menu.addAction(self.toolsReindexItem)
self.toolsFindDuplicates = create_action(tools_menu, u'toolsFindDuplicates',
self.tools_find_duplicates = create_action(tools_menu, u'toolsFindDuplicates',
text=translate('SongsPlugin', 'Find &Duplicate Songs'),
statustip=translate('SongsPlugin',
'Find and remove duplicate songs in the song database.'),
visible=False, triggers=self.onToolsFindDuplicatesTriggered)
tools_menu.addAction(self.toolsFindDuplicates)
visible=False, triggers=self.on_tools_find_duplicates_triggered)
tools_menu.addAction(self.tools_find_duplicates)
def onToolsReindexItemTriggered(self):
"""
@ -174,7 +174,7 @@ class SongsPlugin(Plugin):
self.manager.save_objects(songs)
self.mediaItem.onSearchTextButtonClicked()
def onToolsFindDuplicatesTriggered(self):
def on_tools_find_duplicates_triggered(self):
"""
Search for duplicates in the song database.
"""
@ -300,12 +300,12 @@ class SongsPlugin(Plugin):
self.songImportItem.setVisible(False)
self.songExportItem.setVisible(False)
self.toolsReindexItem.setVisible(False)
self.toolsFindDuplicates.setVisible(False)
self.tools_find_duplicates.setVisible(False)
action_list = ActionList.get_instance()
action_list.remove_action(self.songImportItem, UiStrings().Import)
action_list.remove_action(self.songExportItem, UiStrings().Export)
action_list.remove_action(self.toolsReindexItem, UiStrings().Tools)
action_list.remove_action(self.toolsFindDuplicates, UiStrings().Tools)
action_list.remove_action(self.tools_find_duplicates, UiStrings().Tools)
Plugin.finalise(self)
def new_service_created(self):

View File

@ -53,46 +53,46 @@ class TestLib(TestCase):
that old cross where the dearest and best for a world of lost sinners was slain so ill cherish the old rugged
cross till my trophies at last i lay down i will cling to the old rugged cross and exchange it some day for a
crown'''
dsf = DuplicateSongFinder()
duplicate_song_finder = DuplicateSongFinder()
song1 = MagicMock()
song2 = MagicMock()
#GIVEN: Two equal songs
#GIVEN: Two equal songs.
song1.search_lyrics = full_lyrics
song2.search_lyrics = full_lyrics
#WHEN: We compare those songs for equality
result = dsf.songs_probably_equal(song1, song2)
#WHEN: We compare those songs for equality.
result = duplicate_song_finder.songs_probably_equal(song1, song2)
#THEN: The result should be True
#THEN: The result should be True.
assert result is True, u'The result should be True'
#GIVEN: A song and a short version of the same song
#GIVEN: A song and a short version of the same song.
song1.search_lyrics = full_lyrics
song2.search_lyrics = short_lyrics
#WHEN: We compare those songs for equality
result = dsf.songs_probably_equal(song1, song2)
#WHEN: We compare those songs for equality.
result = duplicate_song_finder.songs_probably_equal(song1, song2)
#THEN: The result should be True
#THEN: The result should be True.
assert result is True, u'The result should be True'
#GIVEN: A song and the same song with lots of errors
#GIVEN: A song and the same song with lots of errors.
song1.search_lyrics = full_lyrics
song2.search_lyrics = error_lyrics
#WHEN: We compare those songs for equality
result = dsf.songs_probably_equal(song1, song2)
#WHEN: We compare those songs for equality.
result = duplicate_song_finder.songs_probably_equal(song1, song2)
#THEN: The result should be True
#THEN: The result should be True.
assert result is True, u'The result should be True'
#GIVEN: Two different songs
#GIVEN: Two different songs.
song1.search_lyrics = full_lyrics
song2.search_lyrics = different_lyrics
#WHEN: We compare those songs for equality
result = dsf.songs_probably_equal(song1, song2)
#WHEN: We compare those songs for equality.
result = duplicate_song_finder.songs_probably_equal(song1, song2)
#THEN: The result should be False
#THEN: The result should be False.
assert result is False, u'The result should be False'