Merge lp:~tomasgroth/openlp/23bugfixes2 into lp:openlp

Proposed by Tomas Groth on 2016-02-06
Status: Merged
Approved by: Tim Bentley on 2016-02-06
Approved revision: 2616
Merged at revision: 2616
Proposed branch: lp:~tomasgroth/openlp/23bugfixes2
Merge into: lp:openlp
Diff against target: 170 lines (+51/-11)
5 files modified
openlp/core/ui/maindisplay.py (+18/-0)
openlp/core/ui/slidecontroller.py (+2/-5)
openlp/plugins/presentations/lib/messagelistener.py (+1/-0)
openlp/plugins/songs/lib/importers/easyworship.py (+6/-6)
tests/functional/openlp_plugins/presentations/test_messagelistener.py (+24/-0)
To merge this branch: bzr merge lp:~tomasgroth/openlp/23bugfixes2
Reviewer Review Type Date Requested Status
Tim Bentley Approve on 2016-02-06
Raoul Snyman 2016-02-06 Approve on 2016-02-06
Review via email: mp+285281@code.launchpad.net

Description of the change

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.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/core/ui/maindisplay.py'
2--- openlp/core/ui/maindisplay.py 2016-01-22 21:33:20 +0000
3+++ openlp/core/ui/maindisplay.py 2016-02-06 20:37:37 +0000
4@@ -326,6 +326,9 @@
5 else:
6 self.setVisible(False)
7 self.setGeometry(self.screen['size'])
8+ # Workaround for bug #1531319, should not be needed with PyQt 5.6.
9+ if is_win():
10+ self.shake_web_view()
11
12 def direct_image(self, path, background):
13 """
14@@ -395,8 +398,17 @@
15 # Wait for the fade to finish before geting the preview.
16 # Important otherwise preview will have incorrect text if at all!
17 if self.service_item.theme_data and self.service_item.theme_data.display_slide_transition:
18+ # Workaround for bug #1531319, should not be needed with PyQt 5.6.
19+ if is_win():
20+ fade_shake_timer = QtCore.QTimer(self)
21+ fade_shake_timer.setInterval(25)
22+ fade_shake_timer.timeout.connect(self.shake_web_view)
23+ fade_shake_timer.start()
24 while not self.frame.evaluateJavaScript('show_text_completed()'):
25 self.application.process_events()
26+ # Workaround for bug #1531319, should not be needed with PyQt 5.6.
27+ if is_win():
28+ fade_shake_timer.stop()
29 # Wait for the webview to update before getting the preview.
30 # Important otherwise first preview will miss the background !
31 while not self.web_loaded:
32@@ -493,6 +505,9 @@
33 if self.isHidden():
34 self.setVisible(True)
35 self.web_view.setVisible(True)
36+ # Workaround for bug #1531319, should not be needed with PyQt 5.6.
37+ if is_win():
38+ self.shake_web_view()
39 self.hide_mode = mode
40
41 def show_display(self):
42@@ -511,6 +526,9 @@
43 # Trigger actions when display is active again.
44 if self.is_live:
45 Registry().execute('live_display_active')
46+ # Workaround for bug #1531319, should not be needed with PyQt 5.6.
47+ if is_win():
48+ self.shake_web_view()
49
50 def _hide_mouse(self):
51 """
52
53=== modified file 'openlp/core/ui/slidecontroller.py'
54--- openlp/core/ui/slidecontroller.py 2016-01-22 21:33:20 +0000
55+++ openlp/core/ui/slidecontroller.py 2016-02-06 20:37:37 +0000
56@@ -1101,9 +1101,6 @@
57 self.display.image(to_display)
58 # reset the store used to display first image
59 self.service_item.bg_image_bytes = None
60- # Workaround for bug #1531319, should not be needed with PyQt 5.6.
61- if self.is_live and is_win():
62- self.display.shake_web_view()
63 self.selected_row = row
64 self.update_preview()
65 self.preview_widget.change_slide(row)
66@@ -1128,8 +1125,8 @@
67 self.log_debug('update_preview %s ' % self.screens.current['primary'])
68 if self.service_item and self.service_item.is_capable(ItemCapabilities.ProvidesOwnDisplay):
69 # Grab now, but try again in a couple of seconds if slide change is slow
70- QtCore.QTimer.singleShot(0.5, self.grab_maindisplay)
71- QtCore.QTimer.singleShot(2.5, self.grab_maindisplay)
72+ QtCore.QTimer.singleShot(500, self.grab_maindisplay)
73+ QtCore.QTimer.singleShot(2500, self.grab_maindisplay)
74 else:
75 self.slide_image = self.display.preview()
76 self.slide_image.setDevicePixelRatio(self.main_window.devicePixelRatio())
77
78=== modified file 'openlp/plugins/presentations/lib/messagelistener.py'
79--- openlp/plugins/presentations/lib/messagelistener.py 2016-01-12 20:14:04 +0000
80+++ openlp/plugins/presentations/lib/messagelistener.py 2016-02-06 20:37:37 +0000
81@@ -63,6 +63,7 @@
82 if not self.doc.load_presentation():
83 # Display error message to user
84 # Inform slidecontroller that the action failed?
85+ self.doc.slidenumber = 0
86 return
87 self.doc.slidenumber = slide_no
88 self.hide_mode = hide_mode
89
90=== modified file 'openlp/plugins/songs/lib/importers/easyworship.py'
91--- openlp/plugins/songs/lib/importers/easyworship.py 2015-12-31 22:46:06 +0000
92+++ openlp/plugins/songs/lib/importers/easyworship.py 2016-02-06 20:37:37 +0000
93@@ -292,7 +292,7 @@
94 raw_record = db_file.read(record_size)
95 self.fields = self.record_structure.unpack(raw_record)
96 self.set_defaults()
97- self.title = self.get_field(fi_title).decode('unicode-escape')
98+ self.title = self.get_field(fi_title).decode(self.encoding)
99 # Get remaining fields.
100 copy = self.get_field(fi_copy)
101 admin = self.get_field(fi_admin)
102@@ -300,16 +300,16 @@
103 authors = self.get_field(fi_author)
104 words = self.get_field(fi_words)
105 if copy:
106- self.copyright = copy.decode('unicode-escape')
107+ self.copyright = copy.decode(self.encoding)
108 if admin:
109 if copy:
110 self.copyright += ', '
111 self.copyright += translate('SongsPlugin.EasyWorshipSongImport',
112- 'Administered by %s') % admin.decode('unicode-escape')
113+ 'Administered by %s') % admin.decode(self.encoding)
114 if ccli:
115- self.ccli_number = ccli.decode('unicode-escape')
116+ self.ccli_number = ccli.decode(self.encoding)
117 if authors:
118- authors = authors.decode('unicode-escape')
119+ authors = authors.decode(self.encoding)
120 else:
121 authors = ''
122 # Set the SongImport object members.
123@@ -497,7 +497,7 @@
124 bytes = self.get_bytes(pos, length)
125 mask = '<' + str(length) + 's'
126 byte_str, = struct.unpack(mask, bytes)
127- return byte_str.decode('unicode-escape').replace('\0', '').strip()
128+ return byte_str.decode(self.encoding).replace('\0', '').strip()
129
130 def get_i16(self, pos):
131 """
132
133=== modified file 'tests/functional/openlp_plugins/presentations/test_messagelistener.py'
134--- tests/functional/openlp_plugins/presentations/test_messagelistener.py 2016-01-13 20:56:55 +0000
135+++ tests/functional/openlp_plugins/presentations/test_messagelistener.py 2016-02-06 20:37:37 +0000
136@@ -26,6 +26,7 @@
137
138 from openlp.core.common import Registry
139 from openlp.plugins.presentations.lib.mediaitem import MessageListener, PresentationMediaItem
140+from openlp.plugins.presentations.lib.messagelistener import Controller
141 from tests.functional import patch, MagicMock
142 from tests.helpers.testmixin import TestMixin
143
144@@ -124,3 +125,26 @@
145
146 # THEN: The handler should be set to None
147 self.assertIsNone(ml.handler, 'The handler should be None')
148+
149+
150+class TestController(TestCase, TestMixin):
151+ """
152+ Test the Presentation Controller.
153+ """
154+
155+ def add_handler_failure_test(self):
156+ """
157+ Test that add_handler does set doc.slidenumber to 0 in case filed loading
158+ """
159+ # GIVEN: A Controller, a mocked doc-controller
160+ controller = Controller(True)
161+ mocked_doc_controller = MagicMock()
162+ mocked_doc = MagicMock()
163+ mocked_doc.load_presentation.return_value = False
164+ mocked_doc_controller.add_document.return_value = mocked_doc
165+
166+ # WHEN: calling add_handler that fails
167+ controller.add_handler(mocked_doc_controller, MagicMock(), True, 0)
168+
169+ # THEN: slidenumber should be 0
170+ self.assertEqual(controller.doc.slidenumber, 0, 'doc.slidenumber should be 0')