← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol/openlp/FTW-screenshot-thread into lp:openlp

 

Andreas Preikschat has proposed merging lp:~googol/openlp/FTW-screenshot-thread into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~googol/openlp/FTW-screenshot-thread/+merge/87104

Hello,

The theme screenshots are now downloaded in a thread to speed up the FTW. I think this will improve the way people experience OpenLP. Nothing is worse than a slow application when you are testing it.

It takes roughly 2-3 seconds after closing the language dialog [1] until the first page is shown [2].

In trunk this takes about 10 seconds longer.

This also works when you click trough the wizard very fast (see line 73-74).

[1] http://manual.openlp.org/_images/001-first-time-language.png
[2] http://manual.openlp.org/_images/002-first-time-wizard-welcome.png
-- 
https://code.launchpad.net/~googol/openlp/FTW-screenshot-thread/+merge/87104
Your team OpenLP Core is requested to review the proposed merge of lp:~googol/openlp/FTW-screenshot-thread into lp:openlp.
=== modified file 'openlp/core/ui/firsttimeform.py'
--- openlp/core/ui/firsttimeform.py	2011-12-29 17:50:42 +0000
+++ openlp/core/ui/firsttimeform.py	2011-12-29 19:38:25 +0000
@@ -29,6 +29,7 @@
 import logging
 import os
 import sys
+import time
 import urllib
 import urllib2
 from tempfile import gettempdir
@@ -43,6 +44,29 @@
 
 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 @@
                     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 @@
             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 @@
             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 @@
         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 @@
         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.