More workarounds for bug 1531319.

If presentation loading fails, set slidenumber to 0 to avoid a later error. Fixes bug 1490508. Added test.
Use the chosen encoding when importing from easyworship db.

bzr-revno: 2616
Fixes: https://launchpad.net/bugs/1490508
This commit is contained in:
second@tgc.dk 2016-02-06 21:53:23 +01:00 committed by Tomas Groth
commit 8d083af742
5 changed files with 51 additions and 11 deletions

View File

@ -326,6 +326,9 @@ class MainDisplay(OpenLPMixin, Display, RegistryProperties):
else:
self.setVisible(False)
self.setGeometry(self.screen['size'])
# Workaround for bug #1531319, should not be needed with PyQt 5.6.
if is_win():
self.shake_web_view()
def direct_image(self, path, background):
"""
@ -395,8 +398,17 @@ class MainDisplay(OpenLPMixin, Display, RegistryProperties):
# Wait for the fade to finish before geting the preview.
# Important otherwise preview will have incorrect text if at all!
if self.service_item.theme_data and self.service_item.theme_data.display_slide_transition:
# Workaround for bug #1531319, should not be needed with PyQt 5.6.
if is_win():
fade_shake_timer = QtCore.QTimer(self)
fade_shake_timer.setInterval(25)
fade_shake_timer.timeout.connect(self.shake_web_view)
fade_shake_timer.start()
while not self.frame.evaluateJavaScript('show_text_completed()'):
self.application.process_events()
# Workaround for bug #1531319, should not be needed with PyQt 5.6.
if is_win():
fade_shake_timer.stop()
# Wait for the webview to update before getting the preview.
# Important otherwise first preview will miss the background !
while not self.web_loaded:
@ -493,6 +505,9 @@ class MainDisplay(OpenLPMixin, Display, RegistryProperties):
if self.isHidden():
self.setVisible(True)
self.web_view.setVisible(True)
# Workaround for bug #1531319, should not be needed with PyQt 5.6.
if is_win():
self.shake_web_view()
self.hide_mode = mode
def show_display(self):
@ -511,6 +526,9 @@ class MainDisplay(OpenLPMixin, Display, RegistryProperties):
# Trigger actions when display is active again.
if self.is_live:
Registry().execute('live_display_active')
# Workaround for bug #1531319, should not be needed with PyQt 5.6.
if is_win():
self.shake_web_view()
def _hide_mouse(self):
"""

View File

@ -1101,9 +1101,6 @@ class SlideController(DisplayController, RegistryProperties):
self.display.image(to_display)
# reset the store used to display first image
self.service_item.bg_image_bytes = None
# Workaround for bug #1531319, should not be needed with PyQt 5.6.
if self.is_live and is_win():
self.display.shake_web_view()
self.selected_row = row
self.update_preview()
self.preview_widget.change_slide(row)
@ -1128,8 +1125,8 @@ class SlideController(DisplayController, RegistryProperties):
self.log_debug('update_preview %s ' % self.screens.current['primary'])
if self.service_item and self.service_item.is_capable(ItemCapabilities.ProvidesOwnDisplay):
# Grab now, but try again in a couple of seconds if slide change is slow
QtCore.QTimer.singleShot(0.5, self.grab_maindisplay)
QtCore.QTimer.singleShot(2.5, self.grab_maindisplay)
QtCore.QTimer.singleShot(500, self.grab_maindisplay)
QtCore.QTimer.singleShot(2500, self.grab_maindisplay)
else:
self.slide_image = self.display.preview()
self.slide_image.setDevicePixelRatio(self.main_window.devicePixelRatio())

View File

@ -63,6 +63,7 @@ class Controller(object):
if not self.doc.load_presentation():
# Display error message to user
# Inform slidecontroller that the action failed?
self.doc.slidenumber = 0
return
self.doc.slidenumber = slide_no
self.hide_mode = hide_mode

View File

@ -292,7 +292,7 @@ class EasyWorshipSongImport(SongImport):
raw_record = db_file.read(record_size)
self.fields = self.record_structure.unpack(raw_record)
self.set_defaults()
self.title = self.get_field(fi_title).decode('unicode-escape')
self.title = self.get_field(fi_title).decode(self.encoding)
# Get remaining fields.
copy = self.get_field(fi_copy)
admin = self.get_field(fi_admin)
@ -300,16 +300,16 @@ class EasyWorshipSongImport(SongImport):
authors = self.get_field(fi_author)
words = self.get_field(fi_words)
if copy:
self.copyright = copy.decode('unicode-escape')
self.copyright = copy.decode(self.encoding)
if admin:
if copy:
self.copyright += ', '
self.copyright += translate('SongsPlugin.EasyWorshipSongImport',
'Administered by %s') % admin.decode('unicode-escape')
'Administered by %s') % admin.decode(self.encoding)
if ccli:
self.ccli_number = ccli.decode('unicode-escape')
self.ccli_number = ccli.decode(self.encoding)
if authors:
authors = authors.decode('unicode-escape')
authors = authors.decode(self.encoding)
else:
authors = ''
# Set the SongImport object members.
@ -497,7 +497,7 @@ class EasyWorshipSongImport(SongImport):
bytes = self.get_bytes(pos, length)
mask = '<' + str(length) + 's'
byte_str, = struct.unpack(mask, bytes)
return byte_str.decode('unicode-escape').replace('\0', '').strip()
return byte_str.decode(self.encoding).replace('\0', '').strip()
def get_i16(self, pos):
"""

View File

@ -26,6 +26,7 @@ from unittest import TestCase
from openlp.core.common import Registry
from openlp.plugins.presentations.lib.mediaitem import MessageListener, PresentationMediaItem
from openlp.plugins.presentations.lib.messagelistener import Controller
from tests.functional import patch, MagicMock
from tests.helpers.testmixin import TestMixin
@ -124,3 +125,26 @@ class TestMessageListener(TestCase, TestMixin):
# THEN: The handler should be set to None
self.assertIsNone(ml.handler, 'The handler should be None')
class TestController(TestCase, TestMixin):
"""
Test the Presentation Controller.
"""
def add_handler_failure_test(self):
"""
Test that add_handler does set doc.slidenumber to 0 in case filed loading
"""
# GIVEN: A Controller, a mocked doc-controller
controller = Controller(True)
mocked_doc_controller = MagicMock()
mocked_doc = MagicMock()
mocked_doc.load_presentation.return_value = False
mocked_doc_controller.add_document.return_value = mocked_doc
# WHEN: calling add_handler that fails
controller.add_handler(mocked_doc_controller, MagicMock(), True, 0)
# THEN: slidenumber should be 0
self.assertEqual(controller.doc.slidenumber, 0, 'doc.slidenumber should be 0')