This commit is contained in:
Raoul Snyman 2011-08-29 20:46:01 +02:00
commit bbc8e04a3f
3 changed files with 68 additions and 21 deletions

View File

@ -228,15 +228,56 @@ 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
# Songs and Custom
if item.is_capable(ItemCapabilities.HasVirtualSplit):
# Do not forget the line breaks!
slides = text.split(u'[---]')
pages = []
for slide in slides:
lines = slide.strip(u'\n').split(u'\n')
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'<br>')
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'<br>')
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.
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')
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'<br>', u'\n')
else:
pages.extend(slides)
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'<br>'):
@ -342,7 +383,7 @@ class Renderer(object):
separator = u'<br>'
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:
@ -375,18 +416,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
@ -443,7 +484,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.
@ -466,8 +507,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(
@ -489,11 +530,11 @@ 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'\\\"'))
return self.web_frame.contentsSize().height() > self.page_height
return self.web_frame.contentsSize().height() <= self.page_height
def _words_split(self, line):
"""

View File

@ -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'))
@ -791,6 +791,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):
"""
@ -997,7 +1000,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 = []

View File

@ -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:
self.plugin.appStartup()
self.updateAutoCompleter()
def initialiseAdvancedBible(self, bible):