Time out after 10 seconds in wait till loaded fn

also fixes comment, update_preview_images() does not handle the timeout case but in reality it should never happen. (just in the case it does, it won't stall the whole application)
This commit is contained in:
Daniel 2019-12-03 17:30:35 +00:00 committed by Tim Bentley
parent 02c83bb8a8
commit 7c4d9a5ffd
4 changed files with 52 additions and 1 deletions

View File

@ -486,6 +486,24 @@ class ThemePreviewRenderer(LogMixin, DisplayWindow):
footer_html = 'Dummy footer text'
return footer_html
def wait_till_loaded(self):
"""
Wait until web engine page loaded
:return boolean: True on success, False on timeout
"""
# Timeout in 10 seconds
end_time = time.time() + 10
app = Registry().get('application')
success = True
while not self._is_initialised:
if time.time() > end_time:
log.error('Timed out waiting for web engine page to load')
success = False
break
time.sleep(0.1)
app.process_events()
return success
def _wait_and_process(self, delay):
"""
Wait while allowing things to process

View File

@ -402,7 +402,9 @@ class DisplayWindow(QtWidgets.QWidget):
Set the HTML scale
"""
self.scale = scale
self.run_javascript('Display.setScale({scale});'.format(scale=scale * 100))
# Only scale if initialised (scale run again once initialised)
if self._is_initialised:
self.run_javascript('Display.setScale({scale});'.format(scale=scale * 100))
def alert(self, text, settings):
"""

View File

@ -722,6 +722,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
theme_name_list = theme_name_list or self.get_theme_names()
self.progress_form.theme_list = theme_name_list
self.progress_form.show()
self.progress_form.theme_display.wait_till_loaded()
for theme_name in theme_name_list:
theme_data = self._get_theme_data(theme_name)
preview_pixmap = self.progress_form.get_preview(theme_name, theme_data)

View File

@ -74,3 +74,33 @@ class TestDisplayWindow(TestCase, TestMixin):
# THEN: The x11 override flag should not be set
x11_bit = display_window.windowFlags() & QtCore.Qt.X11BypassWindowManagerHint
assert x11_bit != QtCore.Qt.X11BypassWindowManagerHint
def test_set_scale_not_initialised(self, MockSettings, mocked_webengine, mocked_addWidget):
"""
Test that the scale js is not run if the page is not initialised
"""
# GIVEN: A display window not yet initialised
display_window = DisplayWindow()
display_window._is_initialised = False
display_window.run_javascript = MagicMock()
# WHEN: set scale is run
display_window.set_scale(0.5)
# THEN: javascript should not be run
display_window.run_javascript.assert_not_called()
def test_set_scale_initialised(self, MockSettings, mocked_webengine, mocked_addWidget):
"""
Test that the scale js is not run if the page is not initialised
"""
# GIVEN: A display window not yet initialised
display_window = DisplayWindow()
display_window._is_initialised = True
display_window.run_javascript = MagicMock()
# WHEN: set scale is run
display_window.set_scale(0.5)
# THEN: javascript should not be run
display_window.run_javascript.assert_called_once_with('Display.setScale(50.0);')