Started work on chords on maindisplay.

This commit is contained in:
Tomas Groth 2016-07-20 22:43:46 +02:00
parent 138e2deb1f
commit c10f71db3a
7 changed files with 47 additions and 34 deletions

View File

@ -301,15 +301,13 @@ 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)
text = expand_chords(text)
for tag in FormattingTags.get_html_tags():
text = text.replace(tag['start tag'], tag['start 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 '[' 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:

View File

@ -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;

View File

@ -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

View File

@ -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('&amp;nbsp;', '&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

View File

@ -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,13 +175,13 @@ 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ť.,;/ ()|"\'!:\\';
var $1len = 0, $2len = 0, slimchars='fiíIÍjlĺľrtť.,;/ ()|"\'!:\\';
$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 < $2.length; i++) if (slimchars.indexOf($2.charAt(i)) === -1) {$2len += 2;} else {$2len += 1;}
@ -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);

View File

@ -558,11 +558,8 @@ 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['text'] = str(frame['text'])
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
elif current_item.is_image() and not frame.get('image', '') and Settings().value('remotes/thumbnails'):

View File

@ -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):