From 20ef9b9730be8ceeb67161380054a2d62ea0c35a Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 29 Dec 2011 13:26:37 +0100 Subject: [PATCH 1/2] download theme screenshots in a thread --- openlp/core/ui/firsttimeform.py | 71 +++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 17 deletions(-) diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index e7f516980..aa1d89bc3 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -29,6 +29,7 @@ import io import logging import os import sys +import time import urllib import urllib2 from tempfile import gettempdir @@ -43,6 +44,29 @@ from firsttimewizard import Ui_FirstTimeWizard, FirstTimePage log = logging.getLogger(__name__) +class ThemeScreenshotThread(QtCore.QThread): + """ + This thread downloads the theme screenshots. + """ + def __init__(self, parent): + QtCore.QThread.__init__(self, parent) + + def run(self): + themes = self.parent().config.get(u'themes', u'files') + themes = themes.split(u',') + config = self.parent().config + for theme in themes: + title = config.get(u'theme_%s' % theme, u'title') + filename = config.get(u'theme_%s' % theme, u'filename') + screenshot = config.get(u'theme_%s' % theme, u'screenshot') + urllib.urlretrieve(u'%s%s' % (self.parent().web, screenshot), + os.path.join(gettempdir(), u'openlp', screenshot)) + item = QtGui.QListWidgetItem(title, self.parent().themesListWidget) + item.setData(QtCore.Qt.UserRole, QtCore.QVariant(filename)) + item.setCheckState(QtCore.Qt.Unchecked) + item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable) + + class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): """ This is the Theme Import Wizard, which allows easy creation and editing of @@ -125,21 +149,9 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): item.setCheckState(0, QtCore.Qt.Unchecked) item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable) self.biblesTreeWidget.expandAll() - themes = self.config.get(u'themes', u'files') - themes = themes.split(u',') - for theme in themes: - title = self.config.get(u'theme_%s' % theme, u'title') - filename = self.config.get(u'theme_%s' % theme, u'filename') - screenshot = self.config.get(u'theme_%s' % theme, u'screenshot') - urllib.urlretrieve(u'%s%s' % (self.web, screenshot), - os.path.join(gettempdir(), u'openlp', screenshot)) - item = QtGui.QListWidgetItem(title, self.themesListWidget) - item.setData(QtCore.Qt.UserRole, - QtCore.QVariant(filename)) - item.setIcon(build_icon( - os.path.join(gettempdir(), u'openlp', screenshot))) - item.setCheckState(QtCore.Qt.Unchecked) - item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable) + # Download the theme screenshots. + self.themeScreenshotThread = ThemeScreenshotThread(self) + self.themeScreenshotThread.start() Receiver.send_message(u'cursor_normal') def nextId(self): @@ -156,6 +168,14 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): return -1 elif self.currentId() == FirstTimePage.NoInternet: return FirstTimePage.Progress + elif self.currentId() == FirstTimePage.Themes: + Receiver.send_message(u'cursor_busy') + while not self.themeScreenshotThread.isFinished(): + time.sleep(0.1) + # Build the screenshot icons, as this can not be done in the thread. + self._buildThemeScreenshot() + Receiver.send_message(u'cursor_normal') + return FirstTimePage.Defaults else: return self.currentId() + 1 @@ -172,7 +192,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): if self.hasRunWizard: self.noInternetLabel.setText(self.noInternetText) else: - self.noInternetLabel.setText(self.noInternetText + + self.noInternetLabel.setText(self.noInternetText + self.cancelWizardText) elif pageId == FirstTimePage.Defaults: self.themeComboBox.clear() @@ -264,6 +284,23 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): if self.downloadCanceled: os.remove(fpath) + def _buildThemeScreenshot(self): + """ + This method builds the theme screenshots' icons for all items in the + ``self.themesListWidget``. + """ + themes = self.config.get(u'themes', u'files') + themes = themes.split(u',') + for theme in themes: + filename = self.config.get(u'theme_%s' % theme, u'filename') + screenshot = self.config.get(u'theme_%s' % theme, u'screenshot') + for index in xrange(self.themesListWidget.count()): + item = self.themesListWidget.item(index) + if item.data(QtCore.Qt.UserRole) == QtCore.QVariant(filename): + break + item.setIcon(build_icon( + os.path.join(gettempdir(), u'openlp', screenshot))) + def _getFileSize(self, url): site = urllib.urlopen(url) meta = site.info() @@ -273,7 +310,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): increment = (count * block_size) - self.previous_size self._incrementProgressBar(None, increment) self.previous_size = count * block_size - + def _incrementProgressBar(self, status_text, increment=1): """ Update the wizard progress page. From 214bd37057ba027285dbd5cd409d7ff29dac33bc Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 29 Dec 2011 20:41:25 +0100 Subject: [PATCH 2/2] fixed method name --- openlp/core/ui/firsttimeform.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index aa1d89bc3..9522b7c8c 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -173,7 +173,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): while not self.themeScreenshotThread.isFinished(): time.sleep(0.1) # Build the screenshot icons, as this can not be done in the thread. - self._buildThemeScreenshot() + self._buildThemeScreenshots() Receiver.send_message(u'cursor_normal') return FirstTimePage.Defaults else: @@ -284,7 +284,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): if self.downloadCanceled: os.remove(fpath) - def _buildThemeScreenshot(self): + def _buildThemeScreenshots(self): """ This method builds the theme screenshots' icons for all items in the ``self.themesListWidget``.