forked from openlp/openlp
Head r1860
This commit is contained in:
commit
c997c38c59
@ -29,6 +29,7 @@ import io
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
import urllib2
|
||||||
from tempfile import gettempdir
|
from tempfile import gettempdir
|
||||||
@ -43,6 +44,29 @@ from firsttimewizard import Ui_FirstTimeWizard, FirstTimePage
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
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):
|
class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
||||||
"""
|
"""
|
||||||
This is the Theme Import Wizard, which allows easy creation and editing of
|
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.setCheckState(0, QtCore.Qt.Unchecked)
|
||||||
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
|
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
|
||||||
self.biblesTreeWidget.expandAll()
|
self.biblesTreeWidget.expandAll()
|
||||||
themes = self.config.get(u'themes', u'files')
|
# Download the theme screenshots.
|
||||||
themes = themes.split(u',')
|
self.themeScreenshotThread = ThemeScreenshotThread(self)
|
||||||
for theme in themes:
|
self.themeScreenshotThread.start()
|
||||||
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)
|
|
||||||
Receiver.send_message(u'cursor_normal')
|
Receiver.send_message(u'cursor_normal')
|
||||||
|
|
||||||
def nextId(self):
|
def nextId(self):
|
||||||
@ -156,6 +168,14 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
|||||||
return -1
|
return -1
|
||||||
elif self.currentId() == FirstTimePage.NoInternet:
|
elif self.currentId() == FirstTimePage.NoInternet:
|
||||||
return FirstTimePage.Progress
|
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._buildThemeScreenshots()
|
||||||
|
Receiver.send_message(u'cursor_normal')
|
||||||
|
return FirstTimePage.Defaults
|
||||||
else:
|
else:
|
||||||
return self.currentId() + 1
|
return self.currentId() + 1
|
||||||
|
|
||||||
@ -264,6 +284,23 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
|||||||
if self.downloadCanceled:
|
if self.downloadCanceled:
|
||||||
os.remove(fpath)
|
os.remove(fpath)
|
||||||
|
|
||||||
|
def _buildThemeScreenshots(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):
|
def _getFileSize(self, url):
|
||||||
site = urllib.urlopen(url)
|
site = urllib.urlopen(url)
|
||||||
meta = site.info()
|
meta = site.info()
|
||||||
|
Loading…
Reference in New Issue
Block a user