Fix problems with start up thread

This commit is contained in:
Tim Bentley 2013-02-07 10:16:08 +00:00
parent c90d45ca73
commit 3063526430
3 changed files with 22 additions and 6 deletions

View File

@ -228,7 +228,8 @@ class Settings(QtCore.QSettings):
u'user interface/main window splitter geometry': QtCore.QByteArray(), u'user interface/main window splitter geometry': QtCore.QByteArray(),
u'user interface/main window state': QtCore.QByteArray(), u'user interface/main window state': QtCore.QByteArray(),
u'user interface/preview panel': True, u'user interface/preview panel': True,
u'user interface/preview splitter geometry': QtCore.QByteArray() u'user interface/preview splitter geometry': QtCore.QByteArray(),
u'servicemanager/last directory': u''
} }
__file_path__ = u'' __file_path__ = u''
__obsolete_settings__ = [ __obsolete_settings__ = [

View File

@ -484,6 +484,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.formattingTagForm = FormattingTagForm(self) self.formattingTagForm = FormattingTagForm(self)
self.shortcutForm = ShortcutListForm(self) self.shortcutForm = ShortcutListForm(self)
self.recentFiles = [] self.recentFiles = []
self.timer_id = 0
self.timer_version_id = 0
# Set up the path with plugins # Set up the path with plugins
plugin_path = AppLocation.get_directory(AppLocation.PluginsDir) plugin_path = AppLocation.get_directory(AppLocation.PluginsDir)
self.plugin_manager = PluginManager(plugin_path) self.plugin_manager = PluginManager(plugin_path)
@ -592,13 +594,12 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def version_notice(self, version): def version_notice(self, version):
""" """
Notifies the user that a newer version of OpenLP is available. Notifies the user that a newer version of OpenLP is available.
Triggered by delay thread. Triggered by delay thread and cannot display popup.
""" """
log.debug(u'version_notice')
version_text = translate('OpenLP.MainWindow', 'Version %s of OpenLP is now available for download (you are ' 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/.') 'currently running version %s). \n\nYou can download the latest version from http://openlp.org/.')
QtGui.QMessageBox.question(self, self.version_text = version_text % (version, get_application_version()[u'full'])
translate('OpenLP.MainWindow', 'OpenLP Version Updated'),
version_text % (version, get_application_version()[u'full']))
def show(self): def show(self):
""" """
@ -618,6 +619,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.serviceManagerContents.load_file(filename) self.serviceManagerContents.load_file(filename)
elif Settings().value(self.generalSettingsSection + u'/auto open'): elif Settings().value(self.generalSettingsSection + u'/auto open'):
self.serviceManagerContents.load_Last_file() self.serviceManagerContents.load_Last_file()
self.timer_version_id = self.startTimer(1000)
view_mode = Settings().value(u'%s/view mode' % self.generalSettingsSection) view_mode = Settings().value(u'%s/view mode' % self.generalSettingsSection)
if view_mode == u'default': if view_mode == u'default':
self.modeDefaultItem.setChecked(True) self.modeDefaultItem.setChecked(True)
@ -1340,6 +1342,17 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.timer_id = 0 self.timer_id = 0
self.loadProgressBar.hide() self.loadProgressBar.hide()
self.application.process_events() 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, u'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,u'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): def set_new_data_path(self, new_data_path):
""" """

View File

@ -72,12 +72,12 @@ class VersionThread(QtCore.QThread):
Run the thread. Run the thread.
""" """
self.sleep(1) self.sleep(1)
log.debug(u'Version thread - run')
app_version = get_application_version() app_version = get_application_version()
version = check_latest_version(app_version) version = check_latest_version(app_version)
if LooseVersion(str(version)) > LooseVersion(str(app_version[u'full'])): if LooseVersion(str(version)) > LooseVersion(str(app_version[u'full'])):
Registry().execute(u'openlp_version_check', u'%s' % version) Registry().execute(u'openlp_version_check', u'%s' % version)
class AppLocation(object): class AppLocation(object):
""" """
The :class:`AppLocation` class is a static class which retrieves a The :class:`AppLocation` class is a static class which retrieves a
@ -288,6 +288,8 @@ def check_latest_version(current_version):
this_test = datetime.now().date() this_test = datetime.now().date()
settings.setValue(u'last version test', this_test) settings.setValue(u'last version test', this_test)
settings.endGroup() settings.endGroup()
# Tell the main window whether there will ever be data to display
Registry().get(u'main_window').version_update_running = last_test != this_test
if last_test != this_test: if last_test != this_test:
if current_version[u'build']: if current_version[u'build']:
req = urllib2.Request(u'http://www.openlp.org/files/nightly_version.txt') req = urllib2.Request(u'http://www.openlp.org/files/nightly_version.txt')