From 0d99f5be96048c5a40862c39970392234593b692 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 23 Aug 2011 21:57:29 +0200 Subject: [PATCH 01/11] hopefully fixed bug #796528 (to be cleaned up Fixes: https://launchpad.net/bugs/796528 --- openlp/core/lib/renderer.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index ac7e95c4c..711be4227 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -229,13 +229,33 @@ class Renderer(object): pages = self._paginate_slide(lines, line_end) if len(pages) > 1: # Songs and Custom - if item.is_capable(ItemCapabilities.AllowsVirtualSplit): - # Do not forget the line breaks! - slides = text.split(u'[---]') + if item.is_capable(ItemCapabilities.AllowsVirtualSplit) and \ + u'[---]' in text: pages = [] - for slide in slides: - lines = slide.strip(u'\n').split(u'\n') - pages.extend(self._paginate_slide(lines, line_end)) + while True: + html_text = expand_tags(text.split(u'[---]', 1)[0]) + html_text = html_text.strip() + html_text = html_text.replace(u'\n', u'
') + if not self._text_fits_on_slide(html_text): + text = text.replace(u'\n[---]', u'', 1) + else: + if u'[---]' in text: + slides = text.split(u'[---]', 1) + text_to_render = slides[0] + text_to_render = text_to_render.strip() + text_to_render = text_to_render.replace(u'\n', u'
') + text = slides[1] + else: + text_to_render = text + text = u'' + lines = text_to_render.strip(u'\n').split(u'\n') + lines = map(expand_tags, lines) + pages.extend(self._paginate_slide(lines, line_end)) + if not text or u'[---]' not in text: + lines = text.strip(u'\n').split(u'\n') + lines = map(expand_tags, lines) + pages.extend(self._paginate_slide(lines, line_end)) + break new_pages = [] for page in pages: while page.endswith(u'
'): @@ -488,7 +508,7 @@ class Renderer(object): returned, otherwise ``False``. ``text`` - The text to check. It can contain HTML tags. + The text to check. It may contain HTML tags. """ self.web_frame.evaluateJavaScript(u'show_text("%s")' % text.replace(u'\\', u'\\\\').replace(u'\"', u'\\\"')) From 6c3d15636301db0249aafa1eee81b2d152824f4d Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 26 Aug 2011 17:22:57 +0200 Subject: [PATCH 02/11] fixed inversion :-D --- openlp/core/lib/renderer.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 711be4227..df8235b33 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -236,7 +236,7 @@ class Renderer(object): html_text = expand_tags(text.split(u'[---]', 1)[0]) html_text = html_text.strip() html_text = html_text.replace(u'\n', u'
') - if not self._text_fits_on_slide(html_text): + if self._text_fits_on_slide(html_text): text = text.replace(u'\n[---]', u'', 1) else: if u'[---]' in text: @@ -361,7 +361,7 @@ class Renderer(object): separator = u'
' html_lines = map(expand_tags, lines) # Text too long so go to next page. - if self._text_fits_on_slide(separator.join(html_lines)): + if not self._text_fits_on_slide(separator.join(html_lines)): html_text, previous_raw = self._binary_chop(formatted, previous_html, previous_raw, html_lines, lines, separator, u'') else: @@ -394,18 +394,18 @@ class Renderer(object): line = line.strip() html_line = expand_tags(line) # Text too long so go to next page. - if self._text_fits_on_slide(previous_html + html_line): + if not self._text_fits_on_slide(previous_html + html_line): # Check if there was a verse before the current one and append # it, when it fits on the page. if previous_html: - if not self._text_fits_on_slide(previous_html): + if self._text_fits_on_slide(previous_html): formatted.append(previous_raw) previous_html = u'' previous_raw = u'' # Now check if the current verse will fit, if it does # not we have to start to process the verse word by # word. - if not self._text_fits_on_slide(html_line): + if self._text_fits_on_slide(html_line): previous_html = html_line + line_end previous_raw = line + line_end continue @@ -462,7 +462,7 @@ class Renderer(object): highest_index = len(html_list) - 1 index = int(highest_index / 2) while True: - if self._text_fits_on_slide( + if not self._text_fits_on_slide( previous_html + separator.join(html_list[:index + 1]).strip()): # We know that it does not fit, so change/calculate the # new index and highest_index accordingly. @@ -485,8 +485,8 @@ class Renderer(object): else: continue # Check if the remaining elements fit on the slide. - if not self._text_fits_on_slide( - separator.join(html_list[index + 1:]).strip()): + if self._text_fits_on_slide( + separator.join(html_list[index + 1:]).strip()): previous_html = separator.join( html_list[index + 1:]).strip() + line_end previous_raw = separator.join( @@ -512,7 +512,7 @@ class Renderer(object): """ self.web_frame.evaluateJavaScript(u'show_text("%s")' % text.replace(u'\\', u'\\\\').replace(u'\"', u'\\\"')) - return self.web_frame.contentsSize().height() > self.page_height + return self.web_frame.contentsSize().height() <= self.page_height def _words_split(self, line): """ From 3722253bcfe4597807331fb3cf9d270155cd3c79 Mon Sep 17 00:00:00 2001 From: Stevan Pettit Date: Fri, 26 Aug 2011 23:14:30 -0400 Subject: [PATCH 03/11] Added code to process any Bibles downloaded during the re-run of the First Time wizard --- openlp/core/ui/mainwindow.py | 3 +++ openlp/plugins/bibles/bibleplugin.py | 5 ++++- openlp/plugins/bibles/lib/mediaitem.py | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 4ecf792bc..5bd8e9fb7 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -767,6 +767,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.themeManagerContents.loadThemes(True) Receiver.send_message(u'theme_update_global', self.themeManagerContents.global_theme) + # Check if any Bibles downloaded. If there are, they will be + # processed. + Receiver.send_message(u'bibles_load_list', True) def blankCheck(self): """ diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 619581b17..900f04b50 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -29,7 +29,8 @@ import logging from PyQt4 import QtCore, QtGui -from openlp.core.lib import Plugin, StringContent, build_icon, translate +from openlp.core.lib import Plugin, StringContent, build_icon, translate, \ + Receiver from openlp.core.lib.ui import base_action, UiStrings from openlp.core.utils.actions import ActionList from openlp.plugins.bibles.lib import BibleManager, BiblesTab, BibleMediaItem @@ -62,6 +63,8 @@ class BiblePlugin(Plugin): self.exportBibleItem.setVisible(False) if len(self.manager.old_bible_databases): self.toolsUpgradeItem.setVisible(True) + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'bibles_appStartup'), self.appStartup) def finalise(self): """ diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 91009424c..710803bd2 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -391,10 +391,13 @@ class BibleMediaItem(MediaManagerItem): elif len(bibles): self.initialiseAdvancedBible(bibles[0]) - def reloadBibles(self): + def reloadBibles(self, process=False): log.debug(u'Reloading Bibles') self.plugin.manager.reload_bibles() self.loadBibles() + # If called from first time wizard re-run, process any new bibles. + if process: + Receiver.send_message(u'bibles_appStartup') self.updateAutoCompleter() def initialiseAdvancedBible(self, bible): From d4e6c44d217d982c2e9e3a6755b05a9e39f14441 Mon Sep 17 00:00:00 2001 From: Stevan Pettit Date: Sat, 27 Aug 2011 16:42:22 -0400 Subject: [PATCH 04/11] Fixed signal name --- openlp/plugins/bibles/bibleplugin.py | 2 +- openlp/plugins/bibles/lib/mediaitem.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 900f04b50..17bad2b64 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -64,7 +64,7 @@ class BiblePlugin(Plugin): if len(self.manager.old_bible_databases): self.toolsUpgradeItem.setVisible(True) QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'bibles_appStartup'), self.appStartup) + QtCore.SIGNAL(u'bibles_app_startup'), self.appStartup) def finalise(self): """ diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 710803bd2..fe0fc58c3 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -397,7 +397,7 @@ class BibleMediaItem(MediaManagerItem): self.loadBibles() # If called from first time wizard re-run, process any new bibles. if process: - Receiver.send_message(u'bibles_appStartup') + Receiver.send_message(u'bibles_app_startup') self.updateAutoCompleter() def initialiseAdvancedBible(self, bible): From 2364ea72c2b4b8fc2da0c7badd317639959b432e Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 28 Aug 2011 17:53:27 +0200 Subject: [PATCH 05/11] hopefully completed the fix --- openlp/core/lib/renderer.py | 43 +++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index df8235b33..b5d507e29 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -227,35 +227,36 @@ class Renderer(object): # Clean up line endings. lines = self._lines_split(text) pages = self._paginate_slide(lines, line_end) - if len(pages) > 1: - # Songs and Custom - if item.is_capable(ItemCapabilities.AllowsVirtualSplit) and \ - u'[---]' in text: - pages = [] - while True: - html_text = expand_tags(text.split(u'[---]', 1)[0]) - html_text = html_text.strip() + # Songs and Custom + if item.is_capable(ItemCapabilities.AllowsVirtualSplit) and \ + len(pages) > 1 and u'[---]' in text: + pages = [] + while True: + html_text = expand_tags( + u'\n'.join(text.split(u'\n[---]\n', 2)[:-1])) + html_text = html_text.replace(u'\n', u'
') + if self._text_fits_on_slide(html_text): + text = text.replace(u'\n[---]', u'', 2) + else: + html_text = expand_tags(text.split(u'\n[---]\n', 1)[1]) html_text = html_text.replace(u'\n', u'
') if self._text_fits_on_slide(html_text): text = text.replace(u'\n[---]', u'', 1) else: if u'[---]' in text: - slides = text.split(u'[---]', 1) - text_to_render = slides[0] - text_to_render = text_to_render.strip() - text_to_render = text_to_render.replace(u'\n', u'
') - text = slides[1] + html_text, text = text.split(u'\n[---]\n', 1) + html_text = html_text.replace(u'\n', u'
') else: - text_to_render = text + html_text = text text = u'' - lines = text_to_render.strip(u'\n').split(u'\n') - lines = map(expand_tags, lines) + lines = expand_tags(html_text) + lines = lines.strip(u'\n').split(u'\n') pages.extend(self._paginate_slide(lines, line_end)) - if not text or u'[---]' not in text: - lines = text.strip(u'\n').split(u'\n') - lines = map(expand_tags, lines) - pages.extend(self._paginate_slide(lines, line_end)) - break + if u'[---]' not in text: + lines = expand_tags(text) + lines = lines.strip(u'\n').split(u'\n') + pages.extend(self._paginate_slide(lines, line_end)) + break new_pages = [] for page in pages: while page.endswith(u'
'): From 2acd1ae2adfdc7f93240d1668a82b8a60677a021 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 28 Aug 2011 18:04:18 +0200 Subject: [PATCH 06/11] added comments --- openlp/core/lib/renderer.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index b5d507e29..c4cbe8568 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -232,17 +232,26 @@ class Renderer(object): len(pages) > 1 and u'[---]' in text: pages = [] while True: + # Check if the first two potential virtual slides will fit + # (as a whole) on one slide. html_text = expand_tags( u'\n'.join(text.split(u'\n[---]\n', 2)[:-1])) html_text = html_text.replace(u'\n', u'
') if self._text_fits_on_slide(html_text): + # The first two virtual slides fit (as a whole) on one + # slide. Replace the occurrences of [---]. text = text.replace(u'\n[---]', u'', 2) else: + # The first two virtual slides did not fit as a whole. + # Check if the first virtual slide will fit. html_text = expand_tags(text.split(u'\n[---]\n', 1)[1]) html_text = html_text.replace(u'\n', u'
') if self._text_fits_on_slide(html_text): + # The first virtual slide fits, so remove it. text = text.replace(u'\n[---]', u'', 1) else: + # The first virtual slide does not fit, which means + # we have to render the first virtual slide. if u'[---]' in text: html_text, text = text.split(u'\n[---]\n', 1) html_text = html_text.replace(u'\n', u'
') From bc1f2d2977f050ddcd392adb9c730f6d11e2e50b Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 28 Aug 2011 18:59:09 +0200 Subject: [PATCH 07/11] removed wrong line --- openlp/core/lib/renderer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index c4cbe8568..94cff011d 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -254,7 +254,6 @@ class Renderer(object): # we have to render the first virtual slide. if u'[---]' in text: html_text, text = text.split(u'\n[---]\n', 1) - html_text = html_text.replace(u'\n', u'
') else: html_text = text text = u'' From fc71905735e4d6fa9712e4bdc762c3a132314eb7 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 28 Aug 2011 19:46:52 +0200 Subject: [PATCH 08/11] append text to the last slide (if more than one) --- openlp/core/lib/renderer.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 94cff011d..eed31a689 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -252,14 +252,26 @@ class Renderer(object): else: # The first virtual slide does not fit, which means # we have to render the first virtual slide. - if u'[---]' in text: + text_contains_break = u'[---]' in text + if text_contains_break: html_text, text = text.split(u'\n[---]\n', 1) else: html_text = text text = u'' lines = expand_tags(html_text) lines = lines.strip(u'\n').split(u'\n') - pages.extend(self._paginate_slide(lines, line_end)) + slides = self._paginate_slide(lines, line_end) + if len(slides) > 1 and text: + # Add all slides apart from the last one the + # list. + pages.extend(slides[:-1]) + if text_contains_break: + text = slides[-1] + u'\n[---]\n' + text + else: + text = slides[-1] + u'\n'+ text + text = text.replace(u'
', u'\n') + else: + pages.extend(slides) if u'[---]' not in text: lines = expand_tags(text) lines = lines.strip(u'\n').split(u'\n') From d061436a35d147ac0578524f262ec65a27a49db4 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 29 Aug 2011 08:30:31 +0200 Subject: [PATCH 09/11] replaced Ini by config --- openlp/core/ui/mainwindow.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 3fe4a777d..1b69e481f 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -289,7 +289,7 @@ class Ui_MainWindow(object): self.settingsImportItem = base_action(mainWindow, u'settingsImportItem', category=UiStrings().Settings) self.settingsExportItem = base_action(mainWindow, - u'settingsExportItem', category=UiStrings().Settings) + u'settingsExportItem', category=UiStrings().Settings) action_list.add_category(UiStrings().Help, CategoryOrder.standardMenu) self.aboutItem = shortcut_action(mainWindow, u'aboutItem', [QtGui.QKeySequence(u'Ctrl+F1')], self.onAboutItemClicked, @@ -428,11 +428,11 @@ class Ui_MainWindow(object): self.settingsConfigureItem.setText( translate('OpenLP.MainWindow', '&Configure OpenLP...')) self.settingsExportItem.setStatusTip(translate('OpenLP.MainWindow', - 'Export OpenLP settings to a specified Ini file')) + 'Export OpenLP settings to a specified *.config file')) self.settingsExportItem.setText( translate('OpenLP.MainWindow', 'Settings')) self.settingsImportItem.setStatusTip(translate('OpenLP.MainWindow', - 'Import OpenLP settings from a specified Ini file previously ' + 'Import OpenLP settings from a specified *.config file previously ' 'exported on this or another machine')) self.settingsImportItem.setText( translate('OpenLP.MainWindow', 'Settings')) @@ -997,7 +997,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # Make sure it's an .ini file. if not exportFileName.endswith(u'conf'): exportFileName = exportFileName + u'.conf' - temp_file = os.path.join(unicode(gettempdir()), + temp_file = os.path.join(unicode(gettempdir()), u'openlp', u'exportIni.tmp') self.saveSettings() settingSections = [] From 7e4825653430ec51fed47f48c117676a6dc64a16 Mon Sep 17 00:00:00 2001 From: Stevan Pettit Date: Mon, 29 Aug 2011 08:47:32 -0400 Subject: [PATCH 10/11] Removed need for signal to run appStartup --- openlp/plugins/bibles/bibleplugin.py | 2 -- openlp/plugins/bibles/lib/mediaitem.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 17bad2b64..b9f4769cf 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -63,8 +63,6 @@ class BiblePlugin(Plugin): self.exportBibleItem.setVisible(False) if len(self.manager.old_bible_databases): self.toolsUpgradeItem.setVisible(True) - QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'bibles_app_startup'), self.appStartup) def finalise(self): """ diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index fe0fc58c3..9083b18a2 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -397,7 +397,7 @@ class BibleMediaItem(MediaManagerItem): self.loadBibles() # If called from first time wizard re-run, process any new bibles. if process: - Receiver.send_message(u'bibles_app_startup') + self.plugin.appStartup() self.updateAutoCompleter() def initialiseAdvancedBible(self, bible): From 96076a4bac95e99872d5e33b4146aa645ffe1d41 Mon Sep 17 00:00:00 2001 From: Stevan Pettit Date: Mon, 29 Aug 2011 08:59:19 -0400 Subject: [PATCH 11/11] Removed import receiver --- openlp/plugins/bibles/bibleplugin.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index b9f4769cf..619581b17 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -29,8 +29,7 @@ import logging from PyQt4 import QtCore, QtGui -from openlp.core.lib import Plugin, StringContent, build_icon, translate, \ - Receiver +from openlp.core.lib import Plugin, StringContent, build_icon, translate from openlp.core.lib.ui import base_action, UiStrings from openlp.core.utils.actions import ActionList from openlp.plugins.bibles.lib import BibleManager, BiblesTab, BibleMediaItem