forked from openlp/openlp
Fix chords in songs being displayed on the display screen and in the slide controller.
bzr-revno: 2897
This commit is contained in:
commit
e78d592892
@ -67,6 +67,15 @@ FOOTER_COPYRIGHT = 'Public Domain'
|
||||
CCLI_NO = '123456'
|
||||
|
||||
|
||||
def remove_chords(text):
|
||||
"""
|
||||
Remove chords from the text
|
||||
|
||||
:param text: Text to be cleaned
|
||||
"""
|
||||
return re.sub(r'\[.+?\]', r'', text)
|
||||
|
||||
|
||||
def remove_tags(text, can_remove_chords=False):
|
||||
"""
|
||||
Remove Tags from text for display
|
||||
@ -82,7 +91,7 @@ def remove_tags(text, can_remove_chords=False):
|
||||
text = text.replace(tag['end tag'], '')
|
||||
# Remove ChordPro tags
|
||||
if can_remove_chords:
|
||||
text = re.sub(r'\[.+?\]', r'', text)
|
||||
text = remove_chords(text)
|
||||
return text
|
||||
|
||||
|
||||
@ -377,6 +386,8 @@ def render_tags(text, can_render_chords=False, is_printing=False):
|
||||
text = render_chords_for_printing(text, '{br}')
|
||||
else:
|
||||
text = render_chords(text)
|
||||
else:
|
||||
text = remove_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'])
|
||||
|
@ -39,7 +39,7 @@ from openlp.core.common.applocation import AppLocation
|
||||
from openlp.core.common.i18n import translate
|
||||
from openlp.core.common.mixins import RegistryProperties
|
||||
from openlp.core.common.settings import Settings
|
||||
from openlp.core.display.render import remove_tags, render_tags
|
||||
from openlp.core.display.render import remove_tags, render_tags, render_chords_for_printing
|
||||
from openlp.core.lib import ItemCapabilities
|
||||
from openlp.core.ui.icons import UiIcons
|
||||
|
||||
@ -74,6 +74,7 @@ class ServiceItem(RegistryProperties):
|
||||
self.name = plugin.name
|
||||
self._rendered_slides = None
|
||||
self._display_slides = None
|
||||
self._print_slides = None
|
||||
self.title = ''
|
||||
self.slides = []
|
||||
self.processor = None
|
||||
@ -185,7 +186,7 @@ class ServiceItem(RegistryProperties):
|
||||
self._rendered_slides.append(rendered_slide)
|
||||
display_slide = {
|
||||
'title': raw_slide['title'],
|
||||
'text': remove_tags(page),
|
||||
'text': remove_tags(page, can_remove_chords=True),
|
||||
'verse': verse_tag,
|
||||
}
|
||||
self._display_slides.append(display_slide)
|
||||
@ -209,6 +210,34 @@ class ServiceItem(RegistryProperties):
|
||||
self._create_slides()
|
||||
return self._display_slides
|
||||
|
||||
@property
|
||||
def print_slides(self):
|
||||
"""
|
||||
Render the frames for printing and return them
|
||||
|
||||
:param can_render_chords: bool Whether or not to render the chords
|
||||
"""
|
||||
if not self._print_slides:
|
||||
self._print_slides = []
|
||||
previous_pages = {}
|
||||
index = 0
|
||||
for raw_slide in self.slides:
|
||||
verse_tag = raw_slide['verse']
|
||||
if verse_tag in previous_pages and previous_pages[verse_tag][0] == raw_slide:
|
||||
pages = previous_pages[verse_tag][1]
|
||||
else:
|
||||
pages = self.renderer.format_slide(raw_slide['text'], self)
|
||||
previous_pages[verse_tag] = (raw_slide, pages)
|
||||
for page in pages:
|
||||
slide = {
|
||||
'title': raw_slide['title'],
|
||||
'text': render_chords_for_printing(remove_tags(page), '\n'),
|
||||
'verse': index,
|
||||
'footer': self.raw_footer,
|
||||
}
|
||||
self._print_slides.append(slide)
|
||||
return self._print_slides
|
||||
|
||||
def add_from_image(self, path, title, background=None, thumbnail=None):
|
||||
"""
|
||||
Add an image slide to the service item.
|
||||
|
@ -218,7 +218,7 @@ class PrintServiceForm(QtWidgets.QDialog, Ui_PrintServiceDialog, RegistryPropert
|
||||
if item.is_text():
|
||||
verse_def = None
|
||||
verse_html = None
|
||||
for slide in item.get_frames():
|
||||
for slide in item.print_slides:
|
||||
if not verse_def or verse_def != slide['verse'] or verse_html == slide['text']:
|
||||
text_div = self._add_element('div', parent=div, class_id='itemText')
|
||||
elif 'chordspacing' not in slide['text']:
|
||||
|
Loading…
Reference in New Issue
Block a user