forked from openlp/openlp
Started work on chords on maindisplay.
This commit is contained in:
parent
138e2deb1f
commit
c10f71db3a
@ -301,15 +301,13 @@ def clean_tags(text, chords=False):
|
|||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
def expand_tags(text, chords=False):
|
def expand_tags(text):
|
||||||
"""
|
"""
|
||||||
Expand tags HTML for display
|
Expand tags HTML for display
|
||||||
|
|
||||||
:param text: The text to be expanded.
|
:param text: The text to be expanded.
|
||||||
:param chords: Convert ChordPro tags to html
|
|
||||||
"""
|
"""
|
||||||
if chords:
|
text = expand_chords(text)
|
||||||
text = expand_chords(text)
|
|
||||||
for tag in FormattingTags.get_html_tags():
|
for tag in FormattingTags.get_html_tags():
|
||||||
text = text.replace(tag['start tag'], tag['start html'])
|
text = text.replace(tag['start tag'], tag['start html'])
|
||||||
text = text.replace(tag['end tag'], tag['end html'])
|
text = text.replace(tag['end tag'], tag['end html'])
|
||||||
@ -328,7 +326,7 @@ def expand_chords(text):
|
|||||||
# If a ChordPro is detected in the line, replace it with a html-span tag and wrap the line in a span tag.
|
# If a ChordPro is detected in the line, replace it with a html-span tag and wrap the line in a span tag.
|
||||||
if '[' in line and ']' in line:
|
if '[' in line and ']' in line:
|
||||||
new_line = '<span class="chordline">'
|
new_line = '<span class="chordline">'
|
||||||
new_line += re.sub(r'(.*?)\[(.+?)\](.*?)', r'\1<span class="chord" style="display:none">\2</span>\3', line)
|
new_line += re.sub(r'(.*?)\[(.+?)\](.*?)', r'\1<span class="chord" style="display:inline"><span><strong>\2</strong></span></span>\3', line)
|
||||||
new_line += '</span>'
|
new_line += '</span>'
|
||||||
expanded_text_lines.append(new_line)
|
expanded_text_lines.append(new_line)
|
||||||
else:
|
else:
|
||||||
|
@ -444,6 +444,32 @@ HTML_SRC = Template("""
|
|||||||
position: relative;
|
position: relative;
|
||||||
top: -0.3em;
|
top: -0.3em;
|
||||||
}
|
}
|
||||||
|
#chords {
|
||||||
|
/*font-size: 20pt;
|
||||||
|
color: gray;
|
||||||
|
background-color: gray;
|
||||||
|
color: white;
|
||||||
|
cursor: pointer;*/
|
||||||
|
}
|
||||||
|
.chordline {
|
||||||
|
line-height: 2.0;
|
||||||
|
}
|
||||||
|
.chordline1 {
|
||||||
|
line-height: 1.0
|
||||||
|
}
|
||||||
|
.chordline span.chord span {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.chordline span.chord span strong {
|
||||||
|
position: absolute;
|
||||||
|
top: -1em;
|
||||||
|
left: 0;
|
||||||
|
font-size: 75%;
|
||||||
|
font-weight: normal;
|
||||||
|
line-height: normal;
|
||||||
|
/*font: 30pt sans-serif;
|
||||||
|
color: yellow;*/
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
var timer = null;
|
var timer = null;
|
||||||
|
@ -255,11 +255,11 @@ class Renderer(OpenLPMixin, RegistryMixin, RegistryProperties):
|
|||||||
# If there are (at least) two occurrences of [---] we use the first two slides (and neglect the last
|
# If there are (at least) two occurrences of [---] we use the first two slides (and neglect the last
|
||||||
# for now).
|
# for now).
|
||||||
if len(slides) == 3:
|
if len(slides) == 3:
|
||||||
html_text = expand_tags('\n'.join(slides[:2]), item.is_capable(ItemCapabilities.HasChords))
|
html_text = expand_tags('\n'.join(slides[:2]))
|
||||||
# We check both slides to determine if the optional split is needed (there is only one optional
|
# We check both slides to determine if the optional split is needed (there is only one optional
|
||||||
# split).
|
# split).
|
||||||
else:
|
else:
|
||||||
html_text = expand_tags('\n'.join(slides), item.is_capable(ItemCapabilities.HasChords))
|
html_text = expand_tags('\n'.join(slides))
|
||||||
html_text = html_text.replace('\n', '<br>')
|
html_text = html_text.replace('\n', '<br>')
|
||||||
if self._text_fits_on_slide(html_text):
|
if self._text_fits_on_slide(html_text):
|
||||||
# The first two optional slides fit (as a whole) on one slide. Replace the first occurrence
|
# The first two optional slides fit (as a whole) on one slide. Replace the first occurrence
|
||||||
|
@ -117,9 +117,6 @@ class ItemCapabilities(object):
|
|||||||
|
|
||||||
``HasThumbnails``
|
``HasThumbnails``
|
||||||
The item has related thumbnails available
|
The item has related thumbnails available
|
||||||
|
|
||||||
``HasChords``
|
|
||||||
The item has chords - only for songs
|
|
||||||
"""
|
"""
|
||||||
CanPreview = 1
|
CanPreview = 1
|
||||||
CanEdit = 2
|
CanEdit = 2
|
||||||
@ -142,7 +139,6 @@ class ItemCapabilities(object):
|
|||||||
HasDisplayTitle = 19
|
HasDisplayTitle = 19
|
||||||
HasNotes = 20
|
HasNotes = 20
|
||||||
HasThumbnails = 21
|
HasThumbnails = 21
|
||||||
HasChords = 22
|
|
||||||
|
|
||||||
|
|
||||||
class ServiceItem(RegistryProperties):
|
class ServiceItem(RegistryProperties):
|
||||||
@ -263,15 +259,14 @@ class ServiceItem(RegistryProperties):
|
|||||||
previous_pages[verse_tag] = (slide['raw_slide'], pages)
|
previous_pages[verse_tag] = (slide['raw_slide'], pages)
|
||||||
for page in pages:
|
for page in pages:
|
||||||
page = page.replace('<br>', '{br}')
|
page = page.replace('<br>', '{br}')
|
||||||
html_data = expand_tags(html.escape(page.rstrip()), self.is_capable(ItemCapabilities.HasChords))
|
html_data = expand_tags(html.escape(page.rstrip()))
|
||||||
new_frame = {
|
new_frame = {
|
||||||
'title': clean_tags(page),
|
'title': clean_tags(page),
|
||||||
'text': clean_tags(page.rstrip(), self.is_capable(ItemCapabilities.HasChords)),
|
'text': clean_tags(page.rstrip(), True),
|
||||||
|
'chords_text': expand_chords(clean_tags(page.rstrip(), False)),
|
||||||
'html': html_data.replace('&nbsp;', ' '),
|
'html': html_data.replace('&nbsp;', ' '),
|
||||||
'verseTag': verse_tag
|
'verseTag': verse_tag,
|
||||||
}
|
}
|
||||||
if self.is_capable(ItemCapabilities.HasChords):
|
|
||||||
new_frame['chords_text'] = expand_chords(clean_tags(page.rstrip()))
|
|
||||||
self._display_frames.append(new_frame)
|
self._display_frames.append(new_frame)
|
||||||
elif self.service_item_type == ServiceItemType.Image or self.service_item_type == ServiceItemType.Command:
|
elif self.service_item_type == ServiceItemType.Image or self.service_item_type == ServiceItemType.Command:
|
||||||
pass
|
pass
|
||||||
|
@ -143,14 +143,14 @@ window.OpenLP = {
|
|||||||
$("#verseorder span").last().attr("id", "tag" + tags).text(tag);
|
$("#verseorder span").last().attr("id", "tag" + tags).text(tag);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ((slide["text"] == data.results.slides[lastChange]["text"]) &&
|
if ((slide["chords_text"] == data.results.slides[lastChange]["chords_text"]) &&
|
||||||
(data.results.slides.length > idx + (idx - lastChange))) {
|
(data.results.slides.length > idx + (idx - lastChange))) {
|
||||||
// If the tag hasn't changed, check to see if the same verse
|
// If the tag hasn't changed, check to see if the same verse
|
||||||
// has been repeated consecutively. Note the verse may have been
|
// has been repeated consecutively. Note the verse may have been
|
||||||
// split over several slides, so search through. If so, repeat the tag.
|
// split over several slides, so search through. If so, repeat the tag.
|
||||||
var match = true;
|
var match = true;
|
||||||
for (var idx2 = 0; idx2 < idx - lastChange; idx2++) {
|
for (var idx2 = 0; idx2 < idx - lastChange; idx2++) {
|
||||||
if(data.results.slides[lastChange + idx2]["text"] != data.results.slides[idx + idx2]["text"]) {
|
if(data.results.slides[lastChange + idx2]["chords_text"] != data.results.slides[idx + idx2]["chords_text"]) {
|
||||||
match = false;
|
match = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -175,13 +175,13 @@ window.OpenLP = {
|
|||||||
// Show the current slide on top. Any trailing slides for the same verse
|
// Show the current slide on top. Any trailing slides for the same verse
|
||||||
// are shown too underneath in grey.
|
// are shown too underneath in grey.
|
||||||
// Then leave a blank line between following verses
|
// Then leave a blank line between following verses
|
||||||
var transposeValue = getTransposeValue(OpenLP.currentSlides[0].text.split("\n")[0]),
|
var transposeValue = getTransposeValue(OpenLP.currentSlides[0].text.split("\n")[0]);
|
||||||
chordclass=/class="[a-z\s]*chord[a-z\s]*"\s*style="display:\s?none"/g,
|
var chordclass=/class="[a-z\s]*chord[a-z\s]*"\s*style="display:\s?none"/g;
|
||||||
chordclassshow='class="chord" style="display:inline"',
|
var chordclassshow='class="chord" style="display:inline"';
|
||||||
regchord=/<span class="chord" style="display:inline">([\(\w#b♭\+\*\d/\)-]+)<\/span>([\u0080-\uFFFF,\w]*)([\u0080-\uFFFF,\w,\s,\.,\,,\!,\?,\;,\:,\|,\",\',\-,\_]*)(<br>)?/g,
|
var regchord=/<span class="chord" style="display:inline"><span><strong>([\(\w#b♭\+\*\d/\)-]+)<\/strong><\/span><\/span>([\u0080-\uFFFF,\w]*)([\u0080-\uFFFF,\w,\s,\.,\,,\!,\?,\;,\:,\|,\",\',\-,\_]*)(<br>)?/g;
|
||||||
replaceChords=function(mstr,$1,$2,$3,$4) {
|
var replaceChords=function(mstr,$1,$2,$3,$4) {
|
||||||
var v='', w='';
|
var v='', w='';
|
||||||
var $1len = 0, $2len = 0, slimchars='fiíIÍjlĺľrtť.,;/ ()|"\'!:\\';
|
var $1len = 0, $2len = 0, slimchars='fiíIÍjlĺľrtť.,;/ ()|"\'!:\\';
|
||||||
$1 = transposeChord($1, transposeValue, OpenLP.chordNotation);
|
$1 = transposeChord($1, transposeValue, OpenLP.chordNotation);
|
||||||
for (var i = 0; i < $1.length; i++) if (slimchars.indexOf($1.charAt(i)) === -1) {$1len += 2;} else {$1len += 1;}
|
for (var i = 0; i < $1.length; i++) if (slimchars.indexOf($1.charAt(i)) === -1) {$1len += 2;} else {$1len += 1;}
|
||||||
for (var i = 0; i < $2.length; i++) if (slimchars.indexOf($2.charAt(i)) === -1) {$2len += 2;} else {$2len += 1;}
|
for (var i = 0; i < $2.length; i++) if (slimchars.indexOf($2.charAt(i)) === -1) {$2len += 2;} else {$2len += 1;}
|
||||||
@ -213,7 +213,7 @@ window.OpenLP = {
|
|||||||
if (slide["title"]) {
|
if (slide["title"]) {
|
||||||
text = slide["title"];
|
text = slide["title"];
|
||||||
} else {
|
} else {
|
||||||
text = slide["text"];
|
text = slide["chords_text"];
|
||||||
if(OpenLP.showchords) {
|
if(OpenLP.showchords) {
|
||||||
text = text.replace(chordclass,chordclassshow);
|
text = text.replace(chordclass,chordclassshow);
|
||||||
text = text.replace(regchord, replaceChords);
|
text = text.replace(regchord, replaceChords);
|
||||||
@ -237,7 +237,7 @@ window.OpenLP = {
|
|||||||
if (OpenLP.currentSlides[idx]["title"]) {
|
if (OpenLP.currentSlides[idx]["title"]) {
|
||||||
text = text + OpenLP.currentSlides[idx]["title"];
|
text = text + OpenLP.currentSlides[idx]["title"];
|
||||||
} else {
|
} else {
|
||||||
text = text + OpenLP.currentSlides[idx]["text"];
|
text = text + OpenLP.currentSlides[idx]["chords_text"];
|
||||||
if(OpenLP.showchords) {
|
if(OpenLP.showchords) {
|
||||||
text = text.replace(chordclass,chordclassshow);
|
text = text.replace(chordclass,chordclassshow);
|
||||||
text = text.replace(regchord, replaceChords);
|
text = text.replace(regchord, replaceChords);
|
||||||
|
@ -558,11 +558,8 @@ class HttpRouter(RegistryProperties):
|
|||||||
item['tag'] = str(frame['verseTag'])
|
item['tag'] = str(frame['verseTag'])
|
||||||
else:
|
else:
|
||||||
item['tag'] = str(index + 1)
|
item['tag'] = str(index + 1)
|
||||||
# Use chords if available and enabled
|
item['chords_text'] = str(frame['chords_text'])
|
||||||
if current_item.is_capable(ItemCapabilities.HasChords):
|
item['text'] = str(frame['text'])
|
||||||
item['text'] = str(frame['chords_text'])
|
|
||||||
else:
|
|
||||||
item['text'] = str(frame['text'])
|
|
||||||
item['html'] = str(frame['html'])
|
item['html'] = str(frame['html'])
|
||||||
# Handle images, unless a custom thumbnail is given or if thumbnails is disabled
|
# Handle images, unless a custom thumbnail is given or if thumbnails is disabled
|
||||||
elif current_item.is_image() and not frame.get('image', '') and Settings().value('remotes/thumbnails'):
|
elif current_item.is_image() and not frame.get('image', '') and Settings().value('remotes/thumbnails'):
|
||||||
|
@ -613,9 +613,6 @@ class SongMediaItem(MediaManagerItem):
|
|||||||
if song.media_files:
|
if song.media_files:
|
||||||
service_item.add_capability(ItemCapabilities.HasBackgroundAudio)
|
service_item.add_capability(ItemCapabilities.HasBackgroundAudio)
|
||||||
service_item.background_audio = [m.file_name for m in song.media_files]
|
service_item.background_audio = [m.file_name for m in song.media_files]
|
||||||
# If chords are detected, mark the item as having chords
|
|
||||||
if '[' in song.lyrics:
|
|
||||||
service_item.add_capability(ItemCapabilities.HasChords)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def generate_footer(self, item, song):
|
def generate_footer(self, item, song):
|
||||||
|
Loading…
Reference in New Issue
Block a user