openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #24391
[Merge] lp:~trb143/openlp/startup_thread_error into lp:openlp
Tim Bentley has proposed merging lp:~trb143/openlp/startup_thread_error into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
For more details, see:
https://code.launchpad.net/~trb143/openlp/startup_thread_error/+merge/239128
Correct the VersionThread code to work without timer.
Add a test to confirm the emit is processed.
Add this to your merge proposal:
--------------------------------
lp:~trb143/openlp/startup_thread_error (revision 2410)
[SUCCESS] http://ci.openlp.org/job/Branch-01-Pull/700/
[SUCCESS] http://ci.openlp.org/job/Branch-02-Functional-Tests/643/
[SUCCESS] http://ci.openlp.org/job/Branch-03-Interface-Tests/587/
[FAILURE] http://ci.openlp.org/job/Branch-04a-Windows_Functional_Tests/529/
Powerpoint test are broken !
--
https://code.launchpad.net/~trb143/openlp/startup_thread_error/+merge/239128
Your team OpenLP Core is requested to review the proposed merge of lp:~trb143/openlp/startup_thread_error into lp:openlp.
=== modified file 'openlp/core/__init__.py'
--- openlp/core/__init__.py 2014-09-21 19:23:40 +0000
+++ openlp/core/__init__.py 2014-10-21 20:09:27 +0000
@@ -154,7 +154,8 @@
self.main_window.first_time()
update_check = Settings().value('core/update check')
if update_check:
- VersionThread(self.main_window).start()
+ version = VersionThread(self.main_window)
+ version.start()
self.main_window.is_display_blank()
self.main_window.app_startup()
return self.exec_()
=== modified file 'openlp/core/ui/mainwindow.py'
--- openlp/core/ui/mainwindow.py 2014-09-04 21:38:39 +0000
+++ openlp/core/ui/mainwindow.py 2014-10-21 20:09:27 +0000
@@ -490,7 +490,6 @@
self.header_section = 'SettingsImport'
self.recent_files = []
self.timer_id = 0
- self.timer_version_id = 0
self.new_data_path = None
self.copy_data = False
Settings().set_up_default_values()
@@ -536,7 +535,7 @@
self.application.set_busy_cursor()
# Simple message boxes
Registry().register_function('theme_update_global', self.default_theme_changed)
- Registry().register_function('openlp_version_check', self.version_notice)
+ QtCore.QObject.connect(self, QtCore.SIGNAL('openlp_version_check'), self.version_notice)
Registry().register_function('config_screen_changed', self.screen_changed)
Registry().register_function('bootstrap_post_set_up', self.bootstrap_post_set_up)
# Reset the cursor
@@ -585,12 +584,15 @@
"""
Notifies the user that a newer version of OpenLP is available.
Triggered by delay thread and cannot display popup.
+
+ :param version: The Version to be displayed.
"""
log.debug('version_notice')
version_text = translate('OpenLP.MainWindow', 'Version %s of OpenLP is now available for download (you are '
'currently running version %s). \n\nYou can download the latest version from '
'http://openlp.org/.')
- self.version_text = version_text % (version, get_application_version()['full'])
+ QtGui.QMessageBox.question(self, translate('OpenLP.MainWindow', 'OpenLP Version Updated'),
+ version_text % (version, get_application_version()[u'full']))
def show(self):
"""
@@ -604,7 +606,6 @@
self.open_cmd_line_files()
elif Settings().value(self.general_settings_section + '/auto open'):
self.service_manager_contents.load_last_file()
- self.timer_version_id = self.startTimer(1000)
view_mode = Settings().value('%s/view mode' % self.general_settings_section)
if view_mode == 'default':
self.mode_default_item.setChecked(True)
@@ -1304,17 +1305,6 @@
self.timer_id = 0
self.load_progress_bar.hide()
self.application.process_events()
- if event.timerId() == self.timer_version_id:
- self.timer_version_id = 0
- # Has the thread passed some data to be displayed so display it and stop all waiting
- if hasattr(self, 'version_text'):
- QtGui.QMessageBox.question(self, translate('OpenLP.MainWindow', 'OpenLP Version Updated'),
- self.version_text)
- else:
- # the thread has not confirmed it is running or it has not yet sent any data so lets keep waiting
- if not hasattr(self, 'version_update_running') or self.version_update_running:
- self.timer_version_id = self.startTimer(1000)
- self.application.process_events()
def set_new_data_path(self, new_data_path):
"""
=== modified file 'openlp/core/utils/__init__.py'
--- openlp/core/utils/__init__.py 2014-08-29 16:37:25 +0000
+++ openlp/core/utils/__init__.py 2014-10-21 20:09:27 +0000
@@ -97,6 +97,16 @@
A special Qt thread class to fetch the version of OpenLP from the website.
This is threaded so that it doesn't affect the loading time of OpenLP.
"""
+ def __init__(self, main_window):
+ """
+ Constructor for the thread class.
+
+ :param main_window: The main window Object.
+ """
+ log.debug("VersionThread - Initialise")
+ super(VersionThread, self).__init__(None)
+ self.main_window = main_window
+
def run(self):
"""
Run the thread.
@@ -105,8 +115,9 @@
log.debug('Version thread - run')
app_version = get_application_version()
version = check_latest_version(app_version)
+ log.debug("Versions %s and %s " % (LooseVersion(str(version)), LooseVersion(str(app_version['full']))))
if LooseVersion(str(version)) > LooseVersion(str(app_version['full'])):
- Registry().execute('openlp_version_check', '%s' % version)
+ self.main_window.emit(QtCore.SIGNAL('openlp_version_check'), '%s' % version)
class HTTPRedirectHandlerFixed(urllib.request.HTTPRedirectHandler):
@@ -216,8 +227,6 @@
this_test = str(datetime.now().date())
settings.setValue('last version test', this_test)
settings.endGroup()
- # Tell the main window whether there will ever be data to display
- Registry().get('main_window').version_update_running = last_test != this_test
if last_test != this_test:
if current_version['build']:
req = urllib.request.Request('http://www.openlp.org/files/nightly_version.txt')
=== added file 'tests/functional/openlp_core_utils/test_init.py'
--- tests/functional/openlp_core_utils/test_init.py 1970-01-01 00:00:00 +0000
+++ tests/functional/openlp_core_utils/test_init.py 2014-10-21 20:09:27 +0000
@@ -0,0 +1,70 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2014 Raoul Snyman #
+# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
+"""
+Package to test the openlp.core.utils.actions package.
+"""
+from unittest import TestCase
+
+from openlp.core.common.settings import Settings
+from openlp.core.utils import VersionThread, get_application_version
+from tests.functional import MagicMock, patch
+from tests.helpers.testmixin import TestMixin
+
+
+class TestInitFunctions(TestMixin, TestCase):
+
+ def setUp(self):
+ """
+ Create an instance and a few example actions.
+ """
+ self.build_settings()
+
+ def tearDown(self):
+ """
+ Clean up
+ """
+ self.destroy_settings()
+
+ def version_thread_triggered_test(self):
+ """
+ Test the version thread call does not trigger UI
+ :return:
+ """
+ # GIVEN: a equal version setup and the data is not today.
+ mocked_main_window = MagicMock()
+ Settings().setValue('core/last version test', '1950-04-01')
+ # WHEN: We check to see if the version is different .
+ with patch('PyQt4.QtCore.QThread'),\
+ patch('openlp.core.utils.get_application_version') as mocked_get_application_version:
+ mocked_get_application_version.return_value = \
+ {'version': '1.0.0', 'build': '', 'full': '2.0.4'}
+ version_thread = VersionThread(mocked_main_window)
+ version_thread.run()
+ # THEN: If the version has changed the main window is notified
+ self.assertTrue(mocked_main_window.emit.called, 'The main windows should have been notified')
Follow ups