Some more updates to the wizard.

This commit is contained in:
Raoul Snyman 2011-03-10 15:15:49 +02:00
parent fd1f983753
commit 8d33f6d360
3 changed files with 161 additions and 155 deletions

View File

@ -24,11 +24,12 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
import ConfigParser
import io import io
import logging import logging
import os import os
import urllib import urllib
from random import randint
from ConfigParser import SafeConfigParser
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -51,13 +52,13 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
self.setupUi(self) self.setupUi(self)
# check to see if we have web access # check to see if we have web access
self.web = u'http://openlp.org/files/frw/' self.web = u'http://openlp.org/files/frw/'
self.config = ConfigParser.ConfigParser() self.config = SafeConfigParser()
self.webAccess = get_web_page(u'%s%s' % (self.web, u'download.cfg')) self.webAccess = get_web_page(u'%s%s' % (self.web, u'download.cfg?%s' % randint(0, 20)))
if self.webAccess: if self.webAccess:
files = self.webAccess.read() files = self.webAccess.read()
self.config.readfp(io.BytesIO(files)) self.config.readfp(io.BytesIO(files))
for screen in screens.get_screen_list(): for screen in screens.get_screen_list():
self.displaySelectionComboBox.addItem(screen) self.displayComboBox.addItem(screen)
self.songsText = translate('OpenLP.FirstTimeWizard', 'Songs') self.songsText = translate('OpenLP.FirstTimeWizard', 'Songs')
self.biblesText = translate('OpenLP.FirstTimeWizard', 'Bibles') self.biblesText = translate('OpenLP.FirstTimeWizard', 'Bibles')
self.themesText = translate('OpenLP.FirstTimeWizard', 'Themes') self.themesText = translate('OpenLP.FirstTimeWizard', 'Themes')
@ -83,39 +84,47 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
self.restart() self.restart()
# Sort out internet access for downloads # Sort out internet access for downloads
if self.webAccess: if self.webAccess:
self.internetGroupBox.setVisible(True) songs = self.config.get(u'songs', u'languages')
# If songs database exists do not allow a copy songs = songs.split(u',')
songs = os.path.join(AppLocation.get_section_data_path(u'songs'), for song in songs:
u'songs.sqlite') title = unicode(self.config.get(
if not os.path.exists(songs): u'songs_%s' % song, u'title'), u'utf8')
treewidgetitem = QtGui.QTreeWidgetItem(self.selectionTreeWidget) filename = unicode(self.config.get(
treewidgetitem.setText(0, self.songsText) u'songs_%s' % song, u'filename'), u'utf8')
self._loadChild(treewidgetitem, u'songs', u'languages', u'songs') item = QtGui.QListWidgetItem(title, self.songsListWidget)
treewidgetitem = QtGui.QTreeWidgetItem(self.selectionTreeWidget) item.setData(QtCore.Qt.UserRole, QtCore.QVariant(filename))
treewidgetitem.setText(0, self.biblesText) item.setCheckState(QtCore.Qt.Unchecked)
self._loadChild(treewidgetitem, u'bibles', u'translations', item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
u'bible') bible_languages = self.config.get(u'bibles', u'languages')
treewidgetitem = QtGui.QTreeWidgetItem(self.selectionTreeWidget) bible_languages = bible_languages.split(u',')
treewidgetitem.setText(0, self.themesText) for lang in bible_languages:
self._loadChild(treewidgetitem, u'themes', u'files', 'theme') language = unicode(self.config.get(
# else: u'bibles_%s' % lang, u'title'), u'utf8')
# self.internetGroupBox.setVisible(False) langItem = QtGui.QTreeWidgetItem(
# self.noInternetLabel.setVisible(True) self.biblesTreeWidget, QtCore.QStringList(language))
bibles = self.config.get(u'bibles_%s' % lang, u'translations')
def _loadChild(self, tree, list, tag, root): bibles = bibles.split(u',')
files = self.config.get(list, tag) for bible in bibles:
files = files.split(u',') title = unicode(self.config.get(
for file in files: u'bible_%s' % bible, u'title'), u'utf8')
if file: filename = unicode(self.config.get(
child = QtGui.QTreeWidgetItem(tree) u'bible_%s' % bible, u'filename'))
child.setText(0, self.config.get(u'%s_%s' item = QtGui.QTreeWidgetItem(
% (root, file), u'title')) langItem, QtCore.QStringList(title))
child.setData(0, QtCore.Qt.UserRole, item.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(filename))
QtCore.QVariant(self.config.get(u'%s_%s' item.setCheckState(0, QtCore.Qt.Unchecked)
% (root, file), u'filename'))) item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
child.setCheckState(0, QtCore.Qt.Unchecked) self.biblesTreeWidget.expandAll()
child.setFlags(QtCore.Qt.ItemIsUserCheckable | themes = self.config.get(u'themes', u'files')
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) 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')
item = QtGui.QListWidgetItem(title, self.themesListWidget)
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(filename))
item.setCheckState(QtCore.Qt.Unchecked)
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
def nextId(self): def nextId(self):
""" """
@ -137,16 +146,16 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
self.finishButton.setVisible(True) self.finishButton.setVisible(True)
self.finishButton.setEnabled(True) self.finishButton.setEnabled(True)
self.nextButton.setVisible(False) self.nextButton.setVisible(False)
elif self.page(pageId) == self.DefaultsPage: elif pageId == FirstTimePage.Defaults:
self.themeSelectionComboBox.clear() self.themeComboBox.clear()
listIterator = QtGui.QTreeWidgetItemIterator( listIterator = QtGui.QTreeWidgetItemIterator(
self.selectionTreeWidget) self.selectionTreeWidget)
while listIterator.value(): while listIterator.value():
parent = listIterator.value().parent() parent = listIterator.value().parent()
if parent and listIterator.value().checkState(0) \ if parent and \
== QtCore.Qt.Checked: listIterator.value().checkState(0) == QtCore.Qt.Checked:
if unicode(parent.text(0)) == self.themesText: if unicode(parent.text(0)) == self.themesText:
self.themeSelectionComboBox.addItem( self.themeComboBox.addItem(
listIterator.value().text(0)) listIterator.value().text(0))
listIterator += 1 listIterator += 1
@ -164,55 +173,47 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
self._pluginStatus(self.songUsageCheckBox, u'songusage/status') self._pluginStatus(self.songUsageCheckBox, u'songusage/status')
self._pluginStatus(self.alertCheckBox, u'alerts/status') self._pluginStatus(self.alertCheckBox, u'alerts/status')
# Build directories for downloads # Build directories for downloads
songsDestination = AppLocation.get_section_data_path(u'songs') destination = AppLocation.get_temp_path()
check_directory_exists(songsDestination) check_directory_exists(destination)
bibleDestination = AppLocation.get_section_data_path(u'bibles') bibles_destination = AppLocation.get_section_data_path(u'bibles')
check_directory_exists(bibleDestination) check_directory_exists(bibles_destination)
themeDestination = AppLocation.get_section_data_path(u'themes') themes_destination = AppLocation.get_section_data_path(u'themes')
check_directory_exists(themeDestination) check_directory_exists(destination)
# Install Selected Items looping through them # Install songs
listIterator = QtGui.QTreeWidgetItemIterator(self.selectionTreeWidget) songs_iterator = QtGui.QListWidgetItemIterator(self.songsListWidget)
while listIterator.value(): while songs_iterator.value():
type = listIterator.value().parent() item = songs_iterator.value()
if listIterator.value().parent(): if item.checkState() == QtCore.Qt.Checked:
if listIterator.value().checkState(0) == QtCore.Qt.Checked: filename = item.data(QtCore.Qt.UserRole).toString()
# Install items as theu have been selected urllib.urlretrieve(u'%s%s' % (self.web, filename),
item = unicode(listIterator.value().text(0)) os.path.join(destination, filename))
# Download Song database if selected #importer = SongImporter()
if unicode(type.text(0)) == self.songsText: songs_iterator += 1
songs = unicode(listIterator.value().data(0, # Install Bibles
QtCore.Qt.UserRole).toString()) bibles_iterator = QtGui.QTreeWidgetItemIterator(self.biblesTreeWidget)
message = self.downloading % item while bibles_iterator.value():
self._updateMessage(message) item = bibles_iterator.value()
# Song database is a fixed file name if item.parent() and item.checkState(0) == QtCore.Qt.Checked:
urllib.urlretrieve(u'%s%s' % (self.web, songs), bible = unicode(item.data(0, QtCore.Qt.UserRole).toString())
os.path.join(songsDestination, u'songs.sqlite')) urllib.urlretrieve(u'%s%s' % (self.web, bible),
# Download and selected Bibles os.path.join(bibles_destination, bible))
if unicode(type.text(0)) == self.biblesText: bibles_iterator += 1
bible = unicode(listIterator.value().data(0, themes_iterator = QtGui.QListWidgetItemIterator(self.themesListWidget)
QtCore.Qt.UserRole).toString()) while themes_iterator.value():
message = self.downloading % item item = themes_iterator.value()
self._updateMessage(message) if item.checkState() == QtCore.Qt.Checked:
urllib.urlretrieve(u'%s%s' % (self.web, bible), theme = unicode(item.data(QtCore.Qt.UserRole).toString())
os.path.join(bibleDestination, bible)) urllib.urlretrieve(u'%s%s' % (self.web, theme),
# Download any themes os.path.join(theme_destination, theme))
if unicode(type.text(0)) == self.themesText: themes_iterator += 1
theme = unicode(listIterator.value().data(0,
QtCore.Qt.UserRole).toString())
message = self.downloading % item
self._updateMessage(message)
urllib.urlretrieve(u'%s%s' % (self.web, theme),
os.path.join(themeDestination, theme))
listIterator += 1
# Set Default Display # Set Default Display
if self.displaySelectionComboBox.currentIndex() != -1: if self.displayComboBox.currentIndex() != -1:
QtCore.QSettings().setValue(u'General/monitor', QtCore.QSettings().setValue(u'General/monitor',
QtCore.QVariant(self.displaySelectionComboBox. QtCore.QVariant(self.displayComboBox.currentIndex()))
currentIndex()))
# Set Global Theme # Set Global Theme
if self.themeSelectionComboBox.currentIndex() != -1: if self.themeComboBox.currentIndex() != -1:
QtCore.QSettings().setValue(u'themes/global theme', QtCore.QSettings().setValue(u'themes/global theme',
QtCore.QVariant(self.themeSelectionComboBox.currentText())) QtCore.QVariant(self.themeComboBox.currentText()))
QtCore.QSettings().setValue(u'general/first time', QtCore.QSettings().setValue(u'general/first time',
QtCore.QVariant(False)) QtCore.QVariant(False))
Receiver.send_message(u'cursor_normal') Receiver.send_message(u'cursor_normal')

View File

@ -35,7 +35,8 @@ class FirstTimePage(object):
NoInternet = 2 NoInternet = 2
Songs = 3 Songs = 3
Bibles = 4 Bibles = 4
Defaults = 5 Themes = 5
Defaults = 6
class Ui_FirstTimeWizard(object): class Ui_FirstTimeWizard(object):
@ -103,65 +104,70 @@ class Ui_FirstTimeWizard(object):
self.noInternetLabel.setObjectName(u'noInternetLabel') self.noInternetLabel.setObjectName(u'noInternetLabel')
self.noInternetLayout.addWidget(self.noInternetLabel) self.noInternetLayout.addWidget(self.noInternetLabel)
FirstTimeWizard.setPage(FirstTimePage.NoInternet, self.noInternetPage) FirstTimeWizard.setPage(FirstTimePage.NoInternet, self.noInternetPage)
# The song samples page # The song samples page
self.songsPage = QtGui.QWizardPage() self.songsPage = QtGui.QWizardPage()
self.songsPage.setObjectName(u'songsPage') self.songsPage.setObjectName(u'songsPage')
self.songsLayout = QtGui.QVBoxLayout(self.songsPage)
self.songsLayout.setContentsMargins(50, 20, 50, 20)
self.songsLayout.setObjectName(u'songsLayout')
self.songsListWidget = QtGui.QListWidget(self.songsPage)
self.songsListWidget.setAlternatingRowColors(True)
self.songsListWidget.setObjectName(u'songsListWidget')
self.songsLayout.addWidget(self.songsListWidget)
FirstTimeWizard.setPage(FirstTimePage.Songs, self.songsPage) FirstTimeWizard.setPage(FirstTimePage.Songs, self.songsPage)
# The Bible samples page
# download page
self.biblesPage = QtGui.QWizardPage() self.biblesPage = QtGui.QWizardPage()
self.biblesPage.setObjectName(u'biblesPage') self.biblesPage.setObjectName(u'biblesPage')
self.internetGroupBox = QtGui.QGroupBox(self.biblesPage) self.biblesLayout = QtGui.QVBoxLayout(self.biblesPage)
self.internetGroupBox.setGeometry(QtCore.QRect(20, 10, 501, 271)) self.biblesLayout.setContentsMargins(50, 20, 50, 20)
self.internetGroupBox.setObjectName(u'internetGroupBox') self.biblesLayout.setObjectName(u'biblesLayout')
self.pluginLayout_4 = QtGui.QVBoxLayout(self.internetGroupBox) self.biblesTreeWidget = QtGui.QTreeWidget(self.biblesPage)
self.pluginLayout_4.setObjectName(u'pluginLayout_4') self.biblesTreeWidget.setAlternatingRowColors(True)
self.selectionTreeWidget = QtGui.QTreeWidget(self.internetGroupBox) self.biblesTreeWidget.header().setVisible(False)
self.selectionTreeWidget.setHorizontalScrollBarPolicy( self.biblesTreeWidget.setObjectName(u'biblesTreeWidget')
QtCore.Qt.ScrollBarAlwaysOff) self.biblesLayout.addWidget(self.biblesTreeWidget)
self.selectionTreeWidget.setProperty(u'showDropIndicator', False)
self.selectionTreeWidget.setAlternatingRowColors(True)
self.selectionTreeWidget.setObjectName(u'selectionTreeWidget')
self.selectionTreeWidget.headerItem().setText(0, u'1')
self.selectionTreeWidget.header().setVisible(False)
self.pluginLayout_4.addWidget(self.selectionTreeWidget)
FirstTimeWizard.setPage(FirstTimePage.Bibles, self.biblesPage) FirstTimeWizard.setPage(FirstTimePage.Bibles, self.biblesPage)
# The theme samples page
self.DefaultsPage = QtGui.QWizardPage() self.themesPage = QtGui.QWizardPage()
self.DefaultsPage.setObjectName(u'DefaultsPage') self.themesPage.setObjectName(u'themesPage')
self.layoutWidget = QtGui.QWidget(self.DefaultsPage) self.themesLayout = QtGui.QVBoxLayout(self.themesPage)
self.layoutWidget.setGeometry(QtCore.QRect(20, 20, 491, 113)) self.themesLayout.setContentsMargins(20, 50, 20, 50)
self.layoutWidget.setObjectName(u'layoutWidget') self.themesLayout.setObjectName(u'themesLayout')
self.gridLayout = QtGui.QGridLayout(self.layoutWidget) self.themesListWidget = QtGui.QListWidget(self.themesPage)
self.gridLayout.setMargin(0) self.themesListWidget.setFlow(QtGui.QListView.LeftToRight)
self.gridLayout.setObjectName(u'gridLayout') self.themesListWidget.setViewMode(QtGui.QListView.IconMode)
self.displaySelectionLabel = QtGui.QLabel(self.layoutWidget) self.themesListWidget.setMovement(QtGui.QListView.Static)
self.displaySelectionLabel.setObjectName(u'displaySelectionLabel') self.themesListWidget.setSpacing(4)
self.gridLayout.addWidget(self.displaySelectionLabel, 0, 0, 1, 1) self.themesListWidget.setUniformItemSizes(True)
self.displaySelectionComboBox = QtGui.QComboBox(self.layoutWidget) self.themesListWidget.setObjectName(u'themesListWidget')
self.displaySelectionComboBox.setEditable(False) self.themesLayout.addWidget(self.themesListWidget)
self.displaySelectionComboBox.setInsertPolicy(QtGui.QComboBox.NoInsert) FirstTimeWizard.setPage(FirstTimePage.Themes, self.themesPage)
self.displaySelectionComboBox.setSizeAdjustPolicy( # the default settings page
self.defaultsPage = QtGui.QWizardPage()
self.defaultsPage.setObjectName(u'defaultsPage')
self.defaultsLayout = QtGui.QFormLayout(self.defaultsPage)
self.defaultsLayout.setContentsMargins(50, 20, 50, 20)
self.defaultsLayout.setObjectName(u'defaultsLayout')
self.displayLabel = QtGui.QLabel(self.defaultsPage)
self.displayLabel.setObjectName(u'displayLabel')
self.displayComboBox = QtGui.QComboBox(self.defaultsPage)
self.displayComboBox.setEditable(False)
self.displayComboBox.setInsertPolicy(QtGui.QComboBox.NoInsert)
self.displayComboBox.setSizeAdjustPolicy(
QtGui.QComboBox.AdjustToContents) QtGui.QComboBox.AdjustToContents)
self.displaySelectionComboBox.setObjectName(u'displaySelectionComboBox') self.displayComboBox.setObjectName(u'displayComboBox')
self.gridLayout.addWidget(self.displaySelectionComboBox, 0, 1, 1, 1) self.defaultsLayout.addRow(self.displayLabel, self.displayComboBox)
self.themeSelectionLabel = QtGui.QLabel(self.layoutWidget) self.themeLabel = QtGui.QLabel(self.defaultsPage)
self.themeSelectionLabel.setObjectName(u'themeSelectionLabel') self.themeLabel.setObjectName(u'themeLabel')
self.gridLayout.addWidget(self.themeSelectionLabel, 1, 0, 1, 1) self.themeComboBox = QtGui.QComboBox(self.defaultsPage)
self.themeSelectionComboBox = QtGui.QComboBox(self.layoutWidget) self.themeComboBox.setEditable(False)
self.themeSelectionComboBox.setSizeAdjustPolicy( self.themeComboBox.setInsertPolicy(QtGui.QComboBox.NoInsert)
self.themeComboBox.setSizeAdjustPolicy(
QtGui.QComboBox.AdjustToContents) QtGui.QComboBox.AdjustToContents)
self.themeSelectionComboBox.setObjectName(u'themeSelectionComboBox') self.themeComboBox.setObjectName(u'themeComboBox')
self.gridLayout.addWidget(self.themeSelectionComboBox, 1, 1, 1, 1) self.defaultsLayout.addRow(self.themeLabel, self.themeComboBox)
self.messageLabel = QtGui.QLabel(self.DefaultsPage) FirstTimeWizard.setPage(FirstTimePage.Defaults, self.defaultsPage)
self.messageLabel.setGeometry(QtCore.QRect(60, 160, 471, 17))
self.messageLabel.setObjectName(u'messageLabel')
self.updateLabel = QtGui.QLabel(self.DefaultsPage)
self.updateLabel.setGeometry(QtCore.QRect(60, 220, 351, 17))
self.updateLabel.setObjectName(u'updateLabel')
FirstTimeWizard.setPage(FirstTimePage.Defaults, self.DefaultsPage)
self.retranslateUi(FirstTimeWizard) self.retranslateUi(FirstTimeWizard)
QtCore.QMetaObject.connectSlotsByName(FirstTimeWizard) QtCore.QMetaObject.connectSlotsByName(FirstTimeWizard)
@ -211,23 +217,21 @@ class Ui_FirstTimeWizard(object):
'button now.')) 'button now.'))
self.songsPage.setTitle(translate('OpenLP.FirstTimeWizard', self.songsPage.setTitle(translate('OpenLP.FirstTimeWizard',
'Sample Songs')) 'Sample Songs'))
self.songsPage.setSubTitle(translate( self.songsPage.setSubTitle(translate('OpenLP.FirstTimeWizard',
'OpenLP.FirstTimeWizard',
'Select and download public domain songs.')) 'Select and download public domain songs.'))
self.biblesPage.setTitle(translate('OpenLP.FirstTimeWizard', self.biblesPage.setTitle(translate('OpenLP.FirstTimeWizard',
'Download Samples from OpenLP.org')) 'Sample Bibles'))
self.biblesPage.setSubTitle(translate( self.biblesPage.setSubTitle(translate('OpenLP.FirstTimeWizard',
'OpenLP.FirstTimeWizard', 'Select and download free Bibles.'))
'Select samples to downlaod and install for use.')) self.themesPage.setTitle(translate('OpenLP.FirstTimeWizard',
self.internetGroupBox.setTitle(translate('OpenLP.FirstTimeWizard', 'Sample Themes'))
'Download Example Files')) self.themesPage.setSubTitle(translate('OpenLP.FirstTimeWizard',
self.DefaultsPage.setTitle(translate('OpenLP.FirstTimeWizard', 'Select and download sample themes.'))
self.defaultsPage.setTitle(translate('OpenLP.FirstTimeWizard',
'Default Settings')) 'Default Settings'))
self.DefaultsPage.setSubTitle(translate('OpenLP.FirstTimeWizard', self.defaultsPage.setSubTitle(translate('OpenLP.FirstTimeWizard',
'Set up default values to be used by OpenLP')) 'Set up default settings to be used by OpenLP.'))
self.displaySelectionLabel.setText(translate('OpenLP.FirstTimeWizard', self.displayLabel.setText(translate('OpenLP.FirstTimeWizard',
'Default output display')) 'Default output display:'))
self.themeSelectionLabel.setText(translate('OpenLP.FirstTimeWizard', self.themeLabel.setText(translate('OpenLP.FirstTimeWizard',
'Select the default Theme')) 'Select default theme:'))
self.messageLabel.setText(translate('OpenLP.FirstTimeWizard',
'Press finish to apply all your changes and start OpenLP'))

View File

@ -337,6 +337,7 @@ def get_web_page(url, header=None, update_openlp=False):
return None return None
if update_openlp: if update_openlp:
Receiver.send_message(u'openlp_process_events') Receiver.send_message(u'openlp_process_events')
log.debug(page)
return page return page
def file_is_unicode(filename): def file_is_unicode(filename):