From c93b073da81dee7c6a315814e14084ab38c552b7 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 27 Mar 2011 09:19:00 +0100 Subject: [PATCH 01/57] Renderer Cleanups - started --- openlp/core/lib/__init__.py | 1 - openlp/core/lib/renderer.py | 121 --------------------- openlp/core/lib/rendermanager.py | 175 ++++++++++++++++++++++++------- openlp/core/lib/serviceitem.py | 2 +- 4 files changed, 137 insertions(+), 162 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index ddb1ae9b1..6f43a7bf2 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -338,6 +338,5 @@ from htmlbuilder import build_html, build_lyrics_format_css, \ build_lyrics_outline_css from toolbar import OpenLPToolbar from dockwidget import OpenLPDockWidget -from renderer import Renderer from rendermanager import RenderManager from mediamanageritem import MediaManagerItem diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 0eeae6abd..a866072e7 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -23,125 +23,4 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -""" -The :mod:`renderer` module enables OpenLP to take the input from plugins and -format it for the output display. -""" -import logging -from PyQt4 import QtWebKit - -from openlp.core.lib import expand_tags, build_lyrics_format_css, \ - build_lyrics_outline_css, Receiver - -log = logging.getLogger(__name__) - -class Renderer(object): - """ - Genarates a pixmap image of a array of text. The Text is formatted to - make sure it fits on the screen and if not extra frames are generated. - """ - log.info(u'Renderer Loaded') - - def __init__(self): - """ - Initialise the renderer. - """ - self._rect = None - self.theme_name = None - self._theme = None - - def set_theme(self, theme): - """ - Set the theme to be used. - - ``theme`` - The theme to be used. - """ - log.debug(u'set theme') - self._theme = theme - self.theme_name = theme.theme_name - - def set_text_rectangle(self, rect_main, rect_footer): - """ - Sets the rectangle within which text should be rendered. - - ``rect_main`` - The main text block. - - ``rect_footer`` - The footer text block. - """ - log.debug(u'set_text_rectangle %s , %s' % (rect_main, rect_footer)) - self._rect = rect_main - self._rect_footer = rect_footer - self.page_width = self._rect.width() - self.page_height = self._rect.height() - if self._theme.font_main_shadow: - self.page_width -= int(self._theme.font_main_shadow_size) - self.page_height -= int(self._theme.font_main_shadow_size) - self.web = QtWebKit.QWebView() - self.web.setVisible(False) - self.web.resize(self.page_width, self.page_height) - self.web_frame = self.web.page().mainFrame() - # Adjust width and height to account for shadow. outline done in css - self.page_shell = u'' \ - u'
' % \ - (build_lyrics_format_css(self._theme, self.page_width, - self.page_height), build_lyrics_outline_css(self._theme)) - - def format_slide(self, words, line_break, force_page=False): - """ - Figure out how much text can appear on a slide, using the current - theme settings. - - ``words`` - The words to be fitted on the slide. - - ``line_break`` - Add line endings after each line of text used for bibles. - - ``force_page`` - Flag to tell message lines in page. - - """ - log.debug(u'format_slide - Start') - line_end = u'' - if line_break: - line_end = u'
' - words = words.replace(u'\r\n', u'\n') - verses_text = words.split(u'\n') - text = [] - for verse in verses_text: - lines = verse.split(u'\n') - for line in lines: - text.append(line) - formatted = [] - html_text = u'' - styled_text = u'' - line_count = 0 - for line in text: - if line_count != -1: - line_count += 1 - styled_line = expand_tags(line) + line_end - styled_text += styled_line - html = self.page_shell + styled_text + u'
' - self.web.setHtml(html) - # Text too long so go to next page - if self.web_frame.contentsSize().height() > self.page_height: - if force_page and line_count > 0: - Receiver.send_message(u'theme_line_count', line_count) - line_count = -1 - if html_text.endswith(u'
'): - html_text = html_text[:len(html_text)-4] - formatted.append(html_text) - html_text = u'' - styled_text = styled_line - html_text += line + line_end - if html_text.endswith(u'
'): - html_text = html_text[:len(html_text)-4] - formatted.append(html_text) - log.debug(u'format_slide - End') - return formatted diff --git a/openlp/core/lib/rendermanager.py b/openlp/core/lib/rendermanager.py index 39c2c3b27..a88bd6e39 100644 --- a/openlp/core/lib/rendermanager.py +++ b/openlp/core/lib/rendermanager.py @@ -26,9 +26,10 @@ import logging -from PyQt4 import QtCore +from PyQt4 import QtCore, QtWebKit -from openlp.core.lib import Renderer, ServiceItem, ImageManager +from openlp.core.lib import ServiceItem, ImageManager, expand_tags, \ + build_lyrics_format_css, build_lyrics_outline_css, Receiver from openlp.core.lib.theme import ThemeLevel from openlp.core.ui import MainDisplay @@ -70,25 +71,25 @@ class RenderManager(object): self.display = MainDisplay(self, screens, False) self.display.imageManager = self.image_manager self.theme_manager = theme_manager - self.renderer = Renderer() - self.calculate_default(self.screens.current[u'size']) self.theme = u'' self.service_theme = u'' self.theme_level = u'' self.override_background = None self.theme_data = None self.force_page = False + self.r_theme_name = None + self._r_theme = None def update_display(self): """ Updates the render manager's information about the current screen. """ log.debug(u'Update Display') - self.calculate_default(self.screens.current[u'size']) + self._calculate_default(self.screens.current[u'size']) self.display = MainDisplay(self, self.screens, False) self.display.imageManager = self.image_manager self.display.setup() - self.renderer.bg_frame = None + self.bg_frame = None self.theme_data = None self.image_manager.update_display(self.width, self.height) @@ -155,7 +156,7 @@ class RenderManager(object): self.theme = self.service_theme else: self.theme = self.global_theme - if self.theme != self.renderer.theme_name or self.theme_data is None \ + if self.theme != self.r_theme_name or self.theme_data is None \ or overrideLevels: log.debug(u'theme is now %s', self.theme) # Force the theme to be the one passed in. @@ -163,37 +164,12 @@ class RenderManager(object): self.theme_data = theme else: self.theme_data = self.theme_manager.getThemeData(self.theme) - self.calculate_default(self.screens.current[u'size']) - self.renderer.set_theme(self.theme_data) - self.build_text_rectangle(self.theme_data) + self._calculate_default(self.screens.current[u'size']) + self._set_theme(self.theme_data) + self._build_text_rectangle(self.theme_data) self.image_manager.add_image(self.theme_data.theme_name, self.theme_data.background_filename) - return self.renderer._rect, self.renderer._rect_footer - - def build_text_rectangle(self, theme): - """ - Builds a text block using the settings in ``theme`` - and the size of the display screen.height. - - ``theme`` - The theme to build a text block for. - """ - log.debug(u'build_text_rectangle') - main_rect = None - footer_rect = None - if not theme.font_main_override: - main_rect = QtCore.QRect(10, 0, self.width - 20, self.footer_start) - else: - main_rect = QtCore.QRect(theme.font_main_x, theme.font_main_y, - theme.font_main_width - 1, theme.font_main_height - 1) - if not theme.font_footer_override: - footer_rect = QtCore.QRect(10, self.footer_start, self.width - 20, - self.height - self.footer_start) - else: - footer_rect = QtCore.QRect(theme.font_footer_x, - theme.font_footer_y, theme.font_footer_width - 1, - theme.font_footer_height - 1) - self.renderer.set_text_rectangle(main_rect, footer_rect) + return self._rect, self._rect_footer def generate_preview(self, theme_data, force_page=False): """ @@ -227,7 +203,7 @@ class RenderManager(object): raw_html = serviceItem.get_rendered_frame(0) preview = self.display.text(raw_html) # Reset the real screen size for subsequent render requests - self.calculate_default(self.screens.current[u'size']) + self._calculate_default(self.screens.current[u'size']) return preview def format_slide(self, words, line_break): @@ -241,9 +217,9 @@ class RenderManager(object): Add line endings after each line of text used for bibles. """ log.debug(u'format slide') - return self.renderer.format_slide(words, line_break, self.force_page) + return self._format_slide(words, line_break, self.force_page) - def calculate_default(self, screen): + def _calculate_default(self, screen): """ Calculate the default dimentions of the screen. @@ -258,3 +234,124 @@ class RenderManager(object): self.width, self.height, self.screen_ratio) # 90% is start of footer self.footer_start = int(self.height * 0.90) + + def _build_text_rectangle(self, theme): + """ + Builds a text block using the settings in ``theme`` + and the size of the display screen.height. + + ``theme`` + The theme to build a text block for. + """ + log.debug(u'_build_text_rectangle') + main_rect = None + footer_rect = None + if not theme.font_main_override: + main_rect = QtCore.QRect(10, 0, self.width - 20, self.footer_start) + else: + main_rect = QtCore.QRect(theme.font_main_x, theme.font_main_y, + theme.font_main_width - 1, theme.font_main_height - 1) + if not theme.font_footer_override: + footer_rect = QtCore.QRect(10, self.footer_start, self.width - 20, + self.height - self.footer_start) + else: + footer_rect = QtCore.QRect(theme.font_footer_x, + theme.font_footer_y, theme.font_footer_width - 1, + theme.font_footer_height - 1) + self._set_text_rectangle(main_rect, footer_rect) + + def _set_theme(self, theme): + """ + Set the theme to be used. + + ``theme`` + The theme to be used. + """ + log.debug(u'set theme') + self._r_theme = theme + self.r_theme_name = theme.theme_name + + def _set_text_rectangle(self, rect_main, rect_footer): + """ + Sets the rectangle within which text should be rendered. + + ``rect_main`` + The main text block. + + ``rect_footer`` + The footer text block. + """ + log.debug(u'set_text_rectangle %s , %s' % (rect_main, rect_footer)) + self._rect = rect_main + self._rect_footer = rect_footer + self.page_width = self._rect.width() + self.page_height = self._rect.height() + if self._r_theme.font_main_shadow: + self.page_width -= int(self._r_theme.font_main_shadow_size) + self.page_height -= int(self._r_theme.font_main_shadow_size) + self.web = QtWebKit.QWebView() + self.web.setVisible(False) + self.web.resize(self.page_width, self.page_height) + self.web_frame = self.web.page().mainFrame() + # Adjust width and height to account for shadow. outline done in css + self.page_shell = u'' \ + u'
' % \ + (build_lyrics_format_css(self._r_theme, self.page_width, + self.page_height), build_lyrics_outline_css(self._r_theme)) + + def _format_slide(self, words, line_break, force_page=False): + """ + Figure out how much text can appear on a slide, using the current + theme settings. + + ``words`` + The words to be fitted on the slide. + + ``line_break`` + Add line endings after each line of text used for bibles. + + ``force_page`` + Flag to tell message lines in page. + + """ + log.debug(u'format_slide - Start') + line_end = u'' + if line_break: + line_end = u'
' + words = words.replace(u'\r\n', u'\n') + verses_text = words.split(u'\n') + text = [] + for verse in verses_text: + lines = verse.split(u'\n') + for line in lines: + text.append(line) + formatted = [] + html_text = u'' + styled_text = u'' + line_count = 0 + for line in text: + if line_count != -1: + line_count += 1 + styled_line = expand_tags(line) + line_end + styled_text += styled_line + html = self.page_shell + styled_text + u'
' + self.web.setHtml(html) + # Text too long so go to next page + if self.web_frame.contentsSize().height() > self.page_height: + if force_page and line_count > 0: + Receiver.send_message(u'theme_line_count', line_count) + line_count = -1 + if html_text.endswith(u'
'): + html_text = html_text[:len(html_text)-4] + formatted.append(html_text) + html_text = u'' + styled_text = styled_line + html_text += line + line_end + if html_text.endswith(u'
'): + html_text = html_text[:len(html_text)-4] + formatted.append(html_text) + log.debug(u'format_slide - End') + return formatted + diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index 63b9dce00..249236f98 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -165,7 +165,7 @@ class ServiceItem(object): theme = self.theme if self.theme else None self.main, self.footer = \ self.render_manager.set_override_theme(theme, useOverride) - self.themedata = self.render_manager.renderer._theme + self.themedata = self.render_manager._r_theme if self.service_item_type == ServiceItemType.Text: log.debug(u'Formatting slides') for slide in self._raw_frames: From 5a4b91b37c3b634e3646de2feb73442faa896782 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 27 Mar 2011 15:39:43 +0200 Subject: [PATCH 02/57] (suggestion) added support for multiple slides --- openlp/plugins/songs/lib/xml.py | 37 +++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/openlp/plugins/songs/lib/xml.py b/openlp/plugins/songs/lib/xml.py index 87e28591e..daec73d64 100644 --- a/openlp/plugins/songs/lib/xml.py +++ b/openlp/plugins/songs/lib/xml.py @@ -226,7 +226,6 @@ class OpenLyrics(object): Convert the song to OpenLyrics Format. """ sxml = SongXML() - verse_list = sxml.get_verses(song.lyrics) song_xml = objectify.fromstring(u'') # Append the necessary meta data to the song. song_xml.set(u'xmlns', u'http://openlyrics.info/namespace/2009/song') @@ -268,17 +267,26 @@ class OpenLyrics(object): themes = etree.SubElement(properties, u'themes') for topic in song.topics: self._add_text_to_element(u'theme', themes, topic.name) + # Process the song's lyrics. lyrics = etree.SubElement(song_xml, u'lyrics') + verse_list = sxml.get_verses(song.lyrics) for verse in verse_list: - verse_tag = u'%s%s' % ( - verse[0][u'type'][0].lower(), verse[0][u'label']) - element = \ - self._add_text_to_element(u'verse', lyrics, None, verse_tag) - if verse[0].has_key(u'lang'): - element.set(u'lang', verse[0][u'lang']) - element = self._add_text_to_element(u'lines', element) - for line in unicode(verse[1]).split(u'\n'): - self._add_text_to_element(u'line', element, line) + verse_tag = verse[0][u'type'][0].lower() + verse_number = verse[0][u'label'] + # Create a list with all "sub" verses. + sub_verses = verse[1].split(u'[---]') + for sub_index, sub_verse in enumerate(sub_verses): + verse_def = verse_tag + verse_number + # We have more than one sub verse, consequently we need "v1a". + if len(sub_verses) > 1: + verse_def += list(u'abcdefghijklmnopqrstuvwxyz')[sub_index] + element = \ + self._add_text_to_element(u'verse', lyrics, None, verse_def) + if verse[0].has_key(u'lang'): + element.set(u'lang', verse[0][u'lang']) + element = self._add_text_to_element(u'lines', element) + for line in sub_verse.strip(u'\n').split(u'\n'): + self._add_text_to_element(u'line', element, line) return self._extract_xml(song_xml) def xml_to_song(self, xml): @@ -446,6 +454,7 @@ class OpenLyrics(object): The song object. """ sxml = SongXML() + verses = {} for verse in lyrics.verse: text = u'' for lines in verse.lines: @@ -465,7 +474,13 @@ class OpenLyrics(object): lang = None if self._get(verse, u'lang'): lang = self._get(verse, u'lang') - sxml.add_verse_to_lyrics(verse_tag, verse_number, text, lang) + if verses.has_key((verse_tag, verse_number, lang)): + verses[(verse_tag, verse_number, lang)] += u'\n[---]\n' + text + else: + verses[(verse_tag, verse_number, lang)] = text + for verse in verses: + sxml.add_verse_to_lyrics( + verse[0], verse[1], verses[verse], verse[2]) song.lyrics = unicode(sxml.extract_xml(), u'utf-8') # Process verse order if hasattr(properties, u'verseOrder'): From 239b62a488d2cdda553cecb1e75ce1b0eab1c1a4 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 28 Mar 2011 18:04:31 +0100 Subject: [PATCH 03/57] Render Ester 8:9 on more than 1 page --- openlp/core/lib/rendermanager.py | 109 ++++++++++++++----------- openlp/core/lib/serviceitem.py | 14 ++-- openlp/plugins/bibles/lib/mediaitem.py | 1 + openlp/plugins/custom/lib/mediaitem.py | 1 + openlp/plugins/songs/lib/mediaitem.py | 1 + 5 files changed, 74 insertions(+), 52 deletions(-) diff --git a/openlp/core/lib/rendermanager.py b/openlp/core/lib/rendermanager.py index d866fd115..c3acc8c34 100644 --- a/openlp/core/lib/rendermanager.py +++ b/openlp/core/lib/rendermanager.py @@ -29,7 +29,8 @@ import logging from PyQt4 import QtCore, QtWebKit from openlp.core.lib import ServiceItem, ImageManager, expand_tags, \ - build_lyrics_format_css, build_lyrics_outline_css, Receiver + build_lyrics_format_css, build_lyrics_outline_css, Receiver, \ + ItemCapabilities from openlp.core.lib.theme import ThemeLevel from openlp.core.ui import MainDisplay @@ -77,8 +78,6 @@ class RenderManager(object): self.override_background = None self.theme_data = None self.force_page = False - self.r_theme_name = None - self._r_theme = None def update_display(self): """ @@ -157,19 +156,16 @@ class RenderManager(object): self.theme = self.service_theme else: self.theme = self.global_theme - if self.theme != self.r_theme_name or self.theme_data is None \ - or overrideLevels: - log.debug(u'theme is now %s', self.theme) - # Force the theme to be the one passed in. - if overrideLevels: - self.theme_data = theme - else: - self.theme_data = self.theme_manager.getThemeData(self.theme) - self._calculate_default(self.screens.current[u'size']) - self._set_theme(self.theme_data) - self._build_text_rectangle(self.theme_data) - self.image_manager.add_image(self.theme_data.theme_name, - self.theme_data.background_filename) + log.debug(u'theme is now %s', self.theme) + # Force the theme to be the one passed in. + if overrideLevels: + self.theme_data = theme + else: + self.theme_data = self.theme_manager.getThemeData(self.theme) + self._calculate_default(self.screens.current[u'size']) + self._build_text_rectangle(self.theme_data) + self.image_manager.add_image(self.theme_data.theme_name, + self.theme_data.background_filename) return self._rect, self._rect_footer def generate_preview(self, theme_data, force_page=False): @@ -207,18 +203,29 @@ class RenderManager(object): self._calculate_default(self.screens.current[u'size']) return preview - def format_slide(self, words, line_break): + def format_slide(self, slide, line_break, item): """ Calculate how much text can fit on a slide. - ``words`` + ``slide`` The words to go on the slides. ``line_break`` Add line endings after each line of text used for bibles. """ log.debug(u'format slide') - return self._format_slide(words, line_break, self.force_page) + # clean up line endings + slide = slide.replace(u'\r\n', u'\n') + lines = self._lines(slide) + pages = self._paginate_slide(lines, line_break, self.force_page) + if len(pages) > 1: + if item.is_capable(ItemCapabilities.AllowsVirtualSplit): + lines = self._words(slide) + pages = self._paginate_slide(lines, line_break, self.force_page) + elif item.is_capable(ItemCapabilities.AllowsWordSplit): + lines = self._words(slide) + pages = self._paginate_slide(lines, False, self.force_page) + return pages def _calculate_default(self, screen): """ @@ -261,17 +268,6 @@ class RenderManager(object): theme.font_footer_height - 1) self._set_text_rectangle(main_rect, footer_rect) - def _set_theme(self, theme): - """ - Set the theme to be used. - - ``theme`` - The theme to be used. - """ - log.debug(u'set theme') - self._r_theme = theme - self.r_theme_name = theme.theme_name - def _set_text_rectangle(self, rect_main, rect_footer): """ Sets the rectangle within which text should be rendered. @@ -287,9 +283,9 @@ class RenderManager(object): self._rect_footer = rect_footer self.page_width = self._rect.width() self.page_height = self._rect.height() - if self._r_theme.font_main_shadow: - self.page_width -= int(self._r_theme.font_main_shadow_size) - self.page_height -= int(self._r_theme.font_main_shadow_size) + if self.theme_data.font_main_shadow: + self.page_width -= int(self.theme_data.font_main_shadow_size) + self.page_height -= int(self.theme_data.font_main_shadow_size) self.web = QtWebKit.QWebView() self.web.setVisible(False) self.web.resize(self.page_width, self.page_height) @@ -299,16 +295,16 @@ class RenderManager(object): u'*{margin: 0; padding: 0; border: 0;} '\ u'#main {position:absolute; top:0px; %s %s}' \ u'
' % \ - (build_lyrics_format_css(self._r_theme, self.page_width, - self.page_height), build_lyrics_outline_css(self._r_theme)) + (build_lyrics_format_css(self.theme_data, self.page_width, + self.page_height), build_lyrics_outline_css(self.theme_data)) - def _format_slide(self, words, line_break, force_page=False): + def _paginate_slide(self, lines, line_break, force_page=False): """ Figure out how much text can appear on a slide, using the current theme settings. - ``words`` - The words to be fitted on the slide. + ``lines`` + The words to be fitted on the slide split into lines. ``line_break`` Add line endings after each line of text used for bibles. @@ -321,18 +317,11 @@ class RenderManager(object): line_end = u'' if line_break: line_end = u'
' - words = words.replace(u'\r\n', u'\n') - verses_text = words.split(u'\n') - text = [] - for verse in verses_text: - lines = verse.split(u'\n') - for line in lines: - text.append(line) formatted = [] html_text = u'' styled_text = u'' line_count = 0 - for line in text: + for line in lines: if line_count != -1: line_count += 1 styled_line = expand_tags(line) + line_end @@ -356,3 +345,31 @@ class RenderManager(object): log.debug(u'format_slide - End') return formatted + def _lines(self, words): + """ + Split the slide up by physical line + """ + # this parse we do not want to use this so remove it + words = words.replace(u'[---]', u'') + verses_text = words.split(u'\n') + text = [] + for verse in verses_text: + lines = verse.split(u'\n') + for line in lines: + text.append(line) + return text + + def _words(self, words): + """ + Split the slide up by word so can wrap better + """ + # this parse we are wordy + words = words.replace(u'\n', u' ') + verses_text = words.split(u' ') + text = [] + for verse in verses_text: + lines = verse.split(u' ') + for line in lines: + text.append(line + u' ') + return text + diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index 7496bc6b0..f996c3f97 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -63,6 +63,8 @@ class ItemCapabilities(object): ProvidesOwnDisplay = 10 AllowsDetailedTitleDisplay = 11 AllowsVariableStartTime = 12 + AllowsVirtualSplit = 13 + AllowsWordSplit = 14 class ServiceItem(object): @@ -81,7 +83,7 @@ class ServiceItem(object): The plugin that this service item belongs to. """ if plugin: - self.render_manager = plugin.renderManager + self.renderer = plugin.renderManager self.name = plugin.name self.title = u'' self.shortname = u'' @@ -166,13 +168,13 @@ class ServiceItem(object): line_break = False theme = self.theme if self.theme else None self.main, self.footer = \ - self.render_manager.set_override_theme(theme, useOverride) - self.themedata = self.render_manager._r_theme + self.renderer.set_override_theme(theme, useOverride) + self.themedata = self.renderer.theme_data if self.service_item_type == ServiceItemType.Text: log.debug(u'Formatting slides') for slide in self._raw_frames: - formatted = self.render_manager \ - .format_slide(slide[u'raw_slide'], line_break) + formatted = self.renderer \ + .format_slide(slide[u'raw_slide'], line_break, self) for page in formatted: self._display_frames.append( {u'title': clean_tags(page), @@ -205,7 +207,7 @@ class ServiceItem(object): """ self.service_item_type = ServiceItemType.Image self._raw_frames.append({u'title': title, u'path': path}) - self.render_manager.image_manager.add_image(title, path) + self.renderer.image_manager.add_image(title, path) self._new_item() def add_from_text(self, title, raw_slide, verse_tag=None): diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index a9694fd0c..405507523 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -685,6 +685,7 @@ class BibleMediaItem(MediaManagerItem): service_item.add_capability(ItemCapabilities.NoLineBreaks) service_item.add_capability(ItemCapabilities.AllowsPreview) service_item.add_capability(ItemCapabilities.AllowsLoop) + service_item.add_capability(ItemCapabilities.AllowsWordSplit) # Service Item: Title service_item.title = u', '.join(raw_title) # Service Item: Theme diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index 69265ed75..0bb9c3aa8 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -139,6 +139,7 @@ class CustomMediaItem(MediaManagerItem): service_item.add_capability(ItemCapabilities.AllowsEdit) service_item.add_capability(ItemCapabilities.AllowsPreview) service_item.add_capability(ItemCapabilities.AllowsLoop) + service_item.add_capability(ItemCapabilities.AllowsVirtualSplit) customSlide = self.parent.manager.get_object(CustomSlide, item_id) title = customSlide.title credit = customSlide.credits diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 723b6c5d5..72509fab1 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -337,6 +337,7 @@ class SongMediaItem(MediaManagerItem): service_item.add_capability(ItemCapabilities.AllowsLoop) service_item.add_capability(ItemCapabilities.OnLoadUpdate) service_item.add_capability(ItemCapabilities.AddIfNewItem) + service_item.add_capability(ItemCapabilities.AllowsVirtualSplit) song = self.parent.manager.get_object(Song, item_id) service_item.theme = song.theme_name service_item.edit_id = item_id From 9aa6bba3a265b88b6a6addc7843cdcc9b18764af Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 28 Mar 2011 19:01:58 +0100 Subject: [PATCH 04/57] Virtual Splits now work --- openlp/core/lib/rendermanager.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/openlp/core/lib/rendermanager.py b/openlp/core/lib/rendermanager.py index c3acc8c34..43210259a 100644 --- a/openlp/core/lib/rendermanager.py +++ b/openlp/core/lib/rendermanager.py @@ -220,8 +220,15 @@ class RenderManager(object): pages = self._paginate_slide(lines, line_break, self.force_page) if len(pages) > 1: if item.is_capable(ItemCapabilities.AllowsVirtualSplit): - lines = self._words(slide) - pages = self._paginate_slide(lines, line_break, self.force_page) + # do not forget the line breaks ! + slides = slide.split(u'\n[###]\n') + pages = [] + for slide in slides: + lines = self._lines(slide) + new_pages = self._paginate_slide(lines, line_break, + self.force_page) + for page in new_pages: + pages.append(page) elif item.is_capable(ItemCapabilities.AllowsWordSplit): lines = self._words(slide) pages = self._paginate_slide(lines, False, self.force_page) From c8a7594685c4babfe5e02b27645d46ccda89ac56 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 28 Mar 2011 19:12:46 +0100 Subject: [PATCH 05/57] Bye Bye RenderManager --- openlp/core/lib/__init__.py | 2 +- openlp/core/lib/renderer.py | 356 ++++++++++++++++++++++++++++ openlp/core/lib/rendermanager.py | 382 ------------------------------ openlp/core/ui/mainwindow.py | 12 +- openlp/core/ui/servicemanager.py | 6 +- openlp/core/ui/slidecontroller.py | 2 +- openlp/core/ui/themestab.py | 2 +- 7 files changed, 368 insertions(+), 394 deletions(-) delete mode 100644 openlp/core/lib/rendermanager.py diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 6f43a7bf2..dc25fae0f 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -338,5 +338,5 @@ from htmlbuilder import build_html, build_lyrics_format_css, \ build_lyrics_outline_css from toolbar import OpenLPToolbar from dockwidget import OpenLPDockWidget -from rendermanager import RenderManager +from renderer import Renderer from mediamanageritem import MediaManagerItem diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index a866072e7..9256eb096 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -24,3 +24,359 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### +import logging + +from PyQt4 import QtCore, QtWebKit + +from openlp.core.lib import ServiceItem, ImageManager, expand_tags, \ + build_lyrics_format_css, build_lyrics_outline_css, Receiver, \ + ItemCapabilities +from openlp.core.lib.theme import ThemeLevel +from openlp.core.ui import MainDisplay + +log = logging.getLogger(__name__) + +VERSE = u'The Lord said to {r}Noah{/r}: \n' \ + 'There\'s gonna be a {su}floody{/su}, {sb}floody{/sb}\n' \ + 'The Lord said to {g}Noah{/g}:\n' \ + 'There\'s gonna be a {st}floody{/st}, {it}floody{/it}\n' \ + 'Get those children out of the muddy, muddy \n' \ + '{r}C{/r}{b}h{/b}{bl}i{/bl}{y}l{/y}{g}d{/g}{pk}' \ + 'r{/pk}{o}e{/o}{pp}n{/pp} of the Lord\n' +FOOTER = [u'Arky Arky (Unknown)', u'Public Domain', u'CCLI 123456'] + +class Renderer(object): + """ + Class to pull all Renderer interactions into one place. The plugins will + call helper methods to do the rendering but this class will provide + display defense code. + + ``theme_manager`` + The ThemeManager instance, used to get the current theme details. + + ``screens`` + Contains information about the Screens. + + ``screen_number`` + Defaults to *0*. The index of the output/display screen. + """ + log.info(u'RenderManager Loaded') + + def __init__(self, theme_manager, screens): + """ + Initialise the render manager. + """ + log.debug(u'Initilisation started') + self.screens = screens + self.image_manager = ImageManager() + self.display = MainDisplay(self, screens, False) + self.display.imageManager = self.image_manager + self.theme_manager = theme_manager + self.theme = u'' + self.service_theme = u'' + self.theme_level = u'' + self.override_background = None + self.theme_data = None + self.force_page = False + + def update_display(self): + """ + Updates the render manager's information about the current screen. + """ + log.debug(u'Update Display') + self._calculate_default(self.screens.current[u'size']) + self.display = MainDisplay(self, self.screens, False) + self.display.imageManager = self.image_manager + self.display.setup() + self.bg_frame = None + self.theme_data = None + self.image_manager.update_display(self.width, self.height) + + def set_global_theme(self, global_theme, theme_level=ThemeLevel.Global): + """ + Set the global-level theme and the theme level. + + ``global_theme`` + The global-level theme to be set. + + ``theme_level`` + Defaults to *``ThemeLevel.Global``*. The theme level, can be + ``ThemeLevel.Global``, ``ThemeLevel.Service`` or + ``ThemeLevel.Song``. + """ + self.global_theme = global_theme + self.theme_level = theme_level + self.global_theme_data = \ + self.theme_manager.getThemeData(self.global_theme) + self.theme_data = None + + def set_service_theme(self, service_theme): + """ + Set the service-level theme. + + ``service_theme`` + The service-level theme to be set. + """ + self.service_theme = service_theme + self.theme_data = None + + def set_override_theme(self, theme, overrideLevels=False): + """ + Set the appropriate theme depending on the theme level. + Called by the service item when building a display frame + + ``theme`` + The name of the song-level theme. None means the service + item wants to use the given value. + + ``overrideLevels`` + Used to force the theme data passed in to be used. + + """ + log.debug(u'set override theme to %s', theme) + theme_level = self.theme_level + if overrideLevels: + theme_level = ThemeLevel.Song + if theme_level == ThemeLevel.Global: + self.theme = self.global_theme + elif theme_level == ThemeLevel.Service: + if self.service_theme == u'': + self.theme = self.global_theme + else: + self.theme = self.service_theme + else: + # Images have a theme of -1 + if theme and theme != -1: + self.theme = theme + elif theme_level == ThemeLevel.Song or \ + theme_level == ThemeLevel.Service: + if self.service_theme == u'': + self.theme = self.global_theme + else: + self.theme = self.service_theme + else: + self.theme = self.global_theme + log.debug(u'theme is now %s', self.theme) + # Force the theme to be the one passed in. + if overrideLevels: + self.theme_data = theme + else: + self.theme_data = self.theme_manager.getThemeData(self.theme) + self._calculate_default(self.screens.current[u'size']) + self._build_text_rectangle(self.theme_data) + self.image_manager.add_image(self.theme_data.theme_name, + self.theme_data.background_filename) + return self._rect, self._rect_footer + + def generate_preview(self, theme_data, force_page=False): + """ + Generate a preview of a theme. + + ``theme_data`` + The theme to generated a preview for. + + ``force_page`` + Flag to tell message lines per page need to be generated. + """ + log.debug(u'generate preview') + # save value for use in format_slide + self.force_page = force_page + # set the default image size for previews + self.calculate_default(self.screens.preview[u'size']) + # build a service item to generate preview + serviceItem = ServiceItem() + serviceItem.theme = theme_data + if self.force_page: + # make big page for theme edit dialog to get line count + serviceItem.add_from_text(u'', VERSE + VERSE + VERSE, FOOTER) + else: + self.image_manager.del_image(theme_data.theme_name) + serviceItem.add_from_text(u'', VERSE, FOOTER) + serviceItem.render_manager = self + serviceItem.raw_footer = FOOTER + serviceItem.render(True) + if not self.force_page: + self.display.buildHtml(serviceItem) + raw_html = serviceItem.get_rendered_frame(0) + preview = self.display.text(raw_html) + # Reset the real screen size for subsequent render requests + self._calculate_default(self.screens.current[u'size']) + return preview + + def format_slide(self, slide, line_break, item): + """ + Calculate how much text can fit on a slide. + + ``slide`` + The words to go on the slides. + + ``line_break`` + Add line endings after each line of text used for bibles. + """ + log.debug(u'format slide') + # clean up line endings + slide = slide.replace(u'\r\n', u'\n') + lines = self._lines(slide) + pages = self._paginate_slide(lines, line_break, self.force_page) + if len(pages) > 1: + if item.is_capable(ItemCapabilities.AllowsVirtualSplit): + # do not forget the line breaks ! + slides = slide.split(u'\n[###]\n') + pages = [] + for slide in slides: + lines = self._lines(slide) + new_pages = self._paginate_slide(lines, line_break, + self.force_page) + for page in new_pages: + pages.append(page) + elif item.is_capable(ItemCapabilities.AllowsWordSplit): + lines = self._words(slide) + pages = self._paginate_slide(lines, False, self.force_page) + return pages + + def _calculate_default(self, screen): + """ + Calculate the default dimentions of the screen. + + ``screen`` + The QSize of the screen. + """ + log.debug(u'calculate default %s', screen) + self.width = screen.width() + self.height = screen.height() + self.screen_ratio = float(self.height) / float(self.width) + log.debug(u'calculate default %d, %d, %f', + self.width, self.height, self.screen_ratio) + # 90% is start of footer + self.footer_start = int(self.height * 0.90) + + def _build_text_rectangle(self, theme): + """ + Builds a text block using the settings in ``theme`` + and the size of the display screen.height. + + ``theme`` + The theme to build a text block for. + """ + log.debug(u'_build_text_rectangle') + main_rect = None + footer_rect = None + if not theme.font_main_override: + main_rect = QtCore.QRect(10, 0, self.width - 20, self.footer_start) + else: + main_rect = QtCore.QRect(theme.font_main_x, theme.font_main_y, + theme.font_main_width - 1, theme.font_main_height - 1) + if not theme.font_footer_override: + footer_rect = QtCore.QRect(10, self.footer_start, self.width - 20, + self.height - self.footer_start) + else: + footer_rect = QtCore.QRect(theme.font_footer_x, + theme.font_footer_y, theme.font_footer_width - 1, + theme.font_footer_height - 1) + self._set_text_rectangle(main_rect, footer_rect) + + def _set_text_rectangle(self, rect_main, rect_footer): + """ + Sets the rectangle within which text should be rendered. + + ``rect_main`` + The main text block. + + ``rect_footer`` + The footer text block. + """ + log.debug(u'set_text_rectangle %s , %s' % (rect_main, rect_footer)) + self._rect = rect_main + self._rect_footer = rect_footer + self.page_width = self._rect.width() + self.page_height = self._rect.height() + if self.theme_data.font_main_shadow: + self.page_width -= int(self.theme_data.font_main_shadow_size) + self.page_height -= int(self.theme_data.font_main_shadow_size) + self.web = QtWebKit.QWebView() + self.web.setVisible(False) + self.web.resize(self.page_width, self.page_height) + self.web_frame = self.web.page().mainFrame() + # Adjust width and height to account for shadow. outline done in css + self.page_shell = u'' \ + u'
' % \ + (build_lyrics_format_css(self.theme_data, self.page_width, + self.page_height), build_lyrics_outline_css(self.theme_data)) + + def _paginate_slide(self, lines, line_break, force_page=False): + """ + Figure out how much text can appear on a slide, using the current + theme settings. + + ``lines`` + The words to be fitted on the slide split into lines. + + ``line_break`` + Add line endings after each line of text used for bibles. + + ``force_page`` + Flag to tell message lines in page. + + """ + log.debug(u'format_slide - Start') + line_end = u'' + if line_break: + line_end = u'
' + formatted = [] + html_text = u'' + styled_text = u'' + line_count = 0 + for line in lines: + if line_count != -1: + line_count += 1 + styled_line = expand_tags(line) + line_end + styled_text += styled_line + html = self.page_shell + styled_text + u'
' + self.web.setHtml(html) + # Text too long so go to next page + if self.web_frame.contentsSize().height() > self.page_height: + if force_page and line_count > 0: + Receiver.send_message(u'theme_line_count', line_count) + line_count = -1 + if html_text.endswith(u'
'): + html_text = html_text[:len(html_text)-4] + formatted.append(html_text) + html_text = u'' + styled_text = styled_line + html_text += line + line_end + if html_text.endswith(u'
'): + html_text = html_text[:len(html_text)-4] + formatted.append(html_text) + log.debug(u'format_slide - End') + return formatted + + def _lines(self, words): + """ + Split the slide up by physical line + """ + # this parse we do not want to use this so remove it + words = words.replace(u'[---]', u'') + verses_text = words.split(u'\n') + text = [] + for verse in verses_text: + lines = verse.split(u'\n') + for line in lines: + text.append(line) + return text + + def _words(self, words): + """ + Split the slide up by word so can wrap better + """ + # this parse we are wordy + words = words.replace(u'\n', u' ') + verses_text = words.split(u' ') + text = [] + for verse in verses_text: + lines = verse.split(u' ') + for line in lines: + text.append(line + u' ') + return text + diff --git a/openlp/core/lib/rendermanager.py b/openlp/core/lib/rendermanager.py deleted file mode 100644 index 43210259a..000000000 --- a/openlp/core/lib/rendermanager.py +++ /dev/null @@ -1,382 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2011 Raoul Snyman # -# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael # -# Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, Armin Köhler, # -# Andreas Preikschat, Mattias Põldaru, Christian Richter, Philip Ridout, # -# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund # -# --------------------------------------------------------------------------- # -# 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 # -# Software Foundation; version 2 of the License. # -# # -# This program is distributed in the hope that it will be useful, but WITHOUT # -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # -# more details. # -# # -# You should have received a copy of the GNU General Public License along # -# with this program; if not, write to the Free Software Foundation, Inc., 59 # -# Temple Place, Suite 330, Boston, MA 02111-1307 USA # -############################################################################### - -import logging - -from PyQt4 import QtCore, QtWebKit - -from openlp.core.lib import ServiceItem, ImageManager, expand_tags, \ - build_lyrics_format_css, build_lyrics_outline_css, Receiver, \ - ItemCapabilities -from openlp.core.lib.theme import ThemeLevel -from openlp.core.ui import MainDisplay - -log = logging.getLogger(__name__) - -VERSE = u'The Lord said to {r}Noah{/r}: \n' \ - 'There\'s gonna be a {su}floody{/su}, {sb}floody{/sb}\n' \ - 'The Lord said to {g}Noah{/g}:\n' \ - 'There\'s gonna be a {st}floody{/st}, {it}floody{/it}\n' \ - 'Get those children out of the muddy, muddy \n' \ - '{r}C{/r}{b}h{/b}{bl}i{/bl}{y}l{/y}{g}d{/g}{pk}' \ - 'r{/pk}{o}e{/o}{pp}n{/pp} of the Lord\n' -FOOTER = [u'Arky Arky (Unknown)', u'Public Domain', u'CCLI 123456'] - -class RenderManager(object): - """ - Class to pull all Renderer interactions into one place. The plugins will - call helper methods to do the rendering but this class will provide - display defense code. - - ``theme_manager`` - The ThemeManager instance, used to get the current theme details. - - ``screens`` - Contains information about the Screens. - - ``screen_number`` - Defaults to *0*. The index of the output/display screen. - """ - log.info(u'RenderManager Loaded') - - def __init__(self, theme_manager, screens): - """ - Initialise the render manager. - """ - log.debug(u'Initilisation started') - self.screens = screens - self.image_manager = ImageManager() - self.display = MainDisplay(self, screens, False) - self.display.imageManager = self.image_manager - self.theme_manager = theme_manager - self.theme = u'' - self.service_theme = u'' - self.theme_level = u'' - self.override_background = None - self.theme_data = None - self.force_page = False - - def update_display(self): - """ - Updates the render manager's information about the current screen. - """ - log.debug(u'Update Display') - self._calculate_default(self.screens.current[u'size']) - self.display = MainDisplay(self, self.screens, False) - self.display.imageManager = self.image_manager - self.display.setup() - self.bg_frame = None - self.theme_data = None - self.image_manager.update_display(self.width, self.height) - - def set_global_theme(self, global_theme, theme_level=ThemeLevel.Global): - """ - Set the global-level theme and the theme level. - - ``global_theme`` - The global-level theme to be set. - - ``theme_level`` - Defaults to *``ThemeLevel.Global``*. The theme level, can be - ``ThemeLevel.Global``, ``ThemeLevel.Service`` or - ``ThemeLevel.Song``. - """ - self.global_theme = global_theme - self.theme_level = theme_level - self.global_theme_data = \ - self.theme_manager.getThemeData(self.global_theme) - self.theme_data = None - - def set_service_theme(self, service_theme): - """ - Set the service-level theme. - - ``service_theme`` - The service-level theme to be set. - """ - self.service_theme = service_theme - self.theme_data = None - - def set_override_theme(self, theme, overrideLevels=False): - """ - Set the appropriate theme depending on the theme level. - Called by the service item when building a display frame - - ``theme`` - The name of the song-level theme. None means the service - item wants to use the given value. - - ``overrideLevels`` - Used to force the theme data passed in to be used. - - """ - log.debug(u'set override theme to %s', theme) - theme_level = self.theme_level - if overrideLevels: - theme_level = ThemeLevel.Song - if theme_level == ThemeLevel.Global: - self.theme = self.global_theme - elif theme_level == ThemeLevel.Service: - if self.service_theme == u'': - self.theme = self.global_theme - else: - self.theme = self.service_theme - else: - # Images have a theme of -1 - if theme and theme != -1: - self.theme = theme - elif theme_level == ThemeLevel.Song or \ - theme_level == ThemeLevel.Service: - if self.service_theme == u'': - self.theme = self.global_theme - else: - self.theme = self.service_theme - else: - self.theme = self.global_theme - log.debug(u'theme is now %s', self.theme) - # Force the theme to be the one passed in. - if overrideLevels: - self.theme_data = theme - else: - self.theme_data = self.theme_manager.getThemeData(self.theme) - self._calculate_default(self.screens.current[u'size']) - self._build_text_rectangle(self.theme_data) - self.image_manager.add_image(self.theme_data.theme_name, - self.theme_data.background_filename) - return self._rect, self._rect_footer - - def generate_preview(self, theme_data, force_page=False): - """ - Generate a preview of a theme. - - ``theme_data`` - The theme to generated a preview for. - - ``force_page`` - Flag to tell message lines per page need to be generated. - """ - log.debug(u'generate preview') - # save value for use in format_slide - self.force_page = force_page - # set the default image size for previews - self.calculate_default(self.screens.preview[u'size']) - # build a service item to generate preview - serviceItem = ServiceItem() - serviceItem.theme = theme_data - if self.force_page: - # make big page for theme edit dialog to get line count - serviceItem.add_from_text(u'', VERSE + VERSE + VERSE, FOOTER) - else: - self.image_manager.del_image(theme_data.theme_name) - serviceItem.add_from_text(u'', VERSE, FOOTER) - serviceItem.render_manager = self - serviceItem.raw_footer = FOOTER - serviceItem.render(True) - if not self.force_page: - self.display.buildHtml(serviceItem) - raw_html = serviceItem.get_rendered_frame(0) - preview = self.display.text(raw_html) - # Reset the real screen size for subsequent render requests - self._calculate_default(self.screens.current[u'size']) - return preview - - def format_slide(self, slide, line_break, item): - """ - Calculate how much text can fit on a slide. - - ``slide`` - The words to go on the slides. - - ``line_break`` - Add line endings after each line of text used for bibles. - """ - log.debug(u'format slide') - # clean up line endings - slide = slide.replace(u'\r\n', u'\n') - lines = self._lines(slide) - pages = self._paginate_slide(lines, line_break, self.force_page) - if len(pages) > 1: - if item.is_capable(ItemCapabilities.AllowsVirtualSplit): - # do not forget the line breaks ! - slides = slide.split(u'\n[###]\n') - pages = [] - for slide in slides: - lines = self._lines(slide) - new_pages = self._paginate_slide(lines, line_break, - self.force_page) - for page in new_pages: - pages.append(page) - elif item.is_capable(ItemCapabilities.AllowsWordSplit): - lines = self._words(slide) - pages = self._paginate_slide(lines, False, self.force_page) - return pages - - def _calculate_default(self, screen): - """ - Calculate the default dimentions of the screen. - - ``screen`` - The QSize of the screen. - """ - log.debug(u'calculate default %s', screen) - self.width = screen.width() - self.height = screen.height() - self.screen_ratio = float(self.height) / float(self.width) - log.debug(u'calculate default %d, %d, %f', - self.width, self.height, self.screen_ratio) - # 90% is start of footer - self.footer_start = int(self.height * 0.90) - - def _build_text_rectangle(self, theme): - """ - Builds a text block using the settings in ``theme`` - and the size of the display screen.height. - - ``theme`` - The theme to build a text block for. - """ - log.debug(u'_build_text_rectangle') - main_rect = None - footer_rect = None - if not theme.font_main_override: - main_rect = QtCore.QRect(10, 0, self.width - 20, self.footer_start) - else: - main_rect = QtCore.QRect(theme.font_main_x, theme.font_main_y, - theme.font_main_width - 1, theme.font_main_height - 1) - if not theme.font_footer_override: - footer_rect = QtCore.QRect(10, self.footer_start, self.width - 20, - self.height - self.footer_start) - else: - footer_rect = QtCore.QRect(theme.font_footer_x, - theme.font_footer_y, theme.font_footer_width - 1, - theme.font_footer_height - 1) - self._set_text_rectangle(main_rect, footer_rect) - - def _set_text_rectangle(self, rect_main, rect_footer): - """ - Sets the rectangle within which text should be rendered. - - ``rect_main`` - The main text block. - - ``rect_footer`` - The footer text block. - """ - log.debug(u'set_text_rectangle %s , %s' % (rect_main, rect_footer)) - self._rect = rect_main - self._rect_footer = rect_footer - self.page_width = self._rect.width() - self.page_height = self._rect.height() - if self.theme_data.font_main_shadow: - self.page_width -= int(self.theme_data.font_main_shadow_size) - self.page_height -= int(self.theme_data.font_main_shadow_size) - self.web = QtWebKit.QWebView() - self.web.setVisible(False) - self.web.resize(self.page_width, self.page_height) - self.web_frame = self.web.page().mainFrame() - # Adjust width and height to account for shadow. outline done in css - self.page_shell = u'' \ - u'
' % \ - (build_lyrics_format_css(self.theme_data, self.page_width, - self.page_height), build_lyrics_outline_css(self.theme_data)) - - def _paginate_slide(self, lines, line_break, force_page=False): - """ - Figure out how much text can appear on a slide, using the current - theme settings. - - ``lines`` - The words to be fitted on the slide split into lines. - - ``line_break`` - Add line endings after each line of text used for bibles. - - ``force_page`` - Flag to tell message lines in page. - - """ - log.debug(u'format_slide - Start') - line_end = u'' - if line_break: - line_end = u'
' - formatted = [] - html_text = u'' - styled_text = u'' - line_count = 0 - for line in lines: - if line_count != -1: - line_count += 1 - styled_line = expand_tags(line) + line_end - styled_text += styled_line - html = self.page_shell + styled_text + u'
' - self.web.setHtml(html) - # Text too long so go to next page - if self.web_frame.contentsSize().height() > self.page_height: - if force_page and line_count > 0: - Receiver.send_message(u'theme_line_count', line_count) - line_count = -1 - if html_text.endswith(u'
'): - html_text = html_text[:len(html_text)-4] - formatted.append(html_text) - html_text = u'' - styled_text = styled_line - html_text += line + line_end - if html_text.endswith(u'
'): - html_text = html_text[:len(html_text)-4] - formatted.append(html_text) - log.debug(u'format_slide - End') - return formatted - - def _lines(self, words): - """ - Split the slide up by physical line - """ - # this parse we do not want to use this so remove it - words = words.replace(u'[---]', u'') - verses_text = words.split(u'\n') - text = [] - for verse in verses_text: - lines = verse.split(u'\n') - for line in lines: - text.append(line) - return text - - def _words(self, words): - """ - Split the slide up by word so can wrap better - """ - # this parse we are wordy - words = words.replace(u'\n', u' ') - verses_text = words.split(u' ') - text = [] - for verse in verses_text: - lines = verse.split(u' ') - for line in lines: - text.append(line + u' ') - return text - diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 594c6cc91..e94273122 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -30,7 +30,7 @@ from tempfile import gettempdir from PyQt4 import QtCore, QtGui -from openlp.core.lib import RenderManager, build_icon, OpenLPDockWidget, \ +from openlp.core.lib import Renderer, build_icon, OpenLPDockWidget, \ SettingsManager, PluginManager, Receiver, translate from openlp.core.lib.ui import UiStrings, base_action, checkable_action, \ icon_action @@ -587,9 +587,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): QtCore.SIGNAL(u'openlp_information_message'), self.onInformationMessage) # warning cyclic dependency - # RenderManager needs to call ThemeManager and - # ThemeManager needs to call RenderManager - self.renderManager = RenderManager( + # renderer needs to call ThemeManager and + # ThemeManager needs to call renderer + self.renderer = Renderer( self.themeManagerContents, self.screens) # Define the media Dock Manager self.mediaDockManager = MediaDockManager(self.MediaToolBox) @@ -597,7 +597,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # make the controllers available to the plugins self.pluginHelpers[u'preview'] = self.previewController self.pluginHelpers[u'live'] = self.liveController - self.pluginHelpers[u'render'] = self.renderManager + self.pluginHelpers[u'render'] = self.renderer self.pluginHelpers[u'service'] = self.ServiceManagerContents self.pluginHelpers[u'settings form'] = self.settingsForm self.pluginHelpers[u'toolbox'] = self.mediaDockManager @@ -818,7 +818,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): their locations """ log.debug(u'screenChanged') - self.renderManager.update_display() + self.renderer.update_display() self.setFocus() self.activateWindow() diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 168ad8a8c..61dc4e3da 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -970,7 +970,7 @@ class ServiceManager(QtGui.QWidget): sure the theme combo box is in the correct state. """ log.debug(u'themeChange') - if self.mainwindow.renderManager.theme_level == ThemeLevel.Global: + if self.mainwindow.renderer.theme_level == ThemeLevel.Global: self.toolbar.actions[u'ThemeLabel'].setVisible(False) self.toolbar.actions[u'ThemeWidget'].setVisible(False) else: @@ -985,7 +985,7 @@ class ServiceManager(QtGui.QWidget): Receiver.send_message(u'cursor_busy') log.debug(u'regenerateServiceItems') # force reset of renderer as theme data has changed - self.mainwindow.renderManager.themedata = None + self.mainwindow.renderer.themedata = None if self.serviceItems: tempServiceItems = self.serviceItems self.serviceManagerList.clear() @@ -1250,7 +1250,7 @@ class ServiceManager(QtGui.QWidget): index = 0 self.service_theme = u'' self.themeComboBox.setCurrentIndex(index) - self.mainwindow.renderManager.set_service_theme(self.service_theme) + self.mainwindow.renderer.set_service_theme(self.service_theme) self.regenerateServiceItems() def onThemeChangeAction(self): diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 232653326..ee617287a 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -407,7 +407,7 @@ class SlideController(QtGui.QWidget): """ # rebuild display as screen size changed self.display = MainDisplay(self, self.screens, self.isLive) - self.display.imageManager = self.parent.renderManager.image_manager + self.display.imageManager = self.parent.renderer.image_manager self.display.alertTab = self.alertTab self.display.setup() if self.isLive: diff --git a/openlp/core/ui/themestab.py b/openlp/core/ui/themestab.py index 1b76d2198..1e6ddb4a8 100644 --- a/openlp/core/ui/themestab.py +++ b/openlp/core/ui/themestab.py @@ -191,7 +191,7 @@ class ThemesTab(SettingsTab): id = 0 # Not Found self.global_theme = u'' self.DefaultComboBox.setCurrentIndex(id) - self.parent.renderManager.set_global_theme( + self.parent.renderer.set_global_theme( self.global_theme, self.theme_level) if self.global_theme is not u'': self.__previewGlobalTheme() From 2ba0d410fc33f8d739b06645fb1ed5d23b1e99e6 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 28 Mar 2011 19:56:39 +0100 Subject: [PATCH 06/57] More Cleanups --- openlp/core/lib/plugin.py | 2 +- openlp/core/lib/renderer.py | 2 +- openlp/core/lib/serviceitem.py | 4 ++-- openlp/core/ui/mainwindow.py | 4 ++-- openlp/core/ui/servicemanager.py | 4 ++-- openlp/core/ui/slidecontroller.py | 12 ++++++------ openlp/core/ui/thememanager.py | 6 +++--- openlp/core/ui/themestab.py | 6 +++--- .../plugins/presentations/lib/impresscontroller.py | 4 ++-- .../presentations/lib/powerpointcontroller.py | 6 +++--- .../plugins/presentations/lib/pptviewcontroller.py | 6 +++--- openlp/plugins/songs/forms/editsongform.py | 4 ++-- 12 files changed, 30 insertions(+), 30 deletions(-) diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index eda8ecfa1..375331719 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -160,7 +160,7 @@ class Plugin(QtCore.QObject): self.log = logging.getLogger(self.name) self.previewController = pluginHelpers[u'preview'] self.liveController = pluginHelpers[u'live'] - self.renderManager = pluginHelpers[u'render'] + self.renderer = pluginHelpers[u'renderer'] self.serviceManager = pluginHelpers[u'service'] self.settingsForm = pluginHelpers[u'settings form'] self.mediadock = pluginHelpers[u'toolbox'] diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 9256eb096..c1a866668 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -60,7 +60,7 @@ class Renderer(object): ``screen_number`` Defaults to *0*. The index of the output/display screen. """ - log.info(u'RenderManager Loaded') + log.info(u'Renderer Loaded') def __init__(self, theme_manager, screens): """ diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index f996c3f97..c3e6b17aa 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -83,7 +83,7 @@ class ServiceItem(object): The plugin that this service item belongs to. """ if plugin: - self.renderer = plugin.renderManager + self.renderer = plugin.renderer self.name = plugin.name self.title = u'' self.shortname = u'' @@ -455,4 +455,4 @@ class ServiceItem(object): elif not start and end: return end else: - return u'%s : %s' % (start, end) + return u'%s : %s' % (start, end) \ No newline at end of file diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index e94273122..e305e06cf 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -588,7 +588,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.onInformationMessage) # warning cyclic dependency # renderer needs to call ThemeManager and - # ThemeManager needs to call renderer + # ThemeManager needs to call Renderer self.renderer = Renderer( self.themeManagerContents, self.screens) # Define the media Dock Manager @@ -597,7 +597,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # make the controllers available to the plugins self.pluginHelpers[u'preview'] = self.previewController self.pluginHelpers[u'live'] = self.liveController - self.pluginHelpers[u'render'] = self.renderer + self.pluginHelpers[u'renderer'] = self.renderer self.pluginHelpers[u'service'] = self.ServiceManagerContents self.pluginHelpers[u'settings form'] = self.settingsForm self.pluginHelpers[u'toolbox'] = self.mediaDockManager diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 61dc4e3da..eaa80afac 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -564,7 +564,7 @@ class ServiceManager(QtGui.QWidget): for item in items: serviceItem = ServiceItem() serviceItem.from_service = True - serviceItem.render_manager = self.mainwindow.renderManager + serviceItem.renderer = self.mainwindow.renderer serviceItem.set_from_service(item, self.servicePath) self.validateItem(serviceItem) self.addServiceItem(serviceItem) @@ -958,7 +958,7 @@ class ServiceManager(QtGui.QWidget): """ log.debug(u'onThemeComboBoxSelected') self.service_theme = unicode(self.themeComboBox.currentText()) - self.mainwindow.renderManager.set_service_theme(self.service_theme) + self.mainwindow.renderer.set_service_theme(self.service_theme) QtCore.QSettings().setValue( self.mainwindow.serviceSettingsSection + u'/service theme', QtCore.QVariant(self.service_theme)) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index ee617287a..da14f3b0a 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -618,19 +618,19 @@ class SlideController(QtGui.QWidget): label.setScaledContents(True) if self.serviceItem.is_command(): image = resize_image(frame[u'image'], - self.parent.renderManager.width, - self.parent.renderManager.height) + self.parent.renderer.width, + self.parent.renderer.height) else: # If current slide set background to image if framenumber == slideno: self.serviceItem.bg_image_bytes = \ - self.parent.renderManager.image_manager. \ + self.parent.renderer.image_manager. \ get_image_bytes(frame[u'title']) - image = self.parent.renderManager.image_manager. \ + image = self.parent.renderer.image_manager. \ get_image(frame[u'title']) label.setPixmap(QtGui.QPixmap.fromImage(image)) self.previewListWidget.setCellWidget(framenumber, 0, label) - slideHeight = width * self.parent.renderManager.screen_ratio + slideHeight = width * self.parent.renderer.screen_ratio row += 1 text.append(unicode(row)) self.previewListWidget.setItem(framenumber, 0, item) @@ -1111,4 +1111,4 @@ class SlideController(QtGui.QWidget): blank.setChecked(False) self.hideMenu.setDefaultAction(blank) QtCore.QSettings().remove( - self.parent.generalSettingsSection + u'/screen blank') + self.parent.generalSettingsSection + u'/screen blank') \ No newline at end of file diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index d033daeb3..1356a30b2 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -656,7 +656,7 @@ class ThemeManager(QtGui.QWidget): def generateImage(self, themeData, forcePage=False): """ - Call the RenderManager to build a Sample Image + Call the renderer to build a Sample Image ``themeData`` The theme to generated a preview for. @@ -665,7 +665,7 @@ class ThemeManager(QtGui.QWidget): Flag to tell message lines per page need to be generated. """ log.debug(u'generateImage \n%s ', themeData) - return self.mainwindow.renderManager.generate_preview( + return self.mainwindow.renderer.generate_preview( themeData, forcePage) def getPreviewImage(self, theme): @@ -802,4 +802,4 @@ class ThemeManager(QtGui.QWidget): vAlignCorrection = VerticalType.Bottom newtheme.display_horizontal_align = theme.HorizontalAlign newtheme.display_vertical_align = vAlignCorrection - return newtheme.extract_xml() + return newtheme.extract_xml() \ No newline at end of file diff --git a/openlp/core/ui/themestab.py b/openlp/core/ui/themestab.py index 1e6ddb4a8..27018af07 100644 --- a/openlp/core/ui/themestab.py +++ b/openlp/core/ui/themestab.py @@ -147,7 +147,7 @@ class ThemesTab(SettingsTab): settings.setValue(u'global theme', QtCore.QVariant(self.global_theme)) settings.endGroup() - self.parent.renderManager.set_global_theme( + self.parent.renderer.set_global_theme( self.global_theme, self.theme_level) Receiver.send_message(u'theme_update_global', self.global_theme) @@ -165,7 +165,7 @@ class ThemesTab(SettingsTab): def onDefaultComboBoxChanged(self, value): self.global_theme = unicode(self.DefaultComboBox.currentText()) - self.parent.renderManager.set_global_theme( + self.parent.renderer.set_global_theme( self.global_theme, self.theme_level) self.__previewGlobalTheme() @@ -206,4 +206,4 @@ class ThemesTab(SettingsTab): if not preview.isNull(): preview = preview.scaled(300, 255, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) - self.DefaultListView.setPixmap(preview) + self.DefaultListView.setPixmap(preview) \ No newline at end of file diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index 8166a2258..c84f0ff1e 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -244,7 +244,7 @@ class ImpressDocument(PresentationDocument): return False self.presentation = self.document.getPresentation() self.presentation.Display = \ - self.controller.plugin.renderManager.screens.current_display + 1 + self.controller.plugin.renderer.screens.current_display + 1 self.control = None self.create_thumbnails() return True @@ -463,4 +463,4 @@ class ImpressDocument(PresentationDocument): shape = page.getByIndex(idx) if shape.supportsService("com.sun.star.drawing.Text"): text += shape.getString() + '\n' - return text + return text \ No newline at end of file diff --git a/openlp/plugins/presentations/lib/powerpointcontroller.py b/openlp/plugins/presentations/lib/powerpointcontroller.py index 793b0b75d..3045eed13 100644 --- a/openlp/plugins/presentations/lib/powerpointcontroller.py +++ b/openlp/plugins/presentations/lib/powerpointcontroller.py @@ -253,8 +253,8 @@ class PowerpointDocument(PresentationDocument): dpi = 96 self.presentation.SlideShowSettings.Run() self.presentation.SlideShowWindow.View.GotoSlide(1) - rendermanager = self.controller.plugin.renderManager - rect = rendermanager.screens.current[u'size'] + renderer = self.controller.plugin.renderer + rect = renderer.screens.current[u'size'] self.presentation.SlideShowWindow.Top = rect.y() * 72 / dpi self.presentation.SlideShowWindow.Height = rect.height() * 72 / dpi self.presentation.SlideShowWindow.Left = rect.x() * 72 / dpi @@ -326,4 +326,4 @@ def _get_text_from_shapes(shapes): shape = shapes(idx + 1) if shape.HasTextFrame: text += shape.TextFrame.TextRange.Text + '\n' - return text + return text \ No newline at end of file diff --git a/openlp/plugins/presentations/lib/pptviewcontroller.py b/openlp/plugins/presentations/lib/pptviewcontroller.py index 94fd05f31..354c33361 100644 --- a/openlp/plugins/presentations/lib/pptviewcontroller.py +++ b/openlp/plugins/presentations/lib/pptviewcontroller.py @@ -121,8 +121,8 @@ class PptviewDocument(PresentationDocument): The file name of the presentations to run. """ log.debug(u'LoadPresentation') - rendermanager = self.controller.plugin.renderManager - rect = rendermanager.screens.current[u'size'] + renderer = self.controller.plugin.renderer + rect = renderer.screens.current[u'size'] rect = RECT(rect.x(), rect.y(), rect.right(), rect.bottom()) filepath = str(self.filepath.replace(u'/', u'\\')) if not os.path.isdir(self.get_temp_folder()): @@ -244,4 +244,4 @@ class PptviewDocument(PresentationDocument): """ Triggers the previous slide on the running presentation """ - self.controller.process.PrevStep(self.pptid) + self.controller.process.PrevStep(self.pptid) \ No newline at end of file diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 7f7b7fd90..9bb58bd82 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -89,7 +89,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.onVerseListViewPressed) QtCore.QObject.connect(self.themeAddButton, QtCore.SIGNAL(u'clicked()'), - self.parent.parent.renderManager.theme_manager.onAddTheme) + self.parent.parent.renderer.theme_manager.onAddTheme) QtCore.QObject.connect(self.maintenanceButton, QtCore.SIGNAL(u'clicked()'), self.onMaintenanceButtonClicked) QtCore.QObject.connect(Receiver.get_receiver(), @@ -788,4 +788,4 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.song.verse_order) except: log.exception(u'Problem processing song Lyrics \n%s', - sxml.dump_xml()) + sxml.dump_xml()) \ No newline at end of file From 8790f17afa78303bfad56690ffc3066cc32aab48 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 29 Mar 2011 17:25:48 +0100 Subject: [PATCH 07/57] Fix theme editing --- openlp/core/lib/renderer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index c1a866668..d612c9a58 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -182,7 +182,7 @@ class Renderer(object): # save value for use in format_slide self.force_page = force_page # set the default image size for previews - self.calculate_default(self.screens.preview[u'size']) + self._calculate_default(self.screens.preview[u'size']) # build a service item to generate preview serviceItem = ServiceItem() serviceItem.theme = theme_data @@ -192,7 +192,7 @@ class Renderer(object): else: self.image_manager.del_image(theme_data.theme_name) serviceItem.add_from_text(u'', VERSE, FOOTER) - serviceItem.render_manager = self + serviceItem.renderer = self serviceItem.raw_footer = FOOTER serviceItem.render(True) if not self.force_page: From 6342a2aaa0fef2f379b4ea5e4340a2ec2a3a782e Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 29 Mar 2011 20:04:16 +0200 Subject: [PATCH 08/57] changed --- to ### --- openlp/plugins/songs/lib/xml.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/songs/lib/xml.py b/openlp/plugins/songs/lib/xml.py index daec73d64..b4a9840a7 100644 --- a/openlp/plugins/songs/lib/xml.py +++ b/openlp/plugins/songs/lib/xml.py @@ -274,7 +274,7 @@ class OpenLyrics(object): verse_tag = verse[0][u'type'][0].lower() verse_number = verse[0][u'label'] # Create a list with all "sub" verses. - sub_verses = verse[1].split(u'[---]') + sub_verses = verse[1].split(u'[###]') for sub_index, sub_verse in enumerate(sub_verses): verse_def = verse_tag + verse_number # We have more than one sub verse, consequently we need "v1a". @@ -475,7 +475,7 @@ class OpenLyrics(object): if self._get(verse, u'lang'): lang = self._get(verse, u'lang') if verses.has_key((verse_tag, verse_number, lang)): - verses[(verse_tag, verse_number, lang)] += u'\n[---]\n' + text + verses[(verse_tag, verse_number, lang)] += u'\n[###]\n' + text else: verses[(verse_tag, verse_number, lang)] = text for verse in verses: From a0798b66bbcdafa9a14550e4aa62d62a67fab5ca Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 29 Mar 2011 20:23:01 +0200 Subject: [PATCH 09/57] changed wording --- openlp/plugins/songs/lib/xml.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/openlp/plugins/songs/lib/xml.py b/openlp/plugins/songs/lib/xml.py index b4a9840a7..556835587 100644 --- a/openlp/plugins/songs/lib/xml.py +++ b/openlp/plugins/songs/lib/xml.py @@ -273,19 +273,19 @@ class OpenLyrics(object): for verse in verse_list: verse_tag = verse[0][u'type'][0].lower() verse_number = verse[0][u'label'] - # Create a list with all "sub" verses. - sub_verses = verse[1].split(u'[###]') - for sub_index, sub_verse in enumerate(sub_verses): + # Create a list with all "virtual" verses. + virtual_verses = verse[1].split(u'[###]') + for index, virtual_verse in enumerate(virtual_verses): verse_def = verse_tag + verse_number - # We have more than one sub verse, consequently we need "v1a". - if len(sub_verses) > 1: - verse_def += list(u'abcdefghijklmnopqrstuvwxyz')[sub_index] + # We need "v1a" because we have more than one virtual verse. + if len(virtual_verses) > 1: + verse_def += list(u'abcdefghijklmnopqrstuvwxyz')[index] element = \ self._add_text_to_element(u'verse', lyrics, None, verse_def) if verse[0].has_key(u'lang'): element.set(u'lang', verse[0][u'lang']) element = self._add_text_to_element(u'lines', element) - for line in sub_verse.strip(u'\n').split(u'\n'): + for line in virtual_verse.strip(u'\n').split(u'\n'): self._add_text_to_element(u'line', element, line) return self._extract_xml(song_xml) From 857756e20f78682e17e56f14cec91605e2e8c6b0 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 29 Mar 2011 21:06:18 +0100 Subject: [PATCH 10/57] Change ### to ==== --- openlp/core/lib/renderer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index d612c9a58..d0bfe6f53 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -221,7 +221,7 @@ class Renderer(object): if len(pages) > 1: if item.is_capable(ItemCapabilities.AllowsVirtualSplit): # do not forget the line breaks ! - slides = slide.split(u'\n[###]\n') + slides = slide.split(u'\n[===]\n') pages = [] for slide in slides: lines = self._lines(slide) From ea6f90fc749933e4db245af029879b892067194e Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 29 Mar 2011 21:38:10 +0100 Subject: [PATCH 11/57] Change === and --- around --- openlp/core/lib/renderer.py | 2 +- openlp/plugins/custom/forms/editcustomform.py | 2 +- openlp/plugins/custom/forms/editcustomslideform.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index d0bfe6f53..16dbfae79 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -221,7 +221,7 @@ class Renderer(object): if len(pages) > 1: if item.is_capable(ItemCapabilities.AllowsVirtualSplit): # do not forget the line breaks ! - slides = slide.split(u'\n[===]\n') + slides = slide.split(u'\n[---]\n') pages = [] for slide in slides: lines = self._lines(slide) diff --git a/openlp/plugins/custom/forms/editcustomform.py b/openlp/plugins/custom/forms/editcustomform.py index f81bd4c7d..1bbc30a49 100644 --- a/openlp/plugins/custom/forms/editcustomform.py +++ b/openlp/plugins/custom/forms/editcustomform.py @@ -173,7 +173,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog): item = self.slideListView.item(row) slide_list += item.text() if row != self.slideListView.count() - 1: - slide_list += u'\n[---]\n' + slide_list += u'\n[===]\n' self.editSlideForm.setText(slide_list) if self.editSlideForm.exec_(): self.updateSlideList(self.editSlideForm.getText(), True) diff --git a/openlp/plugins/custom/forms/editcustomslideform.py b/openlp/plugins/custom/forms/editcustomslideform.py index 7d4e32968..bf775a1f2 100644 --- a/openlp/plugins/custom/forms/editcustomslideform.py +++ b/openlp/plugins/custom/forms/editcustomslideform.py @@ -63,7 +63,7 @@ class EditCustomSlideForm(QtGui.QDialog, Ui_CustomSlideEditDialog): """ Returns a list with all slides. """ - return self.slideTextEdit.toPlainText().split(u'\n[---]\n') + return self.slideTextEdit.toPlainText().split(u'\n[===]\n') def onSplitButtonPressed(self): """ @@ -71,5 +71,5 @@ class EditCustomSlideForm(QtGui.QDialog, Ui_CustomSlideEditDialog): """ if self.slideTextEdit.textCursor().columnNumber() != 0: self.slideTextEdit.insertPlainText(u'\n') - self.slideTextEdit.insertPlainText(u'[---]\n') + self.slideTextEdit.insertPlainText(u'[===]\n') self.slideTextEdit.setFocus() From 253087e2c6016adf07f73434f2eea121d372df25 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 30 Mar 2011 09:13:04 +0200 Subject: [PATCH 12/57] fixed verse sorting, change ### to --- --- openlp/plugins/songs/lib/xml.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/songs/lib/xml.py b/openlp/plugins/songs/lib/xml.py index 556835587..05da325e2 100644 --- a/openlp/plugins/songs/lib/xml.py +++ b/openlp/plugins/songs/lib/xml.py @@ -32,7 +32,7 @@ The basic XML for storing the lyrics in the song database looks like this:: - + @@ -129,7 +129,8 @@ class SongXML(object): The returned list has the following format:: - [[{'lang': 'en', 'type': 'v', 'label': '1'}, u"English verse"], + [[{'type': 'v', 'label': '1'}, + u"virtual slide 1[---]virtual slide 2"], [{'lang': 'en', 'type': 'c', 'label': '1'}, u"English chorus"]] """ self.song_xml = None @@ -274,7 +275,7 @@ class OpenLyrics(object): verse_tag = verse[0][u'type'][0].lower() verse_number = verse[0][u'label'] # Create a list with all "virtual" verses. - virtual_verses = verse[1].split(u'[###]') + virtual_verses = verse[1].split(u'[---]') for index, virtual_verse in enumerate(virtual_verses): verse_def = verse_tag + verse_number # We need "v1a" because we have more than one virtual verse. @@ -455,6 +456,7 @@ class OpenLyrics(object): """ sxml = SongXML() verses = {} + verse_def_list = [] for verse in lyrics.verse: text = u'' for lines in verse.lines: @@ -475,10 +477,12 @@ class OpenLyrics(object): if self._get(verse, u'lang'): lang = self._get(verse, u'lang') if verses.has_key((verse_tag, verse_number, lang)): - verses[(verse_tag, verse_number, lang)] += u'\n[###]\n' + text + verses[(verse_tag, verse_number, lang)] += u'\n[---]\n' + text else: verses[(verse_tag, verse_number, lang)] = text - for verse in verses: + verse_def_list.append((verse_tag, verse_number, lang)) + # We have to use a list to keep the order, as dicts are not sorted. + for verse in verse_def_list: sxml.add_verse_to_lyrics( verse[0], verse[1], verses[verse], verse[2]) song.lyrics = unicode(sxml.extract_xml(), u'utf-8') From 3155bde0b245727af065e7bf2e5ab4b7af715401 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 1 Apr 2011 05:48:09 +0100 Subject: [PATCH 13/57] inprogress --- openlp/core/lib/renderer.py | 58 ++++++++++++++++++++++---- openlp/core/lib/serviceitem.py | 6 +-- openlp/plugins/bibles/lib/mediaitem.py | 8 ++-- 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 16dbfae79..c8e8af41d 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -120,7 +120,7 @@ class Renderer(object): self.service_theme = service_theme self.theme_data = None - def set_override_theme(self, theme, overrideLevels=False): + def set_override_theme(self, theme, override_levels=False): """ Set the appropriate theme depending on the theme level. Called by the service item when building a display frame @@ -129,13 +129,13 @@ class Renderer(object): The name of the song-level theme. None means the service item wants to use the given value. - ``overrideLevels`` + ``override_levels`` Used to force the theme data passed in to be used. """ log.debug(u'set override theme to %s', theme) theme_level = self.theme_level - if overrideLevels: + if override_levels: theme_level = ThemeLevel.Song if theme_level == ThemeLevel.Global: self.theme = self.global_theme @@ -158,7 +158,7 @@ class Renderer(object): self.theme = self.global_theme log.debug(u'theme is now %s', self.theme) # Force the theme to be the one passed in. - if overrideLevels: + if override_levels: self.theme_data = theme else: self.theme_data = self.theme_manager.getThemeData(self.theme) @@ -216,9 +216,13 @@ class Renderer(object): log.debug(u'format slide') # clean up line endings slide = slide.replace(u'\r\n', u'\n') + print "###############" + print [slide] lines = self._lines(slide) pages = self._paginate_slide(lines, line_break, self.force_page) + print len(pages) if len(pages) > 1: + # Songs and Custom if item.is_capable(ItemCapabilities.AllowsVirtualSplit): # do not forget the line breaks ! slides = slide.split(u'\n[---]\n') @@ -229,9 +233,11 @@ class Renderer(object): self.force_page) for page in new_pages: pages.append(page) +# # Bibles elif item.is_capable(ItemCapabilities.AllowsWordSplit): lines = self._words(slide) - pages = self._paginate_slide(lines, False, self.force_page) + pages = self._paginate_slide(lines, False) + print pages return pages def _calculate_default(self, screen): @@ -352,12 +358,50 @@ class Renderer(object): log.debug(u'format_slide - End') return formatted + def _paginate_slide_words(self, lines, line_break): + """ + Figure out how much text can appear on a slide, using the current + theme settings. + + ``lines`` + The words to be fitted on the slide split into lines. + """ + log.debug(u'format_slide - Start') + line_end = u'' + if line_break: + line_end = u'
' + formatted = [] + html_text = u'' + styled_text = u'' + for line in lines: + styled_line = expand_tags(line) + if line.startswith(u'{su}'): + styled_line = line_end + styled_line + styled_text += styled_line + html = self.page_shell + styled_text + u'
' + self.web.setHtml(html) + # Text too long so go to next page + if self.web_frame.contentsSize().height() > self.page_height: + #split + if html_text.endswith(u'
'): + html_text = html_text[:len(html_text)-4] + formatted.append(html_text) + html_text = u'' + styled_text = styled_line + html_text += line# + line_end + if html_text.endswith(u'
'): + html_text = html_text[:len(html_text)-4] + formatted.append(html_text) + log.debug(u'format_slide - End') + return formatted + + def _lines(self, words): """ Split the slide up by physical line """ # this parse we do not want to use this so remove it - words = words.replace(u'[---]', u'') + words = words.replace(u'\n[---]\n', u'') verses_text = words.split(u'\n') text = [] for verse in verses_text: @@ -371,6 +415,7 @@ class Renderer(object): Split the slide up by word so can wrap better """ # this parse we are wordy + words = words.replace(u'[---]', u'').lstrip() words = words.replace(u'\n', u' ') verses_text = words.split(u' ') text = [] @@ -379,4 +424,3 @@ class Renderer(object): for line in lines: text.append(line + u' ') return text - diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index c3e6b17aa..dab4b671a 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -153,7 +153,7 @@ class ServiceItem(object): self.icon = icon self.iconic_representation = build_icon(icon) - def render(self, useOverride=False): + def render(self, use_override=False): """ The render method is what generates the frames for the screen and obtains the display information from the renderemanager. @@ -168,7 +168,7 @@ class ServiceItem(object): line_break = False theme = self.theme if self.theme else None self.main, self.footer = \ - self.renderer.set_override_theme(theme, useOverride) + self.renderer.set_override_theme(theme, use_override) self.themedata = self.renderer.theme_data if self.service_item_type == ServiceItemType.Text: log.debug(u'Formatting slides') @@ -455,4 +455,4 @@ class ServiceItem(object): elif not start and end: return end else: - return u'%s : %s' % (start, end) \ No newline at end of file + return u'%s : %s' % (start, end) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 405507523..afbf9764b 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -799,9 +799,9 @@ class BibleMediaItem(MediaManagerItem): else: verse_text = unicode(verse) if self.settings.display_style == DisplayStyle.Round: - return u'{su}(%s){/su}' % verse_text + return u'\n[---]\n{su}(%s){/su}' % verse_text if self.settings.display_style == DisplayStyle.Curly: - return u'{su}{%s}{/su}' % verse_text + return u'\n[---]\n{su}{%s}{/su}' % verse_text if self.settings.display_style == DisplayStyle.Square: - return u'{su}[%s]{/su}' % verse_text - return u'{su}%s{/su}' % verse_text + return u'\n[---]\n{su}[%s]{/su}' % verse_text + return u'\n[---]\n{su}%s{/su}' % verse_text From 63bfac4b7eb7822b1af8fca9c44fc8c591207a91 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 3 Apr 2011 07:19:03 +0100 Subject: [PATCH 14/57] Changes continue --- openlp/core/lib/renderer.py | 118 ++++++++++++++++--------- openlp/plugins/bibles/lib/mediaitem.py | 8 +- 2 files changed, 80 insertions(+), 46 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index c8e8af41d..0ae9149fa 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -45,6 +45,8 @@ VERSE = u'The Lord said to {r}Noah{/r}: \n' \ 'r{/pk}{o}e{/o}{pp}n{/pp} of the Lord\n' FOOTER = [u'Arky Arky (Unknown)', u'Public Domain', u'CCLI 123456'] +HTML_END = u'' + class Renderer(object): """ Class to pull all Renderer interactions into one place. The plugins will @@ -72,7 +74,6 @@ class Renderer(object): self.display = MainDisplay(self, screens, False) self.display.imageManager = self.image_manager self.theme_manager = theme_manager - self.theme = u'' self.service_theme = u'' self.theme_level = u'' self.override_background = None @@ -120,7 +121,7 @@ class Renderer(object): self.service_theme = service_theme self.theme_data = None - def set_override_theme(self, theme, override_levels=False): + def set_override_theme(self, override_theme, override_levels=False): """ Set the appropriate theme depending on the theme level. Called by the service item when building a display frame @@ -133,35 +134,35 @@ class Renderer(object): Used to force the theme data passed in to be used. """ - log.debug(u'set override theme to %s', theme) + log.debug(u'set override theme to %s', override_theme) theme_level = self.theme_level if override_levels: theme_level = ThemeLevel.Song if theme_level == ThemeLevel.Global: - self.theme = self.global_theme + theme = self.global_theme elif theme_level == ThemeLevel.Service: if self.service_theme == u'': - self.theme = self.global_theme + theme = self.global_theme else: - self.theme = self.service_theme + theme = self.service_theme else: # Images have a theme of -1 - if theme and theme != -1: - self.theme = theme + if override_theme and override_theme != -1: + theme = override_theme elif theme_level == ThemeLevel.Song or \ theme_level == ThemeLevel.Service: if self.service_theme == u'': - self.theme = self.global_theme + theme = self.global_theme else: - self.theme = self.service_theme + theme = self.service_theme else: - self.theme = self.global_theme - log.debug(u'theme is now %s', self.theme) + theme = self.global_theme + log.debug(u'theme is now %s', theme) # Force the theme to be the one passed in. if override_levels: - self.theme_data = theme + self.theme_data = override_theme else: - self.theme_data = self.theme_manager.getThemeData(self.theme) + self.theme_data = self.theme_manager.getThemeData(theme) self._calculate_default(self.screens.current[u'size']) self._build_text_rectangle(self.theme_data) self.image_manager.add_image(self.theme_data.theme_name, @@ -203,11 +204,11 @@ class Renderer(object): self._calculate_default(self.screens.current[u'size']) return preview - def format_slide(self, slide, line_break, item): + def format_slide(self, text, line_break, item): """ Calculate how much text can fit on a slide. - ``slide`` + ``text`` The words to go on the slides. ``line_break`` @@ -215,17 +216,13 @@ class Renderer(object): """ log.debug(u'format slide') # clean up line endings - slide = slide.replace(u'\r\n', u'\n') - print "###############" - print [slide] - lines = self._lines(slide) + lines = self._lines(text) pages = self._paginate_slide(lines, line_break, self.force_page) - print len(pages) if len(pages) > 1: # Songs and Custom if item.is_capable(ItemCapabilities.AllowsVirtualSplit): # do not forget the line breaks ! - slides = slide.split(u'\n[---]\n') + slides = text.split(u'\n[---]\n') pages = [] for slide in slides: lines = self._lines(slide) @@ -235,9 +232,7 @@ class Renderer(object): pages.append(page) # # Bibles elif item.is_capable(ItemCapabilities.AllowsWordSplit): - lines = self._words(slide) - pages = self._paginate_slide(lines, False) - print pages + pages = self._paginate_slide_words(text, line_break) return pages def _calculate_default(self, screen): @@ -339,7 +334,7 @@ class Renderer(object): line_count += 1 styled_line = expand_tags(line) + line_end styled_text += styled_line - html = self.page_shell + styled_text + u'' + html = self.page_shell + styled_text + HTML_END self.web.setHtml(html) # Text too long so go to next page if self.web_frame.contentsSize().height() > self.page_height: @@ -358,14 +353,20 @@ class Renderer(object): log.debug(u'format_slide - End') return formatted - def _paginate_slide_words(self, lines, line_break): + def _paginate_slide_words(self, text, line_break): """ Figure out how much text can appear on a slide, using the current - theme settings. + theme settings. This version is to handle text which needs to be split + into words to get it to fit. - ``lines`` + ``text`` The words to be fitted on the slide split into lines. + + ``line_break`` + Add line endings after each line of text used for bibles. + """ + print [text] log.debug(u'format_slide - Start') line_end = u'' if line_break: @@ -373,35 +374,69 @@ class Renderer(object): formatted = [] html_text = u'' styled_text = u'' + line_count = 0 + force_current = False + lines = self._lines(text, u'[---]') + # Loop through the lines for line in lines: + line_count += 1 styled_line = expand_tags(line) - if line.startswith(u'{su}'): - styled_line = line_end + styled_line + styled_line = line_end + styled_line styled_text += styled_line - html = self.page_shell + styled_text + u'' + html = self.page_shell + styled_text + HTML_END self.web.setHtml(html) # Text too long so go to next page + print self.web_frame.contentsSize().height() , self.page_height, [line] if self.web_frame.contentsSize().height() > self.page_height: - #split - if html_text.endswith(u'
'): - html_text = html_text[:len(html_text)-4] - formatted.append(html_text) + # we have more than 1 verse on the slide + print "A", line_count + if line_count > 1: + if html_text.endswith(u'
'): + html_text = html_text[:len(html_text)-4] + formatted.append(html_text) + force_current = True + print "##### > 1" + print [html_text] html_text = u'' - styled_text = styled_line - html_text += line# + line_end + # only one block on page so lets make it words. + if line_count == 1 or force_current: + print "##### = 1" + print [line] + force_current = False + styled_text = u'' + words = self._words(line) + styled_text = u'' + for word in words: + styled_line = expand_tags(word) + styled_text += styled_line + html = self.page_shell + styled_text + HTML_END + self.web.setHtml(html) + # Text too long so go to next page + print "B", self.web_frame.contentsSize().height() , self.page_height + if self.web_frame.contentsSize().height() > self.page_height: + if html_text.endswith(u'
'): + html_text = html_text[:len(html_text)-4] + print "c", [html_text] + formatted.append(html_text) + html_text = u'' + + styled_text = styled_line + html_text += word + line_count = 0 + styled_text = styled_line + html_text += line + line_end if html_text.endswith(u'
'): html_text = html_text[:len(html_text)-4] formatted.append(html_text) log.debug(u'format_slide - End') return formatted - - def _lines(self, words): + def _lines(self, words, split=u'\n[---]\n'): """ Split the slide up by physical line """ # this parse we do not want to use this so remove it - words = words.replace(u'\n[---]\n', u'') + words = words.replace(split, u'') verses_text = words.split(u'\n') text = [] for verse in verses_text: @@ -415,7 +450,6 @@ class Renderer(object): Split the slide up by word so can wrap better """ # this parse we are wordy - words = words.replace(u'[---]', u'').lstrip() words = words.replace(u'\n', u' ') verses_text = words.split(u' ') text = [] diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index afbf9764b..8440cb783 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -799,9 +799,9 @@ class BibleMediaItem(MediaManagerItem): else: verse_text = unicode(verse) if self.settings.display_style == DisplayStyle.Round: - return u'\n[---]\n{su}(%s){/su}' % verse_text + return u'[---]{su}(%s){/su}' % verse_text if self.settings.display_style == DisplayStyle.Curly: - return u'\n[---]\n{su}{%s}{/su}' % verse_text + return u'[---]{su}{%s}{/su}' % verse_text if self.settings.display_style == DisplayStyle.Square: - return u'\n[---]\n{su}[%s]{/su}' % verse_text - return u'\n[---]\n{su}%s{/su}' % verse_text + return u'[---]{su}[%s]{/su}' % verse_text + return u'[---]{su}%s{/su}' % verse_text From 34348c84656bc910bc4ac749a755a3888d35097c Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 8 Apr 2011 16:35:33 +0100 Subject: [PATCH 15/57] More changes --- openlp/core/lib/renderer.py | 144 ++++++++++++++++++++++++------------ 1 file changed, 96 insertions(+), 48 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 0ae9149fa..7a9e89f7b 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -214,9 +214,10 @@ class Renderer(object): ``line_break`` Add line endings after each line of text used for bibles. """ + print [text] log.debug(u'format slide') # clean up line endings - lines = self._lines(text) + lines = self._lines_split(text) pages = self._paginate_slide(lines, line_break, self.force_page) if len(pages) > 1: # Songs and Custom @@ -377,66 +378,99 @@ class Renderer(object): line_count = 0 force_current = False lines = self._lines(text, u'[---]') + previous_line = u'' # Loop through the lines for line in lines: - line_count += 1 - styled_line = expand_tags(line) - styled_line = line_end + styled_line - styled_text += styled_line - html = self.page_shell + styled_text + HTML_END - self.web.setHtml(html) - # Text too long so go to next page - print self.web_frame.contentsSize().height() , self.page_height, [line] - if self.web_frame.contentsSize().height() > self.page_height: - # we have more than 1 verse on the slide - print "A", line_count - if line_count > 1: - if html_text.endswith(u'
'): - html_text = html_text[:len(html_text)-4] - formatted.append(html_text) - force_current = True - print "##### > 1" - print [html_text] - html_text = u'' + line_added = False + while not line_added: + line_added = True + line_count += 1 + styled_line = expand_tags(line) + styled_line = line_end + styled_line + previous_line = line + previous_styled = styled_line + styled_text += styled_line + html = self.page_shell + styled_text + HTML_END + self.web.setHtml(html) + # Text too long so go to next page + print self.web_frame.contentsSize().height() , self.page_height, [line] + if self.web_frame.contentsSize().height() > self.page_height: + # we have more than 1 verse on the slide + print "A", line_count + print "AA", [previous_line] + print "AAA", [styled_text] + if line_count > 1: + if html_text.endswith(u'
'): + html_text = html_text[:len(html_text)-4] + formatted.append(html_text) + line_added = False + line = previous_line + line_count = 0 + html_text = u'' + print "c", [html_text] + if line_count == 1: + words = self._words_split(line) + for word in words: + styled_word = expand_tags(word) + styled_line = styled_word + #previous_line = line + #previous_styled = styled_line + styled_text += styled_word + html = self.page_shell + styled_text + HTML_END + self.web.setHtml(html) + # Text too long so go to next page + print self.web_frame.contentsSize().height() , self.page_height, [line] + if self.web_frame.contentsSize().height() > self.page_height: + if html_text.endswith(u'
'): + html_text = html_text[:len(html_text)-4] + formatted.append(html_text) + html_text = u'' + html_text += word + pass + print "##### > 1" + print [html_text] # only one block on page so lets make it words. - if line_count == 1 or force_current: - print "##### = 1" - print [line] - force_current = False - styled_text = u'' - words = self._words(line) - styled_text = u'' - for word in words: - styled_line = expand_tags(word) - styled_text += styled_line - html = self.page_shell + styled_text + HTML_END - self.web.setHtml(html) - # Text too long so go to next page - print "B", self.web_frame.contentsSize().height() , self.page_height - if self.web_frame.contentsSize().height() > self.page_height: - if html_text.endswith(u'
'): - html_text = html_text[:len(html_text)-4] - print "c", [html_text] - formatted.append(html_text) - html_text = u'' - - styled_text = styled_line - html_text += word - line_count = 0 +# if line_count == 1 or force_current: +# print "##### = 1" +# print [line] +# print [styled_text] +# print [previous_line] +# force_current = False +# #styled_text = u'' +# words = self._words(previous_line) +# styled_text = u'' +# for word in words: +# styled_line = expand_tags(word) +# styled_text += styled_line +# html = self.page_shell + styled_text + HTML_END +# self.web.setHtml(html) +# # Text too long so go to next page +# print "B", self.web_frame.contentsSize().height() , self.page_height +# if self.web_frame.contentsSize().height() > self.page_height: +# if html_text.endswith(u'
'): +# html_text = html_text[:len(html_text)-4] +# print "c", [html_text] +# formatted.append(html_text) +# html_text = u'' +# +# styled_text = styled_line +# html_text += word + #line_count = 0 styled_text = styled_line html_text += line + line_end + previous_line = line if html_text.endswith(u'
'): html_text = html_text[:len(html_text)-4] formatted.append(html_text) log.debug(u'format_slide - End') return formatted - def _lines(self, words, split=u'\n[---]\n'): + def _lines(self, words, split=u'n[---]n'): """ Split the slide up by physical line """ # this parse we do not want to use this so remove it - words = words.replace(split, u'') + #words = words.replace(split, u'') verses_text = words.split(u'\n') text = [] for verse in verses_text: @@ -445,11 +479,11 @@ class Renderer(object): text.append(line) return text - def _words(self, words): + def _words_split(self, words): """ Split the slide up by word so can wrap better """ - # this parse we are wordy + # this parse we are to be wordy words = words.replace(u'\n', u' ') verses_text = words.split(u' ') text = [] @@ -458,3 +492,17 @@ class Renderer(object): for line in lines: text.append(line + u' ') return text + + def _lines_split(self, text): + """ + Split the slide up by physical line + """ + # this parse we do not want to use this so remove it + lines = text.split(u'\n') + real_lines = [] + for line in lines: + line = line.replace(u' [---]', u'[---]') + sub_lines = line.split(u'\n') + for sub_line in sub_lines: + real_lines.append(sub_line) + return real_lines From 9ce234598aa8ab777b51873c0af88a4abda94374 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 8 Apr 2011 20:40:18 +0100 Subject: [PATCH 16/57] Humm --- openlp/core/lib/renderer.py | 39 ++++++------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 7a9e89f7b..34a555229 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -405,14 +405,16 @@ class Renderer(object): formatted.append(html_text) line_added = False line = previous_line - line_count = 0 + line_count = 1 html_text = u'' print "c", [html_text] if line_count == 1: + line_count = 0 words = self._words_split(line) + styled_text = u'' for word in words: styled_word = expand_tags(word) - styled_line = styled_word + #styled_line = styled_word #previous_line = line #previous_styled = styled_line styled_text += styled_word @@ -420,42 +422,13 @@ class Renderer(object): self.web.setHtml(html) # Text too long so go to next page print self.web_frame.contentsSize().height() , self.page_height, [line] - if self.web_frame.contentsSize().height() > self.page_height: + if self.web_frame.contentsSize().height() >= self.page_height: if html_text.endswith(u'
'): html_text = html_text[:len(html_text)-4] formatted.append(html_text) html_text = u'' + styled_text = u'' html_text += word - pass - print "##### > 1" - print [html_text] - # only one block on page so lets make it words. -# if line_count == 1 or force_current: -# print "##### = 1" -# print [line] -# print [styled_text] -# print [previous_line] -# force_current = False -# #styled_text = u'' -# words = self._words(previous_line) -# styled_text = u'' -# for word in words: -# styled_line = expand_tags(word) -# styled_text += styled_line -# html = self.page_shell + styled_text + HTML_END -# self.web.setHtml(html) -# # Text too long so go to next page -# print "B", self.web_frame.contentsSize().height() , self.page_height -# if self.web_frame.contentsSize().height() > self.page_height: -# if html_text.endswith(u'
'): -# html_text = html_text[:len(html_text)-4] -# print "c", [html_text] -# formatted.append(html_text) -# html_text = u'' -# -# styled_text = styled_line -# html_text += word - #line_count = 0 styled_text = styled_line html_text += line + line_end previous_line = line From 501235a6956bca0491582fb6280f7c0b26dcf57d Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 9 Apr 2011 09:11:46 +0100 Subject: [PATCH 17/57] Looking better --- openlp/core/lib/renderer.py | 96 ++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 50 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 34a555229..703e477cd 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -381,57 +381,53 @@ class Renderer(object): previous_line = u'' # Loop through the lines for line in lines: - line_added = False - while not line_added: - line_added = True - line_count += 1 - styled_line = expand_tags(line) - styled_line = line_end + styled_line - previous_line = line - previous_styled = styled_line - styled_text += styled_line - html = self.page_shell + styled_text + HTML_END - self.web.setHtml(html) - # Text too long so go to next page - print self.web_frame.contentsSize().height() , self.page_height, [line] - if self.web_frame.contentsSize().height() > self.page_height: - # we have more than 1 verse on the slide - print "A", line_count - print "AA", [previous_line] - print "AAA", [styled_text] - if line_count > 1: - if html_text.endswith(u'
'): - html_text = html_text[:len(html_text)-4] - formatted.append(html_text) - line_added = False - line = previous_line - line_count = 1 - html_text = u'' - print "c", [html_text] - if line_count == 1: - line_count = 0 - words = self._words_split(line) - styled_text = u'' - for word in words: - styled_word = expand_tags(word) - #styled_line = styled_word - #previous_line = line - #previous_styled = styled_line - styled_text += styled_word - html = self.page_shell + styled_text + HTML_END - self.web.setHtml(html) - # Text too long so go to next page - print self.web_frame.contentsSize().height() , self.page_height, [line] - if self.web_frame.contentsSize().height() >= self.page_height: - if html_text.endswith(u'
'): - html_text = html_text[:len(html_text)-4] - formatted.append(html_text) - html_text = u'' - styled_text = u'' - html_text += word - styled_text = styled_line - html_text += line + line_end + line_count += 1 + styled_line = expand_tags(line) + styled_line = line_end + styled_line previous_line = line + previous_styled = styled_line + styled_text += styled_line + html = self.page_shell + styled_text + HTML_END + self.web.setHtml(html) + # Text too long so go to next page + print self.web_frame.contentsSize().height() , self.page_height, [line] + if self.web_frame.contentsSize().height() > self.page_height: + # we have more than 1 verse on the slide + print "A", line_count + print "AA", [previous_line] + print "AAA", [styled_text] + if line_count > 1: + if html_text.endswith(u'
'): + html_text = html_text[:len(html_text)-4] + formatted.append(html_text) + line = previous_line + line_count = 1 + html_text = u'' + print "c", [html_text] + if line_count == 1: + line_count = 0 + words = self._words_split(line) + styled_text = u'' + styled_line = u'' + for word in words: + styled_word = expand_tags(word) + styled_text += styled_word + html = self.page_shell + styled_text + HTML_END + self.web.setHtml(html) + # Text too long so go to next page + print self.web_frame.contentsSize().height() , self.page_height, [line] + if self.web_frame.contentsSize().height() > self.page_height: + if html_text.endswith(u'
'): + html_text = html_text[:len(html_text)-4] + formatted.append(html_text) + html_text = u'' + styled_text = u'' + html_text += word + a=1 + else: + styled_text = styled_line + html_text += line + line_end + previous_line = line if html_text.endswith(u'
'): html_text = html_text[:len(html_text)-4] formatted.append(html_text) From 24ec1abb56b47529bf125b65599f9df08ff71808 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 16 Apr 2011 12:36:20 +0100 Subject: [PATCH 18/57] more changes --- openlp/core/lib/renderer.py | 4 ++-- openlp/plugins/bibles/lib/mediaitem.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 703e477cd..ac8e26191 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -399,7 +399,7 @@ class Renderer(object): if line_count > 1: if html_text.endswith(u'
'): html_text = html_text[:len(html_text)-4] - formatted.append(html_text) + formatted.append(html_text + line_end) line = previous_line line_count = 1 html_text = u'' @@ -419,7 +419,7 @@ class Renderer(object): if self.web_frame.contentsSize().height() > self.page_height: if html_text.endswith(u'
'): html_text = html_text[:len(html_text)-4] - formatted.append(html_text) + formatted.append(html_text + line_break) html_text = u'' styled_text = u'' html_text += word diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 8440cb783..405507523 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -799,9 +799,9 @@ class BibleMediaItem(MediaManagerItem): else: verse_text = unicode(verse) if self.settings.display_style == DisplayStyle.Round: - return u'[---]{su}(%s){/su}' % verse_text + return u'{su}(%s){/su}' % verse_text if self.settings.display_style == DisplayStyle.Curly: - return u'[---]{su}{%s}{/su}' % verse_text + return u'{su}{%s}{/su}' % verse_text if self.settings.display_style == DisplayStyle.Square: - return u'[---]{su}[%s]{/su}' % verse_text - return u'[---]{su}%s{/su}' % verse_text + return u'{su}[%s]{/su}' % verse_text + return u'{su}%s{/su}' % verse_text From 56443ed457144acf8e3a77fe9443318b631e2b21 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 26 Apr 2011 17:33:37 +0200 Subject: [PATCH 19/57] r1486 From 68fdc7dee9b1b79d685124df9cea2613e52ad4df Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 26 Apr 2011 19:03:19 +0200 Subject: [PATCH 20/57] fixed virtue breaks, fixed word break --- openlp/core/lib/plugin.py | 16 ++-- openlp/core/lib/renderer.py | 140 +++++++++++++-------------------- openlp/core/lib/serviceitem.py | 14 ++-- 3 files changed, 71 insertions(+), 99 deletions(-) diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 48a54f8ca..d0d83cd0c 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -159,14 +159,14 @@ class Plugin(QtCore.QObject): self.status = PluginStatus.Inactive # Set up logging self.log = logging.getLogger(self.name) - self.previewController = pluginHelpers[u'preview'] - self.liveController = pluginHelpers[u'live'] - self.renderer = pluginHelpers[u'renderer'] - self.serviceManager = pluginHelpers[u'service'] - self.settingsForm = pluginHelpers[u'settings form'] - self.mediadock = pluginHelpers[u'toolbox'] - self.pluginManager = pluginHelpers[u'pluginmanager'] - self.formparent = pluginHelpers[u'formparent'] + self.previewController = plugin_helpers[u'preview'] + self.liveController = plugin_helpers[u'live'] + self.renderer = plugin_helpers[u'renderer'] + self.serviceManager = plugin_helpers[u'service'] + self.settingsForm = plugin_helpers[u'settings form'] + self.mediadock = plugin_helpers[u'toolbox'] + self.pluginManager = plugin_helpers[u'pluginmanager'] + self.formparent = plugin_helpers[u'formparent'] QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_add_service_item' % self.name), self.processAddServiceEvent) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index ac8e26191..d06779cb7 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -214,26 +214,26 @@ class Renderer(object): ``line_break`` Add line endings after each line of text used for bibles. """ - print [text] + log.debug(u'format slide') # clean up line endings lines = self._lines_split(text) - pages = self._paginate_slide(lines, line_break, self.force_page) - if len(pages) > 1: - # Songs and Custom - if item.is_capable(ItemCapabilities.AllowsVirtualSplit): - # do not forget the line breaks ! - slides = text.split(u'\n[---]\n') - pages = [] - for slide in slides: - lines = self._lines(slide) - new_pages = self._paginate_slide(lines, line_break, - self.force_page) - for page in new_pages: - pages.append(page) -# # Bibles - elif item.is_capable(ItemCapabilities.AllowsWordSplit): - pages = self._paginate_slide_words(text, line_break) + # Songs and Custom + if item.is_capable(ItemCapabilities.AllowsVirtualSplit): + # Do not forget the line breaks ! + slides = text.split(u'\n[---]\n') + pages = [] + for slide in slides: + lines = self._lines(slide) + new_pages = self._paginate_slide(lines, line_break, + self.force_page) + pages.extend([page for page in new_pages]) + # Bibles + elif item.is_capable(ItemCapabilities.AllowsWordSplit): + pages = self._paginate_slide_words(text, line_break) + # Theme preview "service items". + else: + pages = self._paginate_slide(lines, line_break, self.force_page) return pages def _calculate_default(self, screen): @@ -316,13 +316,13 @@ class Renderer(object): The words to be fitted on the slide split into lines. ``line_break`` - Add line endings after each line of text used for bibles. + Add line endings after each line of text (used for bibles). ``force_page`` Flag to tell message lines in page. """ - log.debug(u'format_slide - Start') + log.debug(u'_paginate_slide - Start') line_end = u'' if line_break: line_end = u'
' @@ -342,16 +342,14 @@ class Renderer(object): if force_page and line_count > 0: Receiver.send_message(u'theme_line_count', line_count) line_count = -1 - if html_text.endswith(u'
'): - html_text = html_text[:len(html_text)-4] + html_text = html_text.rstrip(u'
') formatted.append(html_text) html_text = u'' styled_text = styled_line html_text += line + line_end - if html_text.endswith(u'
'): - html_text = html_text[:len(html_text)-4] + html_text = html_text.rstrip(u'
') formatted.append(html_text) - log.debug(u'format_slide - End') + log.debug(u'_paginate_slide - End') return formatted def _paginate_slide_words(self, text, line_break): @@ -367,71 +365,48 @@ class Renderer(object): Add line endings after each line of text used for bibles. """ - print [text] - log.debug(u'format_slide - Start') + # TODO: Make sure spaces are striped so that they will not confuse + # rendering. for instance when the style is set to Verse per Line: + # In the beginning ... + # + # + # Verse 2 + log.debug(u'_paginate_slide_words - Start') line_end = u'' if line_break: line_end = u'
' formatted = [] - html_text = u'' - styled_text = u'' - line_count = 0 - force_current = False + previous_html = u'' + previous_raw = u'' lines = self._lines(text, u'[---]') - previous_line = u'' - # Loop through the lines for line in lines: - line_count += 1 styled_line = expand_tags(line) - styled_line = line_end + styled_line - previous_line = line - previous_styled = styled_line - styled_text += styled_line - html = self.page_shell + styled_text + HTML_END + html = self.page_shell + previous_html + styled_line + HTML_END self.web.setHtml(html) # Text too long so go to next page - print self.web_frame.contentsSize().height() , self.page_height, [line] if self.web_frame.contentsSize().height() > self.page_height: - # we have more than 1 verse on the slide - print "A", line_count - print "AA", [previous_line] - print "AAA", [styled_text] - if line_count > 1: - if html_text.endswith(u'
'): - html_text = html_text[:len(html_text)-4] - formatted.append(html_text + line_end) - line = previous_line - line_count = 1 - html_text = u'' - print "c", [html_text] - if line_count == 1: - line_count = 0 - words = self._words_split(line) - styled_text = u'' - styled_line = u'' - for word in words: - styled_word = expand_tags(word) - styled_text += styled_word - html = self.page_shell + styled_text + HTML_END - self.web.setHtml(html) - # Text too long so go to next page - print self.web_frame.contentsSize().height() , self.page_height, [line] - if self.web_frame.contentsSize().height() > self.page_height: - if html_text.endswith(u'
'): - html_text = html_text[:len(html_text)-4] - formatted.append(html_text + line_break) - html_text = u'' - styled_text = u'' - html_text += word - a=1 + words = self._words_split(line) + for word in words: + styled_word = expand_tags(word) + html = self.page_shell + previous_html + styled_word + \ + HTML_END + self.web.setHtml(html) + # Text too long so go to next page + if self.web_frame.contentsSize().height() > self.page_height: + previous_raw = previous_raw.rstrip(u'
') + formatted.append(previous_raw) + previous_html = u'' + previous_raw = u'' + previous_html += styled_word + previous_raw += word + previous_html += line_end + previous_raw += line_end else: - styled_text = styled_line - html_text += line + line_end - previous_line = line - if html_text.endswith(u'
'): - html_text = html_text[:len(html_text)-4] - formatted.append(html_text) - log.debug(u'format_slide - End') + previous_html += styled_line + line_end + previous_raw += line + line_end + previous_raw = previous_raw.rstrip(u'
') + formatted.append(previous_raw) + log.debug(u'_paginate_slide_words - End') return formatted def _lines(self, words, split=u'n[---]n'): @@ -444,8 +419,7 @@ class Renderer(object): text = [] for verse in verses_text: lines = verse.split(u'\n') - for line in lines: - text.append(line) + text.extend([line for line in lines]) return text def _words_split(self, words): @@ -458,8 +432,7 @@ class Renderer(object): text = [] for verse in verses_text: lines = verse.split(u' ') - for line in lines: - text.append(line + u' ') + text.extend([line + u' ' for line in lines]) return text def _lines_split(self, text): @@ -472,6 +445,5 @@ class Renderer(object): for line in lines: line = line.replace(u' [---]', u'[---]') sub_lines = line.split(u'\n') - for sub_line in sub_lines: - real_lines.append(sub_line) + real_lines.extend([sub_line for sub_line in sub_lines]) return real_lines diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index 3810a7bb2..a2cb014a4 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -163,9 +163,7 @@ class ServiceItem(object): log.debug(u'Render called') self._display_frames = [] self.bg_image_bytes = None - line_break = True - if self.is_capable(ItemCapabilities.NoLineBreaks): - line_break = False + line_break = not self.is_capable(ItemCapabilities.NoLineBreaks) theme = self.theme if self.theme else None self.main, self.footer = \ self.renderer.set_override_theme(theme, use_override) @@ -176,11 +174,12 @@ class ServiceItem(object): formatted = self.renderer \ .format_slide(slide[u'raw_slide'], line_break, self) for page in formatted: - self._display_frames.append( - {u'title': clean_tags(page), + self._display_frames.append({ + u'title': clean_tags(page), u'text': clean_tags(page.rstrip()), u'html': expand_tags(page.rstrip()), - u'verseTag': slide[u'verseTag'] }) + u'verseTag': slide[u'verseTag'] + }) elif self.service_item_type == ServiceItemType.Image or \ self.service_item_type == ServiceItemType.Command: pass @@ -455,4 +454,5 @@ class ServiceItem(object): elif not start and end: return end else: - return u'%s : %s' % (start, end) \ No newline at end of file + return u'%s : %s' % (start, end) + From 772c9cb2ca08666c1df907f443c567c4049e33e8 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 26 Apr 2011 19:39:21 +0100 Subject: [PATCH 21/57] Chnages --- openlp/core/lib/renderer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index d20aab38a..9d854b9b5 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -214,7 +214,6 @@ class Renderer(object): ``line_break`` Add line endings after each line of text used for bibles. """ - print [text] log.debug(u'format slide') # clean up line endings lines = self._lines_split(text) @@ -368,7 +367,7 @@ class Renderer(object): Add line endings after each line of text used for bibles. """ - print [text] + print "st", [text] log.debug(u'format_slide - Start') line_end = u'' if line_break: @@ -393,7 +392,8 @@ class Renderer(object): # Text too long so go to next page print self.web_frame.contentsSize().height() , self.page_height, [line] if self.web_frame.contentsSize().height() > self.page_height: - # we have more than 1 verse on the slide + # we have more than 1 verse on the slide and it does not fit! + # Save the previous line as it fits on the page. print "A", line_count print "AA", [previous_line] print "AAA", [styled_text] From 0476fe8b27f703d6fa48538ce0a59412d7501cca Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 26 Apr 2011 20:09:56 +0100 Subject: [PATCH 22/57] Minor cleanups --- openlp/core/lib/renderer.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index d510c0bda..9fd4e8815 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -365,8 +365,6 @@ class Renderer(object): Add line endings after each line of text used for bibles. """ - # TODO: Make sure spaces are striped so that they will not confuse - # rendering. for instance when the style is set to Verse per Line: # In the beginning ... # # @@ -392,7 +390,8 @@ class Renderer(object): HTML_END self.web.setHtml(html) # Text too long so go to next page - if self.web_frame.contentsSize().height() > self.page_height: + if self.web_frame.contentsSize().height() > \ + self.page_height: previous_raw = previous_raw.rstrip(u'
') formatted.append(previous_raw) previous_html = u'' @@ -409,13 +408,12 @@ class Renderer(object): log.debug(u'_paginate_slide_words - End') return formatted - def _lines(self, words, split=u'n[---]n'): + def _lines(self, text, split=u'\n[---]\n'): """ Split the slide up by physical line """ # this parse we do not want to use this so remove it - #words = words.replace(split, u'') - verses_text = words.split(u'\n') + verses_text = text.split(u'\n') text = [] for verse in verses_text: lines = verse.split(u'\n') @@ -423,13 +421,13 @@ class Renderer(object): return text - def _words_split(self, words): + def _words_split(self, line): """ Split the slide up by word so can wrap better """ # this parse we are to be wordy - words = words.replace(u'\n', u' ') - verses_text = words.split(u' ') + line = line.replace(u'\n', u' ') + verses_text = line.split(u' ') text = [] for verse in verses_text: lines = verse.split(u' ') From f732d24f35aadebecec2d0f232f2a7871122fd2d Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 27 Apr 2011 16:54:27 +0200 Subject: [PATCH 23/57] Fixed bug #744515, OSIS import fails to import certain words in ESV (at least). --- openlp/plugins/bibles/lib/osis.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index e2eb25b4f..130356241 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -37,6 +37,9 @@ from openlp.plugins.bibles.lib.db import BibleDB log = logging.getLogger(__name__) +def replacement(match): + return match.group(2).upper() + class OSISBible(BibleDB): """ `OSIS `_ Bible format importer class. @@ -106,6 +109,7 @@ class OSISBible(BibleDB): detect_file.close() try: osis = codecs.open(self.filename, u'r', details['encoding']) + repl = replacement for file_record in osis: if self.stop_import_flag: break @@ -148,12 +152,12 @@ class OSISBible(BibleDB): verse_text = self.rf_regex.sub(u'', verse_text) verse_text = self.lb_regex.sub(u' ', verse_text) verse_text = self.lg_regex.sub(u'', verse_text) - verse_text = self.l_regex.sub(u'', verse_text) + verse_text = self.l_regex.sub(u' ', verse_text) verse_text = self.w_regex.sub(u'', verse_text) verse_text = self.q1_regex.sub(u'"', verse_text) verse_text = self.q2_regex.sub(u'\'', verse_text) + verse_text = self.divine_name_regex.sub(repl, verse_text) verse_text = self.trans_regex.sub(u'', verse_text) - verse_text = self.divine_name_regex.sub(u'', verse_text) verse_text = verse_text.replace(u'', u'')\ .replace(u'', u'').replace(u'', u'')\ .replace(u'', u'').replace(u'', u'')\ From d23e564539127c7dbe7c591be40330436d3874e3 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 27 Apr 2011 18:15:35 +0200 Subject: [PATCH 24/57] Fixed bug #744515, funny quotes in KJV imported from OSIS. --- openlp/plugins/bibles/lib/osis.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index 130356241..a080524eb 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -63,6 +63,7 @@ class OSISBible(BibleDB): self.lg_regex = re.compile(r'') self.l_regex = re.compile(r'') self.w_regex = re.compile(r'') + self.q_regex = re.compile(r'') self.q1_regex = re.compile(r'') self.q2_regex = re.compile(r'') self.trans_regex = re.compile(r'(.*?)') @@ -156,6 +157,7 @@ class OSISBible(BibleDB): verse_text = self.w_regex.sub(u'', verse_text) verse_text = self.q1_regex.sub(u'"', verse_text) verse_text = self.q2_regex.sub(u'\'', verse_text) + verse_text = self.q_regex.sub(u'', verse_text) verse_text = self.divine_name_regex.sub(repl, verse_text) verse_text = self.trans_regex.sub(u'', verse_text) verse_text = verse_text.replace(u'', u'')\ From c9d69c55cd69865a3d8018b735255cb535e97274 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 27 Apr 2011 18:41:03 +0100 Subject: [PATCH 25/57] Fix soft break --- openlp/core/lib/renderer.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 9fd4e8815..a79006201 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -217,22 +217,21 @@ class Renderer(object): log.debug(u'format slide') # clean up line endings lines = self._lines_split(text) - # Songs and Custom - if item.is_capable(ItemCapabilities.AllowsVirtualSplit): - # Do not forget the line breaks ! - slides = text.split(u'\n[---]\n') - pages = [] - for slide in slides: - lines = self._lines(slide) - new_pages = self._paginate_slide(lines, line_break, - self.force_page) - pages.extend([page for page in new_pages]) - # Bibles - elif item.is_capable(ItemCapabilities.AllowsWordSplit): - pages = self._paginate_slide_words(text, line_break) - # Theme preview "service items". - else: - pages = self._paginate_slide(lines, line_break, self.force_page) + pages = self._paginate_slide(lines, line_break, self.force_page) + if len(pages) > 1: + # Songs and Custom + if item.is_capable(ItemCapabilities.AllowsVirtualSplit): + # Do not forget the line breaks ! + slides = text.split(u'\n[---]\n') + pages = [] + for slide in slides: + lines = self._lines(slide) + new_pages = self._paginate_slide(lines, line_break, + self.force_page) + pages.extend([page for page in new_pages]) + # Bibles + elif item.is_capable(ItemCapabilities.AllowsWordSplit): + pages = self._paginate_slide_words(text, line_break) return pages def _calculate_default(self, screen): @@ -376,7 +375,7 @@ class Renderer(object): formatted = [] previous_html = u'' previous_raw = u'' - lines = self._lines(text, u'[---]') + lines = self._lines(text) for line in lines: styled_line = expand_tags(line) html = self.page_shell + previous_html + styled_line + HTML_END @@ -408,7 +407,7 @@ class Renderer(object): log.debug(u'_paginate_slide_words - End') return formatted - def _lines(self, text, split=u'\n[---]\n'): + def _lines(self, text): """ Split the slide up by physical line """ @@ -442,7 +441,7 @@ class Renderer(object): lines = text.split(u'\n') real_lines = [] for line in lines: - line = line.replace(u' [---]', u'[---]') + line = line.replace(u'[---]', u'') sub_lines = line.split(u'\n') real_lines.extend([sub_line for sub_line in sub_lines]) return real_lines From b081c2012816c83c17dbfb5088c96b3c839b45ad Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 27 Apr 2011 20:44:21 +0100 Subject: [PATCH 26/57] Fix blank line --- openlp/core/lib/renderer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index a79006201..c2e64dadc 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -438,6 +438,7 @@ class Renderer(object): Split the slide up by physical line """ # this parse we do not want to use this so remove it + text = text.replace(u'\n[---]', u'') lines = text.split(u'\n') real_lines = [] for line in lines: From 9aa1f580d2cb00123066d161487b241989cc40de Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 28 Apr 2011 08:36:04 +0200 Subject: [PATCH 27/57] fixed right/left shortcuts --- openlp/core/ui/slidecontroller.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 5f2c63c23..dfa313cc1 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -380,18 +380,21 @@ class SlideController(QtGui.QWidget): action_list.add_action(self.previousItem) action_list.add_action(self.nextItem) self.previousService = shortcut_action(parent, u'previousService', - [QtCore.Qt.Key_Left], self.servicePrevious, UiStrings().LiveToolbar) - self.previousService.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) + [QtCore.Qt.Key_Left], self.servicePrevious, + category=UiStrings().LiveToolbar, + context=QtCore.Qt.WidgetWithChildrenShortcut) self.previousService.setText( translate('OpenLP.SlideController', 'Previous Service')) self.nextService = shortcut_action(parent, 'nextService', - [QtCore.Qt.Key_Right], self.serviceNext, UiStrings().LiveToolbar) - self.nextService.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) + [QtCore.Qt.Key_Right], self.serviceNext, + category=UiStrings().LiveToolbar, + context=QtCore.Qt.WidgetWithChildrenShortcut) self.nextService.setText( translate('OpenLP.SlideController', 'Next Service')) self.escapeItem = shortcut_action(parent, 'escapeItem', - [QtCore.Qt.Key_Escape], self.liveEscape, UiStrings().LiveToolbar) - self.escapeItem.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) + [QtCore.Qt.Key_Escape], self.liveEscape, + category=UiStrings().LiveToolbar, + context=QtCore.Qt.WidgetWithChildrenShortcut) self.escapeItem.setText( translate('OpenLP.SlideController', 'Escape Item')) @@ -1150,4 +1153,5 @@ class SlideController(QtGui.QWidget): elif self.desktopScreen.isChecked(): return HideMode.Screen else: - return None \ No newline at end of file + return None + From 9996320522801abe70c9ddf7771c41d60de413c2 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 28 Apr 2011 08:44:48 +0200 Subject: [PATCH 28/57] fixed verse splitting where not necessary --- openlp/core/lib/renderer.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index c2e64dadc..7687ebe9a 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -364,10 +364,6 @@ class Renderer(object): Add line endings after each line of text used for bibles. """ - # In the beginning ... - # - # - # Verse 2 log.debug(u'_paginate_slide_words - Start') line_end = u'' if line_break: @@ -382,6 +378,27 @@ class Renderer(object): self.web.setHtml(html) # Text too long so go to next page if self.web_frame.contentsSize().height() > self.page_height: + # Check if there was a verse before the current one and append + # it, when it fits on the page. + if previous_html: + html = self.page_shell + previous_html + HTML_END + self.web.setHtml(html) + if self.web_frame.contentsSize().height() <= \ + self.page_height: + previous_raw = previous_raw.rstrip(u'
') + formatted.append(previous_raw) + previous_html = u'' + previous_raw = u'' + html = self.page_shell + styled_line + HTML_END + self.web.setHtml(html) + # Now check if the current verse will fit, if it does + # not we have to start to process the verse word by + # word. + if self.web_frame.contentsSize().height() <= \ + self.page_height: + previous_html = styled_line + line_end + previous_raw = line + line_end + continue words = self._words_split(line) for word in words: styled_word = expand_tags(word) From e9ec8aaaaf53e94118dd1ab05b99493b63255207 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 28 Apr 2011 18:32:37 +0200 Subject: [PATCH 29/57] added shorcuts for start/stop/toggle loop (#771966) Fixes: https://launchpad.net/bugs/771966 --- openlp/core/ui/slidecontroller.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index dfa313cc1..5a6e5aec3 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -180,16 +180,25 @@ class SlideController(QtGui.QWidget): self.hideMenu.menu().addAction(self.themeScreen) self.hideMenu.menu().addAction(self.desktopScreen) self.toolbar.addToolbarSeparator(u'Loop Separator') - self.toolbar.addToolbarButton( + startLoop = self.toolbar.addToolbarButton( # Does not need translating - control string. u'Start Loop', u':/media/media_time.png', translate('OpenLP.SlideController', 'Start continuous loop'), self.onStartLoop) - self.toolbar.addToolbarButton( + action_list = ActionList.get_instance() + action_list.add_action(startLoop, UiStrings().LiveToolbar) + stopLoop =self.toolbar.addToolbarButton( # Does not need translating - control string. u'Stop Loop', u':/media/media_stop.png', translate('OpenLP.SlideController', 'Stop continuous loop'), self.onStopLoop) + action_list.add_action(stopLoop, UiStrings().LiveToolbar) + self.toogleLoop = shortcut_action(self, u'toogleLoop', + [QtGui.QKeySequence(u'L')], self.onToggleLoop, + category=UiStrings().LiveToolbar) + self.toogleLoop.setText(translate('OpenLP.SlideController', + 'Start/Stop continuous loop')) + self.addAction(self.toogleLoop) self.delaySpinBox = QtGui.QSpinBox() self.delaySpinBox.setMinimum(1) self.delaySpinBox.setMaximum(180) @@ -494,6 +503,9 @@ class SlideController(QtGui.QWidget): self.mediabar.setVisible(False) self.toolbar.makeWidgetsInvisible([u'Song Menu']) self.toolbar.makeWidgetsInvisible(self.loopList) + self.toogleLoop.setEnabled(False) + self.toolbar.actions[u'Start Loop'].setEnabled(False) + self.toolbar.actions[u'Stop Loop'].setEnabled(False) self.toolbar.actions[u'Stop Loop'].setVisible(False) if item.is_text(): if QtCore.QSettings().value( @@ -503,6 +515,9 @@ class SlideController(QtGui.QWidget): if item.is_capable(ItemCapabilities.AllowsLoop) and \ len(item.get_frames()) > 1: self.toolbar.makeWidgetsVisible(self.loopList) + self.toogleLoop.setEnabled(True) + self.toolbar.actions[u'Start Loop'].setEnabled(True) + self.toolbar.actions[u'Stop Loop'].setEnabled(True) if item.is_media(): self.toolbar.setVisible(False) self.mediabar.setVisible(True) @@ -995,6 +1010,15 @@ class SlideController(QtGui.QWidget): self.previewListWidget.rowCount() - 1) self.slideSelected() + def onToggleLoop(self, toggled): + """ + Toggles the loop state. + """ + if self.toolbar.actions[u'Start Loop'].isVisible(): + self.onStartLoop() + else: + self.onStopLoop() + def onStartLoop(self): """ Start the timer loop running and store the timer id From aea4909201b18c990b8a014a2aa749292438d29f Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 28 Apr 2011 18:36:53 +0200 Subject: [PATCH 30/57] added missing space --- openlp/core/ui/slidecontroller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 5a6e5aec3..3b33f9a22 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -187,7 +187,7 @@ class SlideController(QtGui.QWidget): self.onStartLoop) action_list = ActionList.get_instance() action_list.add_action(startLoop, UiStrings().LiveToolbar) - stopLoop =self.toolbar.addToolbarButton( + stopLoop = self.toolbar.addToolbarButton( # Does not need translating - control string. u'Stop Loop', u':/media/media_stop.png', translate('OpenLP.SlideController', 'Stop continuous loop'), From 17d74a8d9ab04484966aa19a969f61312a0fb019 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 28 Apr 2011 19:13:19 +0100 Subject: [PATCH 31/57] Add Load service Progress Bar --- openlp/core/ui/mainwindow.py | 58 ++++++++++++++++++++++++++------ openlp/core/ui/servicemanager.py | 3 ++ openlp/core/utils/__init__.py | 13 +++++++ 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index cb01e37a1..0ea847248 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -38,7 +38,7 @@ from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, \ ThemeManager, SlideController, PluginForm, MediaDockManager, \ ShortcutListForm, DisplayTagForm from openlp.core.utils import AppLocation, add_actions, LanguageManager, \ - get_application_version + get_application_version, LoadSleepThread from openlp.core.utils.actions import ActionList, CategoryOrder log = logging.getLogger(__name__) @@ -122,12 +122,17 @@ class Ui_MainWindow(object): self.HelpMenu = QtGui.QMenu(self.MenuBar) self.HelpMenu.setObjectName(u'HelpMenu') mainWindow.setMenuBar(self.MenuBar) - self.StatusBar = QtGui.QStatusBar(mainWindow) - self.StatusBar.setObjectName(u'StatusBar') - mainWindow.setStatusBar(self.StatusBar) - self.DefaultThemeLabel = QtGui.QLabel(self.StatusBar) - self.DefaultThemeLabel.setObjectName(u'DefaultThemeLabel') - self.StatusBar.addPermanentWidget(self.DefaultThemeLabel) + self.statusBar = QtGui.QStatusBar(mainWindow) + self.statusBar.setObjectName(u'statusBar') + mainWindow.setStatusBar(self.statusBar) + self.loadProgressBar = QtGui.QProgressBar(self.statusBar) + self.loadProgressBar.setObjectName(u'loadProgressBar') + self.statusBar.addPermanentWidget(self.loadProgressBar) + self.statusBar.removeWidget(self.loadProgressBar) + self.loadProgressBar.setValue(0) + self.defaultThemeLabel = QtGui.QLabel(self.statusBar) + self.defaultThemeLabel.setObjectName(u'defaultThemeLabel') + self.statusBar.addPermanentWidget(self.defaultThemeLabel) # Create the MediaManager self.mediaManagerDock = OpenLPDockWidget(mainWindow, u'mediaManagerDock', u':/system/system_mediamanager.png') @@ -544,6 +549,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'openlp_information_message'), self.onInformationMessage) + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'mainwindow_remove_progress'), + self.removeProgressBar) # warning cyclic dependency # RenderManager needs to call ThemeManager and # ThemeManager needs to call RenderManager @@ -880,10 +888,10 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.setWindowTitle(title) def showStatusMessage(self, message): - self.StatusBar.showMessage(message) + self.statusBar.showMessage(message) def defaultThemeChanged(self, theme): - self.DefaultThemeLabel.setText( + self.defaultThemeLabel.setText( unicode(translate('OpenLP.MainWindow', 'Default Theme: %s')) % theme) @@ -979,7 +987,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): for fileId, filename in enumerate(recentFilesToDisplay): log.debug('Recent file name: %s', filename) action = base_action(self, u'') - action.setText(u'&%d %s' % + action.setText(u'&%d %s' % (fileId + 1, QtCore.QFileInfo(filename).fileName())) action.setData(QtCore.QVariant(filename)) self.connect(action, QtCore.SIGNAL(u'triggered()'), @@ -1008,3 +1016,33 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): while self.recentFiles.count() > maxRecentFiles: # Don't care what API says takeLast works, removeLast doesn't! self.recentFiles.takeLast() + + def displayProgressBar(self, size): + """ + Make Progress bar visible and set size + """ + self.statusBar.addWidget(self.loadProgressBar) + self.loadProgressBar.show() + self.loadProgressBar.setMaximum(size) + self.loadProgressBar.setValue(0) + Receiver.send_message(u'openlp_process_events') + + def incrementProgressBar(self): + """ + Increase the Progress Bar Value by 1 + """ + self.loadProgressBar.setValue(self.loadProgressBar.value() + 1) + Receiver.send_message(u'openlp_process_events') + + def finishedProgressBar(self): + """ + Trigger it's removal after 1 second + """ + LoadSleepThread(self).start() + + def removeProgressBar(self): + """ + Remove the Progress bar from view. + """ + self.statusBar.removeWidget(self.loadProgressBar) + Receiver.send_message(u'openlp_process_events') diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index a2260cce9..dbeaf870d 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -576,7 +576,9 @@ class ServiceManager(QtGui.QWidget): items = cPickle.load(fileTo) fileTo.close() self.newFile() + self.mainwindow.displayProgressBar(len(items)) for item in items: + self.mainwindow.incrementProgressBar() serviceItem = ServiceItem() serviceItem.from_service = True serviceItem.render_manager = self.mainwindow.renderManager @@ -592,6 +594,7 @@ class ServiceManager(QtGui.QWidget): self.setModified(False) QtCore.QSettings().setValue( 'service/last file', QtCore.QVariant(fileName)) + self.mainwindow.finishedProgressBar() Receiver.send_message(u'cursor_normal') else: critical_error_message_box( diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 1bc7037ae..fa1ebf68a 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -100,6 +100,19 @@ class VersionThread(QtCore.QThread): remote_version[u'revision'] > local_version[u'revision']: Receiver.send_message(u'openlp_version_check', u'%s' % version) +class LoadSleepThread(QtCore.QThread): + """ + A special Qt thread class sleep then remove the load progress bar + """ + def __init__(self, parent): + QtCore.QThread.__init__(self, parent) + + def run(self): + """ + Run the thread. + """ + time.sleep(1) + Receiver.send_message(u'mainwindow_remove_progress') class AppLocation(object): """ From 7f1db15ab174f213e42db5a44a6f004e47163d3f Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 29 Apr 2011 01:25:28 +0200 Subject: [PATCH 32/57] Fixed bug #771529, dealing with 1.9.0 databases. --- openlp/plugins/songs/lib/__init__.py | 5 ++++- openlp/plugins/songs/lib/xml.py | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index 249a76a38..f9a160e55 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -293,7 +293,10 @@ def clean_song(manager, song): song.lyrics = unicode(sxml.extract_xml(), u'utf-8') # Rebuild the verse order, to convert translated verse tags, which might # have been added prior to 1.9.5. - order = song.verse_order.strip().split() + if song.verse_order: + order = song.verse_order.strip().split() + else: + order = [] new_order = [] for verse_def in order: verse_type = VerseType.Tags[VerseType.from_loose_input(verse_def[0])] diff --git a/openlp/plugins/songs/lib/xml.py b/openlp/plugins/songs/lib/xml.py index 87e28591e..f2fd897d9 100644 --- a/openlp/plugins/songs/lib/xml.py +++ b/openlp/plugins/songs/lib/xml.py @@ -133,14 +133,26 @@ class SongXML(object): [{'lang': 'en', 'type': 'c', 'label': '1'}, u"English chorus"]] """ self.song_xml = None - if xml[:5] == u'') + self.lyrics = etree.SubElement(self.song_xml, u'lyrics') + verses = xml.split(u'\n\n') + for count, verse in enumerate(verses): + verse_list.append([{u'type': u'v', u'label': unicode(count)}, + unicode(verse)]) + self.add_verse_to_lyrics(u'v', unicode(count), verse) + return verse_list + elif xml[:5] == u' Date: Fri, 29 Apr 2011 08:15:09 +0200 Subject: [PATCH 33/57] also split when [---] is within a line --- openlp/core/lib/renderer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 7687ebe9a..4dd9928fc 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -222,10 +222,10 @@ class Renderer(object): # Songs and Custom if item.is_capable(ItemCapabilities.AllowsVirtualSplit): # Do not forget the line breaks ! - slides = text.split(u'\n[---]\n') + slides = text.split(u'[---]') pages = [] for slide in slides: - lines = self._lines(slide) + lines = self._lines(slide.strip(u'\n')) new_pages = self._paginate_slide(lines, line_break, self.force_page) pages.extend([page for page in new_pages]) From 188431ce37b092f0382248ec665a71c6deb29f81 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Apr 2011 07:21:31 +0100 Subject: [PATCH 34/57] Fix up Service Save --- openlp/core/ui/servicemanager.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index fe5e57db3..24cf5c936 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -460,7 +460,11 @@ class ServiceManager(QtGui.QWidget): service = [] write_list = [] total_size = 0 + Receiver.send_message(u'cursor_busy') + # Number if items + 1 to zip it + self.mainwindow.displayProgressBar(len(self.serviceItems) + 1) for item in self.serviceItems: + self.mainwindow.incrementProgressBar() service.append({u'serviceitem': item[u'service_item'].get_service_repr()}) if not item[u'service_item'].uses_file(): @@ -501,6 +505,7 @@ class ServiceManager(QtGui.QWidget): log.debug(u'ServiceManager.saveFile - allowZip64 is %s' % allow_zip_64) zip = None success = True + self.mainwindow.incrementProgressBar() try: zip = zipfile.ZipFile(path_file_name, 'w', zipfile.ZIP_STORED, allow_zip_64) @@ -516,6 +521,8 @@ class ServiceManager(QtGui.QWidget): finally: if zip: zip.close() + self.mainwindow.finishedProgressBar() + Receiver.send_message(u'cursor_normal') if success: self.mainwindow.addRecentFile(path_file_name) self.setModified(False) From 19d085bb3cdc133d3bb66db5703ff1ddcc2f0795 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 29 Apr 2011 08:28:09 +0200 Subject: [PATCH 35/57] Changed [:] notation to .startswith(). --- openlp/plugins/songs/lib/xml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/songs/lib/xml.py b/openlp/plugins/songs/lib/xml.py index f2fd897d9..1c20b23a5 100644 --- a/openlp/plugins/songs/lib/xml.py +++ b/openlp/plugins/songs/lib/xml.py @@ -146,7 +146,7 @@ class SongXML(object): unicode(verse)]) self.add_verse_to_lyrics(u'v', unicode(count), verse) return verse_list - elif xml[:5] == u' Date: Fri, 29 Apr 2011 08:10:22 +0100 Subject: [PATCH 36/57] Fix up Presentation and Image Imports --- openlp/plugins/images/lib/mediaitem.py | 7 ++++++- openlp/plugins/presentations/lib/mediaitem.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 298e701e3..a2dd292d5 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -108,7 +108,10 @@ class ImageMediaItem(MediaManagerItem): self.settingsSection, self.getFileList()) def loadList(self, list): + Receiver.send_message(u'cursor_busy') + self.parent.formparent.displayProgressBar(len(list)) for imageFile in list: + self.parent.formparent.incrementProgressBar() filename = os.path.split(unicode(imageFile))[1] thumb = os.path.join(self.servicePath, filename) if os.path.exists(thumb): @@ -122,6 +125,8 @@ class ImageMediaItem(MediaManagerItem): item_name.setIcon(icon) item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(imageFile)) self.listView.addItem(item_name) + Receiver.send_message(u'cursor_normal') + self.parent.formparent.finishedProgressBar() def generateSlideData(self, service_item, item=None, xmlVersion=False): items = self.listView.selectedIndexes() @@ -201,4 +206,4 @@ class ImageMediaItem(MediaManagerItem): critical_error_message_box(UiStrings().LiveBGError, unicode(translate('ImagePlugin.MediaItem', 'There was a problem replacing your background, ' - 'the image file "%s" no longer exists.')) % filename) \ No newline at end of file + 'the image file "%s" no longer exists.')) % filename) diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 74ff3fea8..45b8b81c4 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -158,7 +158,10 @@ class PresentationMediaItem(MediaManagerItem): titles = [] for file in currlist: titles.append(os.path.split(file)[1]) + Receiver.send_message(u'cursor_busy') + self.parent.formparent.displayProgressBar(len(list)) for file in list: + self.parent.formparent.incrementProgressBar() if currlist.count(file) > 0: continue filename = os.path.split(unicode(file))[1] @@ -198,6 +201,8 @@ class PresentationMediaItem(MediaManagerItem): item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file)) item_name.setIcon(icon) self.listView.addItem(item_name) + Receiver.send_message(u'cursor_normal') + self.parent.formparent.finishedProgressBar() def onDeleteClick(self): """ @@ -296,4 +301,4 @@ class PresentationMediaItem(MediaManagerItem): if self.controllers[controller].enabled(): if filetype in self.controllers[controller].alsosupports: return controller - return None \ No newline at end of file + return None From f83d52621ad0bd2b77574e6159982af722cf6db8 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Apr 2011 08:40:19 +0100 Subject: [PATCH 37/57] Fixes --- openlp/core/ui/mainwindow.py | 24 ++++++++++++------------ openlp/core/ui/servicemanager.py | 2 +- openlp/core/utils/__init__.py | 13 ------------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 672fa9c44..311aa7ec0 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -38,7 +38,7 @@ from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, \ ThemeManager, SlideController, PluginForm, MediaDockManager, \ ShortcutListForm, DisplayTagForm from openlp.core.utils import AppLocation, add_actions, LanguageManager, \ - get_application_version, LoadSleepThread + get_application_version from openlp.core.utils.actions import ActionList, CategoryOrder log = logging.getLogger(__name__) @@ -128,7 +128,7 @@ class Ui_MainWindow(object): self.loadProgressBar = QtGui.QProgressBar(self.statusBar) self.loadProgressBar.setObjectName(u'loadProgressBar') self.statusBar.addPermanentWidget(self.loadProgressBar) - self.statusBar.removeWidget(self.loadProgressBar) + self.loadProgressBar.hide() self.loadProgressBar.setValue(0) self.defaultThemeLabel = QtGui.QLabel(self.statusBar) self.defaultThemeLabel.setObjectName(u'defaultThemeLabel') @@ -549,9 +549,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'openlp_information_message'), self.onInformationMessage) - QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'mainwindow_remove_progress'), - self.removeProgressBar) +# QtCore.QObject.connect(Receiver.get_receiver(), +# QtCore.SIGNAL(u'mainwindow_remove_progress'), +# self.removeProgressBar) # warning cyclic dependency # renderer needs to call ThemeManager and # ThemeManager needs to call Renderer @@ -1021,7 +1021,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): """ Make Progress bar visible and set size """ - self.statusBar.addWidget(self.loadProgressBar) self.loadProgressBar.show() self.loadProgressBar.setMaximum(size) self.loadProgressBar.setValue(0) @@ -1029,20 +1028,21 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): def incrementProgressBar(self): """ - Increase the Progress Bar Value by 1 + Increase the Progress Bar value by 1 """ self.loadProgressBar.setValue(self.loadProgressBar.value() + 1) Receiver.send_message(u'openlp_process_events') def finishedProgressBar(self): """ - Trigger it's removal after 1 second + Trigger it's removal after 2.5 second """ - LoadSleepThread(self).start() + self.timer_id = self.startTimer(2500) - def removeProgressBar(self): + def timerEvent(self, event): """ Remove the Progress bar from view. """ - self.statusBar.removeWidget(self.loadProgressBar) - Receiver.send_message(u'openlp_process_events') + if event.timerId() == self.timer_id: + self.loadProgressBar.hide() + Receiver.send_message(u'openlp_process_events') diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 24cf5c936..9ad527826 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -461,7 +461,7 @@ class ServiceManager(QtGui.QWidget): write_list = [] total_size = 0 Receiver.send_message(u'cursor_busy') - # Number if items + 1 to zip it + # Number of items + 1 to zip it self.mainwindow.displayProgressBar(len(self.serviceItems) + 1) for item in self.serviceItems: self.mainwindow.incrementProgressBar() diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index fa1ebf68a..1bc7037ae 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -100,19 +100,6 @@ class VersionThread(QtCore.QThread): remote_version[u'revision'] > local_version[u'revision']: Receiver.send_message(u'openlp_version_check', u'%s' % version) -class LoadSleepThread(QtCore.QThread): - """ - A special Qt thread class sleep then remove the load progress bar - """ - def __init__(self, parent): - QtCore.QThread.__init__(self, parent) - - def run(self): - """ - Run the thread. - """ - time.sleep(1) - Receiver.send_message(u'mainwindow_remove_progress') class AppLocation(object): """ From e76421190b5b2e17563a46a7cfc7e173c877265f Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 29 Apr 2011 09:40:44 +0200 Subject: [PATCH 38/57] removed redundant code --- openlp/core/lib/renderer.py | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 4dd9928fc..7aeebe75f 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -429,13 +429,8 @@ class Renderer(object): Split the slide up by physical line """ # this parse we do not want to use this so remove it - verses_text = text.split(u'\n') - text = [] - for verse in verses_text: - lines = verse.split(u'\n') - text.extend([line for line in lines]) - - return text + lines = text.split(u'\n') + return [line for line in lines] def _words_split(self, line): """ @@ -443,12 +438,8 @@ class Renderer(object): """ # this parse we are to be wordy line = line.replace(u'\n', u' ') - verses_text = line.split(u' ') - text = [] - for verse in verses_text: - lines = verse.split(u' ') - text.extend([line + u' ' for line in lines]) - return text + words = line.split(u' ') + return [word + u' ' for word in words] def _lines_split(self, text): """ @@ -457,9 +448,4 @@ class Renderer(object): # this parse we do not want to use this so remove it text = text.replace(u'\n[---]', u'') lines = text.split(u'\n') - real_lines = [] - for line in lines: - line = line.replace(u'[---]', u'') - sub_lines = line.split(u'\n') - real_lines.extend([sub_line for sub_line in sub_lines]) - return real_lines + return [line.replace(u'[---]', u'') for line in lines] From 547a7ac14d6bce6a6f9c9c9d411464faf6544222 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 29 Apr 2011 10:28:41 +0200 Subject: [PATCH 39/57] fix and clean up --- openlp/core/lib/renderer.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 7aeebe75f..8106b742c 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -25,6 +25,7 @@ ############################################################################### import logging +import re from PyQt4 import QtCore, QtWebKit @@ -228,7 +229,7 @@ class Renderer(object): lines = self._lines(slide.strip(u'\n')) new_pages = self._paginate_slide(lines, line_break, self.force_page) - pages.extend([page for page in new_pages]) + pages.extend(new_pages) # Bibles elif item.is_capable(ItemCapabilities.AllowsWordSplit): pages = self._paginate_slide_words(text, line_break) @@ -341,12 +342,12 @@ class Renderer(object): if force_page and line_count > 0: Receiver.send_message(u'theme_line_count', line_count) line_count = -1 - html_text = html_text.rstrip(u'
') + html_text = re.compile(r'
.*$').sub(u'', html_text) formatted.append(html_text) html_text = u'' styled_text = styled_line html_text += line + line_end - html_text = html_text.rstrip(u'
') + html_text = re.compile(r'
.*$').sub(u'', html_text) formatted.append(html_text) log.debug(u'_paginate_slide - End') return formatted @@ -385,7 +386,8 @@ class Renderer(object): self.web.setHtml(html) if self.web_frame.contentsSize().height() <= \ self.page_height: - previous_raw = previous_raw.rstrip(u'
') + previous_raw = re.compile( + r'
.*$').sub(u'', previous_raw) formatted.append(previous_raw) previous_html = u'' previous_raw = u'' @@ -408,7 +410,8 @@ class Renderer(object): # Text too long so go to next page if self.web_frame.contentsSize().height() > \ self.page_height: - previous_raw = previous_raw.rstrip(u'
') + previous_raw = re.compile( + r'
.*$').sub(u'', previous_raw) formatted.append(previous_raw) previous_html = u'' previous_raw = u'' @@ -419,7 +422,7 @@ class Renderer(object): else: previous_html += styled_line + line_end previous_raw += line + line_end - previous_raw = previous_raw.rstrip(u'
') + previous_raw = re.compile(r'
.*$').sub(u'', previous_raw) formatted.append(previous_raw) log.debug(u'_paginate_slide_words - End') return formatted @@ -429,8 +432,7 @@ class Renderer(object): Split the slide up by physical line """ # this parse we do not want to use this so remove it - lines = text.split(u'\n') - return [line for line in lines] + return text.split(u'\n') def _words_split(self, line): """ From 7908ac4f6742ea308a2e7f688cf73ee4f338a5c7 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Apr 2011 09:45:36 +0100 Subject: [PATCH 40/57] Fix large Service Files --- openlp/core/lib/mediamanageritem.py | 2 +- openlp/core/ui/servicemanager.py | 13 ++++++++----- openlp/plugins/images/lib/mediaitem.py | 13 ++++++++----- openlp/plugins/presentations/lib/mediaitem.py | 9 ++++++--- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index e7d7bc4ec..8b63963a0 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -554,4 +554,4 @@ class MediaManagerItem(QtGui.QWidget): item_id = remoteItem else: item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] - return item_id \ No newline at end of file + return item_id diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 9ad527826..8b3e63e4f 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -591,7 +591,7 @@ class ServiceManager(QtGui.QWidget): serviceItem.renderer = self.mainwindow.renderer serviceItem.set_from_service(item, self.servicePath) self.validateItem(serviceItem) - self.addServiceItem(serviceItem) + self.addServiceItem(serviceItem, repaint=False) if serviceItem.is_capable(ItemCapabilities.OnLoadUpdate): Receiver.send_message(u'%s_service_load' % serviceItem.name.lower(), serviceItem) @@ -601,8 +601,6 @@ class ServiceManager(QtGui.QWidget): self.setModified(False) QtCore.QSettings().setValue( 'service/last file', QtCore.QVariant(fileName)) - self.mainwindow.finishedProgressBar() - Receiver.send_message(u'cursor_normal') else: critical_error_message_box( message=translate('OpenLP.ServiceManager', @@ -633,6 +631,9 @@ class ServiceManager(QtGui.QWidget): fileTo.close() if zip: zip.close() + self.mainwindow.finishedProgressBar() + Receiver.send_message(u'cursor_normal') + self.repaintServiceList(-1, -1) def loadLastFile(self): """ @@ -1066,7 +1067,8 @@ class ServiceManager(QtGui.QWidget): newItem) self.setModified() - def addServiceItem(self, item, rebuild=False, expand=None, replace=False): + def addServiceItem(self, item, rebuild=False, expand=None, replace=False, + repaint=True): """ Add a Service item to the list @@ -1099,7 +1101,8 @@ class ServiceManager(QtGui.QWidget): self.serviceItems.append({u'service_item': item, u'order': len(self.serviceItems) + 1, u'expanded': expand}) - self.repaintServiceList(len(self.serviceItems) - 1, -1) + if repaint: + self.repaintServiceList(len(self.serviceItems) - 1, -1) else: self.serviceItems.insert(self.dropPosition, {u'service_item': item, u'order': self.dropPosition, diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index a2dd292d5..68da7fbe1 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -77,7 +77,7 @@ class ImageMediaItem(MediaManagerItem): u'thumbnails') check_directory_exists(self.servicePath) self.loadList(SettingsManager.load_list( - self.settingsSection, self.settingsSection)) + self.settingsSection, self.settingsSection), True) def addListViewToToolBar(self): MediaManagerItem.addListViewToToolBar(self) @@ -107,11 +107,13 @@ class ImageMediaItem(MediaManagerItem): SettingsManager.set_list(self.settingsSection, self.settingsSection, self.getFileList()) - def loadList(self, list): + def loadList(self, list, initialLoad=False): Receiver.send_message(u'cursor_busy') - self.parent.formparent.displayProgressBar(len(list)) + if not initialLoad: + self.parent.formparent.displayProgressBar(len(list)) for imageFile in list: - self.parent.formparent.incrementProgressBar() + if not initialLoad: + self.parent.formparent.incrementProgressBar() filename = os.path.split(unicode(imageFile))[1] thumb = os.path.join(self.servicePath, filename) if os.path.exists(thumb): @@ -126,7 +128,8 @@ class ImageMediaItem(MediaManagerItem): item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(imageFile)) self.listView.addItem(item_name) Receiver.send_message(u'cursor_normal') - self.parent.formparent.finishedProgressBar() + if not initialLoad: + self.parent.formparent.finishedProgressBar() def generateSlideData(self, service_item, item=None, xmlVersion=False): items = self.listView.selectedIndexes() diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 45b8b81c4..455d42a72 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -159,9 +159,11 @@ class PresentationMediaItem(MediaManagerItem): for file in currlist: titles.append(os.path.split(file)[1]) Receiver.send_message(u'cursor_busy') - self.parent.formparent.displayProgressBar(len(list)) + if not initialLoad: + self.parent.formparent.displayProgressBar(len(list)) for file in list: - self.parent.formparent.incrementProgressBar() + if not initialLoad: + self.parent.formparent.incrementProgressBar() if currlist.count(file) > 0: continue filename = os.path.split(unicode(file))[1] @@ -202,7 +204,8 @@ class PresentationMediaItem(MediaManagerItem): item_name.setIcon(icon) self.listView.addItem(item_name) Receiver.send_message(u'cursor_normal') - self.parent.formparent.finishedProgressBar() + if not initialLoad: + self.parent.formparent.finishedProgressBar() def onDeleteClick(self): """ From e4c0d1227e7c8aa970f1e8b3dda03b528fe83620 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Apr 2011 09:54:11 +0100 Subject: [PATCH 41/57] Fix timer --- openlp/core/ui/mainwindow.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 311aa7ec0..a8ffa2b9e 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -1044,5 +1044,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): Remove the Progress bar from view. """ if event.timerId() == self.timer_id: + self.timer_id = 0 self.loadProgressBar.hide() Receiver.send_message(u'openlp_process_events') From ebf5777a02b29c79aa863f13703710fdcbffcc42 Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Fri, 29 Apr 2011 09:58:10 +0100 Subject: [PATCH 42/57] Fix bug 773036 --- openlp/plugins/presentations/lib/mediaitem.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 74ff3fea8..6428ae535 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -285,7 +285,7 @@ class PresentationMediaItem(MediaManagerItem): "supports" the extension. If none found, then look for a controller which "also supports" it instead. """ - filetype = filename.split(u'.')[1] + filetype = filename.split(u'.')[-1] if not filetype: return None for controller in self.controllers: @@ -296,4 +296,4 @@ class PresentationMediaItem(MediaManagerItem): if self.controllers[controller].enabled(): if filetype in self.controllers[controller].alsosupports: return controller - return None \ No newline at end of file + return None From acb4f12ac9f9e71164502469625998104a57b155 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Apr 2011 10:07:41 +0100 Subject: [PATCH 43/57] remove comments --- openlp/core/ui/mainwindow.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index a8ffa2b9e..aadc1c175 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -549,9 +549,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'openlp_information_message'), self.onInformationMessage) -# QtCore.QObject.connect(Receiver.get_receiver(), -# QtCore.SIGNAL(u'mainwindow_remove_progress'), -# self.removeProgressBar) # warning cyclic dependency # renderer needs to call ThemeManager and # ThemeManager needs to call Renderer From e6f69c01f4a8bb51b1a6b62472743b011308124e Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Apr 2011 12:21:14 +0100 Subject: [PATCH 44/57] Remove 2 phonon initialisations --- openlp/core/lib/renderer.py | 2 +- openlp/core/ui/maindisplay.py | 12 +++++++----- openlp/plugins/media/lib/mediaitem.py | 6 ++++-- openlp/plugins/songs/lib/mediaitem.py | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 7687ebe9a..6014602b2 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -71,7 +71,7 @@ class Renderer(object): log.debug(u'Initilisation started') self.screens = screens self.image_manager = ImageManager() - self.display = MainDisplay(self, screens, False) + self.display = MainDisplay(self, screens, False, False) self.display.imageManager = self.image_manager self.theme_manager = theme_manager self.service_theme = u'' diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 7843284b3..74cc09135 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -60,11 +60,12 @@ class MainDisplay(DisplayWidget): """ This is the display screen. """ - def __init__(self, parent, screens, live): + def __init__(self, parent, screens, live, needsPhonon=True): DisplayWidget.__init__(self, live, parent=None) self.parent = parent self.screens = screens self.isLive = live + self.needsPhonon = needsPhonon self.alertTab = None self.hideMode = None self.videoHide = False @@ -102,10 +103,11 @@ class MainDisplay(DisplayWidget): self.videoWidget.setGeometry(QtCore.QRect(0, 0, self.screen[u'size'].width(), self.screen[u'size'].height())) log.debug(u'Setup Phonon for monitor %s' % self.screens.monitor_number) - self.mediaObject = Phonon.MediaObject(self) - self.audio = Phonon.AudioOutput(Phonon.VideoCategory, self.mediaObject) - Phonon.createPath(self.mediaObject, self.videoWidget) - Phonon.createPath(self.mediaObject, self.audio) + if self.needsPhonon: + self.mediaObject = Phonon.MediaObject(self) + self.audio = Phonon.AudioOutput(Phonon.VideoCategory, self.mediaObject) + Phonon.createPath(self.mediaObject, self.videoWidget) + Phonon.createPath(self.mediaObject, self.audio) QtCore.QObject.connect(self.mediaObject, QtCore.SIGNAL(u'stateChanged(Phonon::State, Phonon::State)'), self.videoState) diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 559af11e2..2a0620cf8 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -50,7 +50,7 @@ class MediaMediaItem(MediaManagerItem): u':/media/media_video.png').toImage() MediaManagerItem.__init__(self, parent, self, icon) self.singleServiceItem = False - self.mediaObject = Phonon.MediaObject(self) + self.mediaObject = None QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'video_background_replaced'), self.videobackgroundReplaced) @@ -117,6 +117,8 @@ class MediaMediaItem(MediaManagerItem): 'the media file "%s" no longer exists.')) % filename) def generateSlideData(self, service_item, item=None, xmlVersion=False): + if not self.mediaObject: + self.mediaObject = Phonon.MediaObject(self) if item is None: item = self.listView.currentItem() if item is None: @@ -209,4 +211,4 @@ class MediaMediaItem(MediaManagerItem): img = QtGui.QPixmap(u':/media/media_video.png').toImage() item_name.setIcon(build_icon(img)) item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file)) - self.listView.addItem(item_name) \ No newline at end of file + self.listView.addItem(item_name) diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index d731d8ef8..15fa774ad 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -473,4 +473,4 @@ class SongMediaItem(MediaManagerItem): Locale aware collation of song titles """ return locale.strcoll(unicode(song_1.title.lower()), - unicode(song_2.title.lower())) \ No newline at end of file + unicode(song_2.title.lower())) From 4304d111f185b2daf0d65e7b55e7f167b89c57f2 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Apr 2011 12:55:49 +0100 Subject: [PATCH 45/57] Live Initialisation Delayed --- openlp/core/ui/maindisplay.py | 36 ++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 74cc09135..1ea412fe8 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -71,6 +71,8 @@ class MainDisplay(DisplayWidget): self.videoHide = False self.override = {} self.retranslateUi() + self.mediaObject = None + self.firstTime = True self.setStyleSheet(u'border: 0px; margin: 0px; padding: 0px;') self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.Tool | QtCore.Qt.WindowStaysOnTopHint) @@ -104,19 +106,10 @@ class MainDisplay(DisplayWidget): self.screen[u'size'].width(), self.screen[u'size'].height())) log.debug(u'Setup Phonon for monitor %s' % self.screens.monitor_number) if self.needsPhonon: - self.mediaObject = Phonon.MediaObject(self) - self.audio = Phonon.AudioOutput(Phonon.VideoCategory, self.mediaObject) - Phonon.createPath(self.mediaObject, self.videoWidget) - Phonon.createPath(self.mediaObject, self.audio) - QtCore.QObject.connect(self.mediaObject, - QtCore.SIGNAL(u'stateChanged(Phonon::State, Phonon::State)'), - self.videoState) - QtCore.QObject.connect(self.mediaObject, - QtCore.SIGNAL(u'finished()'), - self.videoFinished) - QtCore.QObject.connect(self.mediaObject, - QtCore.SIGNAL(u'tick(qint64)'), - self.videoTick) + if self.firstTime: + self.firstTime = False + else: + self.createMediaObject() log.debug(u'Setup webView for monitor %s' % self.screens.monitor_number) self.webView = QtWebKit.QWebView(self) self.webView.setGeometry(0, 0, @@ -177,6 +170,21 @@ class MainDisplay(DisplayWidget): log.debug( u'Finished setup for monitor %s' % self.screens.monitor_number) + def createMediaObject(self): + self.mediaObject = Phonon.MediaObject(self) + self.audio = Phonon.AudioOutput(Phonon.VideoCategory, self.mediaObject) + Phonon.createPath(self.mediaObject, self.videoWidget) + Phonon.createPath(self.mediaObject, self.audio) + QtCore.QObject.connect(self.mediaObject, + QtCore.SIGNAL(u'stateChanged(Phonon::State, Phonon::State)'), + self.videoState) + QtCore.QObject.connect(self.mediaObject, + QtCore.SIGNAL(u'finished()'), + self.videoFinished) + QtCore.QObject.connect(self.mediaObject, + QtCore.SIGNAL(u'tick(qint64)'), + self.videoTick) + def text(self, slide): """ Add the slide text from slideController @@ -350,6 +358,8 @@ class MainDisplay(DisplayWidget): """ Loads and starts a video to run with the option of sound """ + if not self.mediaObject: + self.createMediaObject() log.debug(u'video') self.webLoaded = True self.setGeometry(self.screen[u'size']) From 640815ada3fe7c7f215ab4959477300e9550fc0f Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 29 Apr 2011 16:31:17 +0200 Subject: [PATCH 46/57] removed re --- openlp/core/lib/renderer.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 8106b742c..641920852 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -25,7 +25,6 @@ ############################################################################### import logging -import re from PyQt4 import QtCore, QtWebKit @@ -226,7 +225,7 @@ class Renderer(object): slides = text.split(u'[---]') pages = [] for slide in slides: - lines = self._lines(slide.strip(u'\n')) + lines = slide.strip(u'\n').split(u'\n') new_pages = self._paginate_slide(lines, line_break, self.force_page) pages.extend(new_pages) @@ -342,12 +341,14 @@ class Renderer(object): if force_page and line_count > 0: Receiver.send_message(u'theme_line_count', line_count) line_count = -1 - html_text = re.compile(r'
.*$').sub(u'', html_text) + while html_text.endswith(u'
'): + html_text = html_text[:-4] formatted.append(html_text) html_text = u'' styled_text = styled_line html_text += line + line_end - html_text = re.compile(r'
.*$').sub(u'', html_text) + while html_text.endswith(u'
'): + tml_text = html_text[:-4] formatted.append(html_text) log.debug(u'_paginate_slide - End') return formatted @@ -372,7 +373,7 @@ class Renderer(object): formatted = [] previous_html = u'' previous_raw = u'' - lines = self._lines(text) + lines = text.split(u'\n') for line in lines: styled_line = expand_tags(line) html = self.page_shell + previous_html + styled_line + HTML_END @@ -386,8 +387,8 @@ class Renderer(object): self.web.setHtml(html) if self.web_frame.contentsSize().height() <= \ self.page_height: - previous_raw = re.compile( - r'
.*$').sub(u'', previous_raw) + while previous_raw.endswith(u'
'): + previous_raw = previous_raw[:-4] formatted.append(previous_raw) previous_html = u'' previous_raw = u'' @@ -410,8 +411,8 @@ class Renderer(object): # Text too long so go to next page if self.web_frame.contentsSize().height() > \ self.page_height: - previous_raw = re.compile( - r'
.*$').sub(u'', previous_raw) + while previous_raw.endswith(u'
'): + previous_raw = previous_raw[:-4] formatted.append(previous_raw) previous_html = u'' previous_raw = u'' @@ -422,18 +423,12 @@ class Renderer(object): else: previous_html += styled_line + line_end previous_raw += line + line_end - previous_raw = re.compile(r'
.*$').sub(u'', previous_raw) + while previous_raw.endswith(u'
'): + previous_raw = previous_raw[:-4] formatted.append(previous_raw) log.debug(u'_paginate_slide_words - End') return formatted - def _lines(self, text): - """ - Split the slide up by physical line - """ - # this parse we do not want to use this so remove it - return text.split(u'\n') - def _words_split(self, line): """ Split the slide up by word so can wrap better From 0f51c47d9e381a65b488b5133b82e909ef38e947 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 29 Apr 2011 16:36:29 +0200 Subject: [PATCH 47/57] fixed spelling --- openlp/core/lib/renderer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 641920852..bba85d176 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -348,7 +348,7 @@ class Renderer(object): styled_text = styled_line html_text += line + line_end while html_text.endswith(u'
'): - tml_text = html_text[:-4] + html_text = html_text[:-4] formatted.append(html_text) log.debug(u'_paginate_slide - End') return formatted From 08b6d7cee1e063bfd65d6f67ca4e05f8603b42e2 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Apr 2011 17:27:27 +0100 Subject: [PATCH 48/57] Fixes for Jon --- openlp/core/ui/maindisplay.py | 12 ++++++++---- openlp/core/utils/__init__.py | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 1ea412fe8..5eec90682 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -81,6 +81,9 @@ class MainDisplay(DisplayWidget): QtCore.SIGNAL(u'maindisplay_hide'), self.hideDisplay) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'maindisplay_show'), self.showDisplay) + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'openlp_phonon_creation'), + self.createMediaObject) def retranslateUi(self): """ @@ -105,10 +108,8 @@ class MainDisplay(DisplayWidget): self.videoWidget.setGeometry(QtCore.QRect(0, 0, self.screen[u'size'].width(), self.screen[u'size'].height())) log.debug(u'Setup Phonon for monitor %s' % self.screens.monitor_number) - if self.needsPhonon: - if self.firstTime: - self.firstTime = False - else: + if self.isLive: + if not self.firstTime: self.createMediaObject() log.debug(u'Setup webView for monitor %s' % self.screens.monitor_number) self.webView = QtWebKit.QWebView(self) @@ -171,6 +172,8 @@ class MainDisplay(DisplayWidget): u'Finished setup for monitor %s' % self.screens.monitor_number) def createMediaObject(self): + self.firstTime = False + log.debug(u'Creating Phonon objects - Start for %s', self.isLive) self.mediaObject = Phonon.MediaObject(self) self.audio = Phonon.AudioOutput(Phonon.VideoCategory, self.mediaObject) Phonon.createPath(self.mediaObject, self.videoWidget) @@ -184,6 +187,7 @@ class MainDisplay(DisplayWidget): QtCore.QObject.connect(self.mediaObject, QtCore.SIGNAL(u'tick(qint64)'), self.videoTick) + log.debug(u'Creating Phonon objects - Finished for %s', self.isLive) def text(self, slide): """ diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 1bc7037ae..d08a63c4b 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -99,6 +99,7 @@ class VersionThread(QtCore.QThread): local_version.get(u'revision') and \ remote_version[u'revision'] > local_version[u'revision']: Receiver.send_message(u'openlp_version_check', u'%s' % version) + Receiver.send_message(u'openlp_phonon_creation') class AppLocation(object): From 189daad93ce130a85dcd07960ff108bc32c4dbcb Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Apr 2011 17:41:26 +0100 Subject: [PATCH 49/57] More improvements --- openlp/plugins/media/lib/mediaitem.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 2a0620cf8..52f689f41 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -54,6 +54,9 @@ class MediaMediaItem(MediaManagerItem): QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'video_background_replaced'), self.videobackgroundReplaced) + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'openlp_phonon_creation'), + self.createPhonon) def retranslateUi(self): self.onNewPrompt = translate('MediaPlugin.MediaItem', 'Select Media') @@ -117,8 +120,6 @@ class MediaMediaItem(MediaManagerItem): 'the media file "%s" no longer exists.')) % filename) def generateSlideData(self, service_item, item=None, xmlVersion=False): - if not self.mediaObject: - self.mediaObject = Phonon.MediaObject(self) if item is None: item = self.listView.currentItem() if item is None: @@ -212,3 +213,8 @@ class MediaMediaItem(MediaManagerItem): item_name.setIcon(build_icon(img)) item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file)) self.listView.addItem(item_name) + + def createPhonon(self): + if not self.mediaObject: + self.mediaObject = Phonon.MediaObject(self) + From 9e721a4824aa8eaee0e61a116c6c16ad1ab26222 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Apr 2011 19:43:29 +0100 Subject: [PATCH 50/57] More improvements --- openlp/core/ui/slidecontroller.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index ad2b007a4..fdbf184b5 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -277,15 +277,16 @@ class SlideController(QtGui.QWidget): self.slideLayout.setSpacing(0) self.slideLayout.setMargin(0) self.slideLayout.setObjectName(u'SlideLayout') - self.mediaObject = Phonon.MediaObject(self) - self.video = Phonon.VideoWidget() - self.video.setVisible(False) - self.audio = Phonon.AudioOutput(Phonon.VideoCategory, self.mediaObject) - Phonon.createPath(self.mediaObject, self.video) - Phonon.createPath(self.mediaObject, self.audio) if not self.isLive: + self.mediaObject = Phonon.MediaObject(self) + self.video = Phonon.VideoWidget() + self.video.setVisible(False) + self.audio = Phonon.AudioOutput(Phonon.VideoCategory, + self.mediaObject) + Phonon.createPath(self.mediaObject, self.video) + Phonon.createPath(self.mediaObject, self.audio) self.video.setGeometry(QtCore.QRect(0, 0, 300, 225)) - self.slideLayout.insertWidget(0, self.video) + self.slideLayout.insertWidget(0, self.video) # Actual preview screen self.slidePreview = QtGui.QLabel(self) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, From ddf9c3b61b1d3d30549a97ff51879e0e517859b0 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Apr 2011 20:24:21 +0100 Subject: [PATCH 51/57] Remove Var from last merge --- openlp/core/lib/renderer.py | 2 +- openlp/core/ui/maindisplay.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 6e122af81..bba85d176 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -71,7 +71,7 @@ class Renderer(object): log.debug(u'Initilisation started') self.screens = screens self.image_manager = ImageManager() - self.display = MainDisplay(self, screens, False, False) + self.display = MainDisplay(self, screens, False) self.display.imageManager = self.image_manager self.theme_manager = theme_manager self.service_theme = u'' diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 5eec90682..5fd066a12 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -60,12 +60,11 @@ class MainDisplay(DisplayWidget): """ This is the display screen. """ - def __init__(self, parent, screens, live, needsPhonon=True): + def __init__(self, parent, screens, live): DisplayWidget.__init__(self, live, parent=None) self.parent = parent self.screens = screens self.isLive = live - self.needsPhonon = needsPhonon self.alertTab = None self.hideMode = None self.videoHide = False From 69395170e15b79ee8573fcf1e2655b501f1de38c Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Apr 2011 21:08:22 +0100 Subject: [PATCH 52/57] minor cleanups --- openlp/plugins/media/lib/mediaitem.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 52f689f41..6e616a9ef 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -132,6 +132,8 @@ class MediaMediaItem(MediaManagerItem): unicode(translate('MediaPlugin.MediaItem', 'The file %s no longer exists.')) % filename) return False + if not self.mediaObject: + self.mediaObject = Phonon.MediaObject(self) self.mediaObject.stop() self.mediaObject.clearQueue() self.mediaObject.setCurrentSource(Phonon.MediaSource(filename)) @@ -217,4 +219,3 @@ class MediaMediaItem(MediaManagerItem): def createPhonon(self): if not self.mediaObject: self.mediaObject = Phonon.MediaObject(self) - From a9df8468aa6f6b6c2a0d0cb1416204703f30f6d4 Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Fri, 29 Apr 2011 23:29:29 +0100 Subject: [PATCH 53/57] Minimized impress troubles --- .../presentations/lib/impresscontroller.py | 20 +++++++++++-------- openlp/plugins/presentations/lib/mediaitem.py | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index c84f0ff1e..74ebb5672 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -38,6 +38,8 @@ import logging import os import time +from openlp.core.lib import Receiver + if os.name == u'nt': from win32com.client import Dispatch import pywintypes @@ -219,7 +221,6 @@ class ImpressDocument(PresentationDocument): The file name of the presentatios to the run. """ log.debug(u'Load Presentation OpenOffice') - #print "s.dsk1 ", self.desktop if os.name == u'nt': desktop = self.controller.get_com_desktop() if desktop is None: @@ -234,7 +235,6 @@ class ImpressDocument(PresentationDocument): return False self.desktop = desktop properties = [] - properties.append(self.create_property(u'Minimized', True)) properties = tuple(properties) try: self.document = desktop.loadComponentFromURL(url, u'_blank', @@ -242,6 +242,9 @@ class ImpressDocument(PresentationDocument): except: log.exception(u'Failed to load presentation %s' % url) return False + window = self.document.getCurrentController().getFrame() \ + .getContainerWindow() + window.setPosSize(0, 0, 200, 400, 12) self.presentation = self.document.getPresentation() self.presentation.Display = \ self.controller.plugin.renderer.screens.current_display + 1 @@ -387,14 +390,15 @@ class ImpressDocument(PresentationDocument): log.debug(u'start presentation OpenOffice') if self.control is None or not self.control.isRunning(): self.presentation.start() - # start() returns before the getCurrentComponent is ready. - # Try for 5 seconds + self.control = self.presentation.getController() + # start() returns before the Component is ready. + # Try for 30 seconds i = 1 - while self.desktop.getCurrentComponent() is None and i < 50: + while not self.control and i < 300: + Receiver.send_message(u'openlp_process_events') time.sleep(0.1) i = i + 1 - self.control = \ - self.desktop.getCurrentComponent().Presentation.getController() + self.control = self.presentation.getController() else: self.control.activate() self.goto_slide(1) @@ -463,4 +467,4 @@ class ImpressDocument(PresentationDocument): shape = page.getByIndex(idx) if shape.supportsService("com.sun.star.drawing.Text"): text += shape.getString() + '\n' - return text \ No newline at end of file + return text diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 6428ae535..a00fe1879 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -285,7 +285,7 @@ class PresentationMediaItem(MediaManagerItem): "supports" the extension. If none found, then look for a controller which "also supports" it instead. """ - filetype = filename.split(u'.')[-1] + filetype = os.path.splitext(filename)[1] if not filetype: return None for controller in self.controllers: From 6584e6a1eda537f461be40e08e8fb4661fcca8be Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Fri, 29 Apr 2011 23:31:39 +0100 Subject: [PATCH 54/57] process events not required --- openlp/plugins/presentations/lib/impresscontroller.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index 74ebb5672..6d8643611 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -38,8 +38,6 @@ import logging import os import time -from openlp.core.lib import Receiver - if os.name == u'nt': from win32com.client import Dispatch import pywintypes @@ -392,10 +390,9 @@ class ImpressDocument(PresentationDocument): self.presentation.start() self.control = self.presentation.getController() # start() returns before the Component is ready. - # Try for 30 seconds + # Try for 15 seconds i = 1 - while not self.control and i < 300: - Receiver.send_message(u'openlp_process_events') + while not self.control and i < 150: time.sleep(0.1) i = i + 1 self.control = self.presentation.getController() From 9a88a7fcf71600c4fff3355dd249772f8ed05849 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 30 Apr 2011 06:43:41 +0100 Subject: [PATCH 55/57] Logging and comments --- openlp/plugins/media/lib/mediaitem.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 6e616a9ef..70c2bf304 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -132,6 +132,7 @@ class MediaMediaItem(MediaManagerItem): unicode(translate('MediaPlugin.MediaItem', 'The file %s no longer exists.')) % filename) return False + # Guard incase the event fails to get object created. if not self.mediaObject: self.mediaObject = Phonon.MediaObject(self) self.mediaObject.stop() @@ -217,5 +218,6 @@ class MediaMediaItem(MediaManagerItem): self.listView.addItem(item_name) def createPhonon(self): + log.debug(u'CreatePhonon') if not self.mediaObject: self.mediaObject = Phonon.MediaObject(self) From 8bec30cf9c79bdf185ccd0655d6a9dc32b82a255 Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Sat, 30 Apr 2011 08:31:03 +0100 Subject: [PATCH 56/57] Make Impress changes windows specific --- .../plugins/presentations/lib/impresscontroller.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index 6d8643611..a67d8f818 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -233,6 +233,10 @@ class ImpressDocument(PresentationDocument): return False self.desktop = desktop properties = [] + if os.name != u'nt': + # Recent versions of Impress on Windows won't start the presentation + # if it starts as minimized. It seems OK on Linux though. + properties.append(self.create_property(u'Minimized', True)) properties = tuple(properties) try: self.document = desktop.loadComponentFromURL(url, u'_blank', @@ -240,9 +244,12 @@ class ImpressDocument(PresentationDocument): except: log.exception(u'Failed to load presentation %s' % url) return False - window = self.document.getCurrentController().getFrame() \ - .getContainerWindow() - window.setPosSize(0, 0, 200, 400, 12) + if os.name == u'nt': + # As we can't start minimized the Impress window gets in the way. + # Either window.setPosSize(0, 0, 200, 400, 12) or .setVisible(False) + window = self.document.getCurrentController().getFrame() \ + .getContainerWindow() + window.setVisible(False) self.presentation = self.document.getPresentation() self.presentation.Display = \ self.controller.plugin.renderer.screens.current_display + 1 From 3b805f63748f6e3014e89a67fa1be05c7a872481 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 30 Apr 2011 08:42:20 +0100 Subject: [PATCH 57/57] Add new thread at startup time --- openlp.pyw | 5 +++-- openlp/core/utils/__init__.py | 13 +++++++++++++ openlp/plugins/media/lib/mediaitem.py | 3 --- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/openlp.pyw b/openlp.pyw index 425d3c874..0d4e8c200 100755 --- a/openlp.pyw +++ b/openlp.pyw @@ -46,7 +46,7 @@ from openlp.core.ui.firsttimeform import FirstTimeForm from openlp.core.ui.exceptionform import ExceptionForm from openlp.core.ui import SplashScreen, ScreenList from openlp.core.utils import AppLocation, LanguageManager, VersionThread, \ - get_application_version + get_application_version, DelayStartThread log = logging.getLogger() @@ -130,6 +130,7 @@ class OpenLP(QtGui.QApplication): u'general/update check', QtCore.QVariant(True)).toBool() if update_check: VersionThread(self.mainWindow).start() + DelayStartThread(self.mainWindow).start() return self.exec_() def isAlreadyRunning(self): @@ -250,4 +251,4 @@ if __name__ == u'__main__': """ Instantiate and run the application. """ - main() \ No newline at end of file + main() diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index d08a63c4b..3051301d6 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -99,6 +99,19 @@ class VersionThread(QtCore.QThread): local_version.get(u'revision') and \ remote_version[u'revision'] > local_version[u'revision']: Receiver.send_message(u'openlp_version_check', u'%s' % version) + + +class DelayStartThread(QtCore.QThread): + """ + A special Qt thread class to build things after OpenLP has started + """ + def __init__(self, parent): + QtCore.QThread.__init__(self, parent) + + def run(self): + """ + Run the thread. + """ Receiver.send_message(u'openlp_phonon_creation') diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 70c2bf304..e494b9e5e 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -132,9 +132,6 @@ class MediaMediaItem(MediaManagerItem): unicode(translate('MediaPlugin.MediaItem', 'The file %s no longer exists.')) % filename) return False - # Guard incase the event fails to get object created. - if not self.mediaObject: - self.mediaObject = Phonon.MediaObject(self) self.mediaObject.stop() self.mediaObject.clearQueue() self.mediaObject.setCurrentSource(Phonon.MediaSource(filename))