'
active_formatting_tags = []
- if re.search(r'\[\w+.*?\]', line):
+ if re.search(r'\[.*?\]', line):
words = line.split(' ')
in_chord = False
for word in words:
@@ -509,7 +509,7 @@ def expand_chords_for_printing(text, line_split):
lyrics = []
new_line += ''
# If the word contains a chord, we need to handle it.
- if re.search(r'\[\w+.*?\]', word):
+ if re.search(r'\[.*?\]', word):
chord = ''
lyric = ''
# Loop over each character of the word
diff --git a/openlp/core/lib/htmlbuilder.py b/openlp/core/lib/htmlbuilder.py
index 54040b33e..df88f5f91 100644
--- a/openlp/core/lib/htmlbuilder.py
+++ b/openlp/core/lib/htmlbuilder.py
@@ -816,7 +816,7 @@ def build_footer_css(item, height):
def build_chords_css():
- if Settings().value('songs/mainview chords'):
+ if Settings().value('songs/enable chords') and Settings().value('songs/mainview chords'):
chord_line_height = '2.0em'
chords_display = 'inline'
first_chord_line_height = '2.1em'
diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py
index f021eef3c..a0ccfc5f3 100644
--- a/openlp/core/lib/serviceitem.py
+++ b/openlp/core/lib/serviceitem.py
@@ -263,7 +263,6 @@ class ServiceItem(RegistryProperties):
new_frame = {
'title': clean_tags(page),
'text': clean_tags(page.rstrip(), True),
- # 'chords_text': expand_chords(clean_tags(page.rstrip(), False), '\n'),
'chords_text': expand_chords(clean_tags(page.rstrip(), False)),
'html': html_data.replace(' ', ' '),
'printing_html': expand_tags(html.escape(page.rstrip()), True),
diff --git a/openlp/plugins/songs/lib/importers/chordpro.py b/openlp/plugins/songs/lib/importers/chordpro.py
index 4e618c3d9..4f185a713 100644
--- a/openlp/plugins/songs/lib/importers/chordpro.py
+++ b/openlp/plugins/songs/lib/importers/chordpro.py
@@ -25,6 +25,9 @@ ChordPro files into the current database.
"""
import logging
+import re
+
+from openlp.core.common import Settings
from .songimport import SongImport
@@ -77,6 +80,10 @@ class ChordProImport(SongImport):
if tag_value.lower().startswith('chorus'):
if current_verse.strip():
# Add collected verse to the lyrics
+ # Strip out chords if set up to
+ if not Settings().value('songs/enable chords') or Settings().value(
+ 'songs/disable chords import'):
+ current_verse = re.sub(r'\[.*?\]', '', current_verse)
self.add_verse(current_verse.rstrip(), current_verse_type)
current_verse_type = 'v'
current_verse = ''
@@ -87,12 +94,19 @@ class ChordProImport(SongImport):
current_verse_type = 'c'
elif tag_name in ['end_of_chorus', 'eoc']:
# Add collected chorus to the lyrics
+ # Strip out chords if set up to
+ if not Settings().value('songs/enable chords') or Settings().value('songs/disable chords import'):
+ current_verse = re.sub(r'\[.*?\]', '', current_verse)
self.add_verse(current_verse.rstrip(), current_verse_type)
current_verse_type = 'v'
current_verse = ''
elif tag_name in ['start_of_tab', 'sot']:
if current_verse.strip():
# Add collected verse to the lyrics
+ # Strip out chords if set up to
+ if not Settings().value('songs/enable chords') or Settings().value(
+ 'songs/disable chords import'):
+ current_verse = re.sub(r'\[.*?\]', '', current_verse)
self.add_verse(current_verse.rstrip(), current_verse_type)
current_verse_type = 'v'
current_verse = ''
@@ -103,6 +117,10 @@ class ChordProImport(SongImport):
# A new song starts below this tag
if self.verses and self.title:
if current_verse.strip():
+ # Strip out chords if set up to
+ if not Settings().value('songs/enable chords') or Settings().value(
+ 'songs/disable chords import'):
+ current_verse = re.sub(r'\[.*?\]', '', current_verse)
self.add_verse(current_verse.rstrip(), current_verse_type)
if not self.finish():
self.log_error(song_file.name)
@@ -123,6 +141,9 @@ class ChordProImport(SongImport):
continue
elif line == '' and current_verse.strip() and current_verse_type != 'c':
# Add collected verse to the lyrics
+ # Strip out chords if set up to
+ if not Settings().value('songs/enable chords') or Settings().value('songs/disable chords import'):
+ current_verse = re.sub(r'\[.*?\]', '', current_verse)
self.add_verse(current_verse.rstrip(), current_verse_type)
current_verse_type = 'v'
current_verse = ''
@@ -132,6 +153,10 @@ class ChordProImport(SongImport):
else:
current_verse += line + '\n'
if current_verse.strip():
+ # Strip out chords if set up to
+ if not Settings().value('songs/enable chords') or Settings().value(
+ 'songs/disable chords import'):
+ current_verse = re.sub(r'\[.*?\]', '', current_verse)
self.add_verse(current_verse.rstrip(), current_verse_type)
if not self.finish():
self.log_error(song_file.name)
diff --git a/openlp/plugins/songs/lib/importers/opensong.py b/openlp/plugins/songs/lib/importers/opensong.py
index 5def56d80..e184b2847 100644
--- a/openlp/plugins/songs/lib/importers/opensong.py
+++ b/openlp/plugins/songs/lib/importers/opensong.py
@@ -255,7 +255,8 @@ class OpenSongImport(SongImport):
verses[verse_tag][verse_num][inst] = []
our_verse_order.append([verse_tag, verse_num, inst])
# If chords exists insert them
- if chords and not Settings().value('songs/disable chords import'):
+ if chords and Settings().value('songs/enable chords') and not Settings().value(
+ 'songs/disable chords import'):
offset = 0
for (column, chord) in chords:
this_line = '{pre}[{chord}]{post}'.format(pre=this_line[:offset + column], chord=chord,
diff --git a/openlp/plugins/songs/lib/importers/songbeamer.py b/openlp/plugins/songs/lib/importers/songbeamer.py
index fa1d19858..45ec2aafb 100644
--- a/openlp/plugins/songs/lib/importers/songbeamer.py
+++ b/openlp/plugins/songs/lib/importers/songbeamer.py
@@ -22,14 +22,12 @@
"""
The :mod:`songbeamer` module provides the functionality for importing SongBeamer songs into the OpenLP database.
"""
-import chardet
import logging
import os
import re
import base64
import math
-from openlp.core.common import get_file_encoding
from openlp.plugins.songs.lib import VerseType
from openlp.plugins.songs.lib.importers.songimport import SongImport
from openlp.core.common import Settings, is_win, is_macosx, get_file_encoding
@@ -177,7 +175,8 @@ class SongBeamerImport(SongImport):
:param linenumber: Number of the current line
:param line: The line of lyrics to insert chords
"""
- if self.chord_table and not Settings().value('songs/disable chords import') and line_number in self.chord_table:
+ if self.chord_table and Settings().value('songs/enable chords') and not Settings().value(
+ 'songs/disable chords import') and line_number in self.chord_table:
line_idx = sorted(self.chord_table[line_number].keys(), reverse=True)
for idx in line_idx:
# In SongBeamer the column position of the chord can be a decimal, we just round it up.
diff --git a/openlp/plugins/songs/lib/importers/videopsalm.py b/openlp/plugins/songs/lib/importers/videopsalm.py
index f214f1700..5e7f0e8ef 100644
--- a/openlp/plugins/songs/lib/importers/videopsalm.py
+++ b/openlp/plugins/songs/lib/importers/videopsalm.py
@@ -126,8 +126,8 @@ class VideoPsalmImport(SongImport):
continue
verse_text = verse['Text']
# Strip out chords if set up to
- if Settings().value('songs/disable chords import'):
- verse_text = re.sub(r'\[\w.*?\]', '', verse_text)
+ if not Settings().value('songs/enable chords') or Settings().value('songs/disable chords import'):
+ verse_text = re.sub(r'\[.*?\]', '', verse_text)
self.add_verse(verse_text, 'v')
if not self.finish():
self.log_error('Could not import {title}'.format(title=self.title))
diff --git a/openlp/plugins/songs/lib/openlyricsxml.py b/openlp/plugins/songs/lib/openlyricsxml.py
index 315ea3b5b..bc02043ac 100644
--- a/openlp/plugins/songs/lib/openlyricsxml.py
+++ b/openlp/plugins/songs/lib/openlyricsxml.py
@@ -625,7 +625,7 @@ class OpenLyrics(object):
# Convert chords to ChordPro format which OpenLP uses internally
# TODO: Verify format() with template variables
elif element.tag == NSMAP % 'chord':
- if not Settings().value('songs/disable chords import'):
+ if Settings().value('songs/enable chords') and not Settings().value('songs/disable chords import'):
text += '[{chord}]'.format(chord=element.get('name'))
if element.tail:
# Append tail text at chord element.
diff --git a/openlp/plugins/songs/lib/songstab.py b/openlp/plugins/songs/lib/songstab.py
index 3e819516d..d1044b6c3 100644
--- a/openlp/plugins/songs/lib/songstab.py
+++ b/openlp/plugins/songs/lib/songstab.py
@@ -60,19 +60,22 @@ class SongsTab(SettingsTab):
self.display_copyright_check_box.setObjectName('copyright_check_box')
self.mode_layout.addWidget(self.display_copyright_check_box)
self.left_layout.addWidget(self.mode_group_box)
-
+ # Chords group box
self.chords_group_box = QtWidgets.QGroupBox(self.left_column)
self.chords_group_box.setObjectName('chords_group_box')
+ self.chords_group_box.setCheckable(True)
self.chords_layout = QtWidgets.QVBoxLayout(self.chords_group_box)
self.chords_layout.setObjectName('chords_layout')
+ self.chords_info_label = QtWidgets.QLabel(self.chords_group_box)
+ self.chords_info_label.setWordWrap(True)
+ self.chords_layout.addWidget(self.chords_info_label)
self.mainview_chords_check_box = QtWidgets.QCheckBox(self.mode_group_box)
- self.mainview_chords_check_box.setObjectName('tool_bar_active_check_box')
+ self.mainview_chords_check_box.setObjectName('mainview_chords_check_box')
self.chords_layout.addWidget(self.mainview_chords_check_box)
self.disable_chords_import_check_box = QtWidgets.QCheckBox(self.mode_group_box)
- self.disable_chords_import_check_box.setObjectName('tool_bar_active_check_box')
+ self.disable_chords_import_check_box.setObjectName('disable_chords_import_check_box')
self.chords_layout.addWidget(self.disable_chords_import_check_box)
-
- # Chords notation
+ # Chords notation group box
self.chord_notation_label = QtWidgets.QLabel(self.chords_group_box)
self.chord_notation_label.setWordWrap(True)
self.chords_layout.addWidget(self.chord_notation_label)
@@ -85,9 +88,7 @@ class SongsTab(SettingsTab):
self.neolatin_notation_radio_button = QtWidgets.QRadioButton(self.chords_group_box)
self.neolatin_notation_radio_button.setObjectName('neolatin_notation_radio_button')
self.chords_layout.addWidget(self.neolatin_notation_radio_button)
-
self.left_layout.addWidget(self.chords_group_box)
-
self.left_layout.addStretch()
self.right_layout.addStretch()
self.tool_bar_active_check_box.stateChanged.connect(self.on_tool_bar_active_check_box_changed)
@@ -115,6 +116,8 @@ class SongsTab(SettingsTab):
self.display_copyright_check_box.setText(translate('SongsPlugin.SongsTab',
'Display "{symbol}" symbol before copyright '
'info').format(symbol=SongStrings.CopyrightSymbol))
+ self.chords_info_label.setText(translate('SongsPlugin.SongsTab', 'If enabled all text between "[" and "]" will '
+ 'be regarded as chords.'))
self.chords_group_box.setTitle(translate('SongsPlugin.SongsTab', 'Chords'))
self.mainview_chords_check_box.setText(translate('SongsPlugin.SongsTab', 'Display chords in the main view'))
self.disable_chords_import_check_box.setText(translate('SongsPlugin.SongsTab',
@@ -170,6 +173,7 @@ class SongsTab(SettingsTab):
self.display_songbook = settings.value('display songbook')
self.display_written_by = settings.value('display written by')
self.display_copyright_symbol = settings.value('display copyright symbol')
+ self.enable_chords = settings.value('enable chords')
self.chord_notation = settings.value('chord notation')
self.mainview_chords = settings.value('mainview chords')
self.disable_chords_import = settings.value('disable chords import')
@@ -179,6 +183,7 @@ class SongsTab(SettingsTab):
self.display_songbook_check_box.setChecked(self.display_songbook)
self.display_written_by_check_box.setChecked(self.display_written_by)
self.display_copyright_check_box.setChecked(self.display_copyright_symbol)
+ self.chords_group_box.setChecked(self.enable_chords)
self.mainview_chords_check_box.setChecked(self.mainview_chords)
self.disable_chords_import_check_box.setChecked(self.disable_chords_import)
if self.chord_notation == 'german':
@@ -198,6 +203,7 @@ class SongsTab(SettingsTab):
settings.setValue('display songbook', self.display_songbook)
settings.setValue('display written by', self.display_written_by)
settings.setValue('display copyright symbol', self.display_copyright_symbol)
+ settings.setValue('enable chords', self.chords_group_box.isChecked())
settings.setValue('mainview chords', self.mainview_chords)
settings.setValue('disable chords import', self.disable_chords_import)
settings.setValue('chord notation', self.chord_notation)
diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py
index 29cb7a16f..4494ade49 100644
--- a/openlp/plugins/songs/songsplugin.py
+++ b/openlp/plugins/songs/songsplugin.py
@@ -67,6 +67,7 @@ __default_settings__ = {
'songs/songselect username': '',
'songs/songselect password': '',
'songs/songselect searches': '',
+ 'songs/enable chords': True,
'songs/chord notation': 'english', # Can be english, german or neo-latin
'songs/mainview chords': False,
'songs/disable chords import': False,
diff --git a/setup.cfg b/setup.cfg
index 2abc34df1..0ecc03ae8 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,4 +1,4 @@
[pep8]
exclude=resources.py,vlc.py
max-line-length = 120
-ignore = E402
+ignore = E402,E722
diff --git a/tests/functional/openlp_core_lib/test_htmlbuilder.py b/tests/functional/openlp_core_lib/test_htmlbuilder.py
index cd7e3dd0f..4bdbd363c 100644
--- a/tests/functional/openlp_core_lib/test_htmlbuilder.py
+++ b/tests/functional/openlp_core_lib/test_htmlbuilder.py
@@ -260,6 +260,7 @@ CHORD_CSS_ENABLED = """
__default_settings__ = {
'songs/mainview chords': False,
+ 'songs/enable chords': True
}
@@ -460,6 +461,7 @@ class Htmbuilder(TestCase, TestMixin):
Test the build_chords_css() function
"""
# GIVEN: A setting that activates chords on the mainview
+ Settings().setValue('songs/enable chords', True)
Settings().setValue('songs/mainview chords', True)
# WHEN: Building the chord CSS
diff --git a/tests/functional/openlp_plugins/songs/test_chordproimport.py b/tests/functional/openlp_plugins/songs/test_chordproimport.py
index 11461e387..fbf622d3c 100644
--- a/tests/functional/openlp_plugins/songs/test_chordproimport.py
+++ b/tests/functional/openlp_plugins/songs/test_chordproimport.py
@@ -4,7 +4,7 @@
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
-# Copyright (c) 2008-2016 OpenLP Developers #
+# Copyright (c) 2008-2017 OpenLP Developers #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
@@ -38,14 +38,14 @@ class TestChordProFileImport(SongImportTestHelper):
self.importer_module_name = 'chordpro'
super(TestChordProFileImport, self).__init__(*args, **kwargs)
- @patch('openlp.plugins.songs.lib.importers.opensong.Settings')
+ @patch('openlp.plugins.songs.lib.importers.chordpro.Settings')
def test_song_import(self, mocked_settings):
"""
Test that loading an ChordPro file works correctly on various files
"""
# Mock out the settings - always return False
mocked_returned_settings = MagicMock()
- mocked_returned_settings.value.return_value = False
+ mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False
mocked_settings.return_value = mocked_returned_settings
# Do the test import
self.file_import([os.path.join(TEST_PATH, 'swing-low.chordpro')],
diff --git a/tests/functional/openlp_plugins/songs/test_opensongimport.py b/tests/functional/openlp_plugins/songs/test_opensongimport.py
index 894e7142b..d6cec189a 100644
--- a/tests/functional/openlp_plugins/songs/test_opensongimport.py
+++ b/tests/functional/openlp_plugins/songs/test_opensongimport.py
@@ -49,7 +49,7 @@ class TestOpenSongFileImport(SongImportTestHelper):
"""
# Mock out the settings - always return False
mocked_returned_settings = MagicMock()
- mocked_returned_settings.value.return_value = False
+ mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False
mocked_settings.return_value = mocked_returned_settings
# Do the test import
self.file_import([os.path.join(TEST_PATH, 'Amazing Grace')],
diff --git a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py
index 4031b5863..597e7c698 100644
--- a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py
+++ b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py
@@ -49,7 +49,7 @@ class TestSongBeamerFileImport(SongImportTestHelper):
"""
# Mock out the settings - always return False
mocked_returned_settings = MagicMock()
- mocked_returned_settings.value.return_value = False
+ mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False
mocked_settings.return_value = mocked_returned_settings
self.file_import([os.path.join(TEST_PATH, 'Amazing Grace.sng')],
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json')))
diff --git a/tests/functional/openlp_plugins/songs/test_videopsalm.py b/tests/functional/openlp_plugins/songs/test_videopsalm.py
index 656bb2ae5..6fb236bfb 100644
--- a/tests/functional/openlp_plugins/songs/test_videopsalm.py
+++ b/tests/functional/openlp_plugins/songs/test_videopsalm.py
@@ -45,7 +45,7 @@ class TestVideoPsalmFileImport(SongImportTestHelper):
"""
# Mock out the settings - always return False
mocked_returned_settings = MagicMock()
- mocked_returned_settings.value.return_value = False
+ mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False
mocked_settings.return_value = mocked_returned_settings
# Do the test import
self.file_import(os.path.join(TEST_PATH, 'videopsalm-as-safe-a-stronghold.json'),
|