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

View File

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

View File

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