forked from openlp/openlp
Started work on chords on maindisplay.
This commit is contained in:
parent
138e2deb1f
commit
c10f71db3a
@ -301,14 +301,12 @@ def clean_tags(text, chords=False):
|
||||
return text
|
||||
|
||||
|
||||
def expand_tags(text, chords=False):
|
||||
def expand_tags(text):
|
||||
"""
|
||||
Expand tags HTML for display
|
||||
|
||||
:param text: The text to be expanded.
|
||||
:param chords: Convert ChordPro tags to html
|
||||
"""
|
||||
if chords:
|
||||
text = expand_chords(text)
|
||||
for tag in FormattingTags.get_html_tags():
|
||||
text = text.replace(tag['start tag'], tag['start 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 '[' in line and ']' in line:
|
||||
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>'
|
||||
expanded_text_lines.append(new_line)
|
||||
else:
|
||||
|
@ -444,6 +444,32 @@ HTML_SRC = Template("""
|
||||
position: relative;
|
||||
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>
|
||||
<script>
|
||||
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
|
||||
# for now).
|
||||
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
|
||||
# split).
|
||||
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>')
|
||||
if self._text_fits_on_slide(html_text):
|
||||
# The first two optional slides fit (as a whole) on one slide. Replace the first occurrence
|
||||
|
@ -117,9 +117,6 @@ class ItemCapabilities(object):
|
||||
|
||||
``HasThumbnails``
|
||||
The item has related thumbnails available
|
||||
|
||||
``HasChords``
|
||||
The item has chords - only for songs
|
||||
"""
|
||||
CanPreview = 1
|
||||
CanEdit = 2
|
||||
@ -142,7 +139,6 @@ class ItemCapabilities(object):
|
||||
HasDisplayTitle = 19
|
||||
HasNotes = 20
|
||||
HasThumbnails = 21
|
||||
HasChords = 22
|
||||
|
||||
|
||||
class ServiceItem(RegistryProperties):
|
||||
@ -263,15 +259,14 @@ class ServiceItem(RegistryProperties):
|
||||
previous_pages[verse_tag] = (slide['raw_slide'], pages)
|
||||
for page in pages:
|
||||
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 = {
|
||||
'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;', ' '),
|
||||
'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)
|
||||
elif self.service_item_type == ServiceItemType.Image or self.service_item_type == ServiceItemType.Command:
|
||||
pass
|
||||
|
@ -143,14 +143,14 @@ window.OpenLP = {
|
||||
$("#verseorder span").last().attr("id", "tag" + tags).text(tag);
|
||||
}
|
||||
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))) {
|
||||
// If the tag hasn't changed, check to see if the same verse
|
||||
// has been repeated consecutively. Note the verse may have been
|
||||
// split over several slides, so search through. If so, repeat the tag.
|
||||
var match = true;
|
||||
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;
|
||||
break;
|
||||
}
|
||||
@ -175,11 +175,11 @@ window.OpenLP = {
|
||||
// Show the current slide on top. Any trailing slides for the same verse
|
||||
// are shown too underneath in grey.
|
||||
// Then leave a blank line between following verses
|
||||
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,
|
||||
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,
|
||||
replaceChords=function(mstr,$1,$2,$3,$4) {
|
||||
var transposeValue = getTransposeValue(OpenLP.currentSlides[0].text.split("\n")[0]);
|
||||
var chordclass=/class="[a-z\s]*chord[a-z\s]*"\s*style="display:\s?none"/g;
|
||||
var chordclassshow='class="chord" style="display:inline"';
|
||||
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;
|
||||
var replaceChords=function(mstr,$1,$2,$3,$4) {
|
||||
var v='', w='';
|
||||
var $1len = 0, $2len = 0, slimchars='fiíIÍjlĺľrtť.,;/ ()|"\'!:\\';
|
||||
$1 = transposeChord($1, transposeValue, OpenLP.chordNotation);
|
||||
@ -213,7 +213,7 @@ window.OpenLP = {
|
||||
if (slide["title"]) {
|
||||
text = slide["title"];
|
||||
} else {
|
||||
text = slide["text"];
|
||||
text = slide["chords_text"];
|
||||
if(OpenLP.showchords) {
|
||||
text = text.replace(chordclass,chordclassshow);
|
||||
text = text.replace(regchord, replaceChords);
|
||||
@ -237,7 +237,7 @@ window.OpenLP = {
|
||||
if (OpenLP.currentSlides[idx]["title"]) {
|
||||
text = text + OpenLP.currentSlides[idx]["title"];
|
||||
} else {
|
||||
text = text + OpenLP.currentSlides[idx]["text"];
|
||||
text = text + OpenLP.currentSlides[idx]["chords_text"];
|
||||
if(OpenLP.showchords) {
|
||||
text = text.replace(chordclass,chordclassshow);
|
||||
text = text.replace(regchord, replaceChords);
|
||||
|
@ -558,10 +558,7 @@ class HttpRouter(RegistryProperties):
|
||||
item['tag'] = str(frame['verseTag'])
|
||||
else:
|
||||
item['tag'] = str(index + 1)
|
||||
# Use chords if available and enabled
|
||||
if current_item.is_capable(ItemCapabilities.HasChords):
|
||||
item['text'] = str(frame['chords_text'])
|
||||
else:
|
||||
item['chords_text'] = str(frame['chords_text'])
|
||||
item['text'] = str(frame['text'])
|
||||
item['html'] = str(frame['html'])
|
||||
# Handle images, unless a custom thumbnail is given or if thumbnails is disabled
|
||||
|
@ -613,9 +613,6 @@ class SongMediaItem(MediaManagerItem):
|
||||
if song.media_files:
|
||||
service_item.add_capability(ItemCapabilities.HasBackgroundAudio)
|
||||
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
|
||||
|
||||
def generate_footer(self, item, song):
|
||||
|
Loading…
Reference in New Issue
Block a user