From e216356ed8221092c8bbe6897a714a3932248306 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 10 Jan 2011 17:40:47 +0000 Subject: [PATCH 02/60] Remove Theme Delete button on Golbal theme --- openlp/core/lib/mediamanageritem.py | 6 +++--- openlp/core/ui/thememanager.py | 19 +++++++++++++++++-- openlp/core/utils/__init__.py | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 2d6bcce46..01272e438 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -266,7 +266,7 @@ class MediaManagerItem(QtGui.QWidget): """ Creates the main widget for listing items the media item is tracking """ - #Add the List widget + # Add the List widget self.listView = self.ListViewWithDnD_class(self) self.listView.uniformItemSizes = True self.listView.setSpacing(1) @@ -275,9 +275,9 @@ class MediaManagerItem(QtGui.QWidget): self.listView.setAlternatingRowColors(True) self.listView.setDragEnabled(True) self.listView.setObjectName(u'%sListView' % self.plugin.name) - #Add to pageLayout + # Add to pageLayout self.pageLayout.addWidget(self.listView) - #define and add the context menu + # define and add the context menu self.listView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) name_string = self.plugin.getString(StringContent.Name) if self.hasEditIcon: diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 590f33ff7..62744942b 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -51,7 +51,8 @@ class ThemeManager(QtGui.QWidget): self.settingsSection = u'themes' self.themeForm = ThemeForm(self) self.fileRenameForm = FileRenameForm(self) - self.serviceComboBox = self.mainwindow.ServiceManagerContents.themeComboBox + self.serviceComboBox =\ + self.mainwindow.ServiceManagerContents.themeComboBox # start with the layout self.layout = QtGui.QVBoxLayout(self) self.layout.setSpacing(0) @@ -68,7 +69,7 @@ class ThemeManager(QtGui.QWidget): u':/themes/theme_edit.png', translate('OpenLP.ThemeManager', 'Edit a theme.'), self.onEditTheme) - self.toolbar.addToolbarButton( + self.deleteToolbarAction = self.toolbar.addToolbarButton( translate('OpenLP.ThemeManager', 'Delete Theme'), u':/general/general_delete.png', translate('OpenLP.ThemeManager', 'Delete a theme.'), @@ -123,6 +124,9 @@ class ThemeManager(QtGui.QWidget): QtCore.QObject.connect(self.themeListWidget, QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.changeGlobalFromScreen) + QtCore.QObject.connect(self.themeListWidget, + QtCore.SIGNAL(u'itemClicked(QListWidgetItem *)'), + self.checkListState) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'theme_update_global'), self.changeGlobalFromTab) QtCore.QObject.connect(Receiver.get_receiver(), @@ -146,6 +150,17 @@ class ThemeManager(QtGui.QWidget): self.settingsSection + u'/global theme', QtCore.QVariant(u'')).toString()) + def checkListState(self, item): + """ + If Default theme selected remove delete button. + """ + realThemeName = unicode(item.data(QtCore.Qt.UserRole).toString()) + themeName = unicode(item.text()) + if realThemeName == themeName: + self.deleteToolbarAction.setVisible(True) + else: + self.deleteToolbarAction.setVisible(False) + def contextMenu(self, point): """ Build the Right Click Context menu and set state depending on diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 54bd78ccc..28a0b1238 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -207,7 +207,7 @@ def check_latest_version(current_version): The current version of OpenLP. """ version_string = current_version[u'full'] - #set to prod in the distribution config file. + # set to prod in the distribution config file. settings = QtCore.QSettings() settings.beginGroup(u'general') last_test = unicode(settings.value(u'last version test', From 2feefa95f40759965c28cd0109a123733c00dfff Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 11 Jan 2011 17:44:13 +0000 Subject: [PATCH 03/60] Fixes --- openlp/core/ui/thememanager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 62744942b..a19049487 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -156,6 +156,7 @@ class ThemeManager(QtGui.QWidget): """ realThemeName = unicode(item.data(QtCore.Qt.UserRole).toString()) themeName = unicode(item.text()) + # If default theme restrict actions if realThemeName == themeName: self.deleteToolbarAction.setVisible(True) else: From 76000d918be46c6600f3a446b16a82455cf1a4c5 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 11 Jan 2011 20:56:55 +0100 Subject: [PATCH 04/60] removed showprogress and hideprogress and added cursor_busy and cursor_normal --- openlp/core/lib/eventreceiver.py | 6 ------ openlp/plugins/bibles/lib/http.py | 4 ++-- openlp/plugins/bibles/lib/mediaitem.py | 29 -------------------------- 3 files changed, 2 insertions(+), 37 deletions(-) diff --git a/openlp/core/lib/eventreceiver.py b/openlp/core/lib/eventreceiver.py index 63ad5b796..5811ae933 100644 --- a/openlp/core/lib/eventreceiver.py +++ b/openlp/core/lib/eventreceiver.py @@ -207,12 +207,6 @@ class EventReceiver(QtCore.QObject): ``bibles_nobook`` Attempt to find book resulted in no match - ``bibles_showprogress`` - Show progress of bible verse import - - ``bibles_hideprogress`` - Hide progress of bible verse import - ``bibles_stop_import`` Stops the Bible Import diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 54fb5237c..05880871f 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -438,7 +438,7 @@ class HTTPBible(BibleDB): book_details[u'testament_id']) book = db_book.name if BibleDB.get_verse_count(self, book, reference[1]) == 0: - Receiver.send_message(u'bibles_showprogress') + Receiver.send_message(u'cursor_busy') Receiver.send_message(u'openlp_process_events') search_results = self.get_chapter(book, reference[1]) if search_results and search_results.has_verselist(): @@ -453,7 +453,7 @@ class HTTPBible(BibleDB): self.create_chapter(db_book.id, search_results.chapter, search_results.verselist) Receiver.send_message(u'openlp_process_events') - Receiver.send_message(u'bibles_hideprogress') + Receiver.send_message(u'cursor_normal') Receiver.send_message(u'openlp_process_events') return BibleDB.get_verses(self, reference_list) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 253cc2c62..a21a993ce 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -44,10 +44,6 @@ class BibleListView(BaseListWithDnD): self.PluginName = u'Bibles' BaseListWithDnD.__init__(self, parent) - def resizeEvent(self, event): - self.parent().onListViewResize(event.size().width(), - event.size().width()) - class BibleMediaItem(MediaManagerItem): """ @@ -257,22 +253,9 @@ class BibleMediaItem(MediaManagerItem): # Other stuff QtCore.QObject.connect(self.quickSearchEdit, QtCore.SIGNAL(u'returnPressed()'), self.onQuickSearchButton) - QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'bibles_showprogress'), self.onSearchProgressShow) - QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'bibles_hideprogress'), self.onSearchProgressHide) def addListViewToToolBar(self): MediaManagerItem.addListViewToToolBar(self) - # Progress Bar - self.SearchProgress = QtGui.QProgressBar(self) - self.SearchProgress.setFormat('') - self.SearchProgress.setMinimum(0) - self.SearchProgress.setMaximum(0) - self.SearchProgress.setGeometry(self.listView.geometry().left(), - self.listView.geometry().top(), 81, 23) - self.SearchProgress.setVisible(False) - self.SearchProgress.setObjectName(u'SearchProgress') def configUpdated(self): log.debug(u'configUpdated') @@ -341,18 +324,6 @@ class BibleMediaItem(MediaManagerItem): self.configUpdated() log.debug(u'bible manager initialise complete') - def onListViewResize(self, width, height): - listViewGeometry = self.listView.geometry() - self.SearchProgress.setGeometry(listViewGeometry.x(), - (listViewGeometry.y() + listViewGeometry.height()) - 23, 81, 23) - - def onSearchProgressShow(self): - self.SearchProgress.setVisible(True) - Receiver.send_message(u'openlp_process_events') - - def onSearchProgressHide(self): - self.SearchProgress.setVisible(False) - def onImportClick(self): if not hasattr(self, u'import_wizard'): self.import_wizard = BibleImportForm(self, self.parent.manager, From 39bd27d0dfeb65e48aee39a0b65b5f5cbc793348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Wed, 12 Jan 2011 10:59:14 +0200 Subject: [PATCH 05/60] first working example --- openlp/plugins/songs/forms/songimportform.py | 28 +- .../plugins/songs/forms/songimportwizard.py | 12 +- openlp/plugins/songs/lib/easislidesimport.py | 319 ++++++++++++++++++ openlp/plugins/songs/lib/importer.py | 11 +- 4 files changed, 365 insertions(+), 5 deletions(-) create mode 100644 openlp/plugins/songs/lib/easislidesimport.py diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index 5776dd21a..63d3da322 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -109,6 +109,9 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): QtCore.QObject.connect(self.genericRemoveButton, QtCore.SIGNAL(u'clicked()'), self.onGenericRemoveButtonClicked) + QtCore.QObject.connect(self.easiSlidesBrowseButton, + QtCore.SIGNAL(u'clicked()'), + self.onEasiSlidesBrowseButtonClicked) QtCore.QObject.connect(self.ewBrowseButton, QtCore.SIGNAL(u'clicked()'), self.onEWBrowseButtonClicked) @@ -226,6 +229,16 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): 'presentation file to import from.')) self.genericAddButton.setFocus() return False + elif source_format == SongFormat.EasiSlides: + if self.easiSlidesFilenameEdit.text().isEmpty(): + QtGui.QMessageBox.critical(self, + translate('SongsPlugin.ImportWizardForm', + 'No Easislides Song selected'), + translate('SongsPlugin.ImportWizardForm', + 'You need to select an xml song file exported from ' + 'EasiSlides, to import from.')) + self.easiSlidesBrowseButton.setFocus() + return False elif source_format == SongFormat.EasyWorship: if self.ewFilenameEdit.text().isEmpty(): QtGui.QMessageBox.critical(self, @@ -400,6 +413,13 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): def onGenericRemoveButtonClicked(self): self.removeSelectedItems(self.genericFileListWidget) + def onEasiSlidesBrowseButtonClicked(self): + self.getFileName( + translate('SongsPlugin.ImportWizardForm', + 'Select EasiSlides songfile'), + self.easiSlidesFilenameEdit + ) + def onEWBrowseButtonClicked(self): self.getFileName( translate('SongsPlugin.ImportWizardForm', @@ -440,6 +460,7 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): self.ccliFileListWidget.clear() self.songsOfFellowshipFileListWidget.clear() self.genericFileListWidget.clear() + self.easiSlidesFilenameEdit.setText(u'') self.ewFilenameEdit.setText(u'') self.songBeamerFileListWidget.clear() #self.csvFilenameEdit.setText(u'') @@ -512,8 +533,13 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): importer = self.plugin.importSongs(SongFormat.Generic, filenames=self.getListOfFiles(self.genericFileListWidget) ) + elif source_format == SongFormat.EasiSlides: + # Import an EasiSlides export file + importer = self.plugin.importSongs(SongFormat.EasiSlides, + filename=unicode(self.easiSlidesFilenameEdit.text()) + ) elif source_format == SongFormat.EasyWorship: - # Import an OpenLP 2.0 database + # Import an EasyWorship database importer = self.plugin.importSongs(SongFormat.EasyWorship, filename=unicode(self.ewFilenameEdit.text()) ) diff --git a/openlp/plugins/songs/forms/songimportwizard.py b/openlp/plugins/songs/forms/songimportwizard.py index 903300d0c..b6ff4584a 100644 --- a/openlp/plugins/songs/forms/songimportwizard.py +++ b/openlp/plugins/songs/forms/songimportwizard.py @@ -92,6 +92,8 @@ class Ui_SongImportWizard(object): # Generic Document/Presentation import self.addMultiFileSelectItem(u'generic', None, True) # EasyWorship + self.addSingleFileSelectItem(u'easiSlides') + # EasyWorship self.addSingleFileSelectItem(u'ew') # Words of Worship self.addMultiFileSelectItem(u'songBeamer') @@ -156,8 +158,10 @@ class Ui_SongImportWizard(object): translate('SongsPlugin.ImportWizardForm', 'Generic Document/Presentation')) self.formatComboBox.setItemText(8, - translate('SongsPlugin.ImportWizardForm', 'EasyWorship')) + translate('SongsPlugin.ImportWizardForm', 'EasiSlides')) self.formatComboBox.setItemText(9, + translate('SongsPlugin.ImportWizardForm', 'EasyWorship')) + self.formatComboBox.setItemText(10, translate('SongsPlugin.ImportWizardForm', 'SongBeamer')) # self.formatComboBox.setItemText(9, # translate('SongsPlugin.ImportWizardForm', 'CSV')) @@ -211,6 +215,10 @@ class Ui_SongImportWizard(object): translate('SongsPlugin.ImportWizardForm', 'The generic document/' 'presentation importer has been disabled because OpenLP cannot ' 'find OpenOffice.org on your computer.')) + self.easiSlidesFilenameLabel.setText( + translate('SongsPlugin.ImportWizardForm', 'Filename:')) + self.easiSlidesBrowseButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Browse...')) self.ewFilenameLabel.setText( translate('SongsPlugin.ImportWizardForm', 'Filename:')) self.ewBrowseButton.setText( @@ -241,6 +249,8 @@ class Ui_SongImportWizard(object): QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) self.openLP1FormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + self.easiSlidesFormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, + QtGui.QSizePolicy.Fixed) self.ewFormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) # self.csvFormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py new file mode 100644 index 000000000..1dcd2336f --- /dev/null +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -0,0 +1,319 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2011 Raoul Snyman # +# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael # +# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian # +# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, # +# Carsten Tinggaard, Frode Woldsund # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### + +import logging +import os +from lxml import etree +from lxml.etree import Error, LxmlError +import re + +from openlp.core.lib import translate +from openlp.plugins.songs.lib.songimport import SongImport + +log = logging.getLogger(__name__) + +class EasiSlidesImportError(Exception): + pass + +class EasiSlidesImport(SongImport): + """ + Import songs exported from EasiSlides + + The format example is here: + http://wiki.openlp.org/Development:EasiSlides_-_Song_Data_Format + """ + def __init__(self, manager, **kwargs): + """ + Initialise the class. + """ + SongImport.__init__(self, manager) + self.filename = kwargs[u'filename'] + self.song = None + self.commit = True + + def do_import(self): + """ + Import either each of the files in self.filenames - each element of + which can be either a single opensong file, or a zipfile containing + multiple opensong files. If `self.commit` is set False, the + import will not be committed to the database (useful for test scripts). + """ + success = True + + self.import_wizard.importProgressBar.setMaximum(1) + + log.info(u'Direct import %s', self.filename) + self.import_wizard.incrementProgressBar( + unicode(translate('SongsPlugin.ImportWizardForm', + 'Importing %s...')) % os.path.split(self.filename)[-1]) + file = open(self.filename) + count = file.read().count('') + file.seek(0) + self.import_wizard.importProgressBar.setMaximum(count) + self.do_import_file(file) + + return success + + def do_import_file(self, file): + """ + Process the EasiSlides file - pass in a file-like object, + not a filename + """ + self.set_defaults() + try: + context = etree.iterparse(file) + except (Error, LxmlError): + log.exception(u'Error parsing XML') + return + + song_dict = {} + for action, elem in context: + if not elem.text: + text = None + else: + text = elem.text + + song_dict[elem.tag] = text + + if elem.tag.lower() == u"item": + self.parse_song(song_dict) + self.import_wizard.incrementProgressBar( + unicode(translate('SongsPlugin.ImportWizardForm', + 'Importing %s, song %s...')) % + (os.path.split(self.filename)[-1], self.title)) + if self.commit: + self.finish() + song_dict = {} + + def notCapsLock(self, string): + if string.upper() == string: + return string.lower() + else: + return string + + def notCapsLockTitle(self, string): + if string.upper() == string: + ret = string.lower() + return u"%s%s" % (ret[0].upper(), ret[1:]) + else: + return string + + def parse_song(self, song_dict): + #for i in song_dict: + #if i != 'Contents' and song_dict[i] != None: + #print u"%s = '%s'" % (i, song_dict[i]) + toLower = True + + title = unicode(song_dict['Title1']) + if toLower: + self.title = self.notCapsLockTitle(title) + + if song_dict['Title2'] != None: + alttitle = unicode(song_dict['Title2']) + if toLower: + self.alternate_title = self.notCapsLockTitle(alttitle) + + if song_dict['SongNumber'] != None: + self.song_number = int(song_dict['SongNumber']) + else: + self.song_number = 0 + + #song_dict['Notations'] + if song_dict['Sequence'] != None: + seq = song_dict['Sequence'].split(",") + print seq + + if song_dict['Writer'] != None: + self.authors.append(song_dict['Writer']) + + lyrics = unicode(song_dict['Contents']) + + titleIsFirstLine = True + if titleIsFirstLine: + lyrics = u"%s\n%s" % (self.title, lyrics) + + + # data storage while importing + verses = {} + # keep track of a "default" verse order, in case none is specified + our_verse_order = [] + verses_seen = {} + # in the absence of any other indication, verses are the default, + # erm, versetype! + versetype = u'V' + versenum = None + seenorder = [] + + lines = lyrics.split(u'\n') + length = len(lines) + + regions = 0 + separators = 0 + if lyrics.find(u'[') != -1: + match = -1 + while True: + match = lyrics.find(u'[', match+1) + if match == -1: + break + if lyrics[match:match+7].lower() == u'[region': + regions = regions+1 + else: + separators = separators+1 + + for i in range(length): + thisline = lines[i].strip() + if i < length-1: + nextline = lines[i+1].strip() + # we don't care about nextline at the last line + else: + nextline = False + + + if len(thisline) is 0: + if separators == 0: + # empty line starts a new verse or chorus + if nextline and nextline is nextline.upper(): + # the next line is all uppercase, it is chorus + versetype = u'C' + else: + # if the next line is not uppercase, it must be verse + versetype = u'V' + + if verses.has_key(versetype): + keys = verses[versetype].keys() + #print keys + versenum = len(keys)+1 + else: + versenum = u'1' + + seenorder.append([versetype, versenum]) + continue + + # verse/chorus/etc. marker + if thisline[0] == u'[': + if regions > 1: + # region markers are inside verse markers + if thisline[0:6] == u'[region': + # this is a region marker inside verse + # by now we do nothing + print 'region inside verse markers' + continue + elif regions == 0: + # there is only one region marker + if thisline[0:6] == u'[region': + # we should restart verse count + # by now we do nothing + continue + # this is to be handled as normal marker + # drop the square brackets + right_bracket = thisline.find(u']') + content = thisline[1:right_bracket].upper() + # have we got any digits? + # If so, versenumber is everything from the digits + # to the end (even if there are some alpha chars on the end) + match = re.match(u'(.*)(\d+.*)', content) + if match is not None: + versetype = match.group(1) + versenum = match.group(2) + else: + # otherwise we assume number 1 and take the whole prefix as + # the versetype + versetype = content + versenum = u'1' + seenorder.append([versetype, versenum]) + continue + + if i == 0: + # this is the first line, but no separator is found, + # let's say it's V1 + versetype = u'V' + versenum = u'1' + seenorder.append([versetype, versenum]) + + words = None + # number at start of line.. it's verse number + if thisline[0].isdigit(): + versenum = thisline[0] + words = thisline[1:].strip() + if words is None: + words = thisline + if not versenum: + versenum = u'1' + if versenum is not None: + versetag = u'%s%s' % (versetype, versenum) + if not verses.has_key(versetype): + verses[versetype] = {} + if not verses[versetype].has_key(versenum): + # storage for lines in this verse + verses[versetype][versenum] = [] + if not verses_seen.has_key(versetag): + verses_seen[versetag] = 1 + our_verse_order.append(versetag) + if words: + # Tidy text and remove the ____s from extended words + words = self.tidy_text(words) + words = words.replace('_', '') + if toLower: + words = self.notCapsLock(words) + + verses[versetype][versenum].append(words) + # done parsing + + versetypes = verses.keys() + versetags = {} + + for tag in seenorder: + vtype = tag[0] + vnum = tag[1] + + if not vtype in verses: + # something may have gone wrong + continue + if not vnum in verses[vtype]: + # this most likely is caused by an extra empty line at the end, + # to be debugged later + continue + versetag = u'%s%s' % (vtype, vnum) + lines = u'\n'.join(verses[vtype][vnum]) + self.verses.append([versetag, lines]) + + if song_dict['Sequence'] != None: + order = song_dict['Sequence'].split(u',') + for tag in order: + if tag[0].isdigit(): + # Assume it's a verse if it has no prefix + tag = u'V' + tag + elif not re.search('\d+', tag): + # Assume it's no.1 if there's no digits + tag = tag + u'1' + if not versetags.has_key(tag): + log.info(u'Got order %s but not in versetags, dropping this' + u'item from presentation order', tag) + else: + self.verse_order_list.append(tag) + else: + for tag in seenorder: + self.verse_order_list.append(u'%s%s' % (tag[0], tag[1])) diff --git a/openlp/plugins/songs/lib/importer.py b/openlp/plugins/songs/lib/importer.py index 128d80138..038eaa2a2 100644 --- a/openlp/plugins/songs/lib/importer.py +++ b/openlp/plugins/songs/lib/importer.py @@ -25,6 +25,7 @@ ############################################################################### from opensongimport import OpenSongImport +from easislidesimport import EasiSlidesImport from olpimport import OpenLPSongImport from openlyricsimport import OpenLyricsImport from wowimport import WowImport @@ -65,8 +66,9 @@ class SongFormat(object): SongsOfFellowship = 6 Generic = 7 #CSV = 8 - EasyWorship = 8 - SongBeamer = 9 + EasiSlides = 8 + EasyWorship = 9 + SongBeamer = 10 @staticmethod def get_class(format): @@ -92,6 +94,8 @@ class SongFormat(object): return OooImport elif format == SongFormat.CCLI: return CCLIFileImport + elif format == SongFormat.EasiSlides: + return EasiSlidesImport elif format == SongFormat.EasyWorship: return EasyWorshipSongImport elif format == SongFormat.SongBeamer: @@ -112,6 +116,7 @@ class SongFormat(object): SongFormat.CCLI, SongFormat.SongsOfFellowship, SongFormat.Generic, + SongFormat.EasiSlides, SongFormat.EasyWorship, SongFormat.SongBeamer ] @@ -128,4 +133,4 @@ SongFormat.set_availability(SongFormat.OpenLP1, has_openlp1) SongFormat.set_availability(SongFormat.SongsOfFellowship, has_sof) SongFormat.set_availability(SongFormat.Generic, has_ooo) -__all__ = [u'SongFormat'] \ No newline at end of file +__all__ = [u'SongFormat'] From f1a437891ae3d176371409be64351802caac10f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Wed, 12 Jan 2011 17:10:20 +0200 Subject: [PATCH 06/60] a lot of changes for better code --- openlp/plugins/songs/lib/easislidesimport.py | 267 ++++++++++++------- 1 file changed, 164 insertions(+), 103 deletions(-) diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py index 1dcd2336f..435e2177f 100644 --- a/openlp/plugins/songs/lib/easislidesimport.py +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -83,93 +83,145 @@ class EasiSlidesImport(SongImport): not a filename """ self.set_defaults() + + # determines, if ENTIRELY UPPERCASE lines should be converted to lower + self.toLower = True + # determines, if title should be prepended to lyrics + self.titleIsLyrics = True + try: context = etree.iterparse(file) except (Error, LxmlError): log.exception(u'Error parsing XML') return - song_dict = {} + data = {} for action, elem in context: if not elem.text: text = None else: - text = elem.text + text = unicode(elem.text) - song_dict[elem.tag] = text + data[elem.tag.lower()] = text if elem.tag.lower() == u"item": - self.parse_song(song_dict) + self.parse_song(data) self.import_wizard.incrementProgressBar( unicode(translate('SongsPlugin.ImportWizardForm', 'Importing %s, song %s...')) % (os.path.split(self.filename)[-1], self.title)) if self.commit: self.finish() - song_dict = {} + data = {} def notCapsLock(self, string): - if string.upper() == string: + if self.toLower and string.upper() == string: return string.lower() else: return string def notCapsLockTitle(self, string): - if string.upper() == string: + if self.toLower and string.upper() == string: ret = string.lower() return u"%s%s" % (ret[0].upper(), ret[1:]) else: return string - def parse_song(self, song_dict): - #for i in song_dict: - #if i != 'Contents' and song_dict[i] != None: - #print u"%s = '%s'" % (i, song_dict[i]) - toLower = True + def parse_song(self, data): + # We should also check if the title is already used, if yes, + # maybe user sould decide if we should import - title = unicode(song_dict['Title1']) - if toLower: - self.title = self.notCapsLockTitle(title) + # set title + self.title = self.notCapsLockTitle(data['title1']) - if song_dict['Title2'] != None: - alttitle = unicode(song_dict['Title2']) - if toLower: - self.alternate_title = self.notCapsLockTitle(alttitle) + # set alternate title, if present + if data['title2'] != None: + self.alternate_title = self.notCapsLockTitle(data['title2']) - if song_dict['SongNumber'] != None: - self.song_number = int(song_dict['SongNumber']) + # folder name, we have no use for it, usually only one folder is + # used in easislides and this contains no actual data, easislides + # default database is named English, but usersmay not follow their + # example + # data['folder'] + + # set song number, if present, 0 otherwise + if data['songnumber'] != None: + self.song_number = int(data['songnumber']) else: self.song_number = 0 - - #song_dict['Notations'] - if song_dict['Sequence'] != None: - seq = song_dict['Sequence'].split(",") - print seq - if song_dict['Writer'] != None: - self.authors.append(song_dict['Writer']) - - lyrics = unicode(song_dict['Contents']) + # Don't know how to use Notations + # data['notations'] - titleIsFirstLine = True - if titleIsFirstLine: + # set song authors + if data['writer'] != None: + authors = data['writer'].split(u',') + for author in authors: + self.authors.append(author.strip()) + + # set copyright data + # licenceadmins may contain Public Domain or CCLI, as shown in examples + # let's just concatenate these fields, it should be determined, if song + # No is actually CCLI nr, if it is set + copyright = [] + if data['copyright']: + copyright.append(data['copyright'].strip()) + if data['licenceadmin1']: + copyright.append(data['licenceadmin1'].strip()) + if data['licenceadmin2']: + copyright.append(data['licenceadmin2'].strip()) + self.add_copyright(" ".join(copyright)) + + # set topic data, I have seen no example, and should not use it, + # I even was not able to find place to set categories in easislides + # but then again, it would not hurt either + if data['category']: + for topic in data['category'].split(u','): + self.topics.append(topic.strip()) + + # don't know what to do with timing data + # may be either 3/4 or 4/4 + # data['timing'] + + # don't know what to do with music key + # data['musickey'], may be Db, C, G, F#, F#m + # data['capo'], is a number from 0 to 11, determing where to + # place a capo on guitar neck + + # set book data + if data['bookreference']: + for book in data['bookreference'].split(u','): + self.books.append(book.strip()) + + # don't know what to do with user + # data['userreference'], this is simple text entry, no + # notable restrictions + + # there is nothing to do with formatdata, this for sure is a messy + # thing, see an example: + # 21=1>23=0>22=2>25=2>26=-16777216> + # 27=-16777216>28=11>29=-1>30=-256>31=2>32=2> + # 41=16>42=16>43=Microsoft Sans Serif> + # 44=Microsoft Sans Serif>45=0>46=45>47=20>48=40> + # 50=0>51=>52=50>53=-1>54=0>55=1>61=>62=2> + # 63=1>64=2>65=2>66=0>71=0>72=Fade>73=Fade> + # + # data['formatdata'] + + # don't know what to do with settings data either, this is similar + # nonsense: 10=2;5;0;0;1;0;ยป126;232;> + # data['settings'] + + # LYRICS LYRICS LYRICS + # the big and messy part to handle lyrics + lyrics = data['contents'] + + # we add title to first line, if supposed to do so + if self.titleIsLyrics: lyrics = u"%s\n%s" % (self.title, lyrics) - - - # data storage while importing - verses = {} - # keep track of a "default" verse order, in case none is specified - our_verse_order = [] - verses_seen = {} - # in the absence of any other indication, verses are the default, - # erm, versetype! - versetype = u'V' - versenum = None - seenorder = [] - - lines = lyrics.split(u'\n') - length = len(lines) + # we count the [region 2] and [whatever] separartors, to be able + # to tell how region data is used regions = 0 separators = 0 if lyrics.find(u'[') != -1: @@ -182,37 +234,44 @@ class EasiSlidesImport(SongImport): regions = regions+1 else: separators = separators+1 - + + # data storage while importing + verses = {} + # keep track of a "default" verse order, in case none is specified + our_verse_order = [] + + lines = lyrics.split(u'\n') + length = len(lines) for i in range(length): thisline = lines[i].strip() if i < length-1: nextline = lines[i+1].strip() - # we don't care about nextline at the last line else: + # there is no nextline at the last line nextline = False - if len(thisline) is 0: if separators == 0: # empty line starts a new verse or chorus if nextline and nextline is nextline.upper(): - # the next line is all uppercase, it is chorus + # the next line is all uppercase, it must be chorus versetype = u'C' else: # if the next line is not uppercase, it must be verse versetype = u'V' if verses.has_key(versetype): - keys = verses[versetype].keys() - #print keys - versenum = len(keys)+1 + versenum = len(verses[versetype].keys())+1 else: versenum = u'1' - seenorder.append([versetype, versenum]) + our_verse_order.append([versetype, versenum]) + else: + # separators are not used, something must be done + continue continue - - # verse/chorus/etc. marker + + # verse/chorus/etc. marker, this line contains no other data if thisline[0] == u'[': if regions > 1: # region markers are inside verse markers @@ -236,6 +295,11 @@ class EasiSlidesImport(SongImport): # to the end (even if there are some alpha chars on the end) match = re.match(u'(.*)(\d+.*)', content) if match is not None: + # versetype normally is one of the following: + # not set for verse (only number) + # prechorus (p), chorus (c), bridge (w), + # ending, none of these is numbered in sequence + # empty line means split screen versetype = match.group(1) versenum = match.group(2) else: @@ -243,65 +307,51 @@ class EasiSlidesImport(SongImport): # the versetype versetype = content versenum = u'1' - seenorder.append([versetype, versenum]) + our_verse_order.append([versetype, versenum]) continue - + if i == 0: - # this is the first line, but no separator is found, - # let's say it's V1 + # this is the first line, but still no separator is found, + # we say it's V1 versetype = u'V' versenum = u'1' - seenorder.append([versetype, versenum]) + our_verse_order.append([versetype, versenum]) - words = None - # number at start of line.. it's verse number - if thisline[0].isdigit(): - versenum = thisline[0] - words = thisline[1:].strip() - if words is None: - words = thisline - if not versenum: - versenum = u'1' - if versenum is not None: - versetag = u'%s%s' % (versetype, versenum) - if not verses.has_key(versetype): - verses[versetype] = {} - if not verses[versetype].has_key(versenum): - # storage for lines in this verse - verses[versetype][versenum] = [] - if not verses_seen.has_key(versetag): - verses_seen[versetag] = 1 - our_verse_order.append(versetag) - if words: - # Tidy text and remove the ____s from extended words - words = self.tidy_text(words) - words = words.replace('_', '') - if toLower: - words = self.notCapsLock(words) - - verses[versetype][versenum].append(words) + # We have versetype/number data, if it was there, now + # we parse text + if not verses.has_key(versetype): + verses[versetype] = {} + if not verses[versetype].has_key(versenum): + verses[versetype][versenum] = [] + + # Tidy text and remove the ____s from extended words + words = self.tidy_text(thisline) + words = words.replace('_', '') + words = self.notCapsLock(words) + + verses[versetype][versenum].append(words) # done parsing - - versetypes = verses.keys() - versetags = {} - - for tag in seenorder: - vtype = tag[0] - vnum = tag[1] + + # we use our_verse_order to ensure, we insert lyrics in the same order + # as these appeared originally in the file + for tag in our_verse_order: + versetype = tag[0] + versenum = tag[1] - if not vtype in verses: + if not versetype in verses: # something may have gone wrong continue - if not vnum in verses[vtype]: + if not versenum in verses[versetype]: # this most likely is caused by an extra empty line at the end, # to be debugged later continue - versetag = u'%s%s' % (vtype, vnum) - lines = u'\n'.join(verses[vtype][vnum]) + versetag = u'%s%s' % (versetype, versenum) + lines = u'\n'.join(verses[versetype][versenum]) self.verses.append([versetag, lines]) - if song_dict['Sequence'] != None: - order = song_dict['Sequence'].split(u',') + # Make use of Sequence data, determining the order of verses, choruses + if data['sequence'] != None: + order = data['sequence'].split(u',') for tag in order: if tag[0].isdigit(): # Assume it's a verse if it has no prefix @@ -315,5 +365,16 @@ class EasiSlidesImport(SongImport): else: self.verse_order_list.append(tag) else: - for tag in seenorder: + for tag in our_verse_order: + if not tag[0] in verses: + log.info(u'Got order from our_verse_order %s but not in' + u'versetags, dropping this item from presentation order' + u'missing was versetag %s', tag, tag[0]) + continue + if not tag[1] in verses[tag[0]]: + log.info(u'Got order from our_verse_order %s but not in' + u'versetags, dropping this item from presentation order' + u'missing was versenum %s for versetag %s', + tag, tag[1], tag[0]) + continue self.verse_order_list.append(u'%s%s' % (tag[0], tag[1])) From 64367909ba07a7c13a74e4217b52698f9904f680 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Wed, 12 Jan 2011 15:31:32 +0000 Subject: [PATCH 07/60] Improve bibleserver code resiliance --- openlp/plugins/bibles/lib/http.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 2476ae65d..e7beeda29 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -269,11 +269,12 @@ class BSExtract(object): if not soup: return None Receiver.send_message(u'openlp_process_events') - content = soup.find(u'div', u'content').find(u'div').findAll(u'div') + content = soup.find(u'div', u'content') if not content: log.exception(u'No verses found in the Bibleserver response.') send_error_message(u'parse') return None + content = content.find(u'div').findAll(u'div') verse_number = re.compile(r'v(\d{1,2})(\d{3})(\d{3}) verse') verses = {} for verse in content: From af9e9641c498decbe17a1d9e78f321674ac2f0f7 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 12 Jan 2011 18:52:16 +0000 Subject: [PATCH 08/60] Fix black background on Display resizing Fixes: https://launchpad.net/bugs/696557 --- openlp/core/lib/imagemanager.py | 5 ++--- openlp/core/ui/maindisplay.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/openlp/core/lib/imagemanager.py b/openlp/core/lib/imagemanager.py index 0be1a01c8..dcfc50f0f 100644 --- a/openlp/core/lib/imagemanager.py +++ b/openlp/core/lib/imagemanager.py @@ -86,8 +86,7 @@ class ImageManager(QtCore.QObject): for key in self._cache.keys(): image = self._cache[key] image.dirty = True - fullpath = os.path.join(image.path, image.name) - image.image = resize_image(fullpath, + image.image = resize_image(image.path, self.width, self.height) self._cache_dirty = True # only one thread please @@ -165,4 +164,4 @@ class ImageManager(QtCore.QObject): image = self._cache[key] if image.dirty: image.image_bytes = image_to_byte(image.image) - image.dirty = False \ No newline at end of file + image.dirty = False diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index adc2cb5fa..ab69cd1e9 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -198,7 +198,7 @@ class MainDisplay(DisplayWidget): The slide text to be displayed """ log.debug(u'text to display') - # Wait for the webview to update before displayiong text. + # Wait for the webview to update before displaying text. while not self.loaded: Receiver.send_message(u'openlp_process_events') self.frame.evaluateJavaScript(u'show_text("%s")' % \ From 0a5b44c6a35588bba808d0bd28716c916f44d58c Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Wed, 12 Jan 2011 19:12:30 +0000 Subject: [PATCH 09/60] BibleGateway fix --- openlp/plugins/bibles/lib/http.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index e7beeda29..da3a1e9e5 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -208,7 +208,8 @@ class BGExtract(object): u'version': u'%s' % version}) cleaner = [(re.compile(' |
|\'\+\''), lambda match: '')] soup = get_soup_for_bible_ref( - u'http://www.biblegateway.com/passage/?%s' % url_params, cleaner) + u'http://www.biblegateway.com/passage/?%s' % url_params, + cleaner=cleaner) if not soup: return None Receiver.send_message(u'openlp_process_events') From 727f7fe7bf5163f350478cf1a3038b562a5734bb Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 12 Jan 2011 20:31:46 +0100 Subject: [PATCH 10/60] --- openlp/core/lib/mediamanageritem.py | 10 +++++----- openlp/core/lib/serviceitem.py | 1 + openlp/core/ui/slidecontroller.py | 20 ++++++++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 2d6bcce46..6fb834e05 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -266,7 +266,7 @@ class MediaManagerItem(QtGui.QWidget): """ Creates the main widget for listing items the media item is tracking """ - #Add the List widget + # Add the List widget self.listView = self.ListViewWithDnD_class(self) self.listView.uniformItemSizes = True self.listView.setSpacing(1) @@ -275,9 +275,9 @@ class MediaManagerItem(QtGui.QWidget): self.listView.setAlternatingRowColors(True) self.listView.setDragEnabled(True) self.listView.setObjectName(u'%sListView' % self.plugin.name) - #Add to pageLayout + # Add to pageLayout self.pageLayout.addWidget(self.listView) - #define and add the context menu + # define and add the context menu self.listView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) name_string = self.plugin.getString(StringContent.Name) if self.hasEditIcon: @@ -314,7 +314,7 @@ class MediaManagerItem(QtGui.QWidget): context_menu_action( self.listView, u':/general/general_add.png', translate('OpenLP.MediaManagerItem', - '&Add to selected Service Item'), + '&Add to selected Service Item'), self.onAddEditClick)) QtCore.QObject.connect(self.listView, QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), @@ -441,7 +441,7 @@ class MediaManagerItem(QtGui.QWidget): QtGui.QMessageBox.information(self, translate('OpenLP.MediaManagerItem', 'No Items Selected'), translate('OpenLP.MediaManagerItem', - 'You must select one or more items to preview.')) + 'You must select one or more items to preview.')) else: log.debug(u'%s Preview requested', self.plugin.name) serviceItem = self.buildServiceItem() diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index f18605711..ce0907fbb 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -60,6 +60,7 @@ class ItemCapabilities(object): AddIfNewItem = 9 ProvidesOwnDisplay = 10 + class ServiceItem(object): """ The service item is a base class for the plugins to use to interact with diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 690cb9264..92b59a900 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -412,13 +412,17 @@ class SlideController(QtGui.QWidget): max_width = self.PreviewFrame.width() - self.grid.margin() * 2 self.SlidePreview.setFixedSize(QtCore.QSize(max_width, max_width / self.ratio)) - width = self.parent.ControlSplitter.sizes()[self.split] - self.PreviewListWidget.setColumnWidth(0, width) - # Sort out image heights (Songs, bibles excluded) - if self.serviceItem and not self.serviceItem.is_text(): - for framenumber in range(len(self.serviceItem.get_frames())): - self.PreviewListWidget.setRowHeight( - framenumber, width / self.ratio) + # Make sure that the frames have the correct size. + if self.serviceItem: + self.PreviewListWidget.resizeRowsToContents() + # Sort out image heights (Songs, bibles excluded) + if not self.serviceItem.is_text(): + width = self.parent.ControlSplitter.sizes()[self.split] + for framenumber in range(len(self.serviceItem.get_frames())): + self.PreviewListWidget.setRowHeight( + framenumber, width / self.ratio) + self.PreviewListWidget.setColumnWidth(0, + self.PreviewListWidget.viewport().size().width()) def onSongBarHandler(self): request = unicode(self.sender().text()) @@ -590,7 +594,7 @@ class SlideController(QtGui.QWidget): self.parent.renderManager.height) else: image = self.parent.renderManager.image_manager. \ - get_image(frame[u'title']) + get_image(frame[u'title']) label.setPixmap(QtGui.QPixmap.fromImage(image)) self.PreviewListWidget.setCellWidget(framenumber, 0, label) slideHeight = width * self.parent.renderManager.screen_ratio From 7f5293c4c8ba8fbe28913e7488868762ba2807c3 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Thu, 13 Jan 2011 01:14:38 +0000 Subject: [PATCH 11/60] Cleanup and refactor file unicode check --- openlp/core/lib/imagemanager.py | 1 - openlp/core/ui/servicemanager.py | 12 ++++-------- openlp/core/ui/thememanager.py | 21 ++++++--------------- openlp/core/utils/__init__.py | 22 +++++++++++++++++++++- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/openlp/core/lib/imagemanager.py b/openlp/core/lib/imagemanager.py index dcfc50f0f..02d7010be 100644 --- a/openlp/core/lib/imagemanager.py +++ b/openlp/core/lib/imagemanager.py @@ -30,7 +30,6 @@ A Thread is used to convert the image to a byte array so the user does not need to wait for the conversion to happen. """ import logging -import os import time from PyQt4 import QtCore diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 2d85e4b7f..ffc2bee25 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -37,7 +37,7 @@ from openlp.core.lib import OpenLPToolbar, ServiceItem, context_menu_action, \ Receiver, build_icon, ItemCapabilities, SettingsManager, translate, \ ThemeLevel from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm -from openlp.core.utils import AppLocation, split_filename +from openlp.core.utils import AppLocation, file_is_unicode, split_filename class ServiceManagerList(QtGui.QTreeWidget): """ @@ -484,16 +484,13 @@ class ServiceManager(QtGui.QWidget): try: zip = zipfile.ZipFile(fileName) for file in zip.namelist(): - try: - ucsfile = file.decode(u'utf-8') - except UnicodeDecodeError: + ucsfile = file_is_unicode(file) + if not ucsfile: QtGui.QMessageBox.critical( self, translate('OpenLP.ServiceManager', 'Error'), translate('OpenLP.ServiceManager', 'File is not a valid service.\n' 'The content encoding is not UTF-8.')) - log.exception(u'Filename "%s" is not valid UTF-8' % - file.decode(u'utf-8', u'replace')) continue osfile = unicode(QtCore.QDir.toNativeSeparators(ucsfile)) filePath = os.path.join(self.servicePath, @@ -515,8 +512,7 @@ class ServiceManager(QtGui.QWidget): serviceItem.set_from_service(item, self.servicePath) self.validateItem(serviceItem) self.addServiceItem(serviceItem) - if serviceItem.is_capable( - ItemCapabilities.OnLoadUpdate): + if serviceItem.is_capable(ItemCapabilities.OnLoadUpdate): Receiver.send_message(u'%s_service_load' % serviceItem.name.lower(), serviceItem) try: diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 73f1a6d8b..81e191396 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -37,7 +37,8 @@ from openlp.core.theme import Theme from openlp.core.lib import OpenLPToolbar, ThemeXML, get_text_file_string, \ build_icon, Receiver, SettingsManager, translate, check_item_selected, \ BackgroundType, BackgroundGradientType, check_directory_exists -from openlp.core.utils import AppLocation, get_filesystem_encoding +from openlp.core.utils import AppLocation, file_is_unicode, \ + get_filesystem_encoding log = logging.getLogger(__name__) @@ -475,7 +476,8 @@ class ThemeManager(QtGui.QWidget): unicode(themeName) + u'.xml') xml = get_text_file_string(xmlFile) if not xml: - return self._baseTheme() + log.debug("No theme data - using default theme") + return ThemeXML() else: return self._createThemeFromXml(xml, self.path) @@ -494,16 +496,13 @@ class ThemeManager(QtGui.QWidget): filexml = None themename = None for file in zip.namelist(): - try: - ucsfile = file.decode(u'utf-8') - except UnicodeDecodeError: + ucsfile = file_is_unicode(file) + if not ucsfile: QtGui.QMessageBox.critical( self, translate('OpenLP.ThemeManager', 'Error'), translate('OpenLP.ThemeManager', 'File is not a valid theme.\n' 'The content encoding is not UTF-8.')) - log.exception(u'Filename "%s" is not valid UTF-8' % - file.decode(u'utf-8', u'replace')) continue osfile = unicode(QtCore.QDir.toNativeSeparators(ucsfile)) theme_dir = None @@ -668,14 +667,6 @@ class ThemeManager(QtGui.QWidget): image = os.path.join(self.path, theme + u'.png') return image - def _baseTheme(self): - """ - Provide a base theme with sensible defaults - """ - log.debug(u'base theme created') - newtheme = ThemeXML() - return newtheme - def _createThemeFromXml(self, themeXml, path): """ Return a theme object using information parsed from XML diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index ccdb2afa1..75f00f298 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -317,9 +317,29 @@ def get_web_page(url, header=None, update_openlp=False): Receiver.send_message(u'openlp_process_events') return page +def file_is_unicode(filename): + """ + Checks if a file is valid unicode and returns the unicode decoded file or + None. + + ``filename`` + File to check is valid unicode. + """ + if not filename: + return None + ucsfile = None + try: + ucsfile = filename.decode(u'utf-8') + except UnicodeDecodeError: + log.exception(u'Filename "%s" is not valid UTF-8' % + filename.decode(u'utf-8', u'replace')) + if not ucsfile: + return None + return ucsfile + from languagemanager import LanguageManager from actions import ActionList __all__ = [u'AppLocation', u'check_latest_version', u'add_actions', u'get_filesystem_encoding', u'LanguageManager', u'ActionList', - u'get_web_page'] + u'get_web_page', u'file_is_unicode'] From f487464280f87594adcb9da463aa0fedfe70e753 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Thu, 13 Jan 2011 02:28:03 +0000 Subject: [PATCH 12/60] Cleanup exceptions --- openlp/plugins/bibles/lib/csvbible.py | 2 +- openlp/plugins/bibles/lib/opensong.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/lib/csvbible.py b/openlp/plugins/bibles/lib/csvbible.py index 8b1d70128..2e9e9523b 100644 --- a/openlp/plugins/bibles/lib/csvbible.py +++ b/openlp/plugins/bibles/lib/csvbible.py @@ -72,7 +72,7 @@ class CSVBible(BibleDB): self.create_book(unicode(line[1], details['encoding']), line[2], int(line[0])) Receiver.send_message(u'openlp_process_events') - except IOError, IndexError: + except (IOError, IndexError): log.exception(u'Loading books from file failed') success = False finally: diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/opensong.py index c0b60f911..03d243390 100644 --- a/openlp/plugins/bibles/lib/opensong.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -89,7 +89,7 @@ class OpenSongBible(BibleDB): 'Importing ...')) % (db_book.name, int(chapter.attrib[u'n']))) self.session.commit() - except IOError, AttributeError: + except (IOError, AttributeError): log.exception(u'Loading bible from OpenSong file failed') success = False finally: From ccb2e8693c6d7b379a284b059fa0c58241f52b42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Thu, 13 Jan 2011 12:54:36 +0200 Subject: [PATCH 13/60] more changes --- openlp/plugins/songs/lib/easislidesimport.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py index 435e2177f..736d85304 100644 --- a/openlp/plugins/songs/lib/easislidesimport.py +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -367,14 +367,14 @@ class EasiSlidesImport(SongImport): else: for tag in our_verse_order: if not tag[0] in verses: - log.info(u'Got order from our_verse_order %s but not in' - u'versetags, dropping this item from presentation order' - u'missing was versetag %s', tag, tag[0]) + #log.info(u'Got order from our_verse_order %s but not in' + # u'versetags, dropping this item from presentation order' + # u'missing was versetag %s', tag, tag[0]) continue if not tag[1] in verses[tag[0]]: - log.info(u'Got order from our_verse_order %s but not in' - u'versetags, dropping this item from presentation order' - u'missing was versenum %s for versetag %s', - tag, tag[1], tag[0]) + #log.info(u'Got order from our_verse_order %s but not in' + # u'versetags, dropping this item from presentation order' + # u'missing was versenum %s for versetag %s', + # tag, tag[1], tag[0]) continue self.verse_order_list.append(u'%s%s' % (tag[0], tag[1])) From 74909281907a29f17bc1e324fa6267cdb03d27eb Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Thu, 13 Jan 2011 17:55:29 +0000 Subject: [PATCH 14/60] Refactor wizards --- openlp/core/lib/eventreceiver.py | 4 +- openlp/core/ui/wizard.py | 171 ++++++ openlp/core/utils/__init__.py | 21 +- .../plugins/bibles/forms/bibleimportform.py | 522 ++++++++++++++---- .../plugins/bibles/forms/bibleimportwizard.py | 391 ------------- openlp/plugins/bibles/lib/csvbible.py | 4 +- openlp/plugins/bibles/lib/http.py | 18 +- openlp/plugins/bibles/lib/mediaitem.py | 2 +- openlp/plugins/bibles/lib/openlp1.py | 6 +- openlp/plugins/bibles/lib/opensong.py | 4 +- openlp/plugins/bibles/lib/osis.py | 8 +- openlp/plugins/songs/forms/songimportform.py | 444 +++++++++++++-- .../plugins/songs/forms/songimportwizard.py | 362 ------------ openlp/plugins/songs/lib/cclifileimport.py | 2 +- openlp/plugins/songs/lib/ewimport.py | 2 +- openlp/plugins/songs/lib/olp1import.py | 2 +- openlp/plugins/songs/lib/olpimport.py | 2 +- openlp/plugins/songs/lib/oooimport.py | 6 +- openlp/plugins/songs/lib/openlyricsimport.py | 6 +- openlp/plugins/songs/lib/opensongimport.py | 2 +- openlp/plugins/songs/lib/sofimport.py | 4 +- openlp/plugins/songs/lib/songbeamerimport.py | 3 +- openlp/plugins/songs/lib/songimport.py | 4 +- .../songs/lib/test/test_opensongimport.py | 2 +- openlp/plugins/songs/lib/wowimport.py | 4 +- 25 files changed, 1029 insertions(+), 967 deletions(-) create mode 100644 openlp/core/ui/wizard.py delete mode 100644 openlp/plugins/bibles/forms/bibleimportwizard.py delete mode 100644 openlp/plugins/songs/forms/songimportwizard.py diff --git a/openlp/core/lib/eventreceiver.py b/openlp/core/lib/eventreceiver.py index 5811ae933..6fa8e624a 100644 --- a/openlp/core/lib/eventreceiver.py +++ b/openlp/core/lib/eventreceiver.py @@ -207,8 +207,8 @@ class EventReceiver(QtCore.QObject): ``bibles_nobook`` Attempt to find book resulted in no match - ``bibles_stop_import`` - Stops the Bible Import + ``openlp_stop_wizard`` + Stops a wizard before completion ``remotes_poll_request`` Waits for openlp to do something "interesting" and sends a diff --git a/openlp/core/ui/wizard.py b/openlp/core/ui/wizard.py new file mode 100644 index 000000000..3b221455b --- /dev/null +++ b/openlp/core/ui/wizard.py @@ -0,0 +1,171 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2011 Raoul Snyman # +# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael # +# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian # +# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, # +# Carsten Tinggaard, Frode Woldsund # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +The :mod:``wizard`` module provides generic wizard tools for OpenLP. +""" +import logging + +from PyQt4 import QtCore, QtGui + +from openlp.core.lib import build_icon, Receiver + +log = logging.getLogger(__name__) + +class OpenLPWizard(QtGui.QWizard): + """ + Generic OpenLP wizard to provide generic functionality and a unified look + and feel. + """ + def __init__(self, parent, plugin, name, image): + QtGui.QWizard.__init__(self, parent) + self.setObjectName(name) + self.openIcon = build_icon(u':/general/general_open.png') + self.deleteIcon = build_icon(u':/general/general_delete.png') + self.finishButton = self.button(QtGui.QWizard.FinishButton) + self.cancelButton = self.button(QtGui.QWizard.CancelButton) + self.setupUi(image) + self.registerFields() + self.plugin = plugin + self.customInit() + self.customSignals() + QtCore.QObject.connect(self, QtCore.SIGNAL(u'currentIdChanged(int)'), + self.onCurrentIdChanged) + + def setupUi(self, image): + """ + Set up the wizard UI + """ + self.setModal(True) + self.setWizardStyle(QtGui.QWizard.ModernStyle) + self.setOptions(QtGui.QWizard.IndependentPages | + QtGui.QWizard.NoBackButtonOnStartPage | + QtGui.QWizard.NoBackButtonOnLastPage) + self.addWelcomePage(image) + self.addCustomPages() + self.addProgressPage() + self.retranslateUi() + QtCore.QMetaObject.connectSlotsByName(self) + + def addWelcomePage(self, image): + """ + Add the opening welcome page to the wizard. + + ``image`` + A splash image for the wizard + """ + self.welcomePage = QtGui.QWizardPage() + self.welcomePage.setPixmap(QtGui.QWizard.WatermarkPixmap, + QtGui.QPixmap(image)) + self.welcomePage.setObjectName(u'WelcomePage') + self.welcomeLayout = QtGui.QVBoxLayout(self.welcomePage) + self.welcomeLayout.setObjectName(u'WelcomeLayout') + self.titleLabel = QtGui.QLabel(self.welcomePage) + self.titleLabel.setObjectName(u'TitleLabel') + self.welcomeLayout.addWidget(self.titleLabel) + self.welcomeLayout.addSpacing(40) + self.informationLabel = QtGui.QLabel(self.welcomePage) + self.informationLabel.setWordWrap(True) + self.informationLabel.setObjectName(u'InformationLabel') + self.welcomeLayout.addWidget(self.informationLabel) + self.welcomeLayout.addStretch() + self.addPage(self.welcomePage) + + def addProgressPage(self): + """ + Add the progress page for the wizard. This page informs the user how + the wizard is progressing with its task. + """ + self.progressPage = QtGui.QWizardPage() + self.progressPage.setObjectName(u'progressPage') + self.progressLayout = QtGui.QVBoxLayout(self.progressPage) + self.progressLayout.setMargin(48) + self.progressLayout.setObjectName(u'progressLayout') + self.progressLabel = QtGui.QLabel(self.progressPage) + self.progressLabel.setObjectName(u'progressLabel') + self.progressLayout.addWidget(self.progressLabel) + self.progressBar = QtGui.QProgressBar(self.progressPage) + self.progressBar.setObjectName(u'progressBar') + self.progressLayout.addWidget(self.progressBar) + self.addPage(self.progressPage) + + def exec_(self): + """ + Run the wizard. + """ + self.setDefaults() + return QtGui.QWizard.exec_(self) + + def reject(self): + """ + Stop the wizard on cancel button, close button or ESC key. + """ + log.debug(u'Wizard cancelled by user.') + if self.currentPage() == self.progressPage: + Receiver.send_message(u'openlp_stop_wizard') + self.done(QtGui.QDialog.Rejected) + + def onCurrentIdChanged(self, pageId): + """ + Perform necessary functions depending on which wizard page is active. + """ + if self.page(pageId) == self.progressPage: + self.preWizard() + self.performWizard() + self.postWizard() + + def incrementProgressBar(self, status_text, increment=1): + """ + Update the wizard progress page. + + ``status_text`` + Current status information to display. + + ``increment`` + The value to increment the progress bar by. + """ + log.debug(u'IncrementBar %s', status_text) + self.progressLabel.setText(status_text) + if increment > 0: + self.progressBar.setValue(self.progressBar.value() + increment) + Receiver.send_message(u'openlp_process_events') + + def preWizard(self): + """ + Prepare the UI for the import. + """ + self.finishButton.setVisible(False) + self.progressBar.setMinimum(0) + self.progressBar.setMaximum(1188) + self.progressBar.setValue(0) + + def postWizard(self): + """ + Clean up the UI after the import has finished. + """ + self.progressBar.setValue(self.progressBar.maximum()) + self.finishButton.setVisible(True) + self.cancelButton.setVisible(False) + Receiver.send_message(u'openlp_process_events') diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 75f00f298..d8012f433 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -337,9 +337,28 @@ def file_is_unicode(filename): return None return ucsfile +def string_is_unicode(test_string): + """ + Makes sure a string is unicode. + + ``test_string`` + The string to confirm is unicode. + """ + return_string = u'' + if not test_string: + return return_string + if isinstance(test_string, unicode): + return_string = test_string + if not isinstance(test_string, unicode): + try: + return_string = unicode(test_string, u'utf-8') + except UnicodeError: + log.exception("Error encoding string to unicode") + return return_string + from languagemanager import LanguageManager from actions import ActionList __all__ = [u'AppLocation', u'check_latest_version', u'add_actions', u'get_filesystem_encoding', u'LanguageManager', u'ActionList', - u'get_web_page', u'file_is_unicode'] + u'get_web_page', u'file_is_unicode', u'string_is_unicode'] diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index 4590ea739..d79051126 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -23,7 +23,9 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### - +""" +The bible import functions for OpenLP +""" import csv import logging import os @@ -31,15 +33,18 @@ import os.path from PyQt4 import QtCore, QtGui -from bibleimportwizard import Ui_BibleImportWizard from openlp.core.lib import Receiver, SettingsManager, translate from openlp.core.lib.db import delete_database -from openlp.core.utils import AppLocation +from openlp.core.ui.wizard import OpenLPWizard +from openlp.core.utils import AppLocation, string_is_unicode from openlp.plugins.bibles.lib.manager import BibleFormat log = logging.getLogger(__name__) class WebDownload(object): + """ + Provides an enumeration for the web bible types available to OpenLP. + """ Unknown = -1 Crosswalk = 0 BibleGateway = 1 @@ -53,10 +58,13 @@ class WebDownload(object): @classmethod def get_name(cls, name): + """ + Get the web bible type name. + """ return cls.Names[name] -class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): +class BibleImportForm(OpenLPWizard): """ This is the Bible Import Wizard, which allows easy importing of Bibles into OpenLP from other formats like OSIS, CSV and OpenSong. @@ -76,27 +84,42 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): ``bibleplugin`` The Bible plugin. """ - QtGui.QWizard.__init__(self, parent) - self.setupUi(self) - self.registerFields() + self.manager = manager + self.web_bible_list = {} + OpenLPWizard.__init__(self, parent, bibleplugin, u'bibleImportWizard', + u':/wizards/wizard_importbible.bmp') + + def setupUi(self, image): + """ + Set up the UI for the bible wizard. + """ + OpenLPWizard.setupUi(self, image) + QtCore.QObject.connect(self.formatComboBox, + QtCore.SIGNAL(u'currentIndexChanged(int)'), self.selectStack, + QtCore.SLOT(u'setCurrentIndex(int)')) + + def customInit(self): + """ + Perform any custom initialisation for bible importing. + """ if BibleFormat.get_availability(BibleFormat.OpenLP1): self.openlp1DisabledLabel.hide() else: self.openlp1FileLabel.hide() self.openlp1FileEdit.hide() self.openlp1BrowseButton.hide() - self.finishButton = self.button(QtGui.QWizard.FinishButton) - self.cancelButton = self.button(QtGui.QWizard.CancelButton) - self.manager = manager - self.bibleplugin = bibleplugin self.manager.set_process_dialog(self) - self.web_bible_list = {} self.loadWebBibles() self.restart() self.selectStack.setCurrentIndex(0) + + def customSignals(self): + """ + Set up the signals used in the bible importer. + """ QtCore.QObject.connect(self.webSourceComboBox, QtCore.SIGNAL(u'currentIndexChanged(int)'), - self.onWebSourceComboBoxCurrentIndexChanged) + self.onWebSourceComboBoxIndexChanged) QtCore.QObject.connect(self.osisBrowseButton, QtCore.SIGNAL(u'clicked()'), self.onOsisBrowseButtonClicked) @@ -112,25 +135,329 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): QtCore.QObject.connect(self.openlp1BrowseButton, QtCore.SIGNAL(u'clicked()'), self.onOpenlp1BrowseButtonClicked) - QtCore.QObject.connect(self, - QtCore.SIGNAL(u'currentIdChanged(int)'), - self.onCurrentIdChanged) - def exec_(self): + def addCustomPages(self): """ - Run the wizard. + Add the bible import specific wizard pages. """ - self.setDefaults() - return QtGui.QWizard.exec_(self) + # Select Page + self.selectPage = QtGui.QWizardPage() + self.selectPage.setObjectName(u'SelectPage') + self.selectPageLayout = QtGui.QVBoxLayout(self.selectPage) + self.selectPageLayout.setObjectName(u'SelectPageLayout') + self.formatLayout = QtGui.QFormLayout() + self.formatLayout.setObjectName(u'FormatLayout') + self.formatLabel = QtGui.QLabel(self.selectPage) + self.formatLabel.setObjectName(u'FormatLabel') + self.formatComboBox = QtGui.QComboBox(self.selectPage) + self.formatComboBox.addItems([u'', u'', u'', u'', u'']) + self.formatComboBox.setObjectName(u'FormatComboBox') + self.formatLayout.addRow(self.formatLabel, self.formatComboBox) + self.formatSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, + QtGui.QSizePolicy.Minimum) + self.formatLayout.setItem(1, QtGui.QFormLayout.LabelRole, + self.formatSpacer) + self.selectPageLayout.addLayout(self.formatLayout) + self.selectStack = QtGui.QStackedLayout() + self.selectStack.setObjectName(u'SelectStack') + self.osisWidget = QtGui.QWidget(self.selectPage) + self.osisWidget.setObjectName(u'OsisWidget') + self.osisLayout = QtGui.QFormLayout(self.osisWidget) + self.osisLayout.setMargin(0) + self.osisLayout.setObjectName(u'OsisLayout') + self.osisFileLabel = QtGui.QLabel(self.osisWidget) + self.osisFileLabel.setObjectName(u'OsisFileLabel') + self.osisFileLayout = QtGui.QHBoxLayout() + self.osisFileLayout.setObjectName(u'OsisFileLayout') + self.osisFileEdit = QtGui.QLineEdit(self.osisWidget) + self.osisFileEdit.setObjectName(u'OsisFileEdit') + self.osisFileLayout.addWidget(self.osisFileEdit) + self.osisBrowseButton = QtGui.QToolButton(self.osisWidget) + self.osisBrowseButton.setIcon(self.openIcon) + self.osisBrowseButton.setObjectName(u'OsisBrowseButton') + self.osisFileLayout.addWidget(self.osisBrowseButton) + self.osisLayout.addRow(self.osisFileLabel, self.osisFileLayout) + self.osisSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, + QtGui.QSizePolicy.Minimum) + self.osisLayout.setItem(1, QtGui.QFormLayout.LabelRole, self.osisSpacer) + self.selectStack.addWidget(self.osisWidget) + self.csvWidget = QtGui.QWidget(self.selectPage) + self.csvWidget.setObjectName(u'CsvWidget') + self.csvLayout = QtGui.QFormLayout(self.csvWidget) + self.csvLayout.setMargin(0) + self.csvLayout.setObjectName(u'CsvLayout') + self.csvBooksLabel = QtGui.QLabel(self.csvWidget) + self.csvBooksLabel.setObjectName(u'CsvBooksLabel') + self.csvBooksLayout = QtGui.QHBoxLayout() + self.csvBooksLayout.setObjectName(u'CsvBooksLayout') + self.csvBooksEdit = QtGui.QLineEdit(self.csvWidget) + self.csvBooksEdit.setObjectName(u'CsvBooksEdit') + self.csvBooksLayout.addWidget(self.csvBooksEdit) + self.csvBooksButton = QtGui.QToolButton(self.csvWidget) + self.csvBooksButton.setIcon(self.openIcon) + self.csvBooksButton.setObjectName(u'CsvBooksButton') + self.csvBooksLayout.addWidget(self.csvBooksButton) + self.csvLayout.addRow(self.csvBooksLabel, self.csvBooksLayout) + self.csvVersesLabel = QtGui.QLabel(self.csvWidget) + self.csvVersesLabel.setObjectName(u'CsvVersesLabel') + self.csvVersesLayout = QtGui.QHBoxLayout() + self.csvVersesLayout.setObjectName(u'CsvVersesLayout') + self.csvVersesEdit = QtGui.QLineEdit(self.csvWidget) + self.csvVersesEdit.setObjectName(u'CsvVersesEdit') + self.csvVersesLayout.addWidget(self.csvVersesEdit) + self.csvVersesButton = QtGui.QToolButton(self.csvWidget) + self.csvVersesButton.setIcon(self.openIcon) + self.csvVersesButton.setObjectName(u'CsvVersesButton') + self.csvVersesLayout.addWidget(self.csvVersesButton) + self.csvLayout.addRow(self.csvVersesLabel, self.csvVersesLayout) + self.csvSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, + QtGui.QSizePolicy.Minimum) + self.csvLayout.setItem(2, QtGui.QFormLayout.LabelRole, self.csvSpacer) + self.selectStack.addWidget(self.csvWidget) + self.openSongWidget = QtGui.QWidget(self.selectPage) + self.openSongWidget.setObjectName(u'OpenSongWidget') + self.openSongLayout = QtGui.QFormLayout(self.openSongWidget) + self.openSongLayout.setMargin(0) + self.openSongLayout.setObjectName(u'OpenSongLayout') + self.openSongFileLabel = QtGui.QLabel(self.openSongWidget) + self.openSongFileLabel.setObjectName(u'OpenSongFileLabel') + self.openSongFileLayout = QtGui.QHBoxLayout() + self.openSongFileLayout.setObjectName(u'OpenSongFileLayout') + self.openSongFileEdit = QtGui.QLineEdit(self.openSongWidget) + self.openSongFileEdit.setObjectName(u'OpenSongFileEdit') + self.openSongFileLayout.addWidget(self.openSongFileEdit) + self.openSongBrowseButton = QtGui.QToolButton(self.openSongWidget) + self.openSongBrowseButton.setIcon(self.openIcon) + self.openSongBrowseButton.setObjectName(u'OpenSongBrowseButton') + self.openSongFileLayout.addWidget(self.openSongBrowseButton) + self.openSongLayout.addRow(self.openSongFileLabel, + self.openSongFileLayout) + self.openSongSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, + QtGui.QSizePolicy.Minimum) + self.openSongLayout.setItem(1, QtGui.QFormLayout.LabelRole, + self.openSongSpacer) + self.selectStack.addWidget(self.openSongWidget) + self.webTabWidget = QtGui.QTabWidget(self.selectPage) + self.webTabWidget.setObjectName(u'WebTabWidget') + self.webBibleTab = QtGui.QWidget() + self.webBibleTab.setObjectName(u'WebBibleTab') + self.webBibleLayout = QtGui.QFormLayout(self.webBibleTab) + self.webBibleLayout.setObjectName(u'WebBibleLayout') + self.webSourceLabel = QtGui.QLabel(self.webBibleTab) + self.webSourceLabel.setObjectName(u'WebSourceLabel') + self.webBibleLayout.setWidget(0, QtGui.QFormLayout.LabelRole, + self.webSourceLabel) + self.webSourceComboBox = QtGui.QComboBox(self.webBibleTab) + self.webSourceComboBox.setObjectName(u'WebSourceComboBox') + self.webSourceComboBox.addItems([u'', u'', u'']) + self.webBibleLayout.setWidget(0, QtGui.QFormLayout.FieldRole, + self.webSourceComboBox) + self.webTranslationLabel = QtGui.QLabel(self.webBibleTab) + self.webTranslationLabel.setObjectName(u'webTranslationLabel') + self.webBibleLayout.setWidget(1, QtGui.QFormLayout.LabelRole, + self.webTranslationLabel) + self.webTranslationComboBox = QtGui.QComboBox(self.webBibleTab) + self.webTranslationComboBox.setSizeAdjustPolicy( + QtGui.QComboBox.AdjustToContents) + self.webTranslationComboBox.setObjectName(u'WebTranslationComboBox') + self.webBibleLayout.setWidget(1, QtGui.QFormLayout.FieldRole, + self.webTranslationComboBox) + self.webTabWidget.addTab(self.webBibleTab, u'') + self.webProxyTab = QtGui.QWidget() + self.webProxyTab.setObjectName(u'WebProxyTab') + self.webProxyLayout = QtGui.QFormLayout(self.webProxyTab) + self.webProxyLayout.setObjectName(u'WebProxyLayout') + self.webServerLabel = QtGui.QLabel(self.webProxyTab) + self.webServerLabel.setObjectName(u'WebServerLabel') + self.webProxyLayout.setWidget(0, QtGui.QFormLayout.LabelRole, + self.webServerLabel) + self.webServerEdit = QtGui.QLineEdit(self.webProxyTab) + self.webServerEdit.setObjectName(u'WebServerEdit') + self.webProxyLayout.setWidget(0, QtGui.QFormLayout.FieldRole, + self.webServerEdit) + self.webUserLabel = QtGui.QLabel(self.webProxyTab) + self.webUserLabel.setObjectName(u'WebUserLabel') + self.webProxyLayout.setWidget(1, QtGui.QFormLayout.LabelRole, + self.webUserLabel) + self.webUserEdit = QtGui.QLineEdit(self.webProxyTab) + self.webUserEdit.setObjectName(u'WebUserEdit') + self.webProxyLayout.setWidget(1, QtGui.QFormLayout.FieldRole, + self.webUserEdit) + self.webPasswordLabel = QtGui.QLabel(self.webProxyTab) + self.webPasswordLabel.setObjectName(u'WebPasswordLabel') + self.webProxyLayout.setWidget(2, QtGui.QFormLayout.LabelRole, + self.webPasswordLabel) + self.webPasswordEdit = QtGui.QLineEdit(self.webProxyTab) + self.webPasswordEdit.setObjectName(u'WebPasswordEdit') + self.webProxyLayout.setWidget(2, QtGui.QFormLayout.FieldRole, + self.webPasswordEdit) + self.webTabWidget.addTab(self.webProxyTab, u'') + self.selectStack.addWidget(self.webTabWidget) + self.openlp1Widget = QtGui.QWidget(self.selectPage) + self.openlp1Widget.setObjectName(u'Openlp1Widget') + self.openlp1Layout = QtGui.QFormLayout(self.openlp1Widget) + self.openlp1Layout.setMargin(0) + self.openlp1Layout.setObjectName(u'Openlp1Layout') + self.openlp1FileLabel = QtGui.QLabel(self.openlp1Widget) + self.openlp1FileLabel.setObjectName(u'Openlp1FileLabel') + self.openlp1FileLayout = QtGui.QHBoxLayout() + self.openlp1FileLayout.setObjectName(u'Openlp1FileLayout') + self.openlp1FileEdit = QtGui.QLineEdit(self.openlp1Widget) + self.openlp1FileEdit.setObjectName(u'Openlp1FileEdit') + self.openlp1FileLayout.addWidget(self.openlp1FileEdit) + self.openlp1BrowseButton = QtGui.QToolButton(self.openlp1Widget) + self.openlp1BrowseButton.setIcon(self.openIcon) + self.openlp1BrowseButton.setObjectName(u'Openlp1BrowseButton') + self.openlp1FileLayout.addWidget(self.openlp1BrowseButton) + self.openlp1Layout.addRow(self.openlp1FileLabel, self.openlp1FileLayout) + self.openlp1DisabledLabel = QtGui.QLabel(self.openlp1Widget) + self.openlp1DisabledLabel.setWordWrap(True) + self.openlp1DisabledLabel.setObjectName(u'Openlp1DisabledLabel') + self.openlp1Layout.addRow(self.openlp1DisabledLabel) + self.openlp1Spacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, + QtGui.QSizePolicy.Minimum) + self.openlp1Layout.setItem(1, QtGui.QFormLayout.LabelRole, + self.openlp1Spacer) + self.selectStack.addWidget(self.openlp1Widget) + self.selectPageLayout.addLayout(self.selectStack) + self.addPage(self.selectPage) + # License Page + self.licenseDetailsPage = QtGui.QWizardPage() + self.licenseDetailsPage.setObjectName(u'LicenseDetailsPage') + self.licenseDetailsLayout = QtGui.QFormLayout(self.licenseDetailsPage) + self.licenseDetailsLayout.setObjectName(u'LicenseDetailsLayout') + self.versionNameLabel = QtGui.QLabel(self.licenseDetailsPage) + self.versionNameLabel.setObjectName(u'VersionNameLabel') + self.licenseDetailsLayout.setWidget(0, QtGui.QFormLayout.LabelRole, + self.versionNameLabel) + self.versionNameEdit = QtGui.QLineEdit(self.licenseDetailsPage) + self.versionNameEdit.setObjectName(u'VersionNameEdit') + self.licenseDetailsLayout.setWidget(0, QtGui.QFormLayout.FieldRole, + self.versionNameEdit) + self.copyrightLabel = QtGui.QLabel(self.licenseDetailsPage) + self.copyrightLabel.setObjectName(u'CopyrightLabel') + self.licenseDetailsLayout.setWidget(1, QtGui.QFormLayout.LabelRole, + self.copyrightLabel) + self.copyrightEdit = QtGui.QLineEdit(self.licenseDetailsPage) + self.copyrightEdit.setObjectName(u'CopyrightEdit') + self.licenseDetailsLayout.setWidget(1, QtGui.QFormLayout.FieldRole, + self.copyrightEdit) + self.permissionsLabel = QtGui.QLabel(self.licenseDetailsPage) + self.permissionsLabel.setObjectName(u'PermissionsLabel') + self.licenseDetailsLayout.setWidget(2, QtGui.QFormLayout.LabelRole, + self.permissionsLabel) + self.permissionsEdit = QtGui.QLineEdit(self.licenseDetailsPage) + self.permissionsEdit.setObjectName(u'PermissionsEdit') + self.licenseDetailsLayout.setWidget(2, QtGui.QFormLayout.FieldRole, + self.permissionsEdit) + self.addPage(self.licenseDetailsPage) - def reject(self): + def retranslateUi(self): """ - Stop the import on cancel button, close button or ESC key. + Allow for localisation of the bible import wizard. """ - log.debug(u'Import canceled by user.') - if self.currentPage() == self.importPage: - Receiver.send_message(u'bibles_stop_import') - self.done(QtGui.QDialog.Rejected) + self.setWindowTitle( + translate('BiblesPlugin.ImportWizardForm', 'Bible Import Wizard')) + self.titleLabel.setText( + u'%s' % \ + translate('BiblesPlugin.ImportWizardForm', + 'Welcome to the Bible Import Wizard')) + self.informationLabel.setText( + translate('BiblesPlugin.ImportWizardForm', + 'This wizard will help you to import Bibles from a ' + 'variety of formats. Click the next button below to start the ' + 'process by selecting a format to import from.')) + self.selectPage.setTitle(translate('BiblesPlugin.ImportWizardForm', + 'Select Import Source')) + self.selectPage.setSubTitle( + translate('BiblesPlugin.ImportWizardForm', + 'Select the import format, and where to import from.')) + self.formatLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'Format:')) + self.formatComboBox.setItemText(0, + translate('BiblesPlugin.ImportWizardForm', 'OSIS')) + self.formatComboBox.setItemText(1, + translate('BiblesPlugin.ImportWizardForm', 'CSV')) + self.formatComboBox.setItemText(2, + translate('BiblesPlugin.ImportWizardForm', 'OpenSong')) + self.formatComboBox.setItemText(3, + translate('BiblesPlugin.ImportWizardForm', 'Web Download')) + self.formatComboBox.setItemText(4, + translate('BiblesPlugin.ImportWizardForm', 'openlp.org 1.x')) + self.openlp1FileLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'File location:')) + self.osisFileLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'File location:')) + self.csvBooksLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'Books location:')) + self.csvVersesLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'Verse location:')) + self.openSongFileLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'Bible filename:')) + self.webSourceLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'Location:')) + self.webSourceComboBox.setItemText(0, + translate('BiblesPlugin.ImportWizardForm', 'Crosswalk')) + self.webSourceComboBox.setItemText(1, + translate('BiblesPlugin.ImportWizardForm', 'BibleGateway')) + self.webSourceComboBox.setItemText(2, + translate('BiblesPlugin.ImportWizardForm', 'Bibleserver')) + self.webTranslationLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'Bible:')) + self.webTabWidget.setTabText( + self.webTabWidget.indexOf(self.webBibleTab), + translate('BiblesPlugin.ImportWizardForm', 'Download Options')) + self.webServerLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'Server:')) + self.webUserLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'Username:')) + self.webPasswordLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'Password:')) + self.webTabWidget.setTabText( + self.webTabWidget.indexOf(self.webProxyTab), + translate('BiblesPlugin.ImportWizardForm', + 'Proxy Server (Optional)')) + self.licenseDetailsPage.setTitle( + translate('BiblesPlugin.ImportWizardForm', 'License Details')) + self.licenseDetailsPage.setSubTitle( + translate('BiblesPlugin.ImportWizardForm', + 'Set up the Bible\'s license details.')) + self.versionNameLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'Version name:')) + self.copyrightLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'Copyright:')) + self.permissionsLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'Permissions:')) + self.progressPage.setTitle( + translate('BiblesPlugin.ImportWizardForm', 'Importing')) + self.progressPage.setSubTitle( + translate('BiblesPlugin.ImportWizardForm', + 'Please wait while your Bible is imported.')) + self.progressLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'Ready.')) + self.progressBar.setFormat(u'%p%') + self.openlp1DisabledLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'The openlp.org 1.x ' + 'importer has been disabled due to a missing Python module. If ' + 'you want to use this importer, you will need to install the ' + '"python-sqlite" module.')) + # Align all QFormLayouts towards each other. + labelWidth = max(self.formatLabel.minimumSizeHint().width(), + self.osisFileLabel.minimumSizeHint().width(), + self.csvBooksLabel.minimumSizeHint().width(), + self.csvVersesLabel.minimumSizeHint().width(), + self.openSongFileLabel.minimumSizeHint().width(), + self.openlp1FileLabel.minimumSizeHint().width()) + self.formatSpacer.changeSize(labelWidth, 0, + QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + self.osisSpacer.changeSize(labelWidth, 0, + QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + self.csvSpacer.changeSize(labelWidth, 0, + QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + self.openSongSpacer.changeSize(labelWidth, 0, + QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + self.openlp1Spacer.changeSize(labelWidth, 0, + QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) def validateCurrentPage(self): """ @@ -220,10 +547,10 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): self.versionNameEdit.setFocus() return False return True - if self.currentPage() == self.importPage: + if self.currentPage() == self.progressPage: return True - def onWebSourceComboBoxCurrentIndexChanged(self, index): + def onWebSourceComboBoxIndexChanged(self, index): """ Setup the list of Bibles when you select a different source on the web download page. @@ -279,13 +606,10 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): u'%s (*.bible)' % translate('BiblesPlugin.ImportWizardForm', 'openlp.org 1.x bible')) - def onCurrentIdChanged(self, pageId): - if self.page(pageId) == self.importPage: - self.preImport() - self.performImport() - self.postImport() - def registerFields(self): + """ + Register the bible import wizard fields. + """ self.selectPage.registerField(u'source_format', self.formatComboBox) self.selectPage.registerField(u'osis_location', self.osisFileEdit) self.selectPage.registerField(u'csv_booksfile', self.csvBooksEdit) @@ -306,8 +630,11 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): u'license_permissions', self.permissionsEdit) def setDefaults(self): + """ + Set default values for the wizard pages. + """ settings = QtCore.QSettings() - settings.beginGroup(self.bibleplugin.settingsSection) + settings.beginGroup(self.plugin.settingsSection) self.restart() self.finishButton.setVisible(False) self.cancelButton.setVisible(True) @@ -332,72 +659,50 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): QtCore.QVariant(self.copyrightEdit.text())) self.setField(u'license_permissions', QtCore.QVariant(self.permissionsEdit.text())) - self.onWebSourceComboBoxCurrentIndexChanged(WebDownload.Crosswalk) + self.onWebSourceComboBoxIndexChanged(WebDownload.Crosswalk) settings.endGroup() def loadWebBibles(self): """ - Load the list of Crosswalk and BibleGateway bibles. + Load the lists of Crosswalk, BibleGateway and Bibleserver bibles. """ + filepath = AppLocation.get_directory(AppLocation.PluginsDir) + filepath = os.path.join(filepath, u'bibles', u'resources') # Load Crosswalk Bibles. - filepath = AppLocation.get_directory(AppLocation.PluginsDir) - filepath = os.path.join(filepath, u'bibles', u'resources') - books_file = None - try: - self.web_bible_list[WebDownload.Crosswalk] = {} - books_file = open( - os.path.join(filepath, u'crosswalkbooks.csv'), 'rb') - dialect = csv.Sniffer().sniff(books_file.read(1024)) - books_file.seek(0) - books_reader = csv.reader(books_file, dialect) - for line in books_reader: - ver = unicode(line[0], u'utf-8') - name = unicode(line[1], u'utf-8') - self.web_bible_list[WebDownload.Crosswalk][ver] = name.strip() - except IOError: - log.exception(u'Crosswalk resources missing') - finally: - if books_file: - books_file.close() + self.loadBibleResourceFile( + os.path.join(filepath, u'crosswalkbooks.csv'), + WebDownload.Crosswalk) # Load BibleGateway Bibles. - books_file = None - try: - self.web_bible_list[WebDownload.BibleGateway] = {} - books_file = open(os.path.join(filepath, u'biblegateway.csv'), 'r') - dialect = csv.Sniffer().sniff(books_file.read(1024)) - books_file.seek(0) - books_reader = csv.reader(books_file, dialect) - for line in books_reader: - ver = line[0] - name = line[1] - if not isinstance(ver, unicode): - ver = unicode(ver, u'utf8') - if not isinstance(name, unicode): - name = unicode(name, u'utf8') - self.web_bible_list[WebDownload.BibleGateway][ver] = \ - name.strip() - except IOError: - log.exception(u'Biblegateway resources missing') - finally: - if books_file: - books_file.close() + self.loadBibleResourceFile(os.path.join(filepath, u'biblegateway.csv'), + WebDownload.BibleGateway) # Load and Bibleserver Bibles. - filepath = AppLocation.get_directory(AppLocation.PluginsDir) - filepath = os.path.join(filepath, u'bibles', u'resources') + self.loadBibleResourceFile(os.path.join(filepath, u'bibleserver.csv'), + WebDownload.Bibleserver) + + def loadBibleResourceFile(self, file_path_name, download_type): + """ + Loads a web bible resource file. + + ``file_path_name`` + The file to load including the file's path. + + ``download_type`` + The WebDownload type this file is for. + """ + self.web_bible_list[download_type] = {} books_file = None try: - self.web_bible_list[WebDownload.Bibleserver] = {} - books_file = open( - os.path.join(filepath, u'bibleserver.csv'), 'rb') + books_file = open(file_path_name, 'rb') dialect = csv.Sniffer().sniff(books_file.read(1024)) books_file.seek(0) books_reader = csv.reader(books_file, dialect) for line in books_reader: - ver = unicode(line[0], u'utf-8') - name = unicode(line[1], u'utf-8') - self.web_bible_list[WebDownload.Bibleserver][ver] = name.strip() - except IOError, UnicodeError: - log.exception(u'Bibleserver resources missing') + ver = string_is_unicode(line[0]) + name = string_is_unicode(line[1]) + self.web_bible_list[download_type][ver] = name.strip() + except IOError: + log.exception(u'%s resources missing' % + WebDownload.get_name(download_type)) finally: if books_file: books_file.close() @@ -413,8 +718,8 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): A editbox (QLineEdit). ``filters`` - The file extension filters. It should contain the file description as - well as the file extension. For example:: + The file extension filters. It should contain the file description + as well as the file extension. For example:: u'openlp.org 1.x bible (*.bible)' """ @@ -424,37 +729,28 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): 'All Files') filename = QtGui.QFileDialog.getOpenFileName(self, title, os.path.dirname(SettingsManager.get_last_dir( - self.bibleplugin.settingsSection, 1)), filters) + self.plugin.settingsSection, 1)), filters) if filename: editbox.setText(filename) SettingsManager.set_last_dir( - self.bibleplugin.settingsSection, filename, 1) + self.plugin.settingsSection, filename, 1) - def incrementProgressBar(self, status_text): - log.debug(u'IncrementBar %s', status_text) - self.importProgressLabel.setText(status_text) - self.importProgressBar.setValue(self.importProgressBar.value() + 1) - Receiver.send_message(u'openlp_process_events') - - def preImport(self): + def preWizard(self): """ Prepare the UI for the import. """ + OpenLPWizard.preWizard(self) bible_type = self.field(u'source_format').toInt()[0] - self.finishButton.setVisible(False) - self.importProgressBar.setMinimum(0) - self.importProgressBar.setMaximum(1188) - self.importProgressBar.setValue(0) if bible_type == BibleFormat.WebDownload: - self.importProgressLabel.setText(translate( + self.progressLabel.setText(translate( 'BiblesPlugin.ImportWizardForm', 'Starting Registering bible...')) else: - self.importProgressLabel.setText(translate( + self.progressLabel.setText(translate( 'BiblesPlugin.ImportWizardForm', 'Starting import...')) Receiver.send_message(u'openlp_process_events') - def performImport(self): + def performWizard(self): """ Perform the actual import. """ @@ -485,7 +781,7 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): ) elif bible_type == BibleFormat.WebDownload: # Import a bible from the web. - self.importProgressBar.setMaximum(1) + self.progressBar.setMaximum(1) download_location = self.field(u'web_location').toInt()[0] bible_version = unicode(self.webTranslationComboBox.currentText()) if download_location == WebDownload.Crosswalk: @@ -518,20 +814,14 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): license_copyright, license_permissions) self.manager.reload_bibles() if bible_type == BibleFormat.WebDownload: - self.importProgressLabel.setText( + self.progressLabel.setText( translate('BiblesPlugin.ImportWizardForm', 'Registered ' 'bible. Please note, that verses will be downloaded on\n' 'demand and thus an internet connection is required.')) else: - self.importProgressLabel.setText(translate( + self.progressLabel.setText(translate( 'BiblesPlugin.ImportWizardForm', 'Finished import.')) else: - self.importProgressLabel.setText(translate( + self.progressLabel.setText(translate( 'BiblesPlugin.ImportWizardForm', 'Your Bible import failed.')) - delete_database(self.bibleplugin.settingsSection, importer.file) - - def postImport(self): - self.importProgressBar.setValue(self.importProgressBar.maximum()) - self.finishButton.setVisible(True) - self.cancelButton.setVisible(False) - Receiver.send_message(u'openlp_process_events') + delete_database(self.plugin.settingsSection, importer.file) diff --git a/openlp/plugins/bibles/forms/bibleimportwizard.py b/openlp/plugins/bibles/forms/bibleimportwizard.py deleted file mode 100644 index c6a6775a5..000000000 --- a/openlp/plugins/bibles/forms/bibleimportwizard.py +++ /dev/null @@ -1,391 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2011 Raoul Snyman # -# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael # -# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian # -# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, # -# Carsten Tinggaard, Frode Woldsund # -# --------------------------------------------------------------------------- # -# This program is free software; you can redistribute it and/or modify it # -# under the terms of the GNU General Public License as published by the Free # -# Software Foundation; version 2 of the License. # -# # -# This program is distributed in the hope that it will be useful, but WITHOUT # -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # -# more details. # -# # -# You should have received a copy of the GNU General Public License along # -# with this program; if not, write to the Free Software Foundation, Inc., 59 # -# Temple Place, Suite 330, Boston, MA 02111-1307 USA # -############################################################################### - -from PyQt4 import QtCore, QtGui - -from openlp.core.lib import build_icon, translate - -class Ui_BibleImportWizard(object): - def setupUi(self, bibleImportWizard): - bibleImportWizard.setObjectName(u'bibleImportWizard') - bibleImportWizard.setModal(True) - bibleImportWizard.setWizardStyle(QtGui.QWizard.ModernStyle) - bibleImportWizard.setOptions( - QtGui.QWizard.IndependentPages | - QtGui.QWizard.NoBackButtonOnStartPage | - QtGui.QWizard.NoBackButtonOnLastPage) - # Welcome Page - self.welcomePage = QtGui.QWizardPage() - self.welcomePage.setPixmap(QtGui.QWizard.WatermarkPixmap, - QtGui.QPixmap(u':/wizards/wizard_importbible.bmp')) - self.welcomePage.setObjectName(u'WelcomePage') - self.welcomeLayout = QtGui.QVBoxLayout(self.welcomePage) - self.welcomeLayout.setObjectName(u'WelcomeLayout') - self.titleLabel = QtGui.QLabel(self.welcomePage) - self.titleLabel.setObjectName(u'TitleLabel') - self.welcomeLayout.addWidget(self.titleLabel) - self.welcomeLayout.addSpacing(40) - self.informationLabel = QtGui.QLabel(self.welcomePage) - self.informationLabel.setWordWrap(True) - self.informationLabel.setObjectName(u'InformationLabel') - self.welcomeLayout.addWidget(self.informationLabel) - self.welcomeLayout.addStretch() - bibleImportWizard.addPage(self.welcomePage) - # Select Page - self.selectPage = QtGui.QWizardPage() - self.selectPage.setObjectName(u'SelectPage') - self.selectPageLayout = QtGui.QVBoxLayout(self.selectPage) - self.selectPageLayout.setObjectName(u'SelectPageLayout') - self.formatLayout = QtGui.QFormLayout() - self.formatLayout.setObjectName(u'FormatLayout') - self.formatLabel = QtGui.QLabel(self.selectPage) - self.formatLabel.setObjectName(u'FormatLabel') - self.formatComboBox = QtGui.QComboBox(self.selectPage) - self.formatComboBox.addItems([u'', u'', u'', u'', u'']) - self.formatComboBox.setObjectName(u'FormatComboBox') - self.formatLayout.addRow(self.formatLabel, self.formatComboBox) - self.formatSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, - QtGui.QSizePolicy.Minimum) - self.formatLayout.setItem(1, QtGui.QFormLayout.LabelRole, - self.formatSpacer) - self.selectPageLayout.addLayout(self.formatLayout) - self.selectStack = QtGui.QStackedLayout() - self.selectStack.setObjectName(u'SelectStack') - self.osisWidget = QtGui.QWidget(self.selectPage) - self.osisWidget.setObjectName(u'OsisWidget') - self.osisLayout = QtGui.QFormLayout(self.osisWidget) - self.osisLayout.setMargin(0) - self.osisLayout.setObjectName(u'OsisLayout') - self.osisFileLabel = QtGui.QLabel(self.osisWidget) - self.osisFileLabel.setObjectName(u'OsisFileLabel') - self.osisFileLayout = QtGui.QHBoxLayout() - self.osisFileLayout.setObjectName(u'OsisFileLayout') - self.osisFileEdit = QtGui.QLineEdit(self.osisWidget) - self.osisFileEdit.setObjectName(u'OsisFileEdit') - self.osisFileLayout.addWidget(self.osisFileEdit) - self.osisBrowseButton = QtGui.QToolButton(self.osisWidget) - self.osisBrowseButton.setIcon(build_icon(u':/general/general_open.png')) - self.osisBrowseButton.setObjectName(u'OsisBrowseButton') - self.osisFileLayout.addWidget(self.osisBrowseButton) - self.osisLayout.addRow(self.osisFileLabel, self.osisFileLayout) - self.osisSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, - QtGui.QSizePolicy.Minimum) - self.osisLayout.setItem(1, QtGui.QFormLayout.LabelRole, self.osisSpacer) - self.selectStack.addWidget(self.osisWidget) - self.csvWidget = QtGui.QWidget(self.selectPage) - self.csvWidget.setObjectName(u'CsvWidget') - self.csvLayout = QtGui.QFormLayout(self.csvWidget) - self.csvLayout.setMargin(0) - self.csvLayout.setObjectName(u'CsvLayout') - self.csvBooksLabel = QtGui.QLabel(self.csvWidget) - self.csvBooksLabel.setObjectName(u'CsvBooksLabel') - self.csvBooksLayout = QtGui.QHBoxLayout() - self.csvBooksLayout.setObjectName(u'CsvBooksLayout') - self.csvBooksEdit = QtGui.QLineEdit(self.csvWidget) - self.csvBooksEdit.setObjectName(u'CsvBooksEdit') - self.csvBooksLayout.addWidget(self.csvBooksEdit) - self.csvBooksButton = QtGui.QToolButton(self.csvWidget) - self.csvBooksButton.setIcon(build_icon(u':/general/general_open.png')) - self.csvBooksButton.setObjectName(u'CsvBooksButton') - self.csvBooksLayout.addWidget(self.csvBooksButton) - self.csvLayout.addRow(self.csvBooksLabel, self.csvBooksLayout) - self.csvVersesLabel = QtGui.QLabel(self.csvWidget) - self.csvVersesLabel.setObjectName(u'CsvVersesLabel') - self.csvVersesLayout = QtGui.QHBoxLayout() - self.csvVersesLayout.setObjectName(u'CsvVersesLayout') - self.csvVersesEdit = QtGui.QLineEdit(self.csvWidget) - self.csvVersesEdit.setObjectName(u'CsvVersesEdit') - self.csvVersesLayout.addWidget(self.csvVersesEdit) - self.csvVersesButton = QtGui.QToolButton(self.csvWidget) - self.csvVersesButton.setIcon(build_icon(u':/general/general_open.png')) - self.csvVersesButton.setObjectName(u'CsvVersesButton') - self.csvVersesLayout.addWidget(self.csvVersesButton) - self.csvLayout.addRow(self.csvVersesLabel, self.csvVersesLayout) - self.csvSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, - QtGui.QSizePolicy.Minimum) - self.csvLayout.setItem(2, QtGui.QFormLayout.LabelRole, self.csvSpacer) - self.selectStack.addWidget(self.csvWidget) - self.openSongWidget = QtGui.QWidget(self.selectPage) - self.openSongWidget.setObjectName(u'OpenSongWidget') - self.openSongLayout = QtGui.QFormLayout(self.openSongWidget) - self.openSongLayout.setMargin(0) - self.openSongLayout.setObjectName(u'OpenSongLayout') - self.openSongFileLabel = QtGui.QLabel(self.openSongWidget) - self.openSongFileLabel.setObjectName(u'OpenSongFileLabel') - self.openSongFileLayout = QtGui.QHBoxLayout() - self.openSongFileLayout.setObjectName(u'OpenSongFileLayout') - self.openSongFileEdit = QtGui.QLineEdit(self.openSongWidget) - self.openSongFileEdit.setObjectName(u'OpenSongFileEdit') - self.openSongFileLayout.addWidget(self.openSongFileEdit) - self.openSongBrowseButton = QtGui.QToolButton(self.openSongWidget) - self.openSongBrowseButton.setIcon( - build_icon(u':/general/general_open.png')) - self.openSongBrowseButton.setObjectName(u'OpenSongBrowseButton') - self.openSongFileLayout.addWidget(self.openSongBrowseButton) - self.openSongLayout.addRow(self.openSongFileLabel, - self.openSongFileLayout) - self.openSongSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, - QtGui.QSizePolicy.Minimum) - self.openSongLayout.setItem(1, QtGui.QFormLayout.LabelRole, - self.openSongSpacer) - self.selectStack.addWidget(self.openSongWidget) - self.webTabWidget = QtGui.QTabWidget(self.selectPage) - self.webTabWidget.setObjectName(u'WebTabWidget') - self.webBibleTab = QtGui.QWidget() - self.webBibleTab.setObjectName(u'WebBibleTab') - self.webBibleLayout = QtGui.QFormLayout(self.webBibleTab) - self.webBibleLayout.setObjectName(u'WebBibleLayout') - self.webSourceLabel = QtGui.QLabel(self.webBibleTab) - self.webSourceLabel.setObjectName(u'WebSourceLabel') - self.webBibleLayout.setWidget(0, QtGui.QFormLayout.LabelRole, - self.webSourceLabel) - self.webSourceComboBox = QtGui.QComboBox(self.webBibleTab) - self.webSourceComboBox.setObjectName(u'WebSourceComboBox') - self.webSourceComboBox.addItems([u'', u'', u'']) - self.webBibleLayout.setWidget(0, QtGui.QFormLayout.FieldRole, - self.webSourceComboBox) - self.webTranslationLabel = QtGui.QLabel(self.webBibleTab) - self.webTranslationLabel.setObjectName(u'webTranslationLabel') - self.webBibleLayout.setWidget(1, QtGui.QFormLayout.LabelRole, - self.webTranslationLabel) - self.webTranslationComboBox = QtGui.QComboBox(self.webBibleTab) - self.webTranslationComboBox.setSizeAdjustPolicy( - QtGui.QComboBox.AdjustToContents) - self.webTranslationComboBox.setObjectName(u'WebTranslationComboBox') - self.webBibleLayout.setWidget(1, QtGui.QFormLayout.FieldRole, - self.webTranslationComboBox) - self.webTabWidget.addTab(self.webBibleTab, u'') - self.webProxyTab = QtGui.QWidget() - self.webProxyTab.setObjectName(u'WebProxyTab') - self.webProxyLayout = QtGui.QFormLayout(self.webProxyTab) - self.webProxyLayout.setObjectName(u'WebProxyLayout') - self.webServerLabel = QtGui.QLabel(self.webProxyTab) - self.webServerLabel.setObjectName(u'WebServerLabel') - self.webProxyLayout.setWidget(0, QtGui.QFormLayout.LabelRole, - self.webServerLabel) - self.webServerEdit = QtGui.QLineEdit(self.webProxyTab) - self.webServerEdit.setObjectName(u'WebServerEdit') - self.webProxyLayout.setWidget(0, QtGui.QFormLayout.FieldRole, - self.webServerEdit) - self.webUserLabel = QtGui.QLabel(self.webProxyTab) - self.webUserLabel.setObjectName(u'WebUserLabel') - self.webProxyLayout.setWidget(1, QtGui.QFormLayout.LabelRole, - self.webUserLabel) - self.webUserEdit = QtGui.QLineEdit(self.webProxyTab) - self.webUserEdit.setObjectName(u'WebUserEdit') - self.webProxyLayout.setWidget(1, QtGui.QFormLayout.FieldRole, - self.webUserEdit) - self.webPasswordLabel = QtGui.QLabel(self.webProxyTab) - self.webPasswordLabel.setObjectName(u'WebPasswordLabel') - self.webProxyLayout.setWidget(2, QtGui.QFormLayout.LabelRole, - self.webPasswordLabel) - self.webPasswordEdit = QtGui.QLineEdit(self.webProxyTab) - self.webPasswordEdit.setObjectName(u'WebPasswordEdit') - self.webProxyLayout.setWidget(2, QtGui.QFormLayout.FieldRole, - self.webPasswordEdit) - self.webTabWidget.addTab(self.webProxyTab, u'') - self.selectStack.addWidget(self.webTabWidget) - self.openlp1Widget = QtGui.QWidget(self.selectPage) - self.openlp1Widget.setObjectName(u'Openlp1Widget') - self.openlp1Layout = QtGui.QFormLayout(self.openlp1Widget) - self.openlp1Layout.setMargin(0) - self.openlp1Layout.setObjectName(u'Openlp1Layout') - self.openlp1FileLabel = QtGui.QLabel(self.openlp1Widget) - self.openlp1FileLabel.setObjectName(u'Openlp1FileLabel') - self.openlp1FileLayout = QtGui.QHBoxLayout() - self.openlp1FileLayout.setObjectName(u'Openlp1FileLayout') - self.openlp1FileEdit = QtGui.QLineEdit(self.openlp1Widget) - self.openlp1FileEdit.setObjectName(u'Openlp1FileEdit') - self.openlp1FileLayout.addWidget(self.openlp1FileEdit) - self.openlp1BrowseButton = QtGui.QToolButton(self.openlp1Widget) - self.openlp1BrowseButton.setIcon( - build_icon(u':/general/general_open.png')) - self.openlp1BrowseButton.setObjectName(u'Openlp1BrowseButton') - self.openlp1FileLayout.addWidget(self.openlp1BrowseButton) - self.openlp1Layout.addRow(self.openlp1FileLabel, self.openlp1FileLayout) - self.openlp1DisabledLabel = QtGui.QLabel(self.openlp1Widget) - self.openlp1DisabledLabel.setWordWrap(True) - self.openlp1DisabledLabel.setObjectName(u'Openlp1DisabledLabel') - self.openlp1Layout.addRow(self.openlp1DisabledLabel) - self.openlp1Spacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, - QtGui.QSizePolicy.Minimum) - self.openlp1Layout.setItem(1, QtGui.QFormLayout.LabelRole, - self.openlp1Spacer) - self.selectStack.addWidget(self.openlp1Widget) - self.selectPageLayout.addLayout(self.selectStack) - bibleImportWizard.addPage(self.selectPage) - # License Page - self.licenseDetailsPage = QtGui.QWizardPage() - self.licenseDetailsPage.setObjectName(u'LicenseDetailsPage') - self.licenseDetailsLayout = QtGui.QFormLayout(self.licenseDetailsPage) - self.licenseDetailsLayout.setObjectName(u'LicenseDetailsLayout') - self.versionNameLabel = QtGui.QLabel(self.licenseDetailsPage) - self.versionNameLabel.setObjectName(u'VersionNameLabel') - self.licenseDetailsLayout.setWidget(0, QtGui.QFormLayout.LabelRole, - self.versionNameLabel) - self.versionNameEdit = QtGui.QLineEdit(self.licenseDetailsPage) - self.versionNameEdit.setObjectName(u'VersionNameEdit') - self.licenseDetailsLayout.setWidget(0, QtGui.QFormLayout.FieldRole, - self.versionNameEdit) - self.copyrightLabel = QtGui.QLabel(self.licenseDetailsPage) - self.copyrightLabel.setObjectName(u'CopyrightLabel') - self.licenseDetailsLayout.setWidget(1, QtGui.QFormLayout.LabelRole, - self.copyrightLabel) - self.copyrightEdit = QtGui.QLineEdit(self.licenseDetailsPage) - self.copyrightEdit.setObjectName(u'CopyrightEdit') - self.licenseDetailsLayout.setWidget(1, QtGui.QFormLayout.FieldRole, - self.copyrightEdit) - self.permissionsLabel = QtGui.QLabel(self.licenseDetailsPage) - self.permissionsLabel.setObjectName(u'PermissionsLabel') - self.licenseDetailsLayout.setWidget(2, QtGui.QFormLayout.LabelRole, - self.permissionsLabel) - self.permissionsEdit = QtGui.QLineEdit(self.licenseDetailsPage) - self.permissionsEdit.setObjectName(u'PermissionsEdit') - self.licenseDetailsLayout.setWidget(2, QtGui.QFormLayout.FieldRole, - self.permissionsEdit) - bibleImportWizard.addPage(self.licenseDetailsPage) - # Progress Page - self.importPage = QtGui.QWizardPage() - self.importPage.setObjectName(u'ImportPage') - self.importLayout = QtGui.QVBoxLayout(self.importPage) - self.importLayout.setMargin(48) - self.importLayout.setObjectName(u'ImportLayout') - self.importProgressLabel = QtGui.QLabel(self.importPage) - self.importProgressLabel.setObjectName(u'ImportProgressLabel') - self.importLayout.addWidget(self.importProgressLabel) - self.importProgressBar = QtGui.QProgressBar(self.importPage) - self.importProgressBar.setObjectName(u'ImportProgressBar') - self.importLayout.addWidget(self.importProgressBar) - bibleImportWizard.addPage(self.importPage) - self.retranslateUi(bibleImportWizard) - QtCore.QMetaObject.connectSlotsByName(bibleImportWizard) - QtCore.QObject.connect(self.formatComboBox, - QtCore.SIGNAL(u'currentIndexChanged(int)'), self.selectStack, - QtCore.SLOT(u'setCurrentIndex(int)')) - - def retranslateUi(self, bibleImportWizard): - bibleImportWizard.setWindowTitle( - translate('BiblesPlugin.ImportWizardForm', 'Bible Import Wizard')) - self.titleLabel.setText( - u'%s' % \ - translate('BiblesPlugin.ImportWizardForm', - 'Welcome to the Bible Import Wizard')) - self.informationLabel.setText( - translate('BiblesPlugin.ImportWizardForm', - 'This wizard will help you to import Bibles from a ' - 'variety of formats. Click the next button below to start the ' - 'process by selecting a format to import from.')) - self.selectPage.setTitle(translate('BiblesPlugin.ImportWizardForm', - 'Select Import Source')) - self.selectPage.setSubTitle( - translate('BiblesPlugin.ImportWizardForm', - 'Select the import format, and where to import from.')) - self.formatLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'Format:')) - self.formatComboBox.setItemText(0, - translate('BiblesPlugin.ImportWizardForm', 'OSIS')) - self.formatComboBox.setItemText(1, - translate('BiblesPlugin.ImportWizardForm', 'CSV')) - self.formatComboBox.setItemText(2, - translate('BiblesPlugin.ImportWizardForm', 'OpenSong')) - self.formatComboBox.setItemText(3, - translate('BiblesPlugin.ImportWizardForm', 'Web Download')) - self.formatComboBox.setItemText(4, - translate('BiblesPlugin.ImportWizardForm', 'openlp.org 1.x')) - self.openlp1FileLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'File location:')) - self.osisFileLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'File location:')) - self.csvBooksLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'Books location:')) - self.csvVersesLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'Verse location:')) - self.openSongFileLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'Bible filename:')) - self.webSourceLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'Location:')) - self.webSourceComboBox.setItemText(0, - translate('BiblesPlugin.ImportWizardForm', 'Crosswalk')) - self.webSourceComboBox.setItemText(1, - translate('BiblesPlugin.ImportWizardForm', 'BibleGateway')) - self.webSourceComboBox.setItemText(2, - translate('BiblesPlugin.ImportWizardForm', 'Bibleserver')) - self.webTranslationLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'Bible:')) - self.webTabWidget.setTabText( - self.webTabWidget.indexOf(self.webBibleTab), - translate('BiblesPlugin.ImportWizardForm', 'Download Options')) - self.webServerLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'Server:')) - self.webUserLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'Username:')) - self.webPasswordLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'Password:')) - self.webTabWidget.setTabText( - self.webTabWidget.indexOf(self.webProxyTab), - translate('BiblesPlugin.ImportWizardForm', - 'Proxy Server (Optional)')) - self.licenseDetailsPage.setTitle( - translate('BiblesPlugin.ImportWizardForm', 'License Details')) - self.licenseDetailsPage.setSubTitle( - translate('BiblesPlugin.ImportWizardForm', - 'Set up the Bible\'s license details.')) - self.versionNameLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'Version name:')) - self.copyrightLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'Copyright:')) - self.permissionsLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'Permissions:')) - self.importPage.setTitle( - translate('BiblesPlugin.ImportWizardForm', 'Importing')) - self.importPage.setSubTitle( - translate('BiblesPlugin.ImportWizardForm', - 'Please wait while your Bible is imported.')) - self.importProgressLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'Ready.')) - self.importProgressBar.setFormat(u'%p%') - self.openlp1DisabledLabel.setText( - translate('BiblesPlugin.ImportWizardForm', 'The openlp.org 1.x ' - 'importer has been disabled due to a missing Python module. If ' - 'you want to use this importer, you will need to install the ' - '"python-sqlite" module.')) - # Align all QFormLayouts towards each other. - labelWidth = max(self.formatLabel.minimumSizeHint().width(), - self.osisFileLabel.minimumSizeHint().width(), - self.csvBooksLabel.minimumSizeHint().width(), - self.csvVersesLabel.minimumSizeHint().width(), - self.openSongFileLabel.minimumSizeHint().width(), - self.openlp1FileLabel.minimumSizeHint().width()) - self.formatSpacer.changeSize(labelWidth, 0, - QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) - self.osisSpacer.changeSize(labelWidth, 0, - QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) - self.csvSpacer.changeSize(labelWidth, 0, - QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) - self.openSongSpacer.changeSize(labelWidth, 0, - QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) - self.openlp1Spacer.changeSize(labelWidth, 0, - QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) diff --git a/openlp/plugins/bibles/lib/csvbible.py b/openlp/plugins/bibles/lib/csvbible.py index 2e9e9523b..8959167a6 100644 --- a/openlp/plugins/bibles/lib/csvbible.py +++ b/openlp/plugins/bibles/lib/csvbible.py @@ -31,7 +31,7 @@ import csv from PyQt4 import QtCore from openlp.core.lib import Receiver, translate -from db import BibleDB +from openlp.plugins.bibles.lib.db import BibleDB log = logging.getLogger(__name__) @@ -51,7 +51,7 @@ class CSVBible(BibleDB): self.booksfile = kwargs[u'booksfile'] self.versesfile = kwargs[u'versefile'] QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'bibles_stop_import'), self.stop_import) + QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import) def do_import(self): success = True diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index f5468a63a..6f6b861e9 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -387,7 +387,7 @@ class HTTPBible(BibleDB): Run the import. This method overrides the parent class method. Returns ``True`` on success, ``False`` on failure. """ - self.wizard.importProgressBar.setMaximum(2) + self.wizard.progressBar.setMaximum(2) self.wizard.incrementProgressBar('Registering bible...') self.create_meta(u'download source', self.download_source) self.create_meta(u'download name', self.download_name) @@ -532,19 +532,25 @@ def get_soup_for_bible_ref(reference_url, header=None, cleaner=None): Receiver.send_message(u'openlp_process_events') return soup -def send_error_message(reason): - if reason == u'download': +def send_error_message(error_type): + """ + Send a standard error message informing the user of an issue. + + ``error_type`` + The type of error that occured for the issue. + """ + if error_type == u'download': Receiver.send_message(u'openlp_error_message', { u'title': translate('BiblePlugin.HTTPBible', 'Download Error'), u'message': translate('BiblePlugin.HTTPBible', 'There was a ' 'problem downloading your verse selection. Please check your ' 'Internet connection, and if this error continues to occur ' - 'consider reporting a bug.') + 'please consider reporting a bug.') }) - elif reason == u'parse': + elif error_type == u'parse': Receiver.send_message(u'openlp_error_message', { u'title': translate('BiblePlugin.HTTPBible', 'Parse Error'), u'message': translate('BiblePlugin.HTTPBible', 'There was a ' 'problem extracting your verse selection. If this error continues ' - 'to occur consider reporting a bug.') + 'to occur please consider reporting a bug.') }) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 40d76c36a..d60afccd5 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -327,7 +327,7 @@ class BibleMediaItem(MediaManagerItem): if not hasattr(self, u'import_wizard'): self.import_wizard = BibleImportForm(self, self.parent.manager, self.parent) - # If the import was not canceled then reload. + # If the import was not cancelled then reload. if self.import_wizard.exec_(): self.reloadBibles() diff --git a/openlp/plugins/bibles/lib/openlp1.py b/openlp/plugins/bibles/lib/openlp1.py index 866652e5b..2df6b1677 100644 --- a/openlp/plugins/bibles/lib/openlp1.py +++ b/openlp/plugins/bibles/lib/openlp1.py @@ -30,7 +30,7 @@ import sqlite from PyQt4 import QtCore from openlp.core.lib import Receiver, translate -from db import BibleDB +from openlp.plugins.bibles.lib.db import BibleDB log = logging.getLogger(__name__) @@ -46,7 +46,7 @@ class OpenLP1Bible(BibleDB): BibleDB.__init__(self, parent, **kwargs) self.filename = kwargs[u'filename'] QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'bibles_stop_import'), self.stop_import) + QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import) def do_import(self): """ @@ -62,7 +62,7 @@ class OpenLP1Bible(BibleDB): # Create all books. cursor.execute(u'SELECT id, testament_id, name, abbreviation FROM book') books = cursor.fetchall() - self.wizard.importProgressBar.setMaximum(len(books) + 1) + self.wizard.progressBar.setMaximum(len(books) + 1) for book in books: if self.stop_import_flag: connection.close() diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/opensong.py index 03d243390..2b3b6dfb7 100644 --- a/openlp/plugins/bibles/lib/opensong.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -30,7 +30,7 @@ from lxml import objectify from PyQt4 import QtCore from openlp.core.lib import Receiver, translate -from db import BibleDB +from openlp.plugins.bibles.lib.db import BibleDB log = logging.getLogger(__name__) @@ -48,7 +48,7 @@ class OpenSongBible(BibleDB): BibleDB.__init__(self, parent, **kwargs) self.filename = kwargs['filename'] QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'bibles_stop_import'), self.stop_import) + QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import) def do_import(self): """ diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index bf070c4bd..4a001987d 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -35,7 +35,7 @@ from PyQt4 import QtCore from openlp.core.lib import Receiver, translate from openlp.core.utils import AppLocation -from db import BibleDB +from openlp.plugins.bibles.lib.db import BibleDB log = logging.getLogger(__name__) @@ -87,7 +87,7 @@ class OSISBible(BibleDB): if fbibles: fbibles.close() QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'bibles_stop_import'), self.stop_import) + QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import) def do_import(self): """ @@ -134,9 +134,9 @@ class OSISBible(BibleDB): testament) if last_chapter == 0: if book == u'Gen': - self.wizard.importProgressBar.setMaximum(1188) + self.wizard.progressBar.setMaximum(1188) else: - self.wizard.importProgressBar.setMaximum(260) + self.wizard.progressBar.setMaximum(260) if last_chapter != chapter: if last_chapter != 0: self.session.commit() diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index 5776dd21a..22a7ab61f 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -23,19 +23,21 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### - +""" +The song import functions for OpenLP. +""" import logging import os from PyQt4 import QtCore, QtGui -from songimportwizard import Ui_SongImportWizard from openlp.core.lib import Receiver, SettingsManager, translate +from openlp.core.ui.wizard import OpenLPWizard from openlp.plugins.songs.lib.importer import SongFormat log = logging.getLogger(__name__) -class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): +class SongImportForm(OpenLPWizard): """ This is the Song Import Wizard, which allows easy importing of Songs into OpenLP from other formats like OpenLyrics, OpenSong and CCLI. @@ -52,11 +54,23 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): ``plugin`` The songs plugin. """ - QtGui.QWizard.__init__(self, parent) - self.setupUi(self) - self.registerFields() - self.finishButton = self.button(QtGui.QWizard.FinishButton) - self.cancelButton = self.button(QtGui.QWizard.CancelButton) + OpenLPWizard.__init__(self, parent, plugin, u'songImportWizard', + u':/wizards/wizard_importsong.bmp') + + def setupUi(self, image): + """ + Set up the song wizard UI. + """ + OpenLPWizard.setupUi(self, image) + self.formatStack.setCurrentIndex(0) + QtCore.QObject.connect(self.formatComboBox, + QtCore.SIGNAL(u'currentIndexChanged(int)'), + self.formatStack.setCurrentIndex) + + def customInit(self): + """ + Song wizard specific initialisation. + """ if not SongFormat.get_availability(SongFormat.OpenLP1): self.openLP1DisabledWidget.setVisible(True) self.openLP1ImportWidget.setVisible(False) @@ -66,7 +80,11 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): if not SongFormat.get_availability(SongFormat.Generic): self.genericDisabledWidget.setVisible(True) self.genericImportWidget.setVisible(False) - self.plugin = plugin + + def customSignals(self): + """ + Song wizard specific signals. + """ QtCore.QObject.connect(self.openLP2BrowseButton, QtCore.SIGNAL(u'clicked()'), self.onOpenLP2BrowseButtonClicked) @@ -118,25 +136,184 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): QtCore.QObject.connect(self.songBeamerRemoveButton, QtCore.SIGNAL(u'clicked()'), self.onSongBeamerRemoveButtonClicked) - QtCore.QObject.connect(self, - QtCore.SIGNAL(u'currentIdChanged(int)'), - self.onCurrentIdChanged) - def exec_(self): + def addCustomPages(self): """ - Run the wizard. + Add song wizard specific pages. """ - self.setDefaults() - return QtGui.QWizard.exec_(self) + # Source Page + self.sourcePage = QtGui.QWizardPage() + self.sourcePage.setObjectName(u'SourcePage') + self.sourceLayout = QtGui.QVBoxLayout(self.sourcePage) + self.sourceLayout.setObjectName(u'SourceLayout') + self.formatLayout = QtGui.QFormLayout() + self.formatLayout.setObjectName(u'FormatLayout') + self.formatLabel = QtGui.QLabel(self.sourcePage) + self.formatLabel.setObjectName(u'FormatLabel') + self.formatComboBox = QtGui.QComboBox(self.sourcePage) + self.formatComboBox.setObjectName(u'FormatComboBox') + self.formatLayout.addRow(self.formatLabel, self.formatComboBox) + self.formatSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, + QtGui.QSizePolicy.Minimum) + self.formatLayout.setItem(1, QtGui.QFormLayout.LabelRole, + self.formatSpacer) + self.sourceLayout.addLayout(self.formatLayout) + self.formatStack = QtGui.QStackedLayout() + self.formatStack.setObjectName(u'FormatStack') + # OpenLP 2.0 + self.addSingleFileSelectItem(u'openLP2') + # openlp.org 1.x + self.addSingleFileSelectItem(u'openLP1', None, True) + # OpenLyrics + self.addMultiFileSelectItem(u'openLyrics', u'OpenLyrics', True) + # Open Song + self.addMultiFileSelectItem(u'openSong', u'OpenSong') + # Words of Worship + self.addMultiFileSelectItem(u'wordsOfWorship') + # CCLI File import + self.addMultiFileSelectItem(u'ccli') + # Songs of Fellowship + self.addMultiFileSelectItem(u'songsOfFellowship', None, True) + # Generic Document/Presentation import + self.addMultiFileSelectItem(u'generic', None, True) + # EasyWorship + self.addSingleFileSelectItem(u'ew') + # Words of Worship + self.addMultiFileSelectItem(u'songBeamer') +# Commented out for future use. +# self.addSingleFileSelectItem(u'csv', u'CSV') + self.sourceLayout.addLayout(self.formatStack) + self.addPage(self.sourcePage) - def reject(self): + def retranslateUi(self): """ - Stop the import on cancel button, close button or ESC key. + Song wizard localisation. """ - log.debug(u'Import canceled by user.') - if self.currentPage() == self.importPage: - Receiver.send_message(u'songs_stop_import') - self.done(QtGui.QDialog.Rejected) + self.setWindowTitle( + translate('SongsPlugin.ImportWizardForm', 'Song Import Wizard')) + self.titleLabel.setText( + u'%s' % \ + translate('SongsPlugin.ImportWizardForm', + 'Welcome to the Song Import Wizard')) + self.informationLabel.setText( + translate('SongsPlugin.ImportWizardForm', + 'This wizard will help you to import songs from a variety of ' + 'formats. Click the next button below to start the process by ' + 'selecting a format to import from.')) + self.sourcePage.setTitle( + translate('SongsPlugin.ImportWizardForm', 'Select Import Source')) + self.sourcePage.setSubTitle( + translate('SongsPlugin.ImportWizardForm', + 'Select the import format, and where to import from.')) + self.formatLabel.setText( + translate('SongsPlugin.ImportWizardForm', 'Format:')) + self.formatComboBox.setItemText(0, + translate('SongsPlugin.ImportWizardForm', 'OpenLP 2.0')) + self.formatComboBox.setItemText(1, + translate('SongsPlugin.ImportWizardForm', 'openlp.org 1.x')) + self.formatComboBox.setItemText(2, + translate('SongsPlugin.ImportWizardForm', 'OpenLyrics')) + self.formatComboBox.setItemText(3, + translate('SongsPlugin.ImportWizardForm', 'OpenSong')) + self.formatComboBox.setItemText(4, + translate('SongsPlugin.ImportWizardForm', 'Words of Worship')) + self.formatComboBox.setItemText(5, + translate('SongsPlugin.ImportWizardForm', 'CCLI/SongSelect')) + self.formatComboBox.setItemText(6, + translate('SongsPlugin.ImportWizardForm', 'Songs of Fellowship')) + self.formatComboBox.setItemText(7, + translate('SongsPlugin.ImportWizardForm', + 'Generic Document/Presentation')) + self.formatComboBox.setItemText(8, + translate('SongsPlugin.ImportWizardForm', 'EasyWorship')) + self.formatComboBox.setItemText(9, + translate('SongsPlugin.ImportWizardForm', 'SongBeamer')) +# self.formatComboBox.setItemText(9, +# translate('SongsPlugin.ImportWizardForm', 'CSV')) + self.openLP2FilenameLabel.setText( + translate('SongsPlugin.ImportWizardForm', 'Filename:')) + self.openLP2BrowseButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Browse...')) + self.openLP1FilenameLabel.setText( + translate('SongsPlugin.ImportWizardForm', 'Filename:')) + self.openLP1BrowseButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Browse...')) + self.openLP1DisabledLabel.setText( + translate('SongsPlugin.ImportWizardForm', 'The openlp.org 1.x ' + 'importer has been disabled due to a missing Python module. If ' + 'you want to use this importer, you will need to install the ' + '"python-sqlite" module.')) + self.openLyricsAddButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Add Files...')) + self.openLyricsRemoveButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) + self.openLyricsDisabledLabel.setText( + translate('SongsPlugin.ImportWizardForm', 'The OpenLyrics ' + 'importer has not yet been developed, but as you can see, we are ' + 'still intending to do so. Hopefully it will be in the next ' + 'release.')) + self.openSongAddButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Add Files...')) + self.openSongRemoveButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) + self.wordsOfWorshipAddButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Add Files...')) + self.wordsOfWorshipRemoveButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) + self.ccliAddButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Add Files...')) + self.ccliRemoveButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) + self.songsOfFellowshipAddButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Add Files...')) + self.songsOfFellowshipRemoveButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) + self.songsOfFellowshipDisabledLabel.setText( + translate('SongsPlugin.ImportWizardForm', 'The Songs of ' + 'Fellowship importer has been disabled because OpenLP cannot ' + 'find OpenOffice.org on your computer.')) + self.genericAddButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Add Files...')) + self.genericRemoveButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) + self.genericDisabledLabel.setText( + translate('SongsPlugin.ImportWizardForm', 'The generic document/' + 'presentation importer has been disabled because OpenLP cannot ' + 'find OpenOffice.org on your computer.')) + self.ewFilenameLabel.setText( + translate('SongsPlugin.ImportWizardForm', 'Filename:')) + self.ewBrowseButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Browse...')) + self.songBeamerAddButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Add Files...')) + self.songBeamerRemoveButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) +# self.csvFilenameLabel.setText( +# translate('SongsPlugin.ImportWizardForm', 'Filename:')) +# self.csvBrowseButton.setText( +# translate('SongsPlugin.ImportWizardForm', 'Browse...')) + self.progressPage.setTitle( + translate('SongsPlugin.ImportWizardForm', 'Importing')) + self.progressPage.setSubTitle( + translate('SongsPlugin.ImportWizardForm', + 'Please wait while your songs are imported.')) + self.progressLabel.setText( + translate('SongsPlugin.ImportWizardForm', 'Ready.')) + self.progressBar.setFormat( + translate('SongsPlugin.ImportWizardForm', '%p%')) + # Align all QFormLayouts towards each other. + width = max(self.formatLabel.minimumSizeHint().width(), + self.openLP2FilenameLabel.minimumSizeHint().width()) + self.formatSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, + QtGui.QSizePolicy.Fixed) + self.openLP2FormLabelSpacer.changeSize(width, 0, + QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + self.openLP1FormLabelSpacer.changeSize(width, 0, + QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + self.ewFormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, + QtGui.QSizePolicy.Fixed) +# self.csvFormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, +# QtGui.QSizePolicy.Fixed) def validateCurrentPage(self): """ @@ -247,7 +424,7 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): self.songBeamerAddButton.setFocus() return False return True - elif self.currentPage() == self.importPage: + elif self.currentPage() == self.progressPage: return True def getFileName(self, title, editbox, filters=u''): @@ -308,17 +485,26 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): os.path.split(unicode(filenames[0]))[0], 1) def getListOfFiles(self, listbox): + """ + Return a list of file from the listbox + """ files = [] for row in range(0, listbox.count()): files.append(unicode(listbox.item(row).text())) return files def removeSelectedItems(self, listbox): + """ + Remove selected listbox items + """ for item in listbox.selectedItems(): item = listbox.takeItem(listbox.row(item)) del item def onOpenLP2BrowseButtonClicked(self): + """ + Get OpenLP v2 song database file + """ self.getFileName( translate('SongsPlugin.ImportWizardForm', 'Select OpenLP 2.0 Database File'), @@ -328,6 +514,9 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): ) def onOpenLP1BrowseButtonClicked(self): + """ + Get OpenLP v1 song database file + """ self.getFileName( translate('SongsPlugin.ImportWizardForm', 'Select openlp.org 1.x Database File'), @@ -337,6 +526,9 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): ) def onOpenLyricsAddButtonClicked(self): + """ + Get OpenLyrics song database files + """ self.getFiles( translate('SongsPlugin.ImportWizardForm', 'Select OpenLyrics Files'), @@ -344,19 +536,30 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): ) def onOpenLyricsRemoveButtonClicked(self): + """ + Remove selected OpenLyrics files from the import list + """ self.removeSelectedItems(self.openLyricsFileListWidget) def onOpenSongAddButtonClicked(self): + """ + Get OpenSong song database files + """ self.getFiles( - translate('SongsPlugin.ImportWizardForm', - 'Select Open Song Files'), + translate('SongsPlugin.ImportWizardForm', 'Select Open Song Files'), self.openSongFileListWidget ) def onOpenSongRemoveButtonClicked(self): + """ + Remove selected OpenSong files from the import list + """ self.removeSelectedItems(self.openSongFileListWidget) def onWordsOfWorshipAddButtonClicked(self): + """ + Get Words of Worship song database files + """ self.getFiles( translate('SongsPlugin.ImportWizardForm', 'Select Words of Worship Files'), @@ -366,9 +569,15 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): ) def onWordsOfWorshipRemoveButtonClicked(self): + """ + Remove selected Words of Worship files from the import list + """ self.removeSelectedItems(self.wordsOfWorshipFileListWidget) def onCCLIAddButtonClicked(self): + """ + Get CCLI song database files + """ self.getFiles( translate('SongsPlugin.ImportWizardForm', 'Select CCLI Files'), @@ -376,9 +585,15 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): ) def onCCLIRemoveButtonClicked(self): + """ + Remove selected CCLI files from the import list + """ self.removeSelectedItems(self.ccliFileListWidget) def onSongsOfFellowshipAddButtonClicked(self): + """ + Get Songs of Fellowship song database files + """ self.getFiles( translate('SongsPlugin.ImportWizardForm', 'Select Songs of Fellowship Files'), @@ -388,9 +603,15 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): ) def onSongsOfFellowshipRemoveButtonClicked(self): + """ + Remove selected Songs of Fellowship files from the import list + """ self.removeSelectedItems(self.songsOfFellowshipFileListWidget) def onGenericAddButtonClicked(self): + """ + Get song database files + """ self.getFiles( translate('SongsPlugin.ImportWizardForm', 'Select Document/Presentation Files'), @@ -398,9 +619,15 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): ) def onGenericRemoveButtonClicked(self): + """ + Remove selected files from the import list + """ self.removeSelectedItems(self.genericFileListWidget) def onEWBrowseButtonClicked(self): + """ + Get EasyWorship song database files + """ self.getFileName( translate('SongsPlugin.ImportWizardForm', 'Select EasyWorship Database File'), @@ -408,6 +635,9 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): ) def onSongBeamerAddButtonClicked(self): + """ + Get SongBeamer song database files + """ self.getFiles( translate('SongsPlugin.ImportWizardForm', 'Select SongBeamer Files'), @@ -416,18 +646,21 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): ) def onSongBeamerRemoveButtonClicked(self): + """ + Remove selected SongBeamer files from the import list + """ self.removeSelectedItems(self.songBeamerFileListWidget) - def onCurrentIdChanged(self, id): - if self.page(id) == self.importPage: - self.preImport() - self.performImport() - self.postImport() - def registerFields(self): + """ + Register song import wizard fields. + """ pass def setDefaults(self): + """ + Set default form values for the song import wizard. + """ self.restart() self.finishButton.setVisible(False) self.cancelButton.setVisible(True) @@ -444,25 +677,16 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): self.songBeamerFileListWidget.clear() #self.csvFilenameEdit.setText(u'') - def incrementProgressBar(self, status_text, increment=1): - log.debug(u'IncrementBar %s', status_text) - if status_text: - self.importProgressLabel.setText(status_text) - if increment > 0: - self.importProgressBar.setValue(self.importProgressBar.value() + - increment) - Receiver.send_message(u'openlp_process_events') - - def preImport(self): - self.finishButton.setVisible(False) - self.importProgressBar.setMinimum(0) - self.importProgressBar.setMaximum(1188) - self.importProgressBar.setValue(0) - self.importProgressLabel.setText( + def preWizard(self): + """ + Perform pre import tasks + """ + OpenLPWizard.preWizard(self) + self.progressLabel.setText( translate('SongsPlugin.ImportWizardForm', 'Starting import...')) Receiver.send_message(u'openlp_process_events') - def performImport(self): + def performWizard(self): """ Perform the actual import. This method pulls in the correct importer class, and then runs the ``do_import`` method of the importer to do @@ -520,20 +744,128 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): elif source_format == SongFormat.SongBeamer: # Import SongBeamer songs importer = self.plugin.importSongs(SongFormat.SongBeamer, - filenames=self.getListOfFiles( - self.songBeamerFileListWidget) + filenames=self.getListOfFiles(self.songBeamerFileListWidget) ) if importer.do_import(): # reload songs - self.importProgressLabel.setText( + self.progressLabel.setText( translate('SongsPlugin.SongImportForm', 'Finished import.')) else: - self.importProgressLabel.setText( + self.progressLabel.setText( translate('SongsPlugin.SongImportForm', 'Your song import failed.')) - def postImport(self): - self.importProgressBar.setValue(self.importProgressBar.maximum()) - self.finishButton.setVisible(True) - self.cancelButton.setVisible(False) - Receiver.send_message(u'openlp_process_events') + def addSingleFileSelectItem(self, prefix, obj_prefix=None, + can_disable=False): + if not obj_prefix: + obj_prefix = prefix + page = QtGui.QWidget() + page.setObjectName(obj_prefix + u'Page') + if can_disable: + importWidget = self.disablableWidget(page, prefix, obj_prefix) + else: + importWidget = page + importLayout = QtGui.QFormLayout(importWidget) + importLayout.setMargin(0) + if can_disable: + importLayout.setObjectName(obj_prefix + u'ImportLayout') + else: + importLayout.setObjectName(obj_prefix + u'Layout') + filenameLabel = QtGui.QLabel(importWidget) + filenameLabel.setObjectName(obj_prefix + u'FilenameLabel') + fileLayout = QtGui.QHBoxLayout() + fileLayout.setObjectName(obj_prefix + u'FileLayout') + filenameEdit = QtGui.QLineEdit(importWidget) + filenameEdit.setObjectName(obj_prefix + u'FilenameEdit') + fileLayout.addWidget(filenameEdit) + browseButton = QtGui.QToolButton(importWidget) + browseButton.setIcon(self.openIcon) + browseButton.setObjectName(obj_prefix + u'BrowseButton') + fileLayout.addWidget(browseButton) + importLayout.addRow(filenameLabel, fileLayout) + formSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, + QtGui.QSizePolicy.Minimum) + importLayout.setItem(1, QtGui.QFormLayout.LabelRole, formSpacer) + self.formatStack.addWidget(page) + setattr(self, prefix + u'Page', page) + setattr(self, prefix + u'FilenameLabel', filenameLabel) + setattr(self, prefix + u'FormLabelSpacer', formSpacer) + setattr(self, prefix + u'FileLayout', fileLayout) + setattr(self, prefix + u'FilenameEdit', filenameEdit) + setattr(self, prefix + u'BrowseButton', browseButton) + if can_disable: + setattr(self, prefix + u'ImportLayout', importLayout) + else: + setattr(self, prefix + u'Layout', importLayout) + self.formatComboBox.addItem(u'') + + def addMultiFileSelectItem(self, prefix, obj_prefix=None, + can_disable=False): + if not obj_prefix: + obj_prefix = prefix + page = QtGui.QWidget() + page.setObjectName(obj_prefix + u'Page') + if can_disable: + importWidget = self.disablableWidget(page, prefix, obj_prefix) + else: + importWidget = page + importLayout = QtGui.QVBoxLayout(importWidget) + importLayout.setMargin(0) + if can_disable: + importLayout.setObjectName(obj_prefix + u'ImportLayout') + else: + importLayout.setObjectName(obj_prefix + u'Layout') + fileListWidget = QtGui.QListWidget(importWidget) + fileListWidget.setSelectionMode( + QtGui.QAbstractItemView.ExtendedSelection) + fileListWidget.setObjectName(obj_prefix + u'FileListWidget') + importLayout.addWidget(fileListWidget) + buttonLayout = QtGui.QHBoxLayout() + buttonLayout.setObjectName(obj_prefix + u'ButtonLayout') + addButton = QtGui.QPushButton(importWidget) + addButton.setIcon(self.openIcon) + addButton.setObjectName(obj_prefix + u'AddButton') + buttonLayout.addWidget(addButton) + buttonLayout.addStretch() + removeButton = QtGui.QPushButton(importWidget) + removeButton.setIcon(self.deleteIcon) + removeButton.setObjectName(obj_prefix + u'RemoveButton') + buttonLayout.addWidget(removeButton) + importLayout.addLayout(buttonLayout) + self.formatStack.addWidget(page) + setattr(self, prefix + u'Page', page) + setattr(self, prefix + u'FileListWidget', fileListWidget) + setattr(self, prefix + u'ButtonLayout', buttonLayout) + setattr(self, prefix + u'AddButton', addButton) + setattr(self, prefix + u'RemoveButton', removeButton) + if can_disable: + setattr(self, prefix + u'ImportLayout', importLayout) + else: + setattr(self, prefix + u'Layout', importLayout) + self.formatComboBox.addItem(u'') + + def disablableWidget(self, page, prefix, obj_prefix): + layout = QtGui.QVBoxLayout(page) + layout.setMargin(0) + layout.setSpacing(0) + layout.setObjectName(obj_prefix + u'Layout') + disabledWidget = QtGui.QWidget(page) + disabledWidget.setVisible(False) + disabledWidget.setObjectName(obj_prefix + u'DisabledWidget') + disabledLayout = QtGui.QVBoxLayout(disabledWidget) + disabledLayout.setMargin(0) + disabledLayout.setObjectName(obj_prefix + u'DisabledLayout') + disabledLabel = QtGui.QLabel(disabledWidget) + disabledLabel.setWordWrap(True) + disabledLabel.setObjectName(obj_prefix + u'DisabledLabel') + disabledLayout.addWidget(disabledLabel) + layout.addWidget(disabledWidget) + importWidget = QtGui.QWidget(page) + importWidget.setObjectName(obj_prefix + u'ImportWidget') + layout.addWidget(importWidget) + setattr(self, prefix + u'Layout', layout) + setattr(self, prefix + u'DisabledWidget', disabledWidget) + setattr(self, prefix + u'DisabledLayout', disabledLayout) + setattr(self, prefix + u'DisabledLabel', disabledLabel) + setattr(self, prefix + u'ImportWidget', importWidget) + return importWidget diff --git a/openlp/plugins/songs/forms/songimportwizard.py b/openlp/plugins/songs/forms/songimportwizard.py deleted file mode 100644 index 903300d0c..000000000 --- a/openlp/plugins/songs/forms/songimportwizard.py +++ /dev/null @@ -1,362 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2011 Raoul Snyman # -# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael # -# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian # -# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, # -# Carsten Tinggaard, Frode Woldsund # -# --------------------------------------------------------------------------- # -# This program is free software; you can redistribute it and/or modify it # -# under the terms of the GNU General Public License as published by the Free # -# Software Foundation; version 2 of the License. # -# # -# This program is distributed in the hope that it will be useful, but WITHOUT # -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # -# more details. # -# # -# You should have received a copy of the GNU General Public License along # -# with this program; if not, write to the Free Software Foundation, Inc., 59 # -# Temple Place, Suite 330, Boston, MA 02111-1307 USA # -############################################################################### - -from PyQt4 import QtCore, QtGui - -from openlp.core.lib import build_icon, translate - -class Ui_SongImportWizard(object): - def setupUi(self, songImportWizard): - self.openIcon = build_icon(u':/general/general_open.png') - self.deleteIcon = build_icon(u':/general/general_delete.png') - songImportWizard.setObjectName(u'songImportWizard') - songImportWizard.setModal(True) - songImportWizard.setWizardStyle(QtGui.QWizard.ModernStyle) - songImportWizard.setOptions( - QtGui.QWizard.IndependentPages | - QtGui.QWizard.NoBackButtonOnStartPage | - QtGui.QWizard.NoBackButtonOnLastPage) - # Welcome Page - self.welcomePage = QtGui.QWizardPage() - self.welcomePage.setPixmap(QtGui.QWizard.WatermarkPixmap, - QtGui.QPixmap(u':/wizards/wizard_importsong.bmp')) - self.welcomePage.setObjectName(u'WelcomePage') - self.welcomeLayout = QtGui.QVBoxLayout(self.welcomePage) - self.welcomeLayout.setObjectName(u'WelcomeLayout') - self.titleLabel = QtGui.QLabel(self.welcomePage) - self.titleLabel.setObjectName(u'TitleLabel') - self.welcomeLayout.addWidget(self.titleLabel) - self.welcomeLayout.addSpacing(40) - self.informationLabel = QtGui.QLabel(self.welcomePage) - self.informationLabel.setWordWrap(True) - self.informationLabel.setObjectName(u'InformationLabel') - self.welcomeLayout.addWidget(self.informationLabel) - self.welcomeLayout.addStretch() - songImportWizard.addPage(self.welcomePage) - # Source Page - self.sourcePage = QtGui.QWizardPage() - self.sourcePage.setObjectName(u'SourcePage') - self.sourceLayout = QtGui.QVBoxLayout(self.sourcePage) - self.sourceLayout.setObjectName(u'SourceLayout') - self.formatLayout = QtGui.QFormLayout() - self.formatLayout.setObjectName(u'FormatLayout') - self.formatLabel = QtGui.QLabel(self.sourcePage) - self.formatLabel.setObjectName(u'FormatLabel') - self.formatComboBox = QtGui.QComboBox(self.sourcePage) - self.formatComboBox.setObjectName(u'FormatComboBox') - self.formatLayout.addRow(self.formatLabel, self.formatComboBox) - self.formatSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, - QtGui.QSizePolicy.Minimum) - self.formatLayout.setItem(1, QtGui.QFormLayout.LabelRole, - self.formatSpacer) - self.sourceLayout.addLayout(self.formatLayout) - self.formatStack = QtGui.QStackedLayout() - self.formatStack.setObjectName(u'FormatStack') - # OpenLP 2.0 - self.addSingleFileSelectItem(u'openLP2') - # openlp.org 1.x - self.addSingleFileSelectItem(u'openLP1', None, True) - # OpenLyrics - self.addMultiFileSelectItem(u'openLyrics', u'OpenLyrics', True) - # Open Song - self.addMultiFileSelectItem(u'openSong', u'OpenSong') - # Words of Worship - self.addMultiFileSelectItem(u'wordsOfWorship') - # CCLI File import - self.addMultiFileSelectItem(u'ccli') - # Songs of Fellowship - self.addMultiFileSelectItem(u'songsOfFellowship', None, True) - # Generic Document/Presentation import - self.addMultiFileSelectItem(u'generic', None, True) - # EasyWorship - self.addSingleFileSelectItem(u'ew') - # Words of Worship - self.addMultiFileSelectItem(u'songBeamer') -# Commented out for future use. -# self.addSingleFileSelectItem(u'csv', u'CSV') - self.sourceLayout.addLayout(self.formatStack) - songImportWizard.addPage(self.sourcePage) - # Import Page - self.importPage = QtGui.QWizardPage() - self.importPage.setObjectName(u'ImportPage') - self.importLayout = QtGui.QVBoxLayout(self.importPage) - self.importLayout.setMargin(48) - self.importLayout.setObjectName(u'ImportLayout') - self.importProgressLabel = QtGui.QLabel(self.importPage) - self.importProgressLabel.setObjectName(u'ImportProgressLabel') - self.importLayout.addWidget(self.importProgressLabel) - self.importProgressBar = QtGui.QProgressBar(self.importPage) - self.importProgressBar.setObjectName(u'ImportProgressBar') - self.importLayout.addWidget(self.importProgressBar) - songImportWizard.addPage(self.importPage) - self.retranslateUi(songImportWizard) - self.formatStack.setCurrentIndex(0) - QtCore.QObject.connect(self.formatComboBox, - QtCore.SIGNAL(u'currentIndexChanged(int)'), - self.formatStack.setCurrentIndex) - QtCore.QMetaObject.connectSlotsByName(songImportWizard) - - def retranslateUi(self, songImportWizard): - songImportWizard.setWindowTitle( - translate('SongsPlugin.ImportWizardForm', 'Song Import Wizard')) - self.titleLabel.setText( - u'%s' % \ - translate('SongsPlugin.ImportWizardForm', - 'Welcome to the Song Import Wizard')) - self.informationLabel.setText( - translate('SongsPlugin.ImportWizardForm', - 'This wizard will help you to import songs from a variety of ' - 'formats. Click the next button below to start the process by ' - 'selecting a format to import from.')) - self.sourcePage.setTitle( - translate('SongsPlugin.ImportWizardForm', 'Select Import Source')) - self.sourcePage.setSubTitle( - translate('SongsPlugin.ImportWizardForm', - 'Select the import format, and where to import from.')) - self.formatLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'Format:')) - self.formatComboBox.setItemText(0, - translate('SongsPlugin.ImportWizardForm', 'OpenLP 2.0')) - self.formatComboBox.setItemText(1, - translate('SongsPlugin.ImportWizardForm', 'openlp.org 1.x')) - self.formatComboBox.setItemText(2, - translate('SongsPlugin.ImportWizardForm', 'OpenLyrics')) - self.formatComboBox.setItemText(3, - translate('SongsPlugin.ImportWizardForm', 'OpenSong')) - self.formatComboBox.setItemText(4, - translate('SongsPlugin.ImportWizardForm', 'Words of Worship')) - self.formatComboBox.setItemText(5, - translate('SongsPlugin.ImportWizardForm', 'CCLI/SongSelect')) - self.formatComboBox.setItemText(6, - translate('SongsPlugin.ImportWizardForm', 'Songs of Fellowship')) - self.formatComboBox.setItemText(7, - translate('SongsPlugin.ImportWizardForm', - 'Generic Document/Presentation')) - self.formatComboBox.setItemText(8, - translate('SongsPlugin.ImportWizardForm', 'EasyWorship')) - self.formatComboBox.setItemText(9, - translate('SongsPlugin.ImportWizardForm', 'SongBeamer')) -# self.formatComboBox.setItemText(9, -# translate('SongsPlugin.ImportWizardForm', 'CSV')) - self.openLP2FilenameLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'Filename:')) - self.openLP2BrowseButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Browse...')) - self.openLP1FilenameLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'Filename:')) - self.openLP1BrowseButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Browse...')) - self.openLP1DisabledLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'The openlp.org 1.x ' - 'importer has been disabled due to a missing Python module. If ' - 'you want to use this importer, you will need to install the ' - '"python-sqlite" module.')) - self.openLyricsAddButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Add Files...')) - self.openLyricsRemoveButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) - self.openLyricsDisabledLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'The OpenLyrics ' - 'importer has not yet been developed, but as you can see, we are ' - 'still intending to do so. Hopefully it will be in the next ' - 'release.')) - self.openSongAddButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Add Files...')) - self.openSongRemoveButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) - self.wordsOfWorshipAddButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Add Files...')) - self.wordsOfWorshipRemoveButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) - self.ccliAddButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Add Files...')) - self.ccliRemoveButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) - self.songsOfFellowshipAddButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Add Files...')) - self.songsOfFellowshipRemoveButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) - self.songsOfFellowshipDisabledLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'The Songs of ' - 'Fellowship importer has been disabled because OpenLP cannot ' - 'find OpenOffice.org on your computer.')) - self.genericAddButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Add Files...')) - self.genericRemoveButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) - self.genericDisabledLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'The generic document/' - 'presentation importer has been disabled because OpenLP cannot ' - 'find OpenOffice.org on your computer.')) - self.ewFilenameLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'Filename:')) - self.ewBrowseButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Browse...')) - self.songBeamerAddButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Add Files...')) - self.songBeamerRemoveButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) -# self.csvFilenameLabel.setText( -# translate('SongsPlugin.ImportWizardForm', 'Filename:')) -# self.csvBrowseButton.setText( -# translate('SongsPlugin.ImportWizardForm', 'Browse...')) - self.importPage.setTitle( - translate('SongsPlugin.ImportWizardForm', 'Importing')) - self.importPage.setSubTitle( - translate('SongsPlugin.ImportWizardForm', - 'Please wait while your songs are imported.')) - self.importProgressLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'Ready.')) - self.importProgressBar.setFormat( - translate('SongsPlugin.ImportWizardForm', '%p%')) - # Align all QFormLayouts towards each other. - width = max(self.formatLabel.minimumSizeHint().width(), - self.openLP2FilenameLabel.minimumSizeHint().width()) - self.formatSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, - QtGui.QSizePolicy.Fixed) - self.openLP2FormLabelSpacer.changeSize(width, 0, - QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) - self.openLP1FormLabelSpacer.changeSize(width, 0, - QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) - self.ewFormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, - QtGui.QSizePolicy.Fixed) -# self.csvFormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, -# QtGui.QSizePolicy.Fixed) - - def addSingleFileSelectItem(self, prefix, obj_prefix=None, - can_disable=False): - if not obj_prefix: - obj_prefix = prefix - page = QtGui.QWidget() - page.setObjectName(obj_prefix + u'Page') - if can_disable: - importWidget = self.disablableWidget(page, prefix, obj_prefix) - else: - importWidget = page - importLayout = QtGui.QFormLayout(importWidget) - importLayout.setMargin(0) - if can_disable: - importLayout.setObjectName(obj_prefix + u'ImportLayout') - else: - importLayout.setObjectName(obj_prefix + u'Layout') - filenameLabel = QtGui.QLabel(importWidget) - filenameLabel.setObjectName(obj_prefix + u'FilenameLabel') - fileLayout = QtGui.QHBoxLayout() - fileLayout.setObjectName(obj_prefix + u'FileLayout') - filenameEdit = QtGui.QLineEdit(importWidget) - filenameEdit.setObjectName(obj_prefix + u'FilenameEdit') - fileLayout.addWidget(filenameEdit) - browseButton = QtGui.QToolButton(importWidget) - browseButton.setIcon(self.openIcon) - browseButton.setObjectName(obj_prefix + u'BrowseButton') - fileLayout.addWidget(browseButton) - importLayout.addRow(filenameLabel, fileLayout) - formSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, - QtGui.QSizePolicy.Minimum) - importLayout.setItem(1, QtGui.QFormLayout.LabelRole, formSpacer) - self.formatStack.addWidget(page) - setattr(self, prefix + u'Page', page) - setattr(self, prefix + u'FilenameLabel', filenameLabel) - setattr(self, prefix + u'FormLabelSpacer', formSpacer) - setattr(self, prefix + u'FileLayout', fileLayout) - setattr(self, prefix + u'FilenameEdit', filenameEdit) - setattr(self, prefix + u'BrowseButton', browseButton) - if can_disable: - setattr(self, prefix + u'ImportLayout', importLayout) - else: - setattr(self, prefix + u'Layout', importLayout) - self.formatComboBox.addItem(u'') - - def addMultiFileSelectItem(self, prefix, obj_prefix=None, - can_disable=False): - if not obj_prefix: - obj_prefix = prefix - page = QtGui.QWidget() - page.setObjectName(obj_prefix + u'Page') - if can_disable: - importWidget = self.disablableWidget(page, prefix, obj_prefix) - else: - importWidget = page - importLayout = QtGui.QVBoxLayout(importWidget) - importLayout.setMargin(0) - if can_disable: - importLayout.setObjectName(obj_prefix + u'ImportLayout') - else: - importLayout.setObjectName(obj_prefix + u'Layout') - fileListWidget = QtGui.QListWidget(importWidget) - fileListWidget.setSelectionMode( - QtGui.QAbstractItemView.ExtendedSelection) - fileListWidget.setObjectName(obj_prefix + u'FileListWidget') - importLayout.addWidget(fileListWidget) - buttonLayout = QtGui.QHBoxLayout() - buttonLayout.setObjectName(obj_prefix + u'ButtonLayout') - addButton = QtGui.QPushButton(importWidget) - addButton.setIcon(self.openIcon) - addButton.setObjectName(obj_prefix + u'AddButton') - buttonLayout.addWidget(addButton) - buttonLayout.addStretch() - removeButton = QtGui.QPushButton(importWidget) - removeButton.setIcon(self.deleteIcon) - removeButton.setObjectName(obj_prefix + u'RemoveButton') - buttonLayout.addWidget(removeButton) - importLayout.addLayout(buttonLayout) - self.formatStack.addWidget(page) - setattr(self, prefix + u'Page', page) - setattr(self, prefix + u'FileListWidget', fileListWidget) - setattr(self, prefix + u'ButtonLayout', buttonLayout) - setattr(self, prefix + u'AddButton', addButton) - setattr(self, prefix + u'RemoveButton', removeButton) - if can_disable: - setattr(self, prefix + u'ImportLayout', importLayout) - else: - setattr(self, prefix + u'Layout', importLayout) - self.formatComboBox.addItem(u'') - - def disablableWidget(self, page, prefix, obj_prefix): - layout = QtGui.QVBoxLayout(page) - layout.setMargin(0) - layout.setSpacing(0) - layout.setObjectName(obj_prefix + u'Layout') - disabledWidget = QtGui.QWidget(page) - disabledWidget.setVisible(False) - disabledWidget.setObjectName(obj_prefix + u'DisabledWidget') - disabledLayout = QtGui.QVBoxLayout(disabledWidget) - disabledLayout.setMargin(0) - disabledLayout.setObjectName(obj_prefix + u'DisabledLayout') - disabledLabel = QtGui.QLabel(disabledWidget) - disabledLabel.setWordWrap(True) - disabledLabel.setObjectName(obj_prefix + u'DisabledLabel') - disabledLayout.addWidget(disabledLabel) - layout.addWidget(disabledWidget) - importWidget = QtGui.QWidget(page) - importWidget.setObjectName(obj_prefix + u'ImportWidget') - layout.addWidget(importWidget) - setattr(self, prefix + u'Layout', layout) - setattr(self, prefix + u'DisabledWidget', disabledWidget) - setattr(self, prefix + u'DisabledLayout', disabledLayout) - setattr(self, prefix + u'DisabledLabel', disabledLabel) - setattr(self, prefix + u'ImportWidget', importWidget) - return importWidget diff --git a/openlp/plugins/songs/lib/cclifileimport.py b/openlp/plugins/songs/lib/cclifileimport.py index 1b8531755..2234a81b7 100644 --- a/openlp/plugins/songs/lib/cclifileimport.py +++ b/openlp/plugins/songs/lib/cclifileimport.py @@ -67,7 +67,7 @@ class CCLIFileImport(SongImport): """ log.debug(u'Starting CCLI File Import') song_total = len(self.filenames) - self.import_wizard.importProgressBar.setMaximum(song_total) + self.import_wizard.progressBar.setMaximum(song_total) song_count = 1 for filename in self.filenames: self.import_wizard.incrementProgressBar(unicode(translate( diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index d74cd284f..312e3b759 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -186,7 +186,7 @@ class EasyWorshipSongImport(SongImport): # There does not appear to be a _reliable_ way of getting the number # of songs/records, so let's use file blocks for measuring progress. total_blocks = (db_size - header_size) / (block_size * 1024) - self.import_wizard.importProgressBar.setMaximum(total_blocks) + self.import_wizard.progressBar.setMaximum(total_blocks) # Read the field description information db_file.seek(120) field_info = db_file.read(num_fields * 2) diff --git a/openlp/plugins/songs/lib/olp1import.py b/openlp/plugins/songs/lib/olp1import.py index ceaee3302..c3e1ca6b4 100644 --- a/openlp/plugins/songs/lib/olp1import.py +++ b/openlp/plugins/songs/lib/olp1import.py @@ -78,7 +78,7 @@ class OpenLP1SongImport(SongImport): cursor.execute(u'SELECT COUNT(songid) FROM songs') count = cursor.fetchone()[0] success = True - self.import_wizard.importProgressBar.setMaximum(count) + self.import_wizard.progressBar.setMaximum(count) # "cache" our list of authors cursor.execute(u'-- types int, unicode') cursor.execute(u'SELECT authorid, authorname FROM authors') diff --git a/openlp/plugins/songs/lib/olpimport.py b/openlp/plugins/songs/lib/olpimport.py index e366ddf4b..d2a00447f 100644 --- a/openlp/plugins/songs/lib/olpimport.py +++ b/openlp/plugins/songs/lib/olpimport.py @@ -146,7 +146,7 @@ class OpenLPSongImport(SongImport): source_songs = self.source_session.query(OldSong).all() song_total = len(source_songs) - self.import_wizard.importProgressBar.setMaximum(song_total) + self.import_wizard.progressBar.setMaximum(song_total) song_count = 1 for song in source_songs: self.import_wizard.incrementProgressBar(unicode(translate( diff --git a/openlp/plugins/songs/lib/oooimport.py b/openlp/plugins/songs/lib/oooimport.py index c5cca4fd6..be33cb8fb 100644 --- a/openlp/plugins/songs/lib/oooimport.py +++ b/openlp/plugins/songs/lib/oooimport.py @@ -63,11 +63,11 @@ class OooImport(SongImport): self.filenames = kwargs[u'filenames'] self.uno_connection_type = u'pipe' #u'socket' QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'song_stop_import'), self.stop_import) + QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import) def do_import(self): self.abort = False - self.import_wizard.importProgressBar.setMaximum(0) + self.import_wizard.progressBar.setMaximum(0) self.start_ooo() for filename in self.filenames: if self.abort: @@ -85,7 +85,7 @@ class OooImport(SongImport): self.process_doc() self.close_ooo_file() self.close_ooo() - self.import_wizard.importProgressBar.setMaximum(1) + self.import_wizard.progressBar.setMaximum(1) self.import_wizard.incrementProgressBar(u'', 1) return True diff --git a/openlp/plugins/songs/lib/openlyricsimport.py b/openlp/plugins/songs/lib/openlyricsimport.py index c4610dfc0..220160b1d 100644 --- a/openlp/plugins/songs/lib/openlyricsimport.py +++ b/openlp/plugins/songs/lib/openlyricsimport.py @@ -60,7 +60,7 @@ class OpenLyricsImport(SongImport): """ Imports the songs. """ - self.import_wizard.importProgressBar.setMaximum(len(self.import_source)) + self.import_wizard.progressBar.setMaximum(len(self.import_source)) for file_path in self.import_source: if self.stop_import_flag: return False @@ -68,8 +68,8 @@ class OpenLyricsImport(SongImport): 'SongsPlugin.OpenLyricsImport', 'Importing %s...')) % os.path.basename(file_path)) parser = etree.XMLParser(remove_blank_text=True) - file = etree.parse(file_path, parser) - xml = unicode(etree.tostring(file)) + parsed_file = etree.parse(file_path, parser) + xml = unicode(etree.tostring(parsed_file)) if self.openLyrics.xml_to_song(xml) is None: log.debug(u'File could not be imported: %s' % file_path) # Importing this song failed! For now we stop import. diff --git a/openlp/plugins/songs/lib/opensongimport.py b/openlp/plugins/songs/lib/opensongimport.py index 6a60fcc6c..eb16f4ba4 100644 --- a/openlp/plugins/songs/lib/opensongimport.py +++ b/openlp/plugins/songs/lib/opensongimport.py @@ -129,7 +129,7 @@ class OpenSongImport(SongImport): else: numfiles += 1 log.debug(u'Total number of files: %d', numfiles) - self.import_wizard.importProgressBar.setMaximum(numfiles) + self.import_wizard.progressBar.setMaximum(numfiles) for filename in self.filenames: if self.stop_import_flag: success = False diff --git a/openlp/plugins/songs/lib/sofimport.py b/openlp/plugins/songs/lib/sofimport.py index 3e6ee8c3a..8475b0824 100644 --- a/openlp/plugins/songs/lib/sofimport.py +++ b/openlp/plugins/songs/lib/sofimport.py @@ -89,7 +89,7 @@ class SofImport(OooImport): self.process_sof_file() self.close_ooo_file() self.close_ooo() - self.import_wizard.importProgressBar.setMaximum(1) + self.import_wizard.progressBar.setMaximum(1) self.import_wizard.incrementProgressBar(u'', 1) return True @@ -550,4 +550,4 @@ class SofImport(OooImport): return 6 if song_number == 1119: return 7 - return None \ No newline at end of file + return None diff --git a/openlp/plugins/songs/lib/songbeamerimport.py b/openlp/plugins/songs/lib/songbeamerimport.py index 12ff53428..c783793db 100644 --- a/openlp/plugins/songs/lib/songbeamerimport.py +++ b/openlp/plugins/songs/lib/songbeamerimport.py @@ -75,7 +75,6 @@ class SongBeamerImport(SongImport): The song manager for the running OpenLP installation. """ SongImport.__init__(self, master_manager) - self.master_manager = master_manager if kwargs.has_key(u'filename'): self.import_source = kwargs[u'filename'] if kwargs.has_key(u'filenames'): @@ -87,7 +86,7 @@ class SongBeamerImport(SongImport): Recieve a single file, or a list of files to import. """ if isinstance(self.import_source, list): - self.import_wizard.importProgressBar.setMaximum( + self.import_wizard.progressBar.setMaximum( len(self.import_source)) for file in self.import_source: # TODO: check that it is a valid SongBeamer file diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index 05ed320a9..c1105a578 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -55,7 +55,7 @@ class SongImport(QtCore.QObject): self.stop_import_flag = False self.set_defaults() QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'songs_stop_import'), self.stop_import) + QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import) def set_defaults(self): """ @@ -364,4 +364,4 @@ class SongImport(QtCore.QObject): if self.theme_name: print u'THEME: ' + self.theme_name if self.ccli_number: - print u'CCLI: ' + self.ccli_number \ No newline at end of file + print u'CCLI: ' + self.ccli_number diff --git a/openlp/plugins/songs/lib/test/test_opensongimport.py b/openlp/plugins/songs/lib/test/test_opensongimport.py index 27c7cca48..fd1d37e3e 100644 --- a/openlp/plugins/songs/lib/test/test_opensongimport.py +++ b/openlp/plugins/songs/lib/test/test_opensongimport.py @@ -35,7 +35,7 @@ logging.basicConfig(filename=LOG_FILENAME,level=logging.INFO) # Stubs to replace the UI functions for raw testing class wizard_stub: def __init__(self): - self.importProgressBar=progbar_stub() + self.progressBar=progbar_stub() def incrementProgressBar(self, str): pass class progbar_stub: diff --git a/openlp/plugins/songs/lib/wowimport.py b/openlp/plugins/songs/lib/wowimport.py index 1d5470f9b..d0c308413 100644 --- a/openlp/plugins/songs/lib/wowimport.py +++ b/openlp/plugins/songs/lib/wowimport.py @@ -99,7 +99,6 @@ class WowImport(SongImport): The song manager for the running OpenLP installation. """ SongImport.__init__(self, master_manager) - self.master_manager = master_manager if kwargs.has_key(u'filename'): self.import_source = kwargs[u'filename'] if kwargs.has_key(u'filenames'): @@ -112,8 +111,7 @@ class WowImport(SongImport): """ if isinstance(self.import_source, list): - self.import_wizard.importProgressBar.setMaximum( - len(self.import_source)) + self.import_wizard.progressBar.setMaximum(len(self.import_source)) for file in self.import_source: self.author = u'' self.copyright = u'' From b25e128495ef41e6354789d3754de69633847ec7 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 14 Jan 2011 15:12:28 +0000 Subject: [PATCH 15/60] Fix Transitions in Bible display bug 701353 Fix display handling on restart so correct screen mode is set Fixes: https://launchpad.net/bugs/701353 --- openlp/core/lib/htmlbuilder.py | 2 +- openlp/core/ui/slidecontroller.py | 41 ++++++++++++++++++++------ openlp/plugins/bibles/lib/mediaitem.py | 8 ++--- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/openlp/core/lib/htmlbuilder.py b/openlp/core/lib/htmlbuilder.py index 0a26382f8..86056f4b5 100644 --- a/openlp/core/lib/htmlbuilder.py +++ b/openlp/core/lib/htmlbuilder.py @@ -641,4 +641,4 @@ def build_alert_css(alertTab, width): align = u'top' alert = style % (width, align, alertTab.font_face, alertTab.font_size, alertTab.font_color, alertTab.bg_color) - return alert \ No newline at end of file + return alert diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 690cb9264..8600f9afc 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -680,8 +680,17 @@ class SlideController(QtGui.QWidget): Allow the main display to blank the main display at startup time """ log.debug(u'mainDisplaySetBackground live = %s' % self.isLive) + display_type = QtCore.QSettings().value( + self.parent.generalSettingsSection + u'/screen blank', + QtCore.QVariant(u'')).toString() if not self.display.primary: - self.onBlankDisplay(True) + # Order done to handle initial conversion + if display_type == u'themed': + self.onThemeDisplay(True) + elif display_type == u'hidden': + self.onHideDisplay(True) + else: + self.onBlankDisplay(True) def onSlideBlank(self): """ @@ -705,13 +714,15 @@ class SlideController(QtGui.QWidget): self.ThemeScreen.setChecked(False) if self.screens.display_count > 1: self.DesktopScreen.setChecked(False) - QtCore.QSettings().setValue( - self.parent.generalSettingsSection + u'/screen blank', - QtCore.QVariant(checked)) if checked: Receiver.send_message(u'maindisplay_hide', HideMode.Blank) + QtCore.QSettings().setValue( + self.parent.generalSettingsSection + u'/screen blank', + QtCore.QVariant(u'blanked')) else: Receiver.send_message(u'maindisplay_show') + QtCore.QSettings().remove( + self.parent.generalSettingsSection + u'/screen blank') self.blankPlugin(checked) def onThemeDisplay(self, checked): @@ -722,12 +733,18 @@ class SlideController(QtGui.QWidget): self.HideMenu.setDefaultAction(self.ThemeScreen) self.BlankScreen.setChecked(False) self.ThemeScreen.setChecked(checked) + if self.screens.display_count > 1: self.DesktopScreen.setChecked(False) if checked: Receiver.send_message(u'maindisplay_hide', HideMode.Theme) + QtCore.QSettings().setValue( + self.parent.generalSettingsSection + u'/screen blank', + QtCore.QVariant(u'themed')) else: Receiver.send_message(u'maindisplay_show') + QtCore.QSettings().remove( + self.parent.generalSettingsSection + u'/screen blank') self.blankPlugin(checked) def onHideDisplay(self, checked): @@ -738,12 +755,19 @@ class SlideController(QtGui.QWidget): self.HideMenu.setDefaultAction(self.DesktopScreen) self.BlankScreen.setChecked(False) self.ThemeScreen.setChecked(False) - if self.screens.display_count > 1: - self.DesktopScreen.setChecked(checked) + # On valid if more than 1 display + if self.screens.display_count <= 1: + return + self.DesktopScreen.setChecked(checked) if checked: Receiver.send_message(u'maindisplay_hide', HideMode.Screen) + QtCore.QSettings().setValue( + self.parent.generalSettingsSection + u'/screen blank', + QtCore.QVariant(u'hidden')) else: Receiver.send_message(u'maindisplay_show') + QtCore.QSettings().remove( + self.parent.generalSettingsSection + u'/screen blank') self.hidePlugin(checked) def blankPlugin(self, blank): @@ -1033,9 +1057,8 @@ class SlideController(QtGui.QWidget): if self.BlankScreen.isChecked: self.BlankScreen.setChecked(False) self.HideMenu.setDefaultAction(self.BlankScreen) - QtCore.QSettings().setValue( - self.parent.generalSettingsSection + u'/screen blank', - QtCore.QVariant(False)) + QtCore.QSettings().remove( + self.parent.generalSettingsSection + u'/screen blank') if self.ThemeScreen.isChecked: self.ThemeScreen.setChecked(False) self.HideMenu.setDefaultAction(self.ThemeScreen) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 1921fbc6d..646c541b9 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -745,21 +745,21 @@ class BibleMediaItem(MediaManagerItem): second_copyright, second_permissions) if footer not in raw_footer: raw_footer.append(footer) - bible_text = u'%s\u00a0%s\n\n%s\u00a0%s' % (verse_text, text, + bible_text = u'%s%s\n\n%s%s' % (verse_text, text, verse_text, second_text) raw_slides.append(bible_text) bible_text = u'' # If we are 'Verse Per Slide' then create a new slide. elif self.parent.settings_tab.layout_style == 0: - bible_text = u'%s\u00a0%s' % (verse_text, text) + bible_text = u'%s%s' % (verse_text, text) raw_slides.append(bible_text) bible_text = u'' # If we are 'Verse Per Line' then force a new line. elif self.parent.settings_tab.layout_style == 1: - bible_text = u'%s %s\u00a0%s\n' % (bible_text, verse_text, text) + bible_text = u'%s %s%s\n' % (bible_text, verse_text, text) # We have to be 'Continuous'. else: - bible_text = u'%s %s\u00a0%s\n' % (bible_text, verse_text, text) + bible_text = u'%s %s%s\n' % (bible_text, verse_text, text) if not old_item: start_item = item elif self.checkTitle(item, old_item): From be9793f91b2419804ca5f16a8fbf4d23220b7a55 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 14 Jan 2011 16:47:30 +0000 Subject: [PATCH 16/60] Remove old file --- demo_theme.xml | 17 ----------------- openlp/core/ui/slidecontroller.py | 1 - 2 files changed, 18 deletions(-) delete mode 100644 demo_theme.xml diff --git a/demo_theme.xml b/demo_theme.xml deleted file mode 100644 index 118a1d7d4..000000000 --- a/demo_theme.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - openlp.org 2.0 Demo Theme - 2 - ./openlp/core/test/data_for_tests/treesbig.jpg - clBlack - - Tahoma - clWhite - 16 - -1 - $00000001 - -1 - clRed - 2 - 2 - diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 8600f9afc..1ace873ff 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -733,7 +733,6 @@ class SlideController(QtGui.QWidget): self.HideMenu.setDefaultAction(self.ThemeScreen) self.BlankScreen.setChecked(False) self.ThemeScreen.setChecked(checked) - if self.screens.display_count > 1: self.DesktopScreen.setChecked(False) if checked: From 6b2dc8a8bdd437a5f9b7d7e1123845e4812c4c96 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 14 Jan 2011 17:46:59 +0000 Subject: [PATCH 17/60] Remove blank at start of bible verse --- openlp/plugins/bibles/lib/mediaitem.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 831f41098..40deb2244 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -718,12 +718,12 @@ class BibleMediaItem(MediaManagerItem): raw_footer.append(footer) bible_text = u'%s%s\n\n%s%s' % (verse_text, text, verse_text, second_text) - raw_slides.append(bible_text) + raw_slides.append(bible_text.rstrip()) bible_text = u'' # If we are 'Verse Per Slide' then create a new slide. elif self.parent.settings_tab.layout_style == 0: bible_text = u'%s%s' % (verse_text, text) - raw_slides.append(bible_text) + raw_slides.append(bible_text.rstrip()) bible_text = u'' # If we are 'Verse Per Line' then force a new line. elif self.parent.settings_tab.layout_style == 1: @@ -741,7 +741,7 @@ class BibleMediaItem(MediaManagerItem): raw_title.append(self.formatTitle(start_item, item)) # If there are no more items we check whether we have to add bible_text. if bible_text: - raw_slides.append(bible_text) + raw_slides.append(bible_text.lstrip()) bible_text = u'' # Service Item: Capabilities if self.parent.settings_tab.layout_style == 2 and not second_bible: From ecb97881a1b15a6de48520ff6621c4395936fc41 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Fri, 14 Jan 2011 18:58:47 +0000 Subject: [PATCH 18/60] Refactor file deleting, cleanups --- documentation/api/source/plugins/songs.rst | 3 --- openlp/core/lib/db.py | 10 +++------ openlp/core/ui/maindisplay.py | 2 ++ openlp/core/ui/servicemanager.py | 21 +++++-------------- openlp/core/ui/thememanager.py | 18 ++++++---------- openlp/core/utils/__init__.py | 17 +++++++++++++++ openlp/plugins/images/lib/mediaitem.py | 12 ++++------- .../presentations/lib/impresscontroller.py | 4 ++-- openlp/plugins/songs/lib/cclifileimport.py | 4 ---- 9 files changed, 39 insertions(+), 52 deletions(-) diff --git a/documentation/api/source/plugins/songs.rst b/documentation/api/source/plugins/songs.rst index fed9907a2..1e86ce020 100644 --- a/documentation/api/source/plugins/songs.rst +++ b/documentation/api/source/plugins/songs.rst @@ -72,9 +72,6 @@ Song Importers .. automodule:: openlp.plugins.songs.lib.cclifileimport :members: -.. autoclass:: openlp.plugins.songs.lib.cclifileimport.CCLIFileImportError - :members: - .. automodule:: openlp.plugins.songs.lib.ewimport :members: diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index c2e1243ce..3171730ea 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -34,7 +34,7 @@ from sqlalchemy import create_engine, MetaData from sqlalchemy.exceptions import InvalidRequestError from sqlalchemy.orm import scoped_session, sessionmaker -from openlp.core.utils import AppLocation +from openlp.core.utils import AppLocation, delete_file log = logging.getLogger(__name__) @@ -75,11 +75,7 @@ def delete_database(plugin_name, db_file_name=None): else: db_file_path = os.path.join( AppLocation.get_section_data_path(plugin_name), plugin_name) - try: - os.remove(db_file_path) - return True - except OSError: - return False + return delete_file(db_file_path) class BaseModel(object): """ @@ -295,4 +291,4 @@ class Manager(object): if self.is_dirty: engine = create_engine(self.db_url) if self.db_url.startswith(u'sqlite'): - engine.execute("vacuum") \ No newline at end of file + engine.execute("vacuum") diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index ab69cd1e9..273a3c4f0 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -24,6 +24,8 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### """ +The :mod:`maindisplay` module provides the functionality to display screens +and play multimedia within OpenLP. """ import logging import os diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index ffc2bee25..0b5b25e06 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -37,7 +37,8 @@ from openlp.core.lib import OpenLPToolbar, ServiceItem, context_menu_action, \ Receiver, build_icon, ItemCapabilities, SettingsManager, translate, \ ThemeLevel from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm -from openlp.core.utils import AppLocation, file_is_unicode, split_filename +from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \ + split_filename class ServiceManagerList(QtGui.QTreeWidget): """ @@ -445,11 +446,7 @@ class ServiceManager(QtGui.QWidget): file.close() if zip: zip.close() - try: - os.remove(serviceFileName) - except (IOError, OSError): - # if not present do not worry - pass + delete_file(serviceFileName) self.mainwindow.addRecentFile(fileName) self.setModified(False) return True @@ -515,11 +512,7 @@ class ServiceManager(QtGui.QWidget): if serviceItem.is_capable(ItemCapabilities.OnLoadUpdate): Receiver.send_message(u'%s_service_load' % serviceItem.name.lower(), serviceItem) - try: - if os.path.isfile(p_file): - os.remove(p_file) - except (IOError, OSError): - log.exception(u'Failed to remove osd file') + delete_file(p_file) else: QtGui.QMessageBox.critical( self, translate('OpenLP.ServiceManager', 'Error'), @@ -873,11 +866,7 @@ class ServiceManager(QtGui.QWidget): """ for file in os.listdir(self.servicePath): file_path = os.path.join(self.servicePath, file) - try: - if os.path.isfile(file_path): - os.remove(file_path) - except OSError: - log.exception(u'Failed to clean up servicePath') + delete_file(file_path) def onThemeComboBoxSelected(self, currentIndex): """ diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 81e191396..966306eb1 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -37,7 +37,7 @@ from openlp.core.theme import Theme from openlp.core.lib import OpenLPToolbar, ThemeXML, get_text_file_string, \ build_icon, Receiver, SettingsManager, translate, check_item_selected, \ BackgroundType, BackgroundGradientType, check_directory_exists -from openlp.core.utils import AppLocation, file_is_unicode, \ +from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \ get_filesystem_encoding log = logging.getLogger(__name__) @@ -341,9 +341,9 @@ class ThemeManager(QtGui.QWidget): """ self.themelist.remove(theme) thumb = theme + u'.png' + delete_file(os.path.join(self.path, thumb)) + delete_file(os.path.join(self.thumbPath, thumb)) try: - os.remove(os.path.join(self.path, thumb)) - os.remove(os.path.join(self.thumbPath, thumb)) encoding = get_filesystem_encoding() shutil.rmtree(os.path.join(self.path, theme).encode(encoding)) except OSError: @@ -521,11 +521,8 @@ class ThemeManager(QtGui.QWidget): check_directory_exists(theme_dir) if os.path.splitext(ucsfile)[1].lower() in [u'.xml']: xml_data = zip.read(file) - try: - xml_data = xml_data.decode(u'utf-8') - except UnicodeDecodeError: - log.exception(u'Theme XML is not UTF-8 ' - u'encoded.') + xml_data = file_is_unicode(xml_data) + if not xml_data: break filexml = self.checkVersionAndConvert(xml_data) outfile = open(fullpath, u'w') @@ -603,10 +600,7 @@ class ThemeManager(QtGui.QWidget): theme_file = os.path.join(theme_dir, name + u'.xml') if imageTo and self.oldBackgroundImage and \ imageTo != self.oldBackgroundImage: - try: - os.remove(self.oldBackgroundImage) - except OSError: - log.exception(u'Unable to remove old theme background') + delete_file(self.oldBackgroundImage) outfile = None try: outfile = open(theme_file, u'w') diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index d8012f433..b7d95a46d 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -282,6 +282,23 @@ def split_filename(path): else: return os.path.split(path) +def delete_file(file_path_name): + """ + Deletes a file from the system. + + ``file_path_name`` + The file, including path, to delete. + """ + if not file_path_name: + return False + try: + if os.path.exists(file_path_name): + os.remove(file_path_name) + return True + except (IOError, OSError): + log.exception("Unable to delete file %s" % file_path_name) + return False + def get_web_page(url, header=None, update_openlp=False): """ Attempts to download the webpage at url and returns that page or None. diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 063a80d02..e9f41abcd 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -32,7 +32,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \ ItemCapabilities, SettingsManager, translate, check_item_selected, \ Receiver, check_directory_exists -from openlp.core.utils import AppLocation, get_images_filter +from openlp.core.utils import AppLocation, delete_file, get_images_filter log = logging.getLogger(__name__) @@ -115,12 +115,8 @@ class ImageMediaItem(MediaManagerItem): for row in row_list: text = self.listView.item(row) if text: - try: - os.remove(os.path.join(self.servicePath, - unicode(text.text()))) - except OSError: - # if not present do not worry - pass + delete_file(os.path.join(self.servicePath, + unicode(text.text()))) self.listView.takeItem(row) SettingsManager.set_list(self.settingsSection, self.settingsSection, self.getFileList()) @@ -216,4 +212,4 @@ class ImageMediaItem(MediaManagerItem): 'the image file "%s" no longer exists.')) % filename}) def onPreviewClick(self): - MediaManagerItem.onPreviewClick(self) \ No newline at end of file + MediaManagerItem.onPreviewClick(self) diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index 7c8cf593d..516c595c7 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -51,6 +51,7 @@ else: from PyQt4 import QtCore +from openlp.core.utils import delete_file from presentationcontroller import PresentationController, PresentationDocument log = logging.getLogger(__name__) @@ -292,8 +293,7 @@ class ImpressDocument(PresentationDocument): try: doc.storeToURL(urlpath, props) self.convert_thumbnail(path, idx + 1) - if os.path.exists(path): - os.remove(path) + delete_file(path) except: log.exception(u'%s - Unable to store openoffice preview' % path) diff --git a/openlp/plugins/songs/lib/cclifileimport.py b/openlp/plugins/songs/lib/cclifileimport.py index 2234a81b7..441391d02 100644 --- a/openlp/plugins/songs/lib/cclifileimport.py +++ b/openlp/plugins/songs/lib/cclifileimport.py @@ -34,9 +34,6 @@ from songimport import SongImport log = logging.getLogger(__name__) -class CCLIFileImportError(Exception): - pass - class CCLIFileImport(SongImport): """ The :class:`CCLIFileImport` class provides OpenLP with the ability to @@ -152,7 +149,6 @@ class CCLIFileImport(SongImport): """ log.debug(u'USR file text: %s', textList) - lyrics = [] self.set_defaults() for line in textList: if line.startswith(u'Title='): From 6e2cc7ebffd67cc29db81c5e8f52065b3f05cd61 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Fri, 14 Jan 2011 21:19:41 +0000 Subject: [PATCH 19/60] Fix db committing too early (Bug #703073) --- openlp/plugins/songs/forms/editsongform.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 86249f024..52edbdb65 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -331,7 +331,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): else: author = Author.populate(first_name=text.rsplit(u' ', 1)[0], last_name=text.rsplit(u' ', 1)[1], display_name=text) - self.manager.save_object(author) + self.manager.save_object(author, False) author_item = QtGui.QListWidgetItem( unicode(author.display_name)) author_item.setData(QtCore.Qt.UserRole, @@ -386,7 +386,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes: topic = Topic.populate(name=text) - self.manager.save_object(topic) + self.manager.save_object(topic, False) topic_item = QtGui.QListWidgetItem(unicode(topic.name)) topic_item.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id)) @@ -654,7 +654,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): def accept(self): """ - Exit Dialog and save soong if valid + Exit Dialog and save song if valid """ log.debug(u'accept') self.clearCaches() From 2428e9a46a43b70dab37298d3ea9d7b70c83b061 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Fri, 14 Jan 2011 21:37:32 +0000 Subject: [PATCH 20/60] Fix db fix --- openlp/plugins/songs/forms/editsongform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 52edbdb65..0ddcdbcea 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -670,7 +670,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes: book = Book.populate(name=text, publisher=u'') - self.manager.save_object(book) + self.manager.save_object(book, False) else: return if self.saveSong(): From f6a6a7a4fc270a0ade5d6d515bd1657a37639eb5 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Fri, 14 Jan 2011 22:17:46 +0000 Subject: [PATCH 21/60] Fix db flushing for songs --- openlp/plugins/songs/lib/db.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/songs/lib/db.py b/openlp/plugins/songs/lib/db.py index fc3aa06d1..faa0a88da 100644 --- a/openlp/plugins/songs/lib/db.py +++ b/openlp/plugins/songs/lib/db.py @@ -72,7 +72,7 @@ def init_schema(url): ``url`` The database to setup """ - session, metadata = init_db(url) + session, metadata = init_db(url, False) # Definition of the "authors" table authors_table = Table(u'authors', metadata, @@ -181,4 +181,4 @@ def init_schema(url): mapper(Topic, topics_table) metadata.create_all(checkfirst=True) - return session \ No newline at end of file + return session From ee6412e2a0b3884e3d5296b702dbb1207e8484e9 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sat, 15 Jan 2011 00:53:12 +0000 Subject: [PATCH 22/60] Refactor error messages --- openlp/core/ui/__init__.py | 29 ++++++++- openlp/core/ui/servicemanager.py | 12 ++-- openlp/core/ui/thememanager.py | 20 +++--- openlp/plugins/bibles/lib/mediaitem.py | 12 ++-- openlp/plugins/custom/forms/editcustomform.py | 6 +- openlp/plugins/songs/forms/authorsform.py | 26 +++----- openlp/plugins/songs/forms/editsongform.py | 22 +++---- openlp/plugins/songs/forms/editverseform.py | 5 +- openlp/plugins/songs/forms/songbookform.py | 7 +-- .../songs/forms/songmaintenanceform.py | 61 +++++++------------ openlp/plugins/songs/forms/topicsform.py | 7 +-- 11 files changed, 91 insertions(+), 116 deletions(-) diff --git a/openlp/core/ui/__init__.py b/openlp/core/ui/__init__.py index 698216365..931773b8f 100644 --- a/openlp/core/ui/__init__.py +++ b/openlp/core/ui/__init__.py @@ -26,6 +26,9 @@ """ The :mod:`ui` module provides the core user interface for OpenLP """ +from PyQt4 import QtGui + +from openlp.core.lib import translate class HideMode(object): """ @@ -48,6 +51,26 @@ class HideMode(object): Theme = 2 Screen = 3 + +def criticalErrorMessageBox(parent, message, question=False): + """ + Provides a standard critical message box for errors that OpenLP displays + to users. + + ``parent`` + The parent UI element to attach the dialog to. + + ``message`` + The message to display to the user. + """ + if question: + return QtGui.QMessageBox.critical(parent, + translate('OpenLP.Ui', 'Error'), + message, QtGui.QMessageBox.StandardButtons( + QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)) + return QtGui.QMessageBox.critical(parent, translate('OpenLP.Ui', 'Error'), + message) + from themeform import ThemeForm from filerenameform import FileRenameForm from maindisplay import MainDisplay @@ -68,6 +91,6 @@ from mediadockmanager import MediaDockManager from servicemanager import ServiceManager from thememanager import ThemeManager -__all__ = ['SplashScreen', 'AboutForm', 'SettingsForm', - 'MainDisplay', 'SlideController', 'ServiceManager', 'ThemeManager', - 'MediaDockManager', 'ServiceItemEditForm'] +__all__ = ['criticalErrorMessageBox', 'SplashScreen', 'AboutForm', + 'SettingsForm', 'MainDisplay', 'SlideController', 'ServiceManager', + 'ThemeManager', 'MediaDockManager', 'ServiceItemEditForm'] diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index ffc2bee25..229590fa5 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -36,7 +36,8 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import OpenLPToolbar, ServiceItem, context_menu_action, \ Receiver, build_icon, ItemCapabilities, SettingsManager, translate, \ ThemeLevel -from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm +from openlp.core.ui import criticalErrorMessageBox, ServiceNoteForm, \ + ServiceItemEditForm from openlp.core.utils import AppLocation, file_is_unicode, split_filename class ServiceManagerList(QtGui.QTreeWidget): @@ -486,8 +487,7 @@ class ServiceManager(QtGui.QWidget): for file in zip.namelist(): ucsfile = file_is_unicode(file) if not ucsfile: - QtGui.QMessageBox.critical( - self, translate('OpenLP.ServiceManager', 'Error'), + criticalErrorMessageBox(self, translate('OpenLP.ServiceManager', 'File is not a valid service.\n' 'The content encoding is not UTF-8.')) @@ -521,10 +521,8 @@ class ServiceManager(QtGui.QWidget): except (IOError, OSError): log.exception(u'Failed to remove osd file') else: - QtGui.QMessageBox.critical( - self, translate('OpenLP.ServiceManager', 'Error'), - translate('OpenLP.ServiceManager', - 'File is not a valid service.')) + criticalErrorMessageBox(self, translate('OpenLP.ServiceManager', + 'File is not a valid service.')) log.exception(u'File contains no service data') except (IOError, NameError): log.exception(u'Problem loading a service file') diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 81e191396..ccea7faaf 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -32,7 +32,7 @@ import logging from xml.etree.ElementTree import ElementTree, XML from PyQt4 import QtCore, QtGui -from openlp.core.ui import FileRenameForm, ThemeForm +from openlp.core.ui import criticalErrorMessageBox, FileRenameForm, ThemeForm from openlp.core.theme import Theme from openlp.core.lib import OpenLPToolbar, ThemeXML, get_text_file_string, \ build_icon, Receiver, SettingsManager, translate, check_item_selected, \ @@ -359,9 +359,7 @@ class ThemeManager(QtGui.QWidget): """ item = self.themeListWidget.currentItem() if item is None: - QtGui.QMessageBox.critical(self, - translate('OpenLP.ThemeManager', 'Error'), - translate('OpenLP.ThemeManager', + criticalErrorMessageBox(self, translate('OpenLP.ThemeManager', 'You have not selected a theme.')) return theme = unicode(item.data(QtCore.Qt.UserRole).toString()) @@ -498,11 +496,9 @@ class ThemeManager(QtGui.QWidget): for file in zip.namelist(): ucsfile = file_is_unicode(file) if not ucsfile: - QtGui.QMessageBox.critical( - self, translate('OpenLP.ThemeManager', 'Error'), - translate('OpenLP.ThemeManager', - 'File is not a valid theme.\n' - 'The content encoding is not UTF-8.')) + criticalErrorMessageBox(self, + translate('OpenLP.ThemeManager', 'File is not a valid ' + 'theme.\nThe content encoding is not UTF-8.')) continue osfile = unicode(QtCore.QDir.toNativeSeparators(ucsfile)) theme_dir = None @@ -700,10 +696,8 @@ class ThemeManager(QtGui.QWidget): return False # should be the same unless default if theme != unicode(item.data(QtCore.Qt.UserRole).toString()): - QtGui.QMessageBox.critical(self, - translate('OpenLP.ThemeManager', 'Error'), - translate('OpenLP.ThemeManager', - 'You are unable to delete the default theme.')) + criticalErrorMessageBox(self, translate('OpenLP.ThemeManager', + 'You are unable to delete the default theme.')) return False # check for use in the system else where. if testPlugin: diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index d60afccd5..81dd1777b 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -534,13 +534,11 @@ class BibleMediaItem(MediaManagerItem): if item_second_bible and second_bible or not item_second_bible and \ not second_bible: self.displayResults(bible, second_bible) - elif QtGui.QMessageBox.critical(self, - translate('BiblePlugin.MediaItem', 'Error'), + elif criticalErrorMessageBox(self, translate('BiblePlugin.MediaItem', 'You cannot combine single ' 'and second bible verses. Do you want to delete your search ' 'results and start a new search?'), - QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | - QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.Yes: + True) == QtGui.QMessageBox.Yes: self.listView.clear() self.displayResults(bible, second_bible) else: @@ -584,13 +582,11 @@ class BibleMediaItem(MediaManagerItem): if item_second_bible and second_bible or not item_second_bible and \ not second_bible: self.displayResults(bible, second_bible) - elif QtGui.QMessageBox.critical(self, - translate('BiblePlugin.MediaItem', 'Error'), + elif criticalErrorMessageBox(self, translate('BiblePlugin.MediaItem', 'You cannot combine single ' 'and second bible verses. Do you want to delete your search ' 'results and start a new search?'), - QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | - QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.Yes: + True) == QtGui.QMessageBox.Yes: self.listView.clear() self.displayResults(bible, second_bible) elif self.search_results: diff --git a/openlp/plugins/custom/forms/editcustomform.py b/openlp/plugins/custom/forms/editcustomform.py index 2f005828a..794fde9e8 100644 --- a/openlp/plugins/custom/forms/editcustomform.py +++ b/openlp/plugins/custom/forms/editcustomform.py @@ -29,6 +29,7 @@ import logging from PyQt4 import QtCore, QtGui from openlp.core.lib import Receiver, translate +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.custom.lib import CustomXMLBuilder, CustomXMLParser from openlp.plugins.custom.lib.db import CustomSlide from editcustomdialog import Ui_CustomEditDialog @@ -151,8 +152,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog): """ valid, message = self._validate() if not valid: - QtGui.QMessageBox.critical(self, - translate('CustomPlugin.EditCustomForm', 'Error'), message) + criticalErrorMessageBox(self, message) return False sxml = CustomXMLBuilder() sxml.new_document() @@ -265,4 +265,4 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog): if self.slideListView.count() == 0: return False, translate('CustomPlugin.EditCustomForm', 'You need to add at least one slide') - return True, u'' \ No newline at end of file + return True, u'' diff --git a/openlp/plugins/songs/forms/authorsform.py b/openlp/plugins/songs/forms/authorsform.py index 320d3c1d3..09f361816 100644 --- a/openlp/plugins/songs/forms/authorsform.py +++ b/openlp/plugins/songs/forms/authorsform.py @@ -27,6 +27,7 @@ from PyQt4 import QtGui, QtCore from openlp.core.lib import translate +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.songs.forms.authorsdialog import Ui_AuthorsDialog class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog): @@ -79,28 +80,21 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog): def accept(self): if not self.firstNameEdit.text(): - QtGui.QMessageBox.critical( - self, translate('SongsPlugin.AuthorsForm', 'Error'), - translate('SongsPlugin.AuthorsForm', - 'You need to type in the first name of the author.')) + criticalErrorMessageBox(self, translate('SongsPlugin.AuthorsForm', + 'You need to type in the first name of the author.')) self.firstNameEdit.setFocus() return False elif not self.lastNameEdit.text(): - QtGui.QMessageBox.critical( - self, translate('SongsPlugin.AuthorsForm', 'Error'), - translate('SongsPlugin.AuthorsForm', - 'You need to type in the last name of the author.')) + criticalErrorMessageBox(self, translate('SongsPlugin.AuthorsForm', + 'You need to type in the last name of the author.')) self.lastNameEdit.setFocus() return False elif not self.displayEdit.text(): - if QtGui.QMessageBox.critical( - self, translate('SongsPlugin.AuthorsForm', 'Error'), - translate('SongsPlugin.AuthorsForm', - 'You have not set a display name for the ' - 'author, combine the first and last names?'), - QtGui.QMessageBox.StandardButtons( - QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) - ) == QtGui.QMessageBox.Yes: + if criticalErrorMessageBox(self, + translate('SongsPlugin.AuthorsForm', + 'You have not set a display name for the ' + 'author, combine the first and last names?'), + True) == QtGui.QMessageBox.Yes: self.displayEdit.setText(self.firstNameEdit.text() + \ u' ' + self.lastNameEdit.text()) return QtGui.QDialog.accept(self) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 86249f024..980f00076 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -30,6 +30,7 @@ import re from PyQt4 import QtCore, QtGui from openlp.core.lib import Receiver, translate +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.songs.forms import EditVerseForm from openlp.plugins.songs.lib import SongXML, VerseType from openlp.plugins.songs.lib.db import Book, Song, Author, Topic @@ -346,8 +347,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): author = self.manager.get_object(Author, item_id) if self.authorsListView.findItems(unicode(author.display_name), QtCore.Qt.MatchExactly): - QtGui.QMessageBox.warning(self, - translate('SongsPlugin.EditSongForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', 'This author is ' 'already in the list.')) else: @@ -400,8 +400,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): topic = self.manager.get_object(Topic, item_id) if self.topicsListView.findItems(unicode(topic.name), QtCore.Qt.MatchExactly): - QtGui.QMessageBox.warning(self, - translate('SongsPlugin.EditSongForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', 'This topic is ' 'already in the list.')) else: @@ -533,25 +532,19 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): if len(self.titleEdit.displayText()) == 0: self.songTabWidget.setCurrentIndex(0) self.titleEdit.setFocus() - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.EditSongForm', 'Error'), - translate('SongsPlugin.EditSongForm', + criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', 'You need to type in a song title.')) return False if self.verseListWidget.rowCount() == 0: self.songTabWidget.setCurrentIndex(0) self.verseListWidget.setFocus() - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.EditSongForm', 'Error'), - translate('SongsPlugin.EditSongForm', + criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', 'You need to type in at least one verse.')) return False if self.authorsListView.count() == 0: self.songTabWidget.setCurrentIndex(1) self.authorsListView.setFocus() - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.EditSongForm', 'Warning'), - translate('SongsPlugin.EditSongForm', + criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', 'You need to have an author for this song.')) return False if self.song.verse_order: @@ -578,8 +571,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): valid = verses.pop(0) for verse in verses: valid = valid + u', ' + verse - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.EditSongForm', 'Error'), + criticalErrorMessageBox(self, unicode(translate('SongsPlugin.EditSongForm', 'The verse order is invalid. There is no verse ' 'corresponding to %s. Valid entries are %s.')) % \ diff --git a/openlp/plugins/songs/forms/editverseform.py b/openlp/plugins/songs/forms/editverseform.py index c01ad9726..93a259274 100644 --- a/openlp/plugins/songs/forms/editverseform.py +++ b/openlp/plugins/songs/forms/editverseform.py @@ -29,6 +29,7 @@ import logging from PyQt4 import QtCore, QtGui +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.songs.lib import VerseType, translate from editversedialog import Ui_EditVerseDialog @@ -167,9 +168,7 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog): else: value = self.getVerse()[0].split(u'\n')[1] if len(value) == 0: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.EditSongForm', 'Error'), - translate('SongsPlugin.EditSongForm', + criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', 'You need to type some text in to the verse.')) return False QtGui.QDialog.accept(self) diff --git a/openlp/plugins/songs/forms/songbookform.py b/openlp/plugins/songs/forms/songbookform.py index 4a4a08ff6..96d4fdf1b 100644 --- a/openlp/plugins/songs/forms/songbookform.py +++ b/openlp/plugins/songs/forms/songbookform.py @@ -27,6 +27,7 @@ from PyQt4 import QtGui from openlp.core.lib import translate +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.songs.forms.songbookdialog import Ui_SongBookDialog class SongBookForm(QtGui.QDialog, Ui_SongBookDialog): @@ -49,10 +50,8 @@ class SongBookForm(QtGui.QDialog, Ui_SongBookDialog): def accept(self): if not self.nameEdit.text(): - QtGui.QMessageBox.critical( - self, translate('SongsPlugin.SongBookForm', 'Error'), - translate('SongsPlugin.SongBookForm', - 'You need to type in a name for the book.')) + criticalErrorMessageBox(self, translate('SongsPlugin.SongBookForm', + 'You need to type in a name for the book.')) self.nameEdit.setFocus() return False else: diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index c964c5192..4dc9361c5 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -23,15 +23,19 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### +import logging from PyQt4 import QtGui, QtCore from sqlalchemy.sql import and_ from openlp.core.lib import Receiver, translate +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.songs.forms import AuthorsForm, TopicsForm, SongBookForm from openlp.plugins.songs.lib.db import Author, Book, Topic, Song from songmaintenancedialog import Ui_SongMaintenanceDialog +log = logging.getLogger(__name__) + class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): """ Class documentation goes here. @@ -229,13 +233,11 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if self.manager.save_object(author): self.resetAuthors() else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not add your author.')) else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'This author already exists.')) @@ -246,13 +248,11 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if self.manager.save_object(topic): self.resetTopics() else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not add your topic.')) else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'This topic already exists.')) @@ -264,13 +264,11 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if self.manager.save_object(book): self.resetBooks() else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not add your book.')) else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'This book already exists.')) @@ -298,20 +296,15 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): self.resetAuthors() Receiver.send_message(u'songs_load_list') else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', - 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.')) - elif QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + elif criticalErrorMessageBox(self, unicode(translate('SongsPlugin.SongMaintenanceForm', 'The author %s already exists. Would you like to make songs' ' with author %s use the existing author %s?')) % (author.display_name, temp_display_name, - author.display_name), QtGui.QMessageBox.StandardButtons( - QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == \ - QtGui.QMessageBox.Yes: + author.display_name), True) == QtGui.QMessageBox.Yes: self.mergeAuthors(author) self.resetAuthors() Receiver.send_message(u'songs_load_list') @@ -321,8 +314,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): author.first_name = temp_first_name author.last_name = temp_last_name author.display_name = temp_display_name - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not save your modified author, because the ' 'author already exists.')) @@ -340,26 +332,20 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if self.manager.save_object(topic): self.resetTopics() else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', - 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.')) - elif QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + elif criticalErrorMessageBox(self, unicode(translate('SongsPlugin.SongMaintenanceForm', 'The topic %s already exists. Would you like to make songs ' 'with topic %s use the existing topic %s?')) % (topic.name, - temp_name, topic.name), QtGui.QMessageBox.StandardButtons( - QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == \ - QtGui.QMessageBox.Yes: + temp_name, topic.name), True) == QtGui.QMessageBox.Yes: self.mergeTopics(topic) self.resetTopics() else: # We restore the topics's old name. topic.name = temp_name - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not save your modified topic, because it ' 'already exists.')) @@ -383,19 +369,14 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if self.manager.save_object(book): self.resetBooks() else: - QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', - 'Error'), + criticalErrorMessageBox(self, translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.')) - elif QtGui.QMessageBox.critical(self, - translate('SongsPlugin.SongMaintenanceForm', 'Error'), + elif criticalErrorMessageBox(self, unicode(translate('SongsPlugin.SongMaintenanceForm', 'The book %s already exists. Would you like to make songs ' 'with book %s use the existing book %s?')) % (book.name, - temp_name, book.name), QtGui.QMessageBox.StandardButtons( - QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == \ - QtGui.QMessageBox.Yes: + temp_name, book.name), True) == QtGui.QMessageBox.Yes: self.mergeBooks(book) self.resetBooks() else: diff --git a/openlp/plugins/songs/forms/topicsform.py b/openlp/plugins/songs/forms/topicsform.py index 1ff827423..5b330b384 100644 --- a/openlp/plugins/songs/forms/topicsform.py +++ b/openlp/plugins/songs/forms/topicsform.py @@ -27,6 +27,7 @@ from PyQt4 import QtGui from openlp.core.lib import translate +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.songs.forms.topicsdialog import Ui_TopicsDialog class TopicsForm(QtGui.QDialog, Ui_TopicsDialog): @@ -48,10 +49,8 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog): def accept(self): if not self.nameEdit.text(): - QtGui.QMessageBox.critical( - self, translate('SongsPlugin.TopicsForm', 'Error'), - translate('SongsPlugin.TopicsForm', - 'You need to type in a topic name.')) + criticalErrorMessageBox(self, translate('SongsPlugin.TopicsForm', + 'You need to type in a topic name.')) self.nameEdit.setFocus() return False else: From 054f3a41427b04b37db3775faf243f64255f2237 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sat, 15 Jan 2011 00:55:38 +0000 Subject: [PATCH 23/60] Remove duplicated translate --- openlp/core/ui/__init__.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/openlp/core/ui/__init__.py b/openlp/core/ui/__init__.py index 931773b8f..9d7de0726 100644 --- a/openlp/core/ui/__init__.py +++ b/openlp/core/ui/__init__.py @@ -63,13 +63,12 @@ def criticalErrorMessageBox(parent, message, question=False): ``message`` The message to display to the user. """ + error = translate('OpenLP.Ui', 'Error') if question: - return QtGui.QMessageBox.critical(parent, - translate('OpenLP.Ui', 'Error'), - message, QtGui.QMessageBox.StandardButtons( + return QtGui.QMessageBox.critical(parent, error, message, + QtGui.QMessageBox.StandardButtons( QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)) - return QtGui.QMessageBox.critical(parent, translate('OpenLP.Ui', 'Error'), - message) + return QtGui.QMessageBox.critical(parent, error, message) from themeform import ThemeForm from filerenameform import FileRenameForm From 2c958d04cd88bb64ce383270b69ed5eb62e0d7e6 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sat, 15 Jan 2011 01:25:49 +0000 Subject: [PATCH 24/60] Fix docstring --- openlp/core/ui/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/openlp/core/ui/__init__.py b/openlp/core/ui/__init__.py index 9d7de0726..9c43f9da6 100644 --- a/openlp/core/ui/__init__.py +++ b/openlp/core/ui/__init__.py @@ -62,6 +62,9 @@ def criticalErrorMessageBox(parent, message, question=False): ``message`` The message to display to the user. + + ``question`` + Should this message box question the user. """ error = translate('OpenLP.Ui', 'Error') if question: From e33628e049021058f246160171f363ea8093ab3d Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 15 Jan 2011 11:56:40 +0000 Subject: [PATCH 25/60] Merge fixes --- openlp/core/lib/__init__.py | 1 + openlp/core/ui/thememanager.py | 34 +++++++++++++------------- openlp/plugins/bibles/lib/mediaitem.py | 8 +++--- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 7ad377817..76d7c0617 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -293,6 +293,7 @@ def clean_tags(text): Remove Tags from text for display """ text = text.replace(u'
', u'\n') + text = text.replace(u' ', u' ') for tag in DisplayTags.get_html_tags(): text = text.replace(tag[u'start tag'], u'') text = text.replace(tag[u'end tag'], u'') diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 81e191396..b0f3d6147 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -527,7 +527,7 @@ class ThemeManager(QtGui.QWidget): log.exception(u'Theme XML is not UTF-8 ' u'encoded.') break - filexml = self.checkVersionAndConvert(xml_data) + filexml = self._checkVersionAndConvert(xml_data) outfile = open(fullpath, u'w') outfile.write(filexml.encode(u'utf-8')) else: @@ -557,22 +557,6 @@ class ThemeManager(QtGui.QWidget): if outfile: outfile.close() - def checkVersionAndConvert(self, xml_data): - """ - Check if a theme is from OpenLP version 1 - - ``xml_data`` - Theme XML to check the version of - """ - log.debug(u'checkVersion1 ') - theme = xml_data.encode(u'ascii', u'xmlcharrefreplace') - tree = ElementTree(element=XML(theme)).getroot() - # look for old version 1 tags - if tree.find(u'BackgroundType') is None: - return xml_data - else: - return self._migrateVersion122(xml_data) - def checkIfThemeExists(self, themeName): """ Check if theme already exists and displays error message @@ -667,6 +651,22 @@ class ThemeManager(QtGui.QWidget): image = os.path.join(self.path, theme + u'.png') return image + def _checkVersionAndConvert(self, xml_data): + """ + Check if a theme is from OpenLP version 1 + + ``xml_data`` + Theme XML to check the version of + """ + log.debug(u'checkVersion1 ') + theme = xml_data.encode(u'ascii', u'xmlcharrefreplace') + tree = ElementTree(element=XML(theme)).getroot() + # look for old version 1 tags + if tree.find(u'BackgroundType') is None: + return xml_data + else: + return self._migrateVersion122(xml_data) + def _createThemeFromXml(self, themeXml, path): """ Return a theme object using information parsed from XML diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 40deb2244..20adc97fe 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -716,21 +716,21 @@ class BibleMediaItem(MediaManagerItem): second_copyright, second_permissions) if footer not in raw_footer: raw_footer.append(footer) - bible_text = u'%s%s\n\n%s%s' % (verse_text, text, + bible_text = u'%s %s\n\n%s%s' % (verse_text, text, verse_text, second_text) raw_slides.append(bible_text.rstrip()) bible_text = u'' # If we are 'Verse Per Slide' then create a new slide. elif self.parent.settings_tab.layout_style == 0: - bible_text = u'%s%s' % (verse_text, text) + bible_text = u'%s %s' % (verse_text, text) raw_slides.append(bible_text.rstrip()) bible_text = u'' # If we are 'Verse Per Line' then force a new line. elif self.parent.settings_tab.layout_style == 1: - bible_text = u'%s %s%s\n' % (bible_text, verse_text, text) + bible_text = u'%s %s %s\n' % (bible_text, verse_text, text) # We have to be 'Continuous'. else: - bible_text = u'%s %s%s\n' % (bible_text, verse_text, text) + bible_text = u'%s %s %s\n' % (bible_text, verse_text, text) if not old_item: start_item = item elif self.checkTitle(item, old_item): From 4027e4eed794163c0203b0f15467613f448bab08 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 15 Jan 2011 12:14:24 +0000 Subject: [PATCH 26/60] Missed one! --- openlp/plugins/bibles/lib/mediaitem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 20adc97fe..7ee450c8a 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -716,7 +716,7 @@ class BibleMediaItem(MediaManagerItem): second_copyright, second_permissions) if footer not in raw_footer: raw_footer.append(footer) - bible_text = u'%s %s\n\n%s%s' % (verse_text, text, + bible_text = u'%s %s\n\n%s %s' % (verse_text, text, verse_text, second_text) raw_slides.append(bible_text.rstrip()) bible_text = u'' From 284402b7b27e401f7769bd66597c991ae6bd83b2 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sat, 15 Jan 2011 19:24:50 +0000 Subject: [PATCH 27/60] Refactor in existing error framework --- openlp/core/ui/__init__.py | 16 ++-- openlp/core/ui/displaytagtab.py | 13 ++- openlp/core/ui/servicemanager.py | 19 ++--- openlp/core/ui/themeform.py | 13 ++- openlp/core/ui/thememanager.py | 50 ++++++------ .../plugins/bibles/forms/bibleimportform.py | 17 ++-- openlp/plugins/bibles/lib/db.py | 10 +-- openlp/plugins/bibles/lib/http.py | 28 +++---- openlp/plugins/bibles/lib/mediaitem.py | 27 +++---- openlp/plugins/custom/forms/editcustomform.py | 2 +- openlp/plugins/images/lib/mediaitem.py | 16 ++-- openlp/plugins/media/lib/mediaitem.py | 16 ++-- openlp/plugins/presentations/lib/mediaitem.py | 9 ++- openlp/plugins/songs/forms/authorsform.py | 10 +-- openlp/plugins/songs/forms/editsongform.py | 25 +++--- openlp/plugins/songs/forms/editverseform.py | 3 +- openlp/plugins/songs/forms/songbookform.py | 3 +- openlp/plugins/songs/forms/songimportform.py | 21 ++--- .../songs/forms/songmaintenanceform.py | 79 ++++++++++--------- openlp/plugins/songs/forms/topicsform.py | 2 +- 20 files changed, 190 insertions(+), 189 deletions(-) diff --git a/openlp/core/ui/__init__.py b/openlp/core/ui/__init__.py index 9c43f9da6..80124c2be 100644 --- a/openlp/core/ui/__init__.py +++ b/openlp/core/ui/__init__.py @@ -28,7 +28,7 @@ The :mod:`ui` module provides the core user interface for OpenLP """ from PyQt4 import QtGui -from openlp.core.lib import translate +from openlp.core.lib import translate, Receiver class HideMode(object): """ @@ -52,17 +52,21 @@ class HideMode(object): Screen = 3 -def criticalErrorMessageBox(parent, message, question=False): +def criticalErrorMessageBox(title=None, message=None, parent=None, + question=False): """ Provides a standard critical message box for errors that OpenLP displays to users. - ``parent`` - The parent UI element to attach the dialog to. + ``title`` + The title for the message box. ``message`` The message to display to the user. + ``parent`` + The parent UI element to attach the dialog to. + ``question`` Should this message box question the user. """ @@ -71,7 +75,9 @@ def criticalErrorMessageBox(parent, message, question=False): return QtGui.QMessageBox.critical(parent, error, message, QtGui.QMessageBox.StandardButtons( QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)) - return QtGui.QMessageBox.critical(parent, error, message) + data = {u'message': message} + data[u'title'] = title if title else error + return Receiver.send_message(u'openlp_error_message', data) from themeform import ThemeForm from filerenameform import FileRenameForm diff --git a/openlp/core/ui/displaytagtab.py b/openlp/core/ui/displaytagtab.py index 154d397b9..1c77084b9 100644 --- a/openlp/core/ui/displaytagtab.py +++ b/openlp/core/ui/displaytagtab.py @@ -34,6 +34,7 @@ import cPickle from PyQt4 import QtCore, QtGui from openlp.core.lib import SettingsTab, translate, DisplayTags +from openlp.core.ui import criticalErrorMessageBox class DisplayTagTab(SettingsTab): ''' @@ -275,12 +276,10 @@ class DisplayTagTab(SettingsTab): """ for html in DisplayTags.get_html_tags(): if self._strip(html[u'start tag']) == u'n': - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('OpenLP.DisplayTagTab', 'Update Error'), translate('OpenLP.DisplayTagTab', - 'Tag "n" already defined.'), - QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok), - QtGui.QMessageBox.Ok) + 'Tag "n" already defined.')) return # Add new tag to list tag = {u'desc': u'New Item', u'start tag': u'{n}', @@ -318,12 +317,10 @@ class DisplayTagTab(SettingsTab): for linenumber, html1 in enumerate(html_expands): if self._strip(html1[u'start tag']) == tag and \ linenumber != self.selected: - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('OpenLP.DisplayTagTab', 'Update Error'), unicode(translate('OpenLP.DisplayTagTab', - 'Tag %s already defined.')) % tag, - QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok), - QtGui.QMessageBox.Ok) + 'Tag %s already defined.')) % tag) return html[u'desc'] = unicode(self.descriptionLineEdit.text()) html[u'start html'] = unicode(self.startTagLineEdit.text()) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 229590fa5..fcc601de3 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -487,10 +487,10 @@ class ServiceManager(QtGui.QWidget): for file in zip.namelist(): ucsfile = file_is_unicode(file) if not ucsfile: - criticalErrorMessageBox(self, - translate('OpenLP.ServiceManager', - 'File is not a valid service.\n' - 'The content encoding is not UTF-8.')) + criticalErrorMessageBox( + message=translate('OpenLP.ServiceManager', + 'File is not a valid service.\n' + 'The content encoding is not UTF-8.')) continue osfile = unicode(QtCore.QDir.toNativeSeparators(ucsfile)) filePath = os.path.join(self.servicePath, @@ -521,7 +521,8 @@ class ServiceManager(QtGui.QWidget): except (IOError, OSError): log.exception(u'Failed to remove osd file') else: - criticalErrorMessageBox(self, translate('OpenLP.ServiceManager', + criticalErrorMessageBox( + message=translate('OpenLP.ServiceManager', 'File is not a valid service.')) log.exception(u'File contains no service data') except (IOError, NameError): @@ -1002,7 +1003,7 @@ class ServiceManager(QtGui.QWidget): self.mainwindow.previewController.addServiceManagerItem( self.serviceItems[item][u'service_item'], count) else: - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('OpenLP.ServiceManager', 'Missing Display Handler'), translate('OpenLP.ServiceManager', 'Your item cannot be ' 'displayed as there is no handler to display it')) @@ -1036,11 +1037,11 @@ class ServiceManager(QtGui.QWidget): self.serviceItems[item][u'service_item'], 0) self.mainwindow.liveController.PreviewListWidget.setFocus() else: - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('OpenLP.ServiceManager', 'Missing Display Handler'), translate('OpenLP.ServiceManager', 'Your item cannot be ' - 'displayed as the plugin required to display it is missing ' - 'or inactive')) + 'displayed as the plugin required to display it is missing ' + 'or inactive')) def remoteEdit(self): """ diff --git a/openlp/core/ui/themeform.py b/openlp/core/ui/themeform.py index f8236a1eb..0925023bd 100644 --- a/openlp/core/ui/themeform.py +++ b/openlp/core/ui/themeform.py @@ -31,6 +31,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import translate, BackgroundType, BackgroundGradientType, \ Receiver +from openlp.core.ui import criticalErrorMessage from openlp.core.utils import get_images_filter from themewizard import Ui_ThemeWizard @@ -567,20 +568,16 @@ class ThemeForm(QtGui.QWizard, Ui_ThemeWizard): self.theme.theme_name = \ unicode(self.field(u'name').toString()) if not self.theme.theme_name: - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('OpenLP.ThemeForm', 'Theme Name Missing'), translate('OpenLP.ThemeForm', - 'There is no name for this theme. Please enter one.'), - (QtGui.QMessageBox.Ok), - QtGui.QMessageBox.Ok) + 'There is no name for this theme. Please enter one.')) return if self.theme.theme_name == u'-1' or self.theme.theme_name == u'None': - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('OpenLP.ThemeForm', 'Theme Name Invalid'), translate('OpenLP.ThemeForm', - 'Invalid theme name. Please enter one.'), - (QtGui.QMessageBox.Ok), - QtGui.QMessageBox.Ok) + 'Invalid theme name. Please enter one.')) return saveFrom = None saveTo = None diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index ccea7faaf..58a150205 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -359,7 +359,7 @@ class ThemeManager(QtGui.QWidget): """ item = self.themeListWidget.currentItem() if item is None: - criticalErrorMessageBox(self, translate('OpenLP.ThemeManager', + criticalErrorMessageBox(message=translate('OpenLP.ThemeManager', 'You have not selected a theme.')) return theme = unicode(item.data(QtCore.Qt.UserRole).toString()) @@ -386,10 +386,10 @@ class ThemeManager(QtGui.QWidget): 'Your theme has been successfully exported.')) except (IOError, OSError): log.exception(u'Export Theme Failed') - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('OpenLP.ThemeManager', 'Theme Export Failed'), translate('OpenLP.ThemeManager', - 'Your theme could not be exported due to an error.')) + 'Your theme could not be exported due to an error.')) finally: if zip: zip.close() @@ -496,9 +496,10 @@ class ThemeManager(QtGui.QWidget): for file in zip.namelist(): ucsfile = file_is_unicode(file) if not ucsfile: - criticalErrorMessageBox(self, - translate('OpenLP.ThemeManager', 'File is not a valid ' - 'theme.\nThe content encoding is not UTF-8.')) + criticalErrorMessageBox( + message=translate('OpenLP.ThemeManager', + 'File is not a valid theme.\n' + 'The content encoding is not UTF-8.')) continue osfile = unicode(QtCore.QDir.toNativeSeparators(ucsfile)) theme_dir = None @@ -533,19 +534,17 @@ class ThemeManager(QtGui.QWidget): theme = self._createThemeFromXml(filexml, self.path) self.generateAndSaveImage(dir, themename, theme) else: - Receiver.send_message(u'openlp_error_message', { - u'title': translate('OpenLP.ThemeManager', - 'Validation Error'), - u'message':translate('OpenLP.ThemeManager', - 'File is not a valid theme.')}) + criticalErrorMessageBox( + translate('OpenLP.ThemeManager', 'Validation Error'), + translate('OpenLP.ThemeManager', + 'File is not a valid theme.')) log.exception(u'Theme file does not contain XML data %s' % filename) except (IOError, NameError): - Receiver.send_message(u'openlp_error_message', { - u'title': translate('OpenLP.ThemeManager', - 'Validation Error'), - u'message':translate('OpenLP.ThemeManager', - 'File is not a valid theme.')}) + criticalErrorMessageBox( + translate('OpenLP.ThemeManager', 'Validation Error'), + translate('OpenLP.ThemeManager', + 'File is not a valid theme.')) log.exception(u'Importing theme from zip failed %s' % filename) finally: if zip: @@ -578,11 +577,10 @@ class ThemeManager(QtGui.QWidget): """ theme_dir = os.path.join(self.path, themeName) if os.path.exists(theme_dir): - Receiver.send_message(u'openlp_error_message', { - u'title': translate('OpenLP.ThemeManager', - 'Validation Error'), - u'message':translate('OpenLP.ThemeManager', - 'A theme with this name already exists.')}) + criticalErrorMessageBox( + translate('OpenLP.ThemeManager', 'Validation Error'), + translate('OpenLP.ThemeManager', + 'A theme with this name already exists.')) return False return True @@ -696,19 +694,19 @@ class ThemeManager(QtGui.QWidget): return False # should be the same unless default if theme != unicode(item.data(QtCore.Qt.UserRole).toString()): - criticalErrorMessageBox(self, translate('OpenLP.ThemeManager', + criticalErrorMessageBox( + message=translate('OpenLP.ThemeManager', 'You are unable to delete the default theme.')) return False # check for use in the system else where. if testPlugin: for plugin in self.mainwindow.pluginManager.plugins: if plugin.usesTheme(theme): - Receiver.send_message(u'openlp_error_message', { - u'title': translate('OpenLP.ThemeManager', + criticalErrorMessageBox(translate('OpenLP.ThemeManager', 'Validation Error'), - u'message': unicode(translate('OpenLP.ThemeManager', + unicode(translate('OpenLP.ThemeManager', 'Theme %s is used in the %s plugin.')) % \ - (theme, plugin.name)}) + (theme, plugin.name)) return False return True diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index d79051126..d3f41804b 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -35,6 +35,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import Receiver, SettingsManager, translate from openlp.core.lib.db import delete_database +from openlp.core.ui import criticalErrorMessageBox from openlp.core.ui.wizard import OpenLPWizard from openlp.core.utils import AppLocation, string_is_unicode from openlp.plugins.bibles.lib.manager import BibleFormat @@ -468,7 +469,7 @@ class BibleImportForm(OpenLPWizard): elif self.currentPage() == self.selectPage: if self.field(u'source_format').toInt()[0] == BibleFormat.OSIS: if not self.field(u'osis_location').toString(): - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('BiblesPlugin.ImportWizardForm', 'Invalid Bible Location'), translate('BiblesPlugin.ImportWizardForm', @@ -478,7 +479,7 @@ class BibleImportForm(OpenLPWizard): return False elif self.field(u'source_format').toInt()[0] == BibleFormat.CSV: if not self.field(u'csv_booksfile').toString(): - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('BiblesPlugin.ImportWizardForm', 'Invalid Books File'), translate('BiblesPlugin.ImportWizardForm', @@ -487,7 +488,7 @@ class BibleImportForm(OpenLPWizard): self.csvBooksEdit.setFocus() return False elif not self.field(u'csv_versefile').toString(): - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('BiblesPlugin.ImportWizardForm', 'Invalid Verse File'), translate('BiblesPlugin.ImportWizardForm', @@ -498,7 +499,7 @@ class BibleImportForm(OpenLPWizard): elif self.field(u'source_format').toInt()[0] == \ BibleFormat.OpenSong: if not self.field(u'opensong_file').toString(): - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('BiblesPlugin.ImportWizardForm', 'Invalid OpenSong Bible'), translate('BiblesPlugin.ImportWizardForm', @@ -508,7 +509,7 @@ class BibleImportForm(OpenLPWizard): return False elif self.field(u'source_format').toInt()[0] == BibleFormat.OpenLP1: if not self.field(u'openlp1_location').toString(): - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('BiblesPlugin.ImportWizardForm', 'Invalid Bible Location'), translate('BiblesPlugin.ImportWizardForm', @@ -522,7 +523,7 @@ class BibleImportForm(OpenLPWizard): license_copyright = \ unicode(self.field(u'license_copyright').toString()) if not license_version: - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('BiblesPlugin.ImportWizardForm', 'Empty Version Name'), translate('BiblesPlugin.ImportWizardForm', @@ -530,7 +531,7 @@ class BibleImportForm(OpenLPWizard): self.versionNameEdit.setFocus() return False elif not license_copyright: - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('BiblesPlugin.ImportWizardForm', 'Empty Copyright'), translate('BiblesPlugin.ImportWizardForm', @@ -539,7 +540,7 @@ class BibleImportForm(OpenLPWizard): self.copyrightEdit.setFocus() return False elif self.manager.exists(license_version): - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('BiblesPlugin.ImportWizardForm', 'Bible Exists'), translate('BiblesPlugin.ImportWizardForm', 'This Bible already exists. Please import ' diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 9f4376da1..695f4b721 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -35,6 +35,7 @@ from sqlalchemy.orm.exc import UnmappedClassError from openlp.core.lib import Receiver, translate from openlp.core.lib.db import BaseModel, init_db, Manager +from openlp.core.ui import criticalErrorMessageBox log = logging.getLogger(__name__) @@ -354,12 +355,11 @@ class BibleDB(QtCore.QObject, Manager): verse_list.extend(verses) else: log.debug(u'OpenLP failed to find book %s', book) - Receiver.send_message(u'openlp_error_message', { - u'title': translate('BiblesPlugin', 'No Book Found'), - u'message': translate('BiblesPlugin', 'No matching book ' + criticalErrorMessageBox( + translate('BiblesPlugin', 'No Book Found'), + translate('BiblesPlugin', 'No matching book ' 'could be found in this Bible. Check that you have ' - 'spelled the name of the book correctly.') - }) + 'spelled the name of the book correctly.')) return verse_list def verse_search(self, text): diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 6f6b861e9..b844bbe61 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -38,6 +38,7 @@ from HTMLParser import HTMLParseError from BeautifulSoup import BeautifulSoup, NavigableString from openlp.core.lib import Receiver, translate +from openlp.core.ui import criticalErrorMessageBox from openlp.core.utils import AppLocation, get_web_page from openlp.plugins.bibles.lib import SearchResults from openlp.plugins.bibles.lib.db import BibleDB, Book @@ -429,12 +430,11 @@ class HTTPBible(BibleDB): if not db_book: book_details = HTTPBooks.get_book(book) if not book_details: - Receiver.send_message(u'openlp_error_message', { - u'title': translate('BiblesPlugin', 'No Book Found'), - u'message': translate('BiblesPlugin', 'No matching ' + criticalErrorMessageBox( + translate('BiblesPlugin', 'No Book Found'), + translate('BiblesPlugin', 'No matching ' 'book could be found in this Bible. Check that you ' - 'have spelled the name of the book correctly.') - }) + 'have spelled the name of the book correctly.')) return [] db_book = self.create_book(book_details[u'name'], book_details[u'abbreviation'], @@ -540,17 +540,15 @@ def send_error_message(error_type): The type of error that occured for the issue. """ if error_type == u'download': - Receiver.send_message(u'openlp_error_message', { - u'title': translate('BiblePlugin.HTTPBible', 'Download Error'), - u'message': translate('BiblePlugin.HTTPBible', 'There was a ' + criticalErrorMessageBox( + translate('BiblePlugin.HTTPBible', 'Download Error'), + translate('BiblePlugin.HTTPBible', 'There was a ' 'problem downloading your verse selection. Please check your ' 'Internet connection, and if this error continues to occur ' - 'please consider reporting a bug.') - }) + 'please consider reporting a bug.')) elif error_type == u'parse': - Receiver.send_message(u'openlp_error_message', { - u'title': translate('BiblePlugin.HTTPBible', 'Parse Error'), - u'message': translate('BiblePlugin.HTTPBible', 'There was a ' + criticalErrorMessageBox( + translate('BiblePlugin.HTTPBible', 'Parse Error'), + translate('BiblePlugin.HTTPBible', 'There was a ' 'problem extracting your verse selection. If this error continues ' - 'to occur please consider reporting a bug.') - }) + 'to occur please consider reporting a bug.')) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 81dd1777b..b38779680 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -389,11 +389,8 @@ class BibleMediaItem(MediaManagerItem): verse_count = self.parent.manager.get_verse_count(bible, book, 1) if verse_count == 0: self.advancedSearchButton.setEnabled(False) - Receiver.send_message(u'openlp_error_message', { - u'title': translate('BiblePlugin.MediaItem', 'Error'), - u'message': translate('BiblePlugin.MediaItem', - 'Bible not fully loaded') - }) + criticalErrorMessageBox(message=translate('BiblePlugin.MediaItem', + 'Bible not fully loaded')) else: self.advancedSearchButton.setEnabled(True) self.adjustComboBox(1, self.chapter_count, self.advancedFromChapter) @@ -534,11 +531,11 @@ class BibleMediaItem(MediaManagerItem): if item_second_bible and second_bible or not item_second_bible and \ not second_bible: self.displayResults(bible, second_bible) - elif criticalErrorMessageBox(self, - translate('BiblePlugin.MediaItem', 'You cannot combine single ' - 'and second bible verses. Do you want to delete your search ' - 'results and start a new search?'), - True) == QtGui.QMessageBox.Yes: + elif criticalErrorMessageBox( + message=translate('BiblePlugin.MediaItem', + 'You cannot combine single and second bible verses. Do you ' + 'want to delete your search results and start a new search?'), + question=True) == QtGui.QMessageBox.Yes: self.listView.clear() self.displayResults(bible, second_bible) else: @@ -582,11 +579,11 @@ class BibleMediaItem(MediaManagerItem): if item_second_bible and second_bible or not item_second_bible and \ not second_bible: self.displayResults(bible, second_bible) - elif criticalErrorMessageBox(self, - translate('BiblePlugin.MediaItem', 'You cannot combine single ' - 'and second bible verses. Do you want to delete your search ' - 'results and start a new search?'), - True) == QtGui.QMessageBox.Yes: + elif criticalErrorMessageBox( + message=translate('BiblePlugin.MediaItem', + 'You cannot combine single and second bible verses. Do you ' + 'want to delete your search results and start a new search?'), + question=True) == QtGui.QMessageBox.Yes: self.listView.clear() self.displayResults(bible, second_bible) elif self.search_results: diff --git a/openlp/plugins/custom/forms/editcustomform.py b/openlp/plugins/custom/forms/editcustomform.py index 794fde9e8..ebc917e99 100644 --- a/openlp/plugins/custom/forms/editcustomform.py +++ b/openlp/plugins/custom/forms/editcustomform.py @@ -152,7 +152,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog): """ valid, message = self._validate() if not valid: - criticalErrorMessageBox(self, message) + criticalErrorMessageBox(message=message) return False sxml = CustomXMLBuilder() sxml.new_document() diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 063a80d02..64d864ff8 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -31,7 +31,8 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \ ItemCapabilities, SettingsManager, translate, check_item_selected, \ - Receiver, check_directory_exists + check_directory_exists +from openlp.core.ui import criticalErrorMessageBox from openlp.core.utils import AppLocation, get_images_filter log = logging.getLogger(__name__) @@ -164,7 +165,7 @@ class ImageMediaItem(MediaManagerItem): items.remove(item) # We cannot continue, as all images do not exist. if not items: - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('ImagePlugin.MediaItem', 'Missing Image(s)'), unicode(translate('ImagePlugin.MediaItem', 'The following image(s) no longer exist: %s')) % @@ -208,12 +209,11 @@ class ImageMediaItem(MediaManagerItem): self.parent.liveController.display.directImage(name, filename) self.resetAction.setVisible(True) else: - Receiver.send_message(u'openlp_error_message', { - u'title': translate('ImagePlugin.MediaItem', - 'Live Background Error'), - u'message': unicode(translate('ImagePlugin.MediaItem', + criticalErrorMessageBox( + translate('ImagePlugin.MediaItem', 'Live Background Error'), + unicode(translate('ImagePlugin.MediaItem', 'There was a problem replacing your background, ' - 'the image file "%s" no longer exists.')) % filename}) + 'the image file "%s" no longer exists.')) % filename) def onPreviewClick(self): - MediaManagerItem.onPreviewClick(self) \ No newline at end of file + MediaManagerItem.onPreviewClick(self) diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index cc75dfc2b..0280ba937 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -30,8 +30,8 @@ import os from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \ - ItemCapabilities, SettingsManager, translate, check_item_selected, \ - Receiver + ItemCapabilities, SettingsManager, translate, check_item_selected +from openlp.core.ui import criticalErrorMessageBox log = logging.getLogger(__name__) @@ -106,12 +106,11 @@ class MediaMediaItem(MediaManagerItem): self.parent.liveController.display.video(filename, 0, True) self.resetAction.setVisible(True) else: - Receiver.send_message(u'openlp_error_message', { - u'title': translate('MediaPlugin.MediaItem', + criticalErrorMessageBox(translate('MediaPlugin.MediaItem', 'Live Background Error'), - u'message': unicode(translate('MediaPlugin.MediaItem', + unicode(translate('MediaPlugin.MediaItem', 'There was a problem replacing your background, ' - 'the media file "%s" no longer exists.')) % filename}) + 'the media file "%s" no longer exists.')) % filename) def generateSlideData(self, service_item, item=None, xmlVersion=False): if item is None: @@ -131,9 +130,8 @@ class MediaMediaItem(MediaManagerItem): return True else: # File is no longer present - QtGui.QMessageBox.critical( - self, translate('MediaPlugin.MediaItem', - 'Missing Media File'), + criticalErrorMessageBox( + translate('MediaPlugin.MediaItem', 'Missing Media File'), unicode(translate('MediaPlugin.MediaItem', 'The file %s no longer exists.')) % filename) return False diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 1e65a3358..2c9381a70 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -31,6 +31,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \ SettingsManager, translate, check_item_selected, Receiver, ItemCapabilities +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.presentations.lib import MessageListener log = logging.getLogger(__name__) @@ -180,7 +181,7 @@ class PresentationMediaItem(MediaManagerItem): filename = os.path.split(unicode(file))[1] if titles.count(filename) > 0: if not initialLoad: - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('PresentationPlugin.MediaItem', 'File Exists'), translate('PresentationPlugin.MediaItem', @@ -204,7 +205,7 @@ class PresentationMediaItem(MediaManagerItem): if initialLoad: icon = build_icon(u':/general/general_delete.png') else: - QtGui.QMessageBox.critical( + criticalErrorMessageBox( self, translate('PresentationPlugin.MediaItem', 'Unsupported File'), translate('PresentationPlugin.MediaItem', @@ -275,8 +276,8 @@ class PresentationMediaItem(MediaManagerItem): return True else: # File is no longer present - QtGui.QMessageBox.critical( - self, translate('PresentationPlugin.MediaItem', + criticalErrorMessageBox( + translate('PresentationPlugin.MediaItem', 'Missing Presentation'), unicode(translate('PresentationPlugin.MediaItem', 'The Presentation %s no longer exists.')) % filename) diff --git a/openlp/plugins/songs/forms/authorsform.py b/openlp/plugins/songs/forms/authorsform.py index 09f361816..afd3795b1 100644 --- a/openlp/plugins/songs/forms/authorsform.py +++ b/openlp/plugins/songs/forms/authorsform.py @@ -80,21 +80,21 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog): def accept(self): if not self.firstNameEdit.text(): - criticalErrorMessageBox(self, translate('SongsPlugin.AuthorsForm', + criticalErrorMessageBox(message=translate('SongsPlugin.AuthorsForm', 'You need to type in the first name of the author.')) self.firstNameEdit.setFocus() return False elif not self.lastNameEdit.text(): - criticalErrorMessageBox(self, translate('SongsPlugin.AuthorsForm', + criticalErrorMessageBox(message=translate('SongsPlugin.AuthorsForm', 'You need to type in the last name of the author.')) self.lastNameEdit.setFocus() return False elif not self.displayEdit.text(): - if criticalErrorMessageBox(self, - translate('SongsPlugin.AuthorsForm', + if criticalErrorMessageBox( + message=translate('SongsPlugin.AuthorsForm', 'You have not set a display name for the ' 'author, combine the first and last names?'), - True) == QtGui.QMessageBox.Yes: + question=True) == QtGui.QMessageBox.Yes: self.displayEdit.setText(self.firstNameEdit.text() + \ u' ' + self.lastNameEdit.text()) return QtGui.QDialog.accept(self) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 980f00076..a37af5280 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -347,9 +347,9 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): author = self.manager.get_object(Author, item_id) if self.authorsListView.findItems(unicode(author.display_name), QtCore.Qt.MatchExactly): - criticalErrorMessageBox(self, - translate('SongsPlugin.EditSongForm', 'This author is ' - 'already in the list.')) + criticalErrorMessageBox( + message=translate('SongsPlugin.EditSongForm', + 'This author is already in the list.')) else: author_item = QtGui.QListWidgetItem(unicode( author.display_name)) @@ -400,9 +400,9 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): topic = self.manager.get_object(Topic, item_id) if self.topicsListView.findItems(unicode(topic.name), QtCore.Qt.MatchExactly): - criticalErrorMessageBox(self, - translate('SongsPlugin.EditSongForm', 'This topic is ' - 'already in the list.')) + criticalErrorMessageBox( + message=translate('SongsPlugin.EditSongForm', + 'This topic is already in the list.')) else: topic_item = QtGui.QListWidgetItem(unicode(topic.name)) topic_item.setData(QtCore.Qt.UserRole, @@ -532,19 +532,22 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): if len(self.titleEdit.displayText()) == 0: self.songTabWidget.setCurrentIndex(0) self.titleEdit.setFocus() - criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.EditSongForm', 'You need to type in a song title.')) return False if self.verseListWidget.rowCount() == 0: self.songTabWidget.setCurrentIndex(0) self.verseListWidget.setFocus() - criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.EditSongForm', 'You need to type in at least one verse.')) return False if self.authorsListView.count() == 0: self.songTabWidget.setCurrentIndex(1) self.authorsListView.setFocus() - criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.EditSongForm', 'You need to have an author for this song.')) return False if self.song.verse_order: @@ -571,8 +574,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): valid = verses.pop(0) for verse in verses: valid = valid + u', ' + verse - criticalErrorMessageBox(self, - unicode(translate('SongsPlugin.EditSongForm', + criticalErrorMessageBox( + message=unicode(translate('SongsPlugin.EditSongForm', 'The verse order is invalid. There is no verse ' 'corresponding to %s. Valid entries are %s.')) % \ (order_names[count], valid)) diff --git a/openlp/plugins/songs/forms/editverseform.py b/openlp/plugins/songs/forms/editverseform.py index 93a259274..c10e48cb7 100644 --- a/openlp/plugins/songs/forms/editverseform.py +++ b/openlp/plugins/songs/forms/editverseform.py @@ -168,7 +168,8 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog): else: value = self.getVerse()[0].split(u'\n')[1] if len(value) == 0: - criticalErrorMessageBox(self, translate('SongsPlugin.EditSongForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.EditSongForm', 'You need to type some text in to the verse.')) return False QtGui.QDialog.accept(self) diff --git a/openlp/plugins/songs/forms/songbookform.py b/openlp/plugins/songs/forms/songbookform.py index 96d4fdf1b..8341a7c4c 100644 --- a/openlp/plugins/songs/forms/songbookform.py +++ b/openlp/plugins/songs/forms/songbookform.py @@ -50,7 +50,8 @@ class SongBookForm(QtGui.QDialog, Ui_SongBookDialog): def accept(self): if not self.nameEdit.text(): - criticalErrorMessageBox(self, translate('SongsPlugin.SongBookForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.SongBookForm', 'You need to type in a name for the book.')) self.nameEdit.setFocus() return False diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index 22a7ab61f..4cd4c6713 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -32,6 +32,7 @@ import os from PyQt4 import QtCore, QtGui from openlp.core.lib import Receiver, SettingsManager, translate +from openlp.core.ui import criticalErrorMessageBox from openlp.core.ui.wizard import OpenLPWizard from openlp.plugins.songs.lib.importer import SongFormat @@ -325,7 +326,7 @@ class SongImportForm(OpenLPWizard): source_format = self.formatComboBox.currentIndex() if source_format == SongFormat.OpenLP2: if self.openLP2FilenameEdit.text().isEmpty(): - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('SongsPlugin.ImportWizardForm', 'No OpenLP 2.0 Song Database Selected'), translate('SongsPlugin.ImportWizardForm', @@ -335,7 +336,7 @@ class SongImportForm(OpenLPWizard): return False elif source_format == SongFormat.OpenLP1: if self.openLP1FilenameEdit.text().isEmpty(): - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('SongsPlugin.ImportWizardForm', 'No openlp.org 1.x Song Database Selected'), translate('SongsPlugin.ImportWizardForm', @@ -345,7 +346,7 @@ class SongImportForm(OpenLPWizard): return False elif source_format == SongFormat.OpenLyrics: if self.openLyricsFileListWidget.count() == 0: - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('SongsPlugin.ImportWizardForm', 'No OpenLyrics Files Selected'), translate('SongsPlugin.ImportWizardForm', @@ -355,7 +356,7 @@ class SongImportForm(OpenLPWizard): return False elif source_format == SongFormat.OpenSong: if self.openSongFileListWidget.count() == 0: - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('SongsPlugin.ImportWizardForm', 'No OpenSong Files Selected'), translate('SongsPlugin.ImportWizardForm', @@ -365,7 +366,7 @@ class SongImportForm(OpenLPWizard): return False elif source_format == SongFormat.WordsOfWorship: if self.wordsOfWorshipFileListWidget.count() == 0: - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('SongsPlugin.ImportWizardForm', 'No Words of Worship Files Selected'), translate('SongsPlugin.ImportWizardForm', @@ -375,7 +376,7 @@ class SongImportForm(OpenLPWizard): return False elif source_format == SongFormat.CCLI: if self.ccliFileListWidget.count() == 0: - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('SongsPlugin.ImportWizardForm', 'No CCLI Files Selected'), translate('SongsPlugin.ImportWizardForm', @@ -385,7 +386,7 @@ class SongImportForm(OpenLPWizard): return False elif source_format == SongFormat.SongsOfFellowship: if self.songsOfFellowshipFileListWidget.count() == 0: - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('SongsPlugin.ImportWizardForm', 'No Songs of Fellowship File Selected'), translate('SongsPlugin.ImportWizardForm', @@ -395,7 +396,7 @@ class SongImportForm(OpenLPWizard): return False elif source_format == SongFormat.Generic: if self.genericFileListWidget.count() == 0: - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('SongsPlugin.ImportWizardForm', 'No Document/Presentation Selected'), translate('SongsPlugin.ImportWizardForm', @@ -405,7 +406,7 @@ class SongImportForm(OpenLPWizard): return False elif source_format == SongFormat.EasyWorship: if self.ewFilenameEdit.text().isEmpty(): - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('SongsPlugin.ImportWizardForm', 'No EasyWorship Song Database Selected'), translate('SongsPlugin.ImportWizardForm', @@ -415,7 +416,7 @@ class SongImportForm(OpenLPWizard): return False elif source_format == SongFormat.SongBeamer: if self.songBeamerFileListWidget.count() == 0: - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('SongsPlugin.ImportWizardForm', 'No SongBeamer File Selected'), translate('SongsPlugin.ImportWizardForm', diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index 4dc9361c5..2203df4e7 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -91,15 +91,14 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if item_id != -1: item = self.manager.get_object(item_class, item_id) if item and len(item.songs) == 0: - if QtGui.QMessageBox.warning(self, dlg_title, del_text, - QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | - QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.Yes: + if criticalErrorMessageBox(title=dlg_title, message=del_text, + question=True) == QtGui.QMessageBox.Yes: self.manager.delete_object(item_class, item.id) reset_func() else: - QtGui.QMessageBox.critical(self, dlg_title, err_text) + criticalErrorMessageBox(dlg_title, err_text) else: - QtGui.QMessageBox.critical(self, dlg_title, sel_text) + criticalErrorMessageBox(dlg_title, sel_text) def resetAuthors(self): """ @@ -233,12 +232,12 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if self.manager.save_object(author): self.resetAuthors() else: - criticalErrorMessageBox(self, - translate('SongsPlugin.SongMaintenanceForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.SongMaintenanceForm', 'Could not add your author.')) else: - criticalErrorMessageBox(self, - translate('SongsPlugin.SongMaintenanceForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.SongMaintenanceForm', 'This author already exists.')) def onTopicAddButtonClick(self): @@ -248,12 +247,12 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if self.manager.save_object(topic): self.resetTopics() else: - criticalErrorMessageBox(self, - translate('SongsPlugin.SongMaintenanceForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.SongMaintenanceForm', 'Could not add your topic.')) else: - criticalErrorMessageBox(self, - translate('SongsPlugin.SongMaintenanceForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.SongMaintenanceForm', 'This topic already exists.')) def onBookAddButtonClick(self): @@ -264,12 +263,12 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if self.manager.save_object(book): self.resetBooks() else: - criticalErrorMessageBox(self, - translate('SongsPlugin.SongMaintenanceForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.SongMaintenanceForm', 'Could not add your book.')) else: - criticalErrorMessageBox(self, - translate('SongsPlugin.SongMaintenanceForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.SongMaintenanceForm', 'This book already exists.')) def onAuthorEditButtonClick(self): @@ -296,15 +295,15 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): self.resetAuthors() Receiver.send_message(u'songs_load_list') else: - criticalErrorMessageBox(self, - translate('SongsPlugin.SongMaintenanceForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.')) - elif criticalErrorMessageBox(self, - unicode(translate('SongsPlugin.SongMaintenanceForm', - 'The author %s already exists. Would you like to make songs' - ' with author %s use the existing author %s?')) % - (author.display_name, temp_display_name, - author.display_name), True) == QtGui.QMessageBox.Yes: + elif criticalErrorMessageBox(message=unicode(translate( + 'SongsPlugin.SongMaintenanceForm', 'The author %s already ' + 'exists. Would you like to make songs with author %s use ' + 'the existing author %s?')) % (author.display_name, + temp_display_name, author.display_name), + question=True) == QtGui.QMessageBox.Yes: self.mergeAuthors(author) self.resetAuthors() Receiver.send_message(u'songs_load_list') @@ -314,8 +313,8 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): author.first_name = temp_first_name author.last_name = temp_last_name author.display_name = temp_display_name - criticalErrorMessageBox(self, - translate('SongsPlugin.SongMaintenanceForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your modified author, because the ' 'author already exists.')) @@ -332,21 +331,22 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if self.manager.save_object(topic): self.resetTopics() else: - criticalErrorMessageBox(self, - translate('SongsPlugin.SongMaintenanceForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.')) - elif criticalErrorMessageBox(self, - unicode(translate('SongsPlugin.SongMaintenanceForm', + elif criticalErrorMessageBox( + message=unicode(translate('SongsPlugin.SongMaintenanceForm', 'The topic %s already exists. Would you like to make songs ' 'with topic %s use the existing topic %s?')) % (topic.name, - temp_name, topic.name), True) == QtGui.QMessageBox.Yes: + temp_name, topic.name), + question=True) == QtGui.QMessageBox.Yes: self.mergeTopics(topic) self.resetTopics() else: # We restore the topics's old name. topic.name = temp_name - criticalErrorMessageBox(self, - translate('SongsPlugin.SongMaintenanceForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your modified topic, because it ' 'already exists.')) @@ -369,14 +369,15 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if self.manager.save_object(book): self.resetBooks() else: - criticalErrorMessageBox(self, - translate('SongsPlugin.SongMaintenanceForm', + criticalErrorMessageBox( + message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.')) - elif criticalErrorMessageBox(self, - unicode(translate('SongsPlugin.SongMaintenanceForm', + elif criticalErrorMessageBox( + message=unicode(translate('SongsPlugin.SongMaintenanceForm', 'The book %s already exists. Would you like to make songs ' 'with book %s use the existing book %s?')) % (book.name, - temp_name, book.name), True) == QtGui.QMessageBox.Yes: + temp_name, book.name), + question=True) == QtGui.QMessageBox.Yes: self.mergeBooks(book) self.resetBooks() else: diff --git a/openlp/plugins/songs/forms/topicsform.py b/openlp/plugins/songs/forms/topicsform.py index 5b330b384..4ab2b63fa 100644 --- a/openlp/plugins/songs/forms/topicsform.py +++ b/openlp/plugins/songs/forms/topicsform.py @@ -49,7 +49,7 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog): def accept(self): if not self.nameEdit.text(): - criticalErrorMessageBox(self, translate('SongsPlugin.TopicsForm', + criticalErrorMessageBox(message=translate('SongsPlugin.TopicsForm', 'You need to type in a topic name.')) self.nameEdit.setFocus() return False From 5f94cded2b769b6b7bc98d6404091ebd68849af6 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sat, 15 Jan 2011 19:44:31 +0000 Subject: [PATCH 28/60] Fix previous commit --- openlp/core/ui/themeform.py | 2 +- openlp/plugins/bibles/lib/db.py | 2 +- openlp/plugins/bibles/lib/mediaitem.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/themeform.py b/openlp/core/ui/themeform.py index 0925023bd..2db76063c 100644 --- a/openlp/core/ui/themeform.py +++ b/openlp/core/ui/themeform.py @@ -31,7 +31,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import translate, BackgroundType, BackgroundGradientType, \ Receiver -from openlp.core.ui import criticalErrorMessage +from openlp.core.ui import criticalErrorMessageBox from openlp.core.utils import get_images_filter from themewizard import Ui_ThemeWizard diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 695f4b721..1967448cc 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -33,7 +33,7 @@ from sqlalchemy import Column, ForeignKey, or_, Table, types from sqlalchemy.orm import class_mapper, mapper, relation from sqlalchemy.orm.exc import UnmappedClassError -from openlp.core.lib import Receiver, translate +from openlp.core.lib import translate from openlp.core.lib.db import BaseModel, init_db, Manager from openlp.core.ui import criticalErrorMessageBox diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index b38779680..d4b1b627b 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -30,6 +30,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, Receiver, BaseListWithDnD, \ ItemCapabilities, translate +from openlp.core.ui import criticalErrorMessageBox from openlp.plugins.bibles.forms import BibleImportForm from openlp.plugins.bibles.lib import get_reference_match From 1b3de30b92d8dbfb396539858418ef261600f83e Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sat, 15 Jan 2011 23:19:25 +0000 Subject: [PATCH 29/60] Fix local bible quick search --- openlp/plugins/bibles/lib/db.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 1967448cc..f442a9cd6 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -340,11 +340,11 @@ class BibleDB(QtCore.QObject, Manager): verse_list = [] for book, chapter, start_verse, end_verse in reference_list: db_book = self.get_book(book) - if end_verse == -1: - end_verse = self.get_verse_count(book, chapter) if db_book: book = db_book.name log.debug(u'Book name corrected to "%s"', book) + if end_verse == -1: + end_verse = self.get_verse_count(book, chapter) verses = self.session.query(Verse)\ .filter_by(book_id=db_book.id)\ .filter_by(chapter=chapter)\ From 07c906886ea914f55b7a3ecabce2be992e915c8c Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sun, 16 Jan 2011 00:47:14 +0000 Subject: [PATCH 30/60] Fix OpenSong CUV import --- openlp/plugins/bibles/lib/opensong.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/opensong.py index 2b3b6dfb7..12a6562bc 100644 --- a/openlp/plugins/bibles/lib/opensong.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -79,7 +79,7 @@ class OpenSongBible(BibleDB): break self.create_verse( db_book.id, - int(chapter.attrib[u'n']), + int(chapter.attrib[u'n'].split()[-1]), int(verse.attrib[u'n']), unicode(verse.text) ) @@ -87,7 +87,7 @@ class OpenSongBible(BibleDB): self.wizard.incrementProgressBar(unicode(translate( 'BiblesPlugin.Opensong', 'Importing %s %s...', 'Importing ...')) % - (db_book.name, int(chapter.attrib[u'n']))) + (db_book.name, int(chapter.attrib[u'n'].split()[-1]))) self.session.commit() except (IOError, AttributeError): log.exception(u'Loading bible from OpenSong file failed') From 471de78bfe0c5215c486d895a1025a7912974542 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 16 Jan 2011 18:42:26 +0100 Subject: [PATCH 31/60] update preview when live background is replaaced --- openlp/plugins/images/lib/mediaitem.py | 11 +++++++++-- openlp/plugins/media/lib/mediaitem.py | 13 ++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index d2652207c..b31ab5884 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -31,7 +31,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \ ItemCapabilities, SettingsManager, translate, check_item_selected, \ - check_directory_exists + check_directory_exists, Receiver from openlp.core.ui import criticalErrorMessageBox from openlp.core.utils import AppLocation, delete_file, get_images_filter @@ -187,12 +187,17 @@ class ImageMediaItem(MediaManagerItem): return False def onResetClick(self): + """ + Called to reset the Live backgound with the image selected, + """ self.resetAction.setVisible(False) self.parent.liveController.display.resetImage() + # Update the preview frame. + Receiver.send_message(u'maindisplay_active') def onReplaceClick(self): """ - Called to replace Live backgound with the video selected + Called to replace Live backgound with the image selected. """ if check_item_selected(self.listView, translate('ImagePlugin.MediaItem', @@ -204,6 +209,8 @@ class ImageMediaItem(MediaManagerItem): (path, name) = os.path.split(filename) self.parent.liveController.display.directImage(name, filename) self.resetAction.setVisible(True) + # Update the preview frame. + Receiver.send_message(u'maindisplay_active') else: criticalErrorMessageBox( translate('ImagePlugin.MediaItem', 'Live Background Error'), diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 0280ba937..ba0a5dc96 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -30,7 +30,7 @@ import os from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \ - ItemCapabilities, SettingsManager, translate, check_item_selected + ItemCapabilities, SettingsManager, translate, check_item_selected, Receiver from openlp.core.ui import criticalErrorMessageBox log = logging.getLogger(__name__) @@ -40,6 +40,7 @@ class MediaListView(BaseListWithDnD): self.PluginName = u'Media' BaseListWithDnD.__init__(self, parent) + class MediaMediaItem(MediaManagerItem): """ This is the custom media manager item for Media Slides. @@ -92,10 +93,18 @@ class MediaMediaItem(MediaManagerItem): self.resetAction.setVisible(False) def onResetClick(self): + """ + Called to reset the Live backgound with the media selected, + """ self.resetAction.setVisible(False) self.parent.liveController.display.resetVideo() + # Update the preview frame. + Receiver.send_message(u'maindisplay_active') def onReplaceClick(self): + """ + Called to replace Live backgound with the media selected. + """ if check_item_selected(self.listView, translate('MediaPlugin.MediaItem', 'You must select a media file to replace the background with.')): @@ -105,6 +114,8 @@ class MediaMediaItem(MediaManagerItem): (path, name) = os.path.split(filename) self.parent.liveController.display.video(filename, 0, True) self.resetAction.setVisible(True) + # Update the preview frame. + Receiver.send_message(u'maindisplay_active') else: criticalErrorMessageBox(translate('MediaPlugin.MediaItem', 'Live Background Error'), From 4414d7e4211ce1f4b653650dc77061dd92cc0c3b Mon Sep 17 00:00:00 2001 From: Garrett Date: Sun, 16 Jan 2011 14:32:39 -0800 Subject: [PATCH 32/60] Add a setting to hide the mouse cursor on the display. --- openlp/core/ui/generaltab.py | 16 ++++++++++++++++ openlp/core/ui/maindisplay.py | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/openlp/core/ui/generaltab.py b/openlp/core/ui/generaltab.py index 773637481..b829a67d2 100644 --- a/openlp/core/ui/generaltab.py +++ b/openlp/core/ui/generaltab.py @@ -213,6 +213,14 @@ class GeneralTab(SettingsTab): self.customHeightValueEdit.setObjectName(u'customHeightValueEdit') self.displayLayout.addWidget(self.customHeightValueEdit, 4, 3) self.rightLayout.addWidget(self.displayGroupBox) + self.hideMouseGroupBox = QtGui.QGroupBox(self.rightColumn) + self.hideMouseGroupBox.setObjectName(u'hideMouseGroupBox') + self.hideMouseLayout = QtGui.QVBoxLayout(self.hideMouseGroupBox) + self.hideMouseLayout.setObjectName(u'hideMouseLayout') + self.hideMouseCheckBox = QtGui.QCheckBox(self.hideMouseGroupBox) + self.hideMouseCheckBox.setObjectName(u'hideMouseCheckBox') + self.hideMouseLayout.addWidget(self.hideMouseCheckBox) + self.rightLayout.addWidget(self.hideMouseGroupBox) self.rightLayout.addStretch() # Signals and slots QtCore.QObject.connect(self.overrideCheckBox, @@ -287,6 +295,10 @@ class GeneralTab(SettingsTab): self.customHeightLabel.setText( translate('OpenLP.GeneralTab', 'Height')) self.customWidthLabel.setText(translate('OpenLP.GeneralTab', 'Width')) + self.hideMouseGroupBox.setTitle(translate('OpenLP.GeneralTab', + 'Mouse Cursor')) + self.hideMouseCheckBox.setText(translate('OpenLP.GeneralTab', + 'Hide the Mouse Cursor')) def load(self): """ @@ -341,6 +353,8 @@ class GeneralTab(SettingsTab): self.customWidthValueEdit.setText( settings.value(u'width', QtCore.QVariant( self.screens.current[u'size'].width())).toString()) + self.hideMouseCheckBox.setChecked(settings.value(u'hide mouse', + QtCore.QVariant(False)).toBool()) settings.endGroup() self.customXValueEdit.setEnabled(self.overrideCheckBox.isChecked()) self.customYValueEdit.setEnabled(self.overrideCheckBox.isChecked()) @@ -385,6 +399,8 @@ class GeneralTab(SettingsTab): QtCore.QVariant(self.customWidthValueEdit.text())) settings.setValue(u'override position', QtCore.QVariant(self.overrideCheckBox.isChecked())) + settings.setValue(u'hide mouse', + QtCore.QVariant(self.hideMouseCheckBox.isChecked())) settings.endGroup() self.screens.display = self.displayOnMonitorCheck.isChecked() # Monitor Number has changed. diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 273a3c4f0..2638c99e8 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -117,6 +117,8 @@ class MainDisplay(DisplayWidget): QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'maindisplay_show'), self.showDisplay) + self.generalSettingsSection = u'general' + def retranslateUi(self): """ Setup the interface translation strings. @@ -205,6 +207,8 @@ class MainDisplay(DisplayWidget): Receiver.send_message(u'openlp_process_events') self.frame.evaluateJavaScript(u'show_text("%s")' % \ slide.replace(u'\\', u'\\\\').replace(u'\"', u'\\\"')) + + self.hideMouseCursor() return self.preview() def alert(self, text): @@ -270,6 +274,7 @@ class MainDisplay(DisplayWidget): else: js = u'show_image("");' self.frame.evaluateJavaScript(js) + self.hideMouseCursor() def resetImage(self): """ @@ -359,6 +364,8 @@ class MainDisplay(DisplayWidget): self.webView.setVisible(False) self.videoWidget.setVisible(True) self.audio.setVolume(vol) + + self.hideMouseCursor() return self.preview() def isLoaded(self): @@ -474,6 +481,19 @@ class MainDisplay(DisplayWidget): self.hideMode = None # Trigger actions when display is active again Receiver.send_message(u'maindisplay_active') + + def hideMouseCursor(self): + """ + Hide the mouse cursor if enabled in settings + """ + settings = QtCore.QSettings() + if settings.value(u'%s/hide mouse' % self.generalSettingsSection, + QtCore.QVariant(False)).toBool(): + self.setCursor(QtCore.Qt.BlankCursor) + self.frame.evaluateJavaScript('document.body.style.cursor = "none"') + else: + self.setCursor(QtCore.Qt.ArrowCursor) + self.frame.evaluateJavaScript('document.body.style.cursor = "auto"') class AudioPlayer(QtCore.QObject): """ From e664205282327c8e1f09c8a1d3553a29ceb78331 Mon Sep 17 00:00:00 2001 From: Garrett Date: Sun, 16 Jan 2011 15:52:12 -0800 Subject: [PATCH 33/60] add a setting to the advanced tab to allow hiding the mouse cursor --- openlp/core/ui/advancedtab.py | 17 +++++++++++++++++ openlp/core/ui/maindisplay.py | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index 7cebe9930..d7b2a5555 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -72,6 +72,14 @@ class AdvancedTab(SettingsTab): u'enableAutoCloseCheckBox') self.uiLayout.addRow(self.enableAutoCloseCheckBox) self.leftLayout.addWidget(self.uiGroupBox) + self.hideMouseGroupBox = QtGui.QGroupBox(self.leftColumn) + self.hideMouseGroupBox.setObjectName(u'hideMouseGroupBox') + self.hideMouseLayout = QtGui.QVBoxLayout(self.hideMouseGroupBox) + self.hideMouseLayout.setObjectName(u'hideMouseLayout') + self.hideMouseCheckBox = QtGui.QCheckBox(self.hideMouseGroupBox) + self.hideMouseCheckBox.setObjectName(u'hideMouseCheckBox') + self.hideMouseLayout.addWidget(self.hideMouseCheckBox) + self.leftLayout.addWidget(self.hideMouseGroupBox) # self.sharedDirGroupBox = QtGui.QGroupBox(self.leftColumn) # self.sharedDirGroupBox.setObjectName(u'sharedDirGroupBox') # self.sharedDirLayout = QtGui.QFormLayout(self.sharedDirGroupBox) @@ -117,6 +125,10 @@ class AdvancedTab(SettingsTab): 'Expand new service items on creation')) self.enableAutoCloseCheckBox.setText(translate('OpenLP.AdvancedTab', 'Enable application exit confirmation')) + self.hideMouseGroupBox.setTitle(translate('OpenLP.GeneralTab', + 'Mouse Cursor')) + self.hideMouseCheckBox.setText(translate('OpenLP.GeneralTab', + 'Hide the Mouse Cursor')) # self.sharedDirGroupBox.setTitle( # translate('AdvancedTab', 'Central Data Store')) # self.sharedCheckBox.setText( @@ -150,6 +162,9 @@ class AdvancedTab(SettingsTab): self.enableAutoCloseCheckBox.setChecked( settings.value(u'enable exit confirmation', QtCore.QVariant(True)).toBool()) + self.hideMouseCheckBox.setChecked( + settings.value(u'hide mouse', + QtCore.QVariant(False)).toBool()) settings.endGroup() def save(self): @@ -168,6 +183,8 @@ class AdvancedTab(SettingsTab): QtCore.QVariant(self.expandServiceItemCheckBox.isChecked())) settings.setValue(u'enable exit confirmation', QtCore.QVariant(self.enableAutoCloseCheckBox.isChecked())) + settings.setValue(u'hide mouse', + QtCore.QVariant(self.hideMouseCheckBox.isChecked())) settings.endGroup() # def onSharedCheckBoxChanged(self, checked): diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 273a3c4f0..a13608bb5 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -117,6 +117,7 @@ class MainDisplay(DisplayWidget): QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'maindisplay_show'), self.showDisplay) + self.advancedSettingsSection = u'advanced' def retranslateUi(self): """ Setup the interface translation strings. @@ -205,6 +206,7 @@ class MainDisplay(DisplayWidget): Receiver.send_message(u'openlp_process_events') self.frame.evaluateJavaScript(u'show_text("%s")' % \ slide.replace(u'\\', u'\\\\').replace(u'\"', u'\\\"')) + self.hideMouseCursor() return self.preview() def alert(self, text): @@ -270,6 +272,7 @@ class MainDisplay(DisplayWidget): else: js = u'show_image("");' self.frame.evaluateJavaScript(js) + self.hideMouseCursor() def resetImage(self): """ @@ -359,6 +362,7 @@ class MainDisplay(DisplayWidget): self.webView.setVisible(False) self.videoWidget.setVisible(True) self.audio.setVolume(vol) + self.hideMouseCursor() return self.preview() def isLoaded(self): @@ -474,6 +478,19 @@ class MainDisplay(DisplayWidget): self.hideMode = None # Trigger actions when display is active again Receiver.send_message(u'maindisplay_active') + + def hideMouseCursor(self): + """ + Hide the mouse cursor if enabled in settings + """ + settings = QtCore.QSettings() + if settings.value(u'%s/hide mouse' % self.advancedSettingsSection, + QtCore.QVariant(False)).toBool(): + self.setCursor(QtCore.Qt.BlankCursor) + self.frame.evaluateJavaScript('document.body.style.cursor = "none"') + else: + self.setCursor(QtCore.Qt.ArrowCursor) + self.frame.evaluateJavaScript('document.body.style.cursor = "auto"') class AudioPlayer(QtCore.QObject): """ From 90c742f9ba03c59cc402cc0b04102d92a1f50b64 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Mon, 17 Jan 2011 00:52:00 +0000 Subject: [PATCH 34/60] Fix song validating and saving process --- openlp/plugins/songs/forms/editsongform.py | 97 ++++++++++++---------- openlp/plugins/songs/lib/db.py | 2 +- 2 files changed, 55 insertions(+), 44 deletions(-) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index a1f1e97bb..8a7157e29 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -332,7 +332,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): else: author = Author.populate(first_name=text.rsplit(u' ', 1)[0], last_name=text.rsplit(u' ', 1)[1], display_name=text) - self.manager.save_object(author, False) + self.manager.save_object(author) author_item = QtGui.QListWidgetItem( unicode(author.display_name)) author_item.setData(QtCore.Qt.UserRole, @@ -386,7 +386,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes: topic = Topic.populate(name=text) - self.manager.save_object(topic, False) + self.manager.save_object(topic) topic_item = QtGui.QListWidgetItem(unicode(topic.name)) topic_item.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id)) @@ -524,12 +524,13 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): def _validate_song(self): """ - Check the validity of the form. Only display the 'save' if the data - can be saved. + Check the validity of the song. """ + # This checks data in the form *not* self.song. self.song is still + # None at this point. log.debug(u'Validate Song') # Lets be nice and assume the data is correct. - if len(self.titleEdit.displayText()) == 0: + if not self.titleEdit.text(): self.songTabWidget.setCurrentIndex(0) self.titleEdit.setFocus() criticalErrorMessageBox( @@ -550,9 +551,9 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): message=translate('SongsPlugin.EditSongForm', 'You need to have an author for this song.')) return False - if self.song.verse_order: + if self.verseOrderEdit.text(): order = [] - order_names = self.song.verse_order.split() + order_names = self.verseOrderEdit.text().split() for item in order_names: if len(item) == 1: order.append(item.lower() + u'1') @@ -593,6 +594,19 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) if answer == QtGui.QMessageBox.No: return False + item = int(self.songBookComboBox.currentIndex()) + text = unicode(self.songBookComboBox.currentText()) + if self.songBookComboBox.findText(text, QtCore.Qt.MatchExactly) < 0: + if QtGui.QMessageBox.question(self, + translate('SongsPlugin.EditSongForm', 'Add Book'), + translate('SongsPlugin.EditSongForm', 'This song book does ' + 'not exist, do you want to add it?'), + QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, + QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes: + book = Book.populate(name=text, publisher=u'') + self.manager.save_object(book) + else: + return False return True def onCopyrightInsertButtonTriggered(self): @@ -653,33 +667,25 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): """ log.debug(u'accept') self.clearCaches() - if not self.song: - self.song = Song() - item = int(self.songBookComboBox.currentIndex()) - text = unicode(self.songBookComboBox.currentText()) - if self.songBookComboBox.findText(text, QtCore.Qt.MatchExactly) < 0: - if QtGui.QMessageBox.question(self, - translate('SongsPlugin.EditSongForm', 'Add Book'), - translate('SongsPlugin.EditSongForm', 'This song book does ' - 'not exist, do you want to add it?'), - QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, - QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes: - book = Book.populate(name=text, publisher=u'') - self.manager.save_object(book, False) - else: - return - if self.saveSong(): + if self._validate_song(): + self.saveSong() Receiver.send_message(u'songs_load_list') self.close() def saveSong(self, preview=False): """ Get all the data from the widgets on the form, and then save it to the - database. + database. The form has been validated and all reference items + (Authors, Books and Topics) have been saved before this function is + called. ``preview`` Should be ``True`` if the song is also previewed (boolean). """ + # The Song() assignment. No database calls should be made while a + # Song() is in a partially complete state. + if not self.song: + self.song = Song() self.song.title = unicode(self.titleEdit.text()) self.song.alternate_title = unicode(self.alternativeEdit.text()) self.song.copyright = unicode(self.copyrightEdit.text()) @@ -703,27 +709,27 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.song.theme_name = theme_name else: self.song.theme_name = None - if self._validate_song(): - self.processLyrics() - self.processTitle() - self.song.authors = [] - for row in range(self.authorsListView.count()): - item = self.authorsListView.item(row) - authorId = (item.data(QtCore.Qt.UserRole)).toInt()[0] - self.song.authors.append(self.manager.get_object(Author, - authorId)) - self.song.topics = [] - for row in range(self.topicsListView.count()): - item = self.topicsListView.item(row) - topicId = (item.data(QtCore.Qt.UserRole)).toInt()[0] - self.song.topics.append(self.manager.get_object(Topic, topicId)) - self.manager.save_object(self.song) - if not preview: - self.song = None - return True - return False + self.processLyrics() + self.processTitle() + self.song.authors = [] + for row in range(self.authorsListView.count()): + item = self.authorsListView.item(row) + authorId = (item.data(QtCore.Qt.UserRole)).toInt()[0] + self.song.authors.append(self.manager.get_object(Author, authorId)) + self.song.topics = [] + for row in range(self.topicsListView.count()): + item = self.topicsListView.item(row) + topicId = (item.data(QtCore.Qt.UserRole)).toInt()[0] + self.song.topics.append(self.manager.get_object(Topic, topicId)) + self.manager.save_object(self.song) + if not preview: + self.song = None def processLyrics(self): + """ + Process the lyric data entered by the user into the OpenLP XML format. + """ + # This method must only be run after the self.song = Song() assignment. log.debug(u'processLyrics') try: sxml = SongXML() @@ -749,6 +755,11 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): sxml.dump_xml()) def processTitle(self): + """ + Process the song title entered by the user to remove stray punctuation + characters. + """ + # This method must only be run after the self.song = Song() assignment. log.debug(u'processTitle') self.song.search_title = re.sub(r'[\'"`,;:(){}?]+', u'', unicode(self.song.search_title)).lower() diff --git a/openlp/plugins/songs/lib/db.py b/openlp/plugins/songs/lib/db.py index faa0a88da..838172893 100644 --- a/openlp/plugins/songs/lib/db.py +++ b/openlp/plugins/songs/lib/db.py @@ -72,7 +72,7 @@ def init_schema(url): ``url`` The database to setup """ - session, metadata = init_db(url, False) + session, metadata = init_db(url) # Definition of the "authors" table authors_table = Table(u'authors', metadata, From 42a955582bbd1d258f69ddb3f46621364ee90f7f Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 17 Jan 2011 16:38:10 +0100 Subject: [PATCH 35/60] moved code to core --- openlp/core/ui/maindisplay.py | 11 +++++++++++ openlp/plugins/images/lib/mediaitem.py | 6 +----- openlp/plugins/media/lib/mediaitem.py | 6 +----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 273a3c4f0..ad45d200d 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -94,6 +94,8 @@ class DisplayWidget(QtGui.QGraphicsView): else: event.ignore() + + class MainDisplay(DisplayWidget): """ This is the display screen. @@ -270,6 +272,8 @@ class MainDisplay(DisplayWidget): else: js = u'show_image("");' self.frame.evaluateJavaScript(js) + # Update the preview frame. + Receiver.send_message(u'maindisplay_active') def resetImage(self): """ @@ -278,6 +282,8 @@ class MainDisplay(DisplayWidget): """ log.debug(u'resetImage') self.displayImage(self.serviceItem.bg_image_bytes) + # Update the preview frame. + Receiver.send_message(u'maindisplay_active') def resetVideo(self): """ @@ -292,6 +298,8 @@ class MainDisplay(DisplayWidget): self.phononActive = False else: self.frame.evaluateJavaScript(u'show_video("close");') + # Update the preview frame. + Receiver.send_message(u'maindisplay_active') def videoPlay(self): """ @@ -359,6 +367,8 @@ class MainDisplay(DisplayWidget): self.webView.setVisible(False) self.videoWidget.setVisible(True) self.audio.setVolume(vol) + # Update the preview frame. + Receiver.send_message(u'maindisplay_active') return self.preview() def isLoaded(self): @@ -475,6 +485,7 @@ class MainDisplay(DisplayWidget): # Trigger actions when display is active again Receiver.send_message(u'maindisplay_active') + class AudioPlayer(QtCore.QObject): """ This Class will play audio only allowing components to work with a diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index b31ab5884..bd84219fb 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -31,7 +31,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \ ItemCapabilities, SettingsManager, translate, check_item_selected, \ - check_directory_exists, Receiver + check_directory_exists from openlp.core.ui import criticalErrorMessageBox from openlp.core.utils import AppLocation, delete_file, get_images_filter @@ -192,8 +192,6 @@ class ImageMediaItem(MediaManagerItem): """ self.resetAction.setVisible(False) self.parent.liveController.display.resetImage() - # Update the preview frame. - Receiver.send_message(u'maindisplay_active') def onReplaceClick(self): """ @@ -209,8 +207,6 @@ class ImageMediaItem(MediaManagerItem): (path, name) = os.path.split(filename) self.parent.liveController.display.directImage(name, filename) self.resetAction.setVisible(True) - # Update the preview frame. - Receiver.send_message(u'maindisplay_active') else: criticalErrorMessageBox( translate('ImagePlugin.MediaItem', 'Live Background Error'), diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index ba0a5dc96..121fa80a0 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -30,7 +30,7 @@ import os from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \ - ItemCapabilities, SettingsManager, translate, check_item_selected, Receiver + ItemCapabilities, SettingsManager, translate, check_item_selected from openlp.core.ui import criticalErrorMessageBox log = logging.getLogger(__name__) @@ -98,8 +98,6 @@ class MediaMediaItem(MediaManagerItem): """ self.resetAction.setVisible(False) self.parent.liveController.display.resetVideo() - # Update the preview frame. - Receiver.send_message(u'maindisplay_active') def onReplaceClick(self): """ @@ -114,8 +112,6 @@ class MediaMediaItem(MediaManagerItem): (path, name) = os.path.split(filename) self.parent.liveController.display.video(filename, 0, True) self.resetAction.setVisible(True) - # Update the preview frame. - Receiver.send_message(u'maindisplay_active') else: criticalErrorMessageBox(translate('MediaPlugin.MediaItem', 'Live Background Error'), From 12ce267ff380b41095f4b4e6a6eeabf771be9739 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 17 Jan 2011 16:43:07 +0100 Subject: [PATCH 36/60] removed blank line --- openlp/core/ui/maindisplay.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index ad45d200d..84697f376 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -95,7 +95,6 @@ class DisplayWidget(QtGui.QGraphicsView): event.ignore() - class MainDisplay(DisplayWidget): """ This is the display screen. From a93a37c494923e9d849f8a36cef8926a7b063ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Mon, 17 Jan 2011 18:21:46 +0200 Subject: [PATCH 37/60] just another massive rewrite, now with regions --- openlp/plugins/songs/lib/easislidesimport.py | 390 +++++++++++++------ openlp/plugins/songs/lib/songimport.py | 3 +- 2 files changed, 263 insertions(+), 130 deletions(-) diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py index 736d85304..608777fe2 100644 --- a/openlp/plugins/songs/lib/easislidesimport.py +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -62,19 +62,19 @@ class EasiSlidesImport(SongImport): import will not be committed to the database (useful for test scripts). """ success = True - + self.import_wizard.importProgressBar.setMaximum(1) - + log.info(u'Direct import %s', self.filename) self.import_wizard.incrementProgressBar( unicode(translate('SongsPlugin.ImportWizardForm', - 'Importing %s...')) % os.path.split(self.filename)[-1]) + u'Importing %s...')) % os.path.split(self.filename)[-1]) file = open(self.filename) count = file.read().count('') file.seek(0) self.import_wizard.importProgressBar.setMaximum(count) self.do_import_file(file) - + return success def do_import_file(self, file): @@ -85,16 +85,19 @@ class EasiSlidesImport(SongImport): self.set_defaults() # determines, if ENTIRELY UPPERCASE lines should be converted to lower - self.toLower = True + self.toLower = False + # list of names, which have always to be Uppercase, like Jesus + # only used, when self.toLower is True + self.backToUpper = [u'Jesus', u'God'] # determines, if title should be prepended to lyrics - self.titleIsLyrics = True - + self.titleIsLyrics = False + try: context = etree.iterparse(file) except (Error, LxmlError): log.exception(u'Error parsing XML') return - + data = {} for action, elem in context: if not elem.text: @@ -108,25 +111,51 @@ class EasiSlidesImport(SongImport): self.parse_song(data) self.import_wizard.incrementProgressBar( unicode(translate('SongsPlugin.ImportWizardForm', - 'Importing %s, song %s...')) % + u'Importing %s, song %s...')) % (os.path.split(self.filename)[-1], self.title)) if self.commit: self.finish() data = {} - + def notCapsLock(self, string): if self.toLower and string.upper() == string: - return string.lower() + ret = string.lower() + if len(self.backToUpper) > 0: + for repl in self.backToUpper: + if repl == u'': + continue + ret = ret.replace(repl.lower(), repl) + return ret else: return string - + def notCapsLockTitle(self, string): if self.toLower and string.upper() == string: ret = string.lower() + if len(self.backToUpper) > 0: + for repl in self.backToUpper: + if repl == u'': + continue + ret = ret.replace(repl.lower(), repl) return u"%s%s" % (ret[0].upper(), ret[1:]) else: return string - + + def listHas(self, lst, subitems): + for i in subitems: + if type(lst) == type({}) and lst.has_key(i): + lst = lst[i] + elif type(lst) == type([]) and i in lst: + lst = lst[i] + else: + return False + return True + + def extractRegion(self, line): + # this was true already: thisline[0:7] == u'[region': + right_bracket = line.find(u']') + return line[7:right_bracket].strip() + def parse_song(self, data): # We should also check if the title is already used, if yes, # maybe user sould decide if we should import @@ -137,6 +166,9 @@ class EasiSlidesImport(SongImport): # set alternate title, if present if data['title2'] != None: self.alternate_title = self.notCapsLockTitle(data['title2']) + print self.alternate_title + print data['title2'] + print "HERE HERE HERE" # folder name, we have no use for it, usually only one folder is # used in easislides and this contains no actual data, easislides @@ -154,6 +186,7 @@ class EasiSlidesImport(SongImport): # data['notations'] # set song authors + # we don't have to handle the no author case, it is done afterwards if data['writer'] != None: authors = data['writer'].split(u',') for author in authors: @@ -170,9 +203,9 @@ class EasiSlidesImport(SongImport): copyright.append(data['licenceadmin1'].strip()) if data['licenceadmin2']: copyright.append(data['licenceadmin2'].strip()) - self.add_copyright(" ".join(copyright)) + self.add_copyright(u' '.join(copyright)) - # set topic data, I have seen no example, and should not use it, + # set topic data, I have seen no example, and probably should not do it, # I even was not able to find place to set categories in easislides # but then again, it would not hurt either if data['category']: @@ -189,13 +222,16 @@ class EasiSlidesImport(SongImport): # place a capo on guitar neck # set book data - if data['bookreference']: - for book in data['bookreference'].split(u','): - self.books.append(book.strip()) - + #if data['bookreference']: + # for book in data['bookreference'].split(u','): + # self.books.append(book.strip()) + # THIS NEEDS ATTENTION, DON'T KNOW HOW TO MAKE THIS WORK โ†‘ + # don't know what to do with user # data['userreference'], this is simple text entry, no - # notable restrictions + # notable restrictions, no idea what this is used for + # U: I have seen one use of this as "searchable field" or similar, + # still no use for us # there is nothing to do with formatdata, this for sure is a messy # thing, see an example: @@ -209,172 +245,268 @@ class EasiSlidesImport(SongImport): # data['formatdata'] # don't know what to do with settings data either, this is similar - # nonsense: 10=2;5;0;0;1;0;ยป126;232;> + # nonsense as formatdata: 10=2;5;0;0;1;0;ยป126;232;> # data['settings'] - + # LYRICS LYRICS LYRICS # the big and messy part to handle lyrics lyrics = data['contents'] # we add title to first line, if supposed to do so + # we don't use self.title, because this may have changed case if self.titleIsLyrics: - lyrics = u"%s\n%s" % (self.title, lyrics) - - # we count the [region 2] and [whatever] separartors, to be able - # to tell how region data is used - regions = 0 - separators = 0 - if lyrics.find(u'[') != -1: - match = -1 - while True: - match = lyrics.find(u'[', match+1) - if match == -1: - break - if lyrics[match:match+7].lower() == u'[region': - regions = regions+1 - else: - separators = separators+1 + lyrics = u"%s\n%s" % (data['title1'], lyrics) + #if lyrics.find(u'[') != -1: + # # this must have at least one separator + # match = -1 + # while True: + # match = lyrics.find(u'[', match+1) + # if match == -1: + # break + # elif lyrics[match:match+7].lower() == u'[region': + # regions = regions+1 + # else: + # separators = separators+1 + + lines = lyrics.split(u'\n') + length = len(lines) + + # we go over lines first, to determine some information, + # which tells us how to parse verses later + emptylines = 0 + regionlines = {} + separatorlines = 0 + uppercaselines = 0 + notuppercaselines = 0 + for i in range(length): + lines[i] = lines[i].strip() + thisline = lines[i] + if len(thisline) == 0: + emptylines = emptylines + 1 + elif thisline[0] == u'[': + if thisline[1:7] == u'region': + # this is region separator [region 2] + # Easislides song can have only one extra region zone, + # at least by now, but just in case the file happens + # to have [region 3] or more, we add a possiblity to + # count these separately, yeah, rather stupid, but + # count this as a programming exercise + region = self.extractRegion(thisline) + if regionlines.has_key(region): + regionlines[region] = regionlines[region] + 1 + else: + regionlines[region] = 1 + else: + separatorlines = separatorlines + 1 + elif thisline == thisline.upper(): + uppercaselines = uppercaselines + 1 + else: + notuppercaselines = notuppercaselines + 1 + + # if the whole song is entirely UPPERCASE + allUpperCase = (notuppercaselines == 0) + # if the song has separators + separators = (separatorlines > 0) + # the number of regions in song, conting the default as one + regions = len(regionlines)+1 + if regions > 2: + log.info(u'EasiSlidesImport: the file contained a song named "%s"' + u'with more than two regions, but only two regions are', + u'tested, all regions were: %s', + self.title, u','.join(regionlines.keys())) + # if the song has regions + regions = (len(regionlines) > 1) + # if the regions are inside verses (more than one ) + regionsInVerses = (len(regionlines) and \ + regionlines[regionlines.keys()[0]] > 1) + # data storage while importing verses = {} # keep track of a "default" verse order, in case none is specified + # this list contains list as [region, versetype, versenum, instance] our_verse_order = [] + # default region + defaultregion = u'1' + reg = defaultregion + verses[reg] = {} + # instance + inst = 1 + + MarkTypes = { + u'chorus': u'C', + u'verse': u'V', + u'intro': u'I', + u'ending': u'E', + u'bridge': u'B', + u'prechorus': u'P', + } - lines = lyrics.split(u'\n') - length = len(lines) for i in range(length): - thisline = lines[i].strip() + # we iterate once more over lines + thisline = lines[i] if i < length-1: nextline = lines[i+1].strip() else: # there is no nextline at the last line nextline = False - - if len(thisline) is 0: - if separators == 0: - # empty line starts a new verse or chorus - if nextline and nextline is nextline.upper(): - # the next line is all uppercase, it must be chorus - versetype = u'C' - else: - # if the next line is not uppercase, it must be verse - versetype = u'V' - - if verses.has_key(versetype): - versenum = len(verses[versetype].keys())+1 - else: - versenum = u'1' - - our_verse_order.append([versetype, versenum]) + + + if len(thisline) == 0: + if separators: + # separators are used, so empty line means slide break + # inside verse + if self.listHas(verses, [reg, vt, vn, inst]): + inst = inst + 1 else: - # separators are not used, something must be done + # separators are not used, so empty line starts a new verse + if not allUpperCase and nextline and \ + nextline is nextline.upper(): + # the next line is all uppercase, it must be chorus + vt = u'C' + else: + # if the next line is not uppercase, + # or whole song is uppercase, this must be verse + vt = u'V' + + # changing the region is not possible in this case + + if verses[reg].has_key(vt): + vn = len(verses[reg][vt].keys())+1 + else: + vn = u'1' + + inst = 1 + if not [reg, vt, vn, inst] in our_verse_order: + our_verse_order.append([reg, vt, vn, inst]) continue continue - # verse/chorus/etc. marker, this line contains no other data - if thisline[0] == u'[': - if regions > 1: - # region markers are inside verse markers - if thisline[0:6] == u'[region': - # this is a region marker inside verse - # by now we do nothing - print 'region inside verse markers' - continue - elif regions == 0: - # there is only one region marker - if thisline[0:6] == u'[region': - # we should restart verse count - # by now we do nothing - continue - # this is to be handled as normal marker + elif thisline[0:7] == u'[region': + reg = self.extractRegion(thisline) + if not verses.has_key(reg): + verses[reg] = {} + if i == 0: + # the file started with [region 2] + vt = u'V' + vn = u'1' + our_verse_order.append([reg, vt, vn, inst]) + continue + + elif thisline[0] == u'[': + # this is a normal section marker # drop the square brackets right_bracket = thisline.find(u']') - content = thisline[1:right_bracket].upper() + marker = thisline[1:right_bracket].upper() # have we got any digits? # If so, versenumber is everything from the digits # to the end (even if there are some alpha chars on the end) - match = re.match(u'(.*)(\d+.*)', content) + match = re.match(u'(.*)(\d+.*)', marker) if match is not None: - # versetype normally is one of the following: - # not set for verse (only number) - # prechorus (p), chorus (c), bridge (w), - # ending, none of these is numbered in sequence - # empty line means split screen - versetype = match.group(1) - versenum = match.group(2) + vt = match.group(1).strip() + vn = match.group(2) + if vt == u'': + vt = u'V' + elif MarkTypes.has_key(vt.lower()): + vt = MarkTypes[vt.lower()] + else: + vt = u'O' else: - # otherwise we assume number 1 and take the whole prefix as - # the versetype - versetype = content - versenum = u'1' - our_verse_order.append([versetype, versenum]) + if marker == u'': + vt = u'V' + elif MarkTypes.has_key(marker.lower()): + vt = MarkTypes[marker.lower()] + else: + vt = u'O' + vn = u'1' + + if regionsInVerses: + region = defaultregion + + inst = 1 + if self.listHas(verses, [reg, vt, vn, inst]): + inst = len(verses[reg][vt][vn])+1 + + if not [reg, vt, vn, inst] in our_verse_order: + our_verse_order.append([reg, vt, vn, inst]) continue - + if i == 0: - # this is the first line, but still no separator is found, + # this is the first line, but no separator is found, # we say it's V1 - versetype = u'V' - versenum = u'1' - our_verse_order.append([versetype, versenum]) + vt = u'V' + vn = u'1' + our_verse_order.append([reg, vt, vn, inst]) # We have versetype/number data, if it was there, now # we parse text - if not verses.has_key(versetype): - verses[versetype] = {} - if not verses[versetype].has_key(versenum): - verses[versetype][versenum] = [] + if not verses[reg].has_key(vt): + verses[reg][vt] = {} + if not verses[reg][vt].has_key(vn): + verses[reg][vt][vn] = {} + if not verses[reg][vt][vn].has_key(inst): + verses[reg][vt][vn][inst] = [] # Tidy text and remove the ____s from extended words words = self.tidy_text(thisline) - words = words.replace('_', '') words = self.notCapsLock(words) - verses[versetype][versenum].append(words) + verses[reg][vt][vn][inst].append(words) # done parsing + + versetags = [] # we use our_verse_order to ensure, we insert lyrics in the same order # as these appeared originally in the file + for tag in our_verse_order: - versetype = tag[0] - versenum = tag[1] + reg = tag[0] + vt = tag[1] + vn = tag[2] + inst = tag[3] - if not versetype in verses: - # something may have gone wrong + if not self.listHas(verses, [reg, vt, vn, inst]): continue - if not versenum in verses[versetype]: - # this most likely is caused by an extra empty line at the end, - # to be debugged later - continue - versetag = u'%s%s' % (versetype, versenum) - lines = u'\n'.join(verses[versetype][versenum]) + versetag = u'%s%s' % (vt, vn) + versetags.append(versetag) + lines = u'\n'.join(verses[reg][vt][vn][inst]) self.verses.append([versetag, lines]) + # Sequence keys: + # numbers refer to verses + # p = prechorus + # q = prechorus 2 + # c = chorus + # t = chorus 2 + # b = bridge + # w = bridge 2 + # e = ending + SeqTypes = { + u'p': u'P1', + u'q': u'P2', + u'c': u'C1', + u't': u'C2', + u'b': u'B1', + u'w': u'B2', + u'e': u'E1' + } # Make use of Sequence data, determining the order of verses, choruses + # if this is not present, we don't need it either, since the + # verses already are in the right order if data['sequence'] != None: order = data['sequence'].split(u',') for tag in order: if tag[0].isdigit(): - # Assume it's a verse if it has no prefix + # it's a verse if it has no prefix, but has a number tag = u'V' + tag - elif not re.search('\d+', tag): - # Assume it's no.1 if there's no digits - tag = tag + u'1' - if not versetags.has_key(tag): + elif SeqTypes.has_key(tag.lower()): + tag = SeqTypes[tag.lower()] + else: + # maybe we should continue here instead + tag = u'O1' + + if not tag in versetags: log.info(u'Got order %s but not in versetags, dropping this' u'item from presentation order', tag) else: self.verse_order_list.append(tag) - else: - for tag in our_verse_order: - if not tag[0] in verses: - #log.info(u'Got order from our_verse_order %s but not in' - # u'versetags, dropping this item from presentation order' - # u'missing was versetag %s', tag, tag[0]) - continue - if not tag[1] in verses[tag[0]]: - #log.info(u'Got order from our_verse_order %s but not in' - # u'versetags, dropping this item from presentation order' - # u'missing was versenum %s for versetag %s', - # tag, tag[1], tag[0]) - continue - self.verse_order_list.append(u'%s%s' % (tag[0], tag[1])) diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index 05ed320a9..4bae9f2e5 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -265,6 +265,7 @@ class SongImport(QtCore.QObject): log.info(u'commiting song %s to database', self.title) song = Song() song.title = self.title + song.alternate_title = self.title song.search_title = self.remove_punctuation(self.title).lower() \ + '@' + self.remove_punctuation(self.alternate_title).lower() song.song_number = self.song_number @@ -364,4 +365,4 @@ class SongImport(QtCore.QObject): if self.theme_name: print u'THEME: ' + self.theme_name if self.ccli_number: - print u'CCLI: ' + self.ccli_number \ No newline at end of file + print u'CCLI: ' + self.ccli_number From 0cab45bcf825fd817e81e1f7b659cd192f0717bd Mon Sep 17 00:00:00 2001 From: Garrett Date: Mon, 17 Jan 2011 08:24:23 -0800 Subject: [PATCH 38/60] moved function code into buildHtml, made setting name more descriptive --- openlp/core/ui/advancedtab.py | 2 +- openlp/core/ui/maindisplay.py | 25 +++++++++---------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index d7b2a5555..2c016ae7b 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -128,7 +128,7 @@ class AdvancedTab(SettingsTab): self.hideMouseGroupBox.setTitle(translate('OpenLP.GeneralTab', 'Mouse Cursor')) self.hideMouseCheckBox.setText(translate('OpenLP.GeneralTab', - 'Hide the Mouse Cursor')) + 'Hide the ouse cursor when over the display window')) # self.sharedDirGroupBox.setTitle( # translate('AdvancedTab', 'Central Data Store')) # self.sharedCheckBox.setText( diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index a13608bb5..acbd1ce62 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -206,7 +206,6 @@ class MainDisplay(DisplayWidget): Receiver.send_message(u'openlp_process_events') self.frame.evaluateJavaScript(u'show_text("%s")' % \ slide.replace(u'\\', u'\\\\').replace(u'\"', u'\\\"')) - self.hideMouseCursor() return self.preview() def alert(self, text): @@ -272,7 +271,6 @@ class MainDisplay(DisplayWidget): else: js = u'show_image("");' self.frame.evaluateJavaScript(js) - self.hideMouseCursor() def resetImage(self): """ @@ -362,7 +360,6 @@ class MainDisplay(DisplayWidget): self.webView.setVisible(False) self.videoWidget.setVisible(True) self.audio.setVolume(vol) - self.hideMouseCursor() return self.preview() def isLoaded(self): @@ -430,6 +427,15 @@ class MainDisplay(DisplayWidget): # if was hidden keep it hidden if self.hideMode and self.isLive: self.hideDisplay(self.hideMode) + # Hide the mouse cursor over display if enabled in settings + settings = QtCore.QSettings() + if settings.value(u'%s/hide mouse' % self.advancedSettingsSection, + QtCore.QVariant(False)).toBool(): + self.setCursor(QtCore.Qt.BlankCursor) + self.frame.evaluateJavaScript('document.body.style.cursor = "none"') + else: + self.setCursor(QtCore.Qt.ArrowCursor) + self.frame.evaluateJavaScript('document.body.style.cursor = "auto"') def footer(self, text): """ @@ -478,19 +484,6 @@ class MainDisplay(DisplayWidget): self.hideMode = None # Trigger actions when display is active again Receiver.send_message(u'maindisplay_active') - - def hideMouseCursor(self): - """ - Hide the mouse cursor if enabled in settings - """ - settings = QtCore.QSettings() - if settings.value(u'%s/hide mouse' % self.advancedSettingsSection, - QtCore.QVariant(False)).toBool(): - self.setCursor(QtCore.Qt.BlankCursor) - self.frame.evaluateJavaScript('document.body.style.cursor = "none"') - else: - self.setCursor(QtCore.Qt.ArrowCursor) - self.frame.evaluateJavaScript('document.body.style.cursor = "auto"') class AudioPlayer(QtCore.QObject): """ From 6a7edfc7c0e0b09790c406d076b47733acea90d4 Mon Sep 17 00:00:00 2001 From: Garrett Date: Mon, 17 Jan 2011 08:32:58 -0800 Subject: [PATCH 39/60] changed GeneralTab to AdvancedTab when translating since I moved the code --- openlp/core/ui/advancedtab.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index 2c016ae7b..22fbfb281 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -125,9 +125,9 @@ class AdvancedTab(SettingsTab): 'Expand new service items on creation')) self.enableAutoCloseCheckBox.setText(translate('OpenLP.AdvancedTab', 'Enable application exit confirmation')) - self.hideMouseGroupBox.setTitle(translate('OpenLP.GeneralTab', + self.hideMouseGroupBox.setTitle(translate('OpenLP.AdvancedTab', 'Mouse Cursor')) - self.hideMouseCheckBox.setText(translate('OpenLP.GeneralTab', + self.hideMouseCheckBox.setText(translate('OpenLP.AdvancedTab', 'Hide the ouse cursor when over the display window')) # self.sharedDirGroupBox.setTitle( # translate('AdvancedTab', 'Central Data Store')) From d3bc39a2620320a27245a23b91ccb97c3885c956 Mon Sep 17 00:00:00 2001 From: Garrett Date: Mon, 17 Jan 2011 08:36:48 -0800 Subject: [PATCH 40/60] fixed my sad spelling mistakes --- openlp/core/ui/advancedtab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index 22fbfb281..b79f1f766 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -128,7 +128,7 @@ class AdvancedTab(SettingsTab): self.hideMouseGroupBox.setTitle(translate('OpenLP.AdvancedTab', 'Mouse Cursor')) self.hideMouseCheckBox.setText(translate('OpenLP.AdvancedTab', - 'Hide the ouse cursor when over the display window')) + 'Hide the mouse cursor when over the display window')) # self.sharedDirGroupBox.setTitle( # translate('AdvancedTab', 'Central Data Store')) # self.sharedCheckBox.setText( From 55e23bcfbca8038feb4a7b3916fcc3bdd8b57003 Mon Sep 17 00:00:00 2001 From: Garrett Date: Mon, 17 Jan 2011 08:38:39 -0800 Subject: [PATCH 41/60] fixed spelling mistakes --- openlp/core/ui/advancedtab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index b79f1f766..52151e5b8 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -128,7 +128,7 @@ class AdvancedTab(SettingsTab): self.hideMouseGroupBox.setTitle(translate('OpenLP.AdvancedTab', 'Mouse Cursor')) self.hideMouseCheckBox.setText(translate('OpenLP.AdvancedTab', - 'Hide the mouse cursor when over the display window')) + 'Hide the mouse cursor when moved over the display window')) # self.sharedDirGroupBox.setTitle( # translate('AdvancedTab', 'Central Data Store')) # self.sharedCheckBox.setText( From 83ca6f4230d8dbd3a4a194491353de5ef500c93c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Mon, 17 Jan 2011 19:35:19 +0200 Subject: [PATCH 42/60] more modifications, now this works again --- openlp/plugins/songs/forms/songimportform.py | 16 ++++++++++--- .../plugins/songs/forms/songimportwizard.py | 2 +- openlp/plugins/songs/lib/easislidesimport.py | 23 ++++++++----------- openlp/plugins/songs/lib/opensongimport.py | 2 +- openlp/plugins/songs/lib/songimport.py | 2 +- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index 445170ce5..ae4b289b1 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -180,6 +180,8 @@ class SongImportForm(OpenLPWizard): self.addMultiFileSelectItem(u'songsOfFellowship', None, True) # Generic Document/Presentation import self.addMultiFileSelectItem(u'generic', None, True) + # EasySlides + self.addSingleFileSelectItem(u'easiSlides') # EasyWorship self.addSingleFileSelectItem(u'ew') # Words of Worship @@ -229,10 +231,12 @@ class SongImportForm(OpenLPWizard): translate('SongsPlugin.ImportWizardForm', 'Generic Document/Presentation')) self.formatComboBox.setItemText(8, - translate('SongsPlugin.ImportWizardForm', 'EasyWorship')) + translate('SongsPlugin.ImportWizardForm', 'EasiSlides')) self.formatComboBox.setItemText(9, + translate('SongsPlugin.ImportWizardForm', 'EasyWorship')) + self.formatComboBox.setItemText(10, translate('SongsPlugin.ImportWizardForm', 'SongBeamer')) -# self.formatComboBox.setItemText(9, +# self.formatComboBox.setItemText(11, # translate('SongsPlugin.ImportWizardForm', 'CSV')) self.openLP2FilenameLabel.setText( translate('SongsPlugin.ImportWizardForm', 'Filename:')) @@ -284,6 +288,10 @@ class SongImportForm(OpenLPWizard): translate('SongsPlugin.ImportWizardForm', 'The generic document/' 'presentation importer has been disabled because OpenLP cannot ' 'find OpenOffice.org on your computer.')) + self.easiSlidesFilenameLabel.setText( + translate('SongsPlugin.ImportWizardForm', 'Filename:')) + self.easiSlidesBrowseButton.setText( + translate('SongsPlugin.ImportWizardForm', 'Browse...')) self.ewFilenameLabel.setText( translate('SongsPlugin.ImportWizardForm', 'Filename:')) self.ewBrowseButton.setText( @@ -314,6 +322,8 @@ class SongImportForm(OpenLPWizard): QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) self.openLP1FormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + self.easiSlidesFormLabelSpacer.changeSize(width, 0, + QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) self.ewFormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) # self.csvFormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, @@ -411,7 +421,7 @@ class SongImportForm(OpenLPWizard): if self.easiSlidesFilenameEdit.text().isEmpty(): QtGui.QMessageBox.critical(self, translate('SongsPlugin.ImportWizardForm', - 'No Easislides Song selected'), + 'No Easislides Songs file selected'), translate('SongsPlugin.ImportWizardForm', 'You need to select an xml song file exported from ' 'EasiSlides, to import from.')) diff --git a/openlp/plugins/songs/forms/songimportwizard.py b/openlp/plugins/songs/forms/songimportwizard.py index b6ff4584a..56346ead9 100644 --- a/openlp/plugins/songs/forms/songimportwizard.py +++ b/openlp/plugins/songs/forms/songimportwizard.py @@ -91,7 +91,7 @@ class Ui_SongImportWizard(object): self.addMultiFileSelectItem(u'songsOfFellowship', None, True) # Generic Document/Presentation import self.addMultiFileSelectItem(u'generic', None, True) - # EasyWorship + # EasySlides self.addSingleFileSelectItem(u'easiSlides') # EasyWorship self.addSingleFileSelectItem(u'ew') diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py index 608777fe2..6e610518f 100644 --- a/openlp/plugins/songs/lib/easislidesimport.py +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -63,7 +63,7 @@ class EasiSlidesImport(SongImport): """ success = True - self.import_wizard.importProgressBar.setMaximum(1) + self.import_wizard.progressBar.setMaximum(1) log.info(u'Direct import %s', self.filename) self.import_wizard.incrementProgressBar( @@ -72,7 +72,7 @@ class EasiSlidesImport(SongImport): file = open(self.filename) count = file.read().count('') file.seek(0) - self.import_wizard.importProgressBar.setMaximum(count) + self.import_wizard.progressBar.setMaximum(count) self.do_import_file(file) return success @@ -158,7 +158,7 @@ class EasiSlidesImport(SongImport): def parse_song(self, data): # We should also check if the title is already used, if yes, - # maybe user sould decide if we should import + # maybe user sould be asked if we should import or not # set title self.title = self.notCapsLockTitle(data['title1']) @@ -166,9 +166,6 @@ class EasiSlidesImport(SongImport): # set alternate title, if present if data['title2'] != None: self.alternate_title = self.notCapsLockTitle(data['title2']) - print self.alternate_title - print data['title2'] - print "HERE HERE HERE" # folder name, we have no use for it, usually only one folder is # used in easislides and this contains no actual data, easislides @@ -176,11 +173,11 @@ class EasiSlidesImport(SongImport): # example # data['folder'] - # set song number, if present, 0 otherwise - if data['songnumber'] != None: + # set song number, if present, empty otherwise + # EasiSlides tends to set all not changed song numbers to 0, + # so this hardly ever carries any information + if data['songnumber'] != None and data['songnumber'] != u'0': self.song_number = int(data['songnumber']) - else: - self.song_number = 0 # Don't know how to use Notations # data['notations'] @@ -222,10 +219,8 @@ class EasiSlidesImport(SongImport): # place a capo on guitar neck # set book data - #if data['bookreference']: - # for book in data['bookreference'].split(u','): - # self.books.append(book.strip()) - # THIS NEEDS ATTENTION, DON'T KNOW HOW TO MAKE THIS WORK โ†‘ + if data['bookreference']: + self.song_book_name = data['bookreference'].strip() # don't know what to do with user # data['userreference'], this is simple text entry, no diff --git a/openlp/plugins/songs/lib/opensongimport.py b/openlp/plugins/songs/lib/opensongimport.py index eb16f4ba4..6a60fcc6c 100644 --- a/openlp/plugins/songs/lib/opensongimport.py +++ b/openlp/plugins/songs/lib/opensongimport.py @@ -129,7 +129,7 @@ class OpenSongImport(SongImport): else: numfiles += 1 log.debug(u'Total number of files: %d', numfiles) - self.import_wizard.progressBar.setMaximum(numfiles) + self.import_wizard.importProgressBar.setMaximum(numfiles) for filename in self.filenames: if self.stop_import_flag: success = False diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index 5af871c00..4720ec1c5 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -265,7 +265,7 @@ class SongImport(QtCore.QObject): log.info(u'commiting song %s to database', self.title) song = Song() song.title = self.title - song.alternate_title = self.title + song.alternate_title = self.alternate_title song.search_title = self.remove_punctuation(self.title).lower() \ + '@' + self.remove_punctuation(self.alternate_title).lower() song.song_number = self.song_number From 88166c22a666042e7c89dafc2453d8af8963006e Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 17 Jan 2011 19:51:26 +0100 Subject: [PATCH 43/60] tweaked 'Reorder Service Item' dialog --- openlp/core/ui/serviceitemeditform.py | 135 +++++++++++++++----------- 1 file changed, 80 insertions(+), 55 deletions(-) diff --git a/openlp/core/ui/serviceitemeditform.py b/openlp/core/ui/serviceitemeditform.py index 6516fa40f..807b8dfb7 100644 --- a/openlp/core/ui/serviceitemeditform.py +++ b/openlp/core/ui/serviceitemeditform.py @@ -25,6 +25,7 @@ ############################################################################### from PyQt4 import QtCore, QtGui + from serviceitemeditdialog import Ui_ServiceItemEditDialog class ServiceItemEditForm(QtGui.QDialog, Ui_ServiceItemEditDialog): @@ -39,16 +40,18 @@ class ServiceItemEditForm(QtGui.QDialog, Ui_ServiceItemEditDialog): self.setupUi(self) self.itemList = [] # enable drop - QtCore.QObject.connect(self.upButton, QtCore.SIGNAL(u'clicked()'), - self.onItemUp) - QtCore.QObject.connect(self.downButton, QtCore.SIGNAL(u'clicked()'), - self.onItemDown) - QtCore.QObject.connect(self.deleteButton, QtCore.SIGNAL(u'clicked()'), - self.onItemDelete) - QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'accepted()'), - self.accept) - QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'rejected()'), - self.reject) + QtCore.QObject.connect(self.upButton, + QtCore.SIGNAL(u'clicked()'), self.onItemUp) + QtCore.QObject.connect(self.downButton, + QtCore.SIGNAL(u'clicked()'), self.onItemDown) + QtCore.QObject.connect(self.deleteButton, + QtCore.SIGNAL(u'clicked()'), self.onItemDelete) + QtCore.QObject.connect(self.buttonBox, + QtCore.SIGNAL(u'accepted()'), self.accept) + QtCore.QObject.connect(self.buttonBox, + QtCore.SIGNAL(u'rejected()'), self.reject) + QtCore.QObject.connect(self.listWidget, + QtCore.SIGNAL(u'currentRowChanged(int)'), self.onCurrentRowChanged) def setServiceItem(self, item): self.item = item @@ -58,6 +61,7 @@ class ServiceItemEditForm(QtGui.QDialog, Ui_ServiceItemEditDialog): for frame in self.item._raw_frames: self.itemList.append(frame) self.loadData() + self.listWidget.setCurrentItem(self.listWidget.currentItem()) def getServiceItem(self): if self.data: @@ -69,57 +73,78 @@ class ServiceItemEditForm(QtGui.QDialog, Ui_ServiceItemEditDialog): return self.item def loadData(self): + """ + Loads the image list. + """ self.listWidget.clear() for frame in self.itemList: item_name = QtGui.QListWidgetItem(frame[u'title']) self.listWidget.addItem(item_name) - if self.listWidget.count() == 1: + + def onItemDelete(self): + """ + Delete the current row. + """ + item = self.listWidget.currentItem() + if not item: + return + row = self.listWidget.row(item) + self.itemList.remove(self.itemList[row]) + self.loadData() + if row == self.listWidget.count(): + self.listWidget.setCurrentRow(row - 1) + else: + self.listWidget.setCurrentRow(row) + + def onItemUp(self): + """ + Move the current row up in the list. + """ + item = self.listWidget.currentItem() + if not item: + return + row = self.listWidget.row(item) + temp = self.itemList[row] + self.itemList.remove(self.itemList[row]) + self.itemList.insert(row - 1, temp) + self.loadData() + self.listWidget.setCurrentRow(row - 1) + + def onItemDown(self): + """ + Move the current row down in the list + """ + item = self.listWidget.currentItem() + if not item: + return + row = self.listWidget.row(item) + temp = self.itemList[row] + self.itemList.remove(self.itemList[row]) + self.itemList.insert(row + 1, temp) + self.loadData() + self.listWidget.setCurrentRow(row + 1) + + def onCurrentRowChanged(self, row): + """ + Called when the currentRow has changed. + + ``row`` + The row number (int). + """ + # Disable all buttons, as no row is selected or only one image is left. + if row == -1 or self.listWidget.count() == 1: self.downButton.setEnabled(False) self.upButton.setEnabled(False) self.deleteButton.setEnabled(False) else: - self.downButton.setEnabled(True) - self.upButton.setEnabled(True) - self.deleteButton.setEnabled(True) - - def onItemDelete(self): - """ - Delete the selected row - """ - items = self.listWidget.selectedItems() - for item in items: - row = self.listWidget.row(item) - self.itemList.remove(self.itemList[row]) - self.loadData() - if row == self.listWidget.count(): - self.listWidget.setCurrentRow(row - 1) + # Check if we are at the end of the list. + if self.listWidget.count() == row + 1: + self.downButton.setEnabled(False) else: - self.listWidget.setCurrentRow(row) - - def onItemUp(self): - """ - Move the selected row up in the list - """ - items = self.listWidget.selectedItems() - for item in items: - row = self.listWidget.row(item) - if row > 0: - temp = self.itemList[row] - self.itemList.remove(self.itemList[row]) - self.itemList.insert(row - 1, temp) - self.loadData() - self.listWidget.setCurrentRow(row - 1) - - def onItemDown(self): - """ - Move the selected row down in the list - """ - items = self.listWidget.selectedItems() - for item in items: - row = self.listWidget.row(item) - if row < len(self.itemList) and row is not -1: - temp = self.itemList[row] - self.itemList.remove(self.itemList[row]) - self.itemList.insert(row + 1, temp) - self.loadData() - self.listWidget.setCurrentRow(row + 1) \ No newline at end of file + self.downButton.setEnabled(True) + # Check if we are at the beginning of the list. + if row == 0: + self.upButton.setEnabled(False) + else: + self.upButton.setEnabled(True) + self.deleteButton.setEnabled(True) From 9e02f15995f8d37c755b454540626de0572e6741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Mon, 17 Jan 2011 21:09:35 +0200 Subject: [PATCH 44/60] more fixes, thanks to o123hallo and Meths --- openlp/plugins/songs/forms/songimportform.py | 2 +- .../plugins/songs/forms/songimportwizard.py | 372 ------------------ openlp/plugins/songs/lib/easislidesimport.py | 148 ++----- 3 files changed, 31 insertions(+), 491 deletions(-) delete mode 100644 openlp/plugins/songs/forms/songimportwizard.py diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index ae4b289b1..433c9abfc 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -419,7 +419,7 @@ class SongImportForm(OpenLPWizard): return False elif source_format == SongFormat.EasiSlides: if self.easiSlidesFilenameEdit.text().isEmpty(): - QtGui.QMessageBox.critical(self, + criticalErrorMessageBox( translate('SongsPlugin.ImportWizardForm', 'No Easislides Songs file selected'), translate('SongsPlugin.ImportWizardForm', diff --git a/openlp/plugins/songs/forms/songimportwizard.py b/openlp/plugins/songs/forms/songimportwizard.py deleted file mode 100644 index 56346ead9..000000000 --- a/openlp/plugins/songs/forms/songimportwizard.py +++ /dev/null @@ -1,372 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2011 Raoul Snyman # -# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael # -# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian # -# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, # -# Carsten Tinggaard, Frode Woldsund # -# --------------------------------------------------------------------------- # -# This program is free software; you can redistribute it and/or modify it # -# under the terms of the GNU General Public License as published by the Free # -# Software Foundation; version 2 of the License. # -# # -# This program is distributed in the hope that it will be useful, but WITHOUT # -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # -# more details. # -# # -# You should have received a copy of the GNU General Public License along # -# with this program; if not, write to the Free Software Foundation, Inc., 59 # -# Temple Place, Suite 330, Boston, MA 02111-1307 USA # -############################################################################### - -from PyQt4 import QtCore, QtGui - -from openlp.core.lib import build_icon, translate - -class Ui_SongImportWizard(object): - def setupUi(self, songImportWizard): - self.openIcon = build_icon(u':/general/general_open.png') - self.deleteIcon = build_icon(u':/general/general_delete.png') - songImportWizard.setObjectName(u'songImportWizard') - songImportWizard.setModal(True) - songImportWizard.setWizardStyle(QtGui.QWizard.ModernStyle) - songImportWizard.setOptions( - QtGui.QWizard.IndependentPages | - QtGui.QWizard.NoBackButtonOnStartPage | - QtGui.QWizard.NoBackButtonOnLastPage) - # Welcome Page - self.welcomePage = QtGui.QWizardPage() - self.welcomePage.setPixmap(QtGui.QWizard.WatermarkPixmap, - QtGui.QPixmap(u':/wizards/wizard_importsong.bmp')) - self.welcomePage.setObjectName(u'WelcomePage') - self.welcomeLayout = QtGui.QVBoxLayout(self.welcomePage) - self.welcomeLayout.setObjectName(u'WelcomeLayout') - self.titleLabel = QtGui.QLabel(self.welcomePage) - self.titleLabel.setObjectName(u'TitleLabel') - self.welcomeLayout.addWidget(self.titleLabel) - self.welcomeLayout.addSpacing(40) - self.informationLabel = QtGui.QLabel(self.welcomePage) - self.informationLabel.setWordWrap(True) - self.informationLabel.setObjectName(u'InformationLabel') - self.welcomeLayout.addWidget(self.informationLabel) - self.welcomeLayout.addStretch() - songImportWizard.addPage(self.welcomePage) - # Source Page - self.sourcePage = QtGui.QWizardPage() - self.sourcePage.setObjectName(u'SourcePage') - self.sourceLayout = QtGui.QVBoxLayout(self.sourcePage) - self.sourceLayout.setObjectName(u'SourceLayout') - self.formatLayout = QtGui.QFormLayout() - self.formatLayout.setObjectName(u'FormatLayout') - self.formatLabel = QtGui.QLabel(self.sourcePage) - self.formatLabel.setObjectName(u'FormatLabel') - self.formatComboBox = QtGui.QComboBox(self.sourcePage) - self.formatComboBox.setObjectName(u'FormatComboBox') - self.formatLayout.addRow(self.formatLabel, self.formatComboBox) - self.formatSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, - QtGui.QSizePolicy.Minimum) - self.formatLayout.setItem(1, QtGui.QFormLayout.LabelRole, - self.formatSpacer) - self.sourceLayout.addLayout(self.formatLayout) - self.formatStack = QtGui.QStackedLayout() - self.formatStack.setObjectName(u'FormatStack') - # OpenLP 2.0 - self.addSingleFileSelectItem(u'openLP2') - # openlp.org 1.x - self.addSingleFileSelectItem(u'openLP1', None, True) - # OpenLyrics - self.addMultiFileSelectItem(u'openLyrics', u'OpenLyrics', True) - # Open Song - self.addMultiFileSelectItem(u'openSong', u'OpenSong') - # Words of Worship - self.addMultiFileSelectItem(u'wordsOfWorship') - # CCLI File import - self.addMultiFileSelectItem(u'ccli') - # Songs of Fellowship - self.addMultiFileSelectItem(u'songsOfFellowship', None, True) - # Generic Document/Presentation import - self.addMultiFileSelectItem(u'generic', None, True) - # EasySlides - self.addSingleFileSelectItem(u'easiSlides') - # EasyWorship - self.addSingleFileSelectItem(u'ew') - # Words of Worship - self.addMultiFileSelectItem(u'songBeamer') -# Commented out for future use. -# self.addSingleFileSelectItem(u'csv', u'CSV') - self.sourceLayout.addLayout(self.formatStack) - songImportWizard.addPage(self.sourcePage) - # Import Page - self.importPage = QtGui.QWizardPage() - self.importPage.setObjectName(u'ImportPage') - self.importLayout = QtGui.QVBoxLayout(self.importPage) - self.importLayout.setMargin(48) - self.importLayout.setObjectName(u'ImportLayout') - self.importProgressLabel = QtGui.QLabel(self.importPage) - self.importProgressLabel.setObjectName(u'ImportProgressLabel') - self.importLayout.addWidget(self.importProgressLabel) - self.importProgressBar = QtGui.QProgressBar(self.importPage) - self.importProgressBar.setObjectName(u'ImportProgressBar') - self.importLayout.addWidget(self.importProgressBar) - songImportWizard.addPage(self.importPage) - self.retranslateUi(songImportWizard) - self.formatStack.setCurrentIndex(0) - QtCore.QObject.connect(self.formatComboBox, - QtCore.SIGNAL(u'currentIndexChanged(int)'), - self.formatStack.setCurrentIndex) - QtCore.QMetaObject.connectSlotsByName(songImportWizard) - - def retranslateUi(self, songImportWizard): - songImportWizard.setWindowTitle( - translate('SongsPlugin.ImportWizardForm', 'Song Import Wizard')) - self.titleLabel.setText( - u'%s' % \ - translate('SongsPlugin.ImportWizardForm', - 'Welcome to the Song Import Wizard')) - self.informationLabel.setText( - translate('SongsPlugin.ImportWizardForm', - 'This wizard will help you to import songs from a variety of ' - 'formats. Click the next button below to start the process by ' - 'selecting a format to import from.')) - self.sourcePage.setTitle( - translate('SongsPlugin.ImportWizardForm', 'Select Import Source')) - self.sourcePage.setSubTitle( - translate('SongsPlugin.ImportWizardForm', - 'Select the import format, and where to import from.')) - self.formatLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'Format:')) - self.formatComboBox.setItemText(0, - translate('SongsPlugin.ImportWizardForm', 'OpenLP 2.0')) - self.formatComboBox.setItemText(1, - translate('SongsPlugin.ImportWizardForm', 'openlp.org 1.x')) - self.formatComboBox.setItemText(2, - translate('SongsPlugin.ImportWizardForm', 'OpenLyrics')) - self.formatComboBox.setItemText(3, - translate('SongsPlugin.ImportWizardForm', 'OpenSong')) - self.formatComboBox.setItemText(4, - translate('SongsPlugin.ImportWizardForm', 'Words of Worship')) - self.formatComboBox.setItemText(5, - translate('SongsPlugin.ImportWizardForm', 'CCLI/SongSelect')) - self.formatComboBox.setItemText(6, - translate('SongsPlugin.ImportWizardForm', 'Songs of Fellowship')) - self.formatComboBox.setItemText(7, - translate('SongsPlugin.ImportWizardForm', - 'Generic Document/Presentation')) - self.formatComboBox.setItemText(8, - translate('SongsPlugin.ImportWizardForm', 'EasiSlides')) - self.formatComboBox.setItemText(9, - translate('SongsPlugin.ImportWizardForm', 'EasyWorship')) - self.formatComboBox.setItemText(10, - translate('SongsPlugin.ImportWizardForm', 'SongBeamer')) -# self.formatComboBox.setItemText(9, -# translate('SongsPlugin.ImportWizardForm', 'CSV')) - self.openLP2FilenameLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'Filename:')) - self.openLP2BrowseButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Browse...')) - self.openLP1FilenameLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'Filename:')) - self.openLP1BrowseButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Browse...')) - self.openLP1DisabledLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'The openlp.org 1.x ' - 'importer has been disabled due to a missing Python module. If ' - 'you want to use this importer, you will need to install the ' - '"python-sqlite" module.')) - self.openLyricsAddButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Add Files...')) - self.openLyricsRemoveButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) - self.openLyricsDisabledLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'The OpenLyrics ' - 'importer has not yet been developed, but as you can see, we are ' - 'still intending to do so. Hopefully it will be in the next ' - 'release.')) - self.openSongAddButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Add Files...')) - self.openSongRemoveButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) - self.wordsOfWorshipAddButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Add Files...')) - self.wordsOfWorshipRemoveButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) - self.ccliAddButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Add Files...')) - self.ccliRemoveButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) - self.songsOfFellowshipAddButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Add Files...')) - self.songsOfFellowshipRemoveButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) - self.songsOfFellowshipDisabledLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'The Songs of ' - 'Fellowship importer has been disabled because OpenLP cannot ' - 'find OpenOffice.org on your computer.')) - self.genericAddButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Add Files...')) - self.genericRemoveButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) - self.genericDisabledLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'The generic document/' - 'presentation importer has been disabled because OpenLP cannot ' - 'find OpenOffice.org on your computer.')) - self.easiSlidesFilenameLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'Filename:')) - self.easiSlidesBrowseButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Browse...')) - self.ewFilenameLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'Filename:')) - self.ewBrowseButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Browse...')) - self.songBeamerAddButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Add Files...')) - self.songBeamerRemoveButton.setText( - translate('SongsPlugin.ImportWizardForm', 'Remove File(s)')) -# self.csvFilenameLabel.setText( -# translate('SongsPlugin.ImportWizardForm', 'Filename:')) -# self.csvBrowseButton.setText( -# translate('SongsPlugin.ImportWizardForm', 'Browse...')) - self.importPage.setTitle( - translate('SongsPlugin.ImportWizardForm', 'Importing')) - self.importPage.setSubTitle( - translate('SongsPlugin.ImportWizardForm', - 'Please wait while your songs are imported.')) - self.importProgressLabel.setText( - translate('SongsPlugin.ImportWizardForm', 'Ready.')) - self.importProgressBar.setFormat( - translate('SongsPlugin.ImportWizardForm', '%p%')) - # Align all QFormLayouts towards each other. - width = max(self.formatLabel.minimumSizeHint().width(), - self.openLP2FilenameLabel.minimumSizeHint().width()) - self.formatSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, - QtGui.QSizePolicy.Fixed) - self.openLP2FormLabelSpacer.changeSize(width, 0, - QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) - self.openLP1FormLabelSpacer.changeSize(width, 0, - QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) - self.easiSlidesFormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, - QtGui.QSizePolicy.Fixed) - self.ewFormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, - QtGui.QSizePolicy.Fixed) -# self.csvFormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, -# QtGui.QSizePolicy.Fixed) - - def addSingleFileSelectItem(self, prefix, obj_prefix=None, - can_disable=False): - if not obj_prefix: - obj_prefix = prefix - page = QtGui.QWidget() - page.setObjectName(obj_prefix + u'Page') - if can_disable: - importWidget = self.disablableWidget(page, prefix, obj_prefix) - else: - importWidget = page - importLayout = QtGui.QFormLayout(importWidget) - importLayout.setMargin(0) - if can_disable: - importLayout.setObjectName(obj_prefix + u'ImportLayout') - else: - importLayout.setObjectName(obj_prefix + u'Layout') - filenameLabel = QtGui.QLabel(importWidget) - filenameLabel.setObjectName(obj_prefix + u'FilenameLabel') - fileLayout = QtGui.QHBoxLayout() - fileLayout.setObjectName(obj_prefix + u'FileLayout') - filenameEdit = QtGui.QLineEdit(importWidget) - filenameEdit.setObjectName(obj_prefix + u'FilenameEdit') - fileLayout.addWidget(filenameEdit) - browseButton = QtGui.QToolButton(importWidget) - browseButton.setIcon(self.openIcon) - browseButton.setObjectName(obj_prefix + u'BrowseButton') - fileLayout.addWidget(browseButton) - importLayout.addRow(filenameLabel, fileLayout) - formSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, - QtGui.QSizePolicy.Minimum) - importLayout.setItem(1, QtGui.QFormLayout.LabelRole, formSpacer) - self.formatStack.addWidget(page) - setattr(self, prefix + u'Page', page) - setattr(self, prefix + u'FilenameLabel', filenameLabel) - setattr(self, prefix + u'FormLabelSpacer', formSpacer) - setattr(self, prefix + u'FileLayout', fileLayout) - setattr(self, prefix + u'FilenameEdit', filenameEdit) - setattr(self, prefix + u'BrowseButton', browseButton) - if can_disable: - setattr(self, prefix + u'ImportLayout', importLayout) - else: - setattr(self, prefix + u'Layout', importLayout) - self.formatComboBox.addItem(u'') - - def addMultiFileSelectItem(self, prefix, obj_prefix=None, - can_disable=False): - if not obj_prefix: - obj_prefix = prefix - page = QtGui.QWidget() - page.setObjectName(obj_prefix + u'Page') - if can_disable: - importWidget = self.disablableWidget(page, prefix, obj_prefix) - else: - importWidget = page - importLayout = QtGui.QVBoxLayout(importWidget) - importLayout.setMargin(0) - if can_disable: - importLayout.setObjectName(obj_prefix + u'ImportLayout') - else: - importLayout.setObjectName(obj_prefix + u'Layout') - fileListWidget = QtGui.QListWidget(importWidget) - fileListWidget.setSelectionMode( - QtGui.QAbstractItemView.ExtendedSelection) - fileListWidget.setObjectName(obj_prefix + u'FileListWidget') - importLayout.addWidget(fileListWidget) - buttonLayout = QtGui.QHBoxLayout() - buttonLayout.setObjectName(obj_prefix + u'ButtonLayout') - addButton = QtGui.QPushButton(importWidget) - addButton.setIcon(self.openIcon) - addButton.setObjectName(obj_prefix + u'AddButton') - buttonLayout.addWidget(addButton) - buttonLayout.addStretch() - removeButton = QtGui.QPushButton(importWidget) - removeButton.setIcon(self.deleteIcon) - removeButton.setObjectName(obj_prefix + u'RemoveButton') - buttonLayout.addWidget(removeButton) - importLayout.addLayout(buttonLayout) - self.formatStack.addWidget(page) - setattr(self, prefix + u'Page', page) - setattr(self, prefix + u'FileListWidget', fileListWidget) - setattr(self, prefix + u'ButtonLayout', buttonLayout) - setattr(self, prefix + u'AddButton', addButton) - setattr(self, prefix + u'RemoveButton', removeButton) - if can_disable: - setattr(self, prefix + u'ImportLayout', importLayout) - else: - setattr(self, prefix + u'Layout', importLayout) - self.formatComboBox.addItem(u'') - - def disablableWidget(self, page, prefix, obj_prefix): - layout = QtGui.QVBoxLayout(page) - layout.setMargin(0) - layout.setSpacing(0) - layout.setObjectName(obj_prefix + u'Layout') - disabledWidget = QtGui.QWidget(page) - disabledWidget.setVisible(False) - disabledWidget.setObjectName(obj_prefix + u'DisabledWidget') - disabledLayout = QtGui.QVBoxLayout(disabledWidget) - disabledLayout.setMargin(0) - disabledLayout.setObjectName(obj_prefix + u'DisabledLayout') - disabledLabel = QtGui.QLabel(disabledWidget) - disabledLabel.setWordWrap(True) - disabledLabel.setObjectName(obj_prefix + u'DisabledLabel') - disabledLayout.addWidget(disabledLabel) - layout.addWidget(disabledWidget) - importWidget = QtGui.QWidget(page) - importWidget.setObjectName(obj_prefix + u'ImportWidget') - layout.addWidget(importWidget) - setattr(self, prefix + u'Layout', layout) - setattr(self, prefix + u'DisabledWidget', disabledWidget) - setattr(self, prefix + u'DisabledLayout', disabledLayout) - setattr(self, prefix + u'DisabledLabel', disabledLabel) - setattr(self, prefix + u'ImportWidget', importWidget) - return importWidget diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py index 6e610518f..11f4df1e2 100644 --- a/openlp/plugins/songs/lib/easislidesimport.py +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -35,9 +35,6 @@ from openlp.plugins.songs.lib.songimport import SongImport log = logging.getLogger(__name__) -class EasiSlidesImportError(Exception): - pass - class EasiSlidesImport(SongImport): """ Import songs exported from EasiSlides @@ -61,8 +58,6 @@ class EasiSlidesImport(SongImport): multiple opensong files. If `self.commit` is set False, the import will not be committed to the database (useful for test scripts). """ - success = True - self.import_wizard.progressBar.setMaximum(1) log.info(u'Direct import %s', self.filename) @@ -73,9 +68,7 @@ class EasiSlidesImport(SongImport): count = file.read().count('') file.seek(0) self.import_wizard.progressBar.setMaximum(count) - self.do_import_file(file) - - return success + return self.do_import_file(file) def do_import_file(self, file): """ @@ -83,6 +76,7 @@ class EasiSlidesImport(SongImport): not a filename """ self.set_defaults() + success = True # determines, if ENTIRELY UPPERCASE lines should be converted to lower self.toLower = False @@ -108,6 +102,8 @@ class EasiSlidesImport(SongImport): data[elem.tag.lower()] = text if elem.tag.lower() == u"item": + # just in case, it worked without set_defaults as well + self.set_defaults() self.parse_song(data) self.import_wizard.incrementProgressBar( unicode(translate('SongsPlugin.ImportWizardForm', @@ -116,6 +112,11 @@ class EasiSlidesImport(SongImport): if self.commit: self.finish() data = {} + # breakpoint here + if self.stop_import_flag: + success = False + break + return success def notCapsLock(self, string): if self.toLower and string.upper() == string: @@ -157,42 +158,23 @@ class EasiSlidesImport(SongImport): return line[7:right_bracket].strip() def parse_song(self, data): - # We should also check if the title is already used, if yes, - # maybe user sould be asked if we should import or not - - # set title self.title = self.notCapsLockTitle(data['title1']) - # set alternate title, if present if data['title2'] != None: self.alternate_title = self.notCapsLockTitle(data['title2']) - # folder name, we have no use for it, usually only one folder is - # used in easislides and this contains no actual data, easislides - # default database is named English, but usersmay not follow their - # example - # data['folder'] - - # set song number, if present, empty otherwise # EasiSlides tends to set all not changed song numbers to 0, # so this hardly ever carries any information if data['songnumber'] != None and data['songnumber'] != u'0': self.song_number = int(data['songnumber']) - # Don't know how to use Notations - # data['notations'] - - # set song authors - # we don't have to handle the no author case, it is done afterwards if data['writer'] != None: authors = data['writer'].split(u',') for author in authors: self.authors.append(author.strip()) - # set copyright data # licenceadmins may contain Public Domain or CCLI, as shown in examples - # let's just concatenate these fields, it should be determined, if song - # No is actually CCLI nr, if it is set + # let's just concatenate these fields copyright = [] if data['copyright']: copyright.append(data['copyright'].strip()) @@ -202,72 +184,26 @@ class EasiSlidesImport(SongImport): copyright.append(data['licenceadmin2'].strip()) self.add_copyright(u' '.join(copyright)) - # set topic data, I have seen no example, and probably should not do it, - # I even was not able to find place to set categories in easislides - # but then again, it would not hurt either + # I was not able to find place to set categories in easislides + # but then again, it does not hurt either if data['category']: for topic in data['category'].split(u','): self.topics.append(topic.strip()) - - # don't know what to do with timing data - # may be either 3/4 or 4/4 - # data['timing'] - # don't know what to do with music key - # data['musickey'], may be Db, C, G, F#, F#m - # data['capo'], is a number from 0 to 11, determing where to - # place a capo on guitar neck - - # set book data if data['bookreference']: self.song_book_name = data['bookreference'].strip() - # don't know what to do with user - # data['userreference'], this is simple text entry, no - # notable restrictions, no idea what this is used for - # U: I have seen one use of this as "searchable field" or similar, - # still no use for us - - # there is nothing to do with formatdata, this for sure is a messy - # thing, see an example: - # 21=1>23=0>22=2>25=2>26=-16777216> - # 27=-16777216>28=11>29=-1>30=-256>31=2>32=2> - # 41=16>42=16>43=Microsoft Sans Serif> - # 44=Microsoft Sans Serif>45=0>46=45>47=20>48=40> - # 50=0>51=>52=50>53=-1>54=0>55=1>61=>62=2> - # 63=1>64=2>65=2>66=0>71=0>72=Fade>73=Fade> - # - # data['formatdata'] - - # don't know what to do with settings data either, this is similar - # nonsense as formatdata: 10=2;5;0;0;1;0;ยป126;232;> - # data['settings'] - # LYRICS LYRICS LYRICS - # the big and messy part to handle lyrics lyrics = data['contents'] # we add title to first line, if supposed to do so - # we don't use self.title, because this may have changed case if self.titleIsLyrics: lyrics = u"%s\n%s" % (data['title1'], lyrics) - #if lyrics.find(u'[') != -1: - # # this must have at least one separator - # match = -1 - # while True: - # match = lyrics.find(u'[', match+1) - # if match == -1: - # break - # elif lyrics[match:match+7].lower() == u'[region': - # regions = regions+1 - # else: - # separators = separators+1 - lines = lyrics.split(u'\n') length = len(lines) - # we go over lines first, to determine some information, + # we go over all lines first, to determine some information, # which tells us how to parse verses later emptylines = 0 regionlines = {} @@ -298,34 +234,30 @@ class EasiSlidesImport(SongImport): uppercaselines = uppercaselines + 1 else: notuppercaselines = notuppercaselines + 1 - + # if the whole song is entirely UPPERCASE allUpperCase = (notuppercaselines == 0) # if the song has separators separators = (separatorlines > 0) - # the number of regions in song, conting the default as one - regions = len(regionlines)+1 - if regions > 2: + # the number of different regions in song - 1 + if len(regionlines) > 1: log.info(u'EasiSlidesImport: the file contained a song named "%s"' u'with more than two regions, but only two regions are', - u'tested, all regions were: %s', + u'tested, encountered regions were: %s', self.title, u','.join(regionlines.keys())) # if the song has regions - regions = (len(regionlines) > 1) - # if the regions are inside verses (more than one ) - regionsInVerses = (len(regionlines) and \ + regions = (len(regionlines) > 0) + # if the regions are inside verses + regionsInVerses = (regions and \ regionlines[regionlines.keys()[0]] > 1) - # data storage while importing verses = {} - # keep track of a "default" verse order, in case none is specified - # this list contains list as [region, versetype, versenum, instance] + # list as [region, versetype, versenum, instance] our_verse_order = [] - # default region defaultregion = u'1' reg = defaultregion verses[reg] = {} - # instance + # instance differentiates occurrences of same verse tag inst = 1 MarkTypes = { @@ -334,11 +266,9 @@ class EasiSlidesImport(SongImport): u'intro': u'I', u'ending': u'E', u'bridge': u'B', - u'prechorus': u'P', - } + u'prechorus': u'P'} for i in range(length): - # we iterate once more over lines thisline = lines[i] if i < length-1: nextline = lines[i+1].strip() @@ -346,7 +276,6 @@ class EasiSlidesImport(SongImport): # there is no nextline at the last line nextline = False - if len(thisline) == 0: if separators: # separators are used, so empty line means slide break @@ -364,8 +293,6 @@ class EasiSlidesImport(SongImport): # or whole song is uppercase, this must be verse vt = u'V' - # changing the region is not possible in this case - if verses[reg].has_key(vt): vn = len(verses[reg][vt].keys())+1 else: @@ -394,8 +321,7 @@ class EasiSlidesImport(SongImport): right_bracket = thisline.find(u']') marker = thisline[1:right_bracket].upper() # have we got any digits? - # If so, versenumber is everything from the digits - # to the end (even if there are some alpha chars on the end) + # If so, versenumber is everything from the digits to the end match = re.match(u'(.*)(\d+.*)', marker) if match is not None: vt = match.group(1).strip() @@ -442,13 +368,12 @@ class EasiSlidesImport(SongImport): if not verses[reg][vt][vn].has_key(inst): verses[reg][vt][vn][inst] = [] - # Tidy text and remove the ____s from extended words words = self.tidy_text(thisline) words = self.notCapsLock(words) verses[reg][vt][vn][inst].append(words) # done parsing - + versetags = [] # we use our_verse_order to ensure, we insert lyrics in the same order @@ -467,15 +392,6 @@ class EasiSlidesImport(SongImport): lines = u'\n'.join(verses[reg][vt][vn][inst]) self.verses.append([versetag, lines]) - # Sequence keys: - # numbers refer to verses - # p = prechorus - # q = prechorus 2 - # c = chorus - # t = chorus 2 - # b = bridge - # w = bridge 2 - # e = ending SeqTypes = { u'p': u'P1', u'q': u'P2', @@ -483,11 +399,8 @@ class EasiSlidesImport(SongImport): u't': u'C2', u'b': u'B1', u'w': u'B2', - u'e': u'E1' - } - # Make use of Sequence data, determining the order of verses, choruses - # if this is not present, we don't need it either, since the - # verses already are in the right order + u'e': u'E1'} + # Make use of Sequence data, determining the order of verses if data['sequence'] != None: order = data['sequence'].split(u',') for tag in order: @@ -497,11 +410,10 @@ class EasiSlidesImport(SongImport): elif SeqTypes.has_key(tag.lower()): tag = SeqTypes[tag.lower()] else: - # maybe we should continue here instead - tag = u'O1' + continue if not tag in versetags: - log.info(u'Got order %s but not in versetags, dropping this' - u'item from presentation order', tag) + log.info(u'Got order item %s, which is not in versetags,' + u'dropping item from presentation order', tag) else: self.verse_order_list.append(tag) From 84882c4841592f6655115b9cb66c0c9d29acf129 Mon Sep 17 00:00:00 2001 From: Garrett Date: Mon, 17 Jan 2011 11:24:37 -0800 Subject: [PATCH 45/60] removed non-necessary variable --- openlp/core/ui/maindisplay.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index acbd1ce62..93b4709f4 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -117,7 +117,6 @@ class MainDisplay(DisplayWidget): QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'maindisplay_show'), self.showDisplay) - self.advancedSettingsSection = u'advanced' def retranslateUi(self): """ Setup the interface translation strings. @@ -427,10 +426,9 @@ class MainDisplay(DisplayWidget): # if was hidden keep it hidden if self.hideMode and self.isLive: self.hideDisplay(self.hideMode) - # Hide the mouse cursor over display if enabled in settings + # Hide mouse cursor when moved over display if enabled in settings settings = QtCore.QSettings() - if settings.value(u'%s/hide mouse' % self.advancedSettingsSection, - QtCore.QVariant(False)).toBool(): + if settings.value(u'advanced/hide mouse', QtCore.QVariant(False)).toBool(): self.setCursor(QtCore.Qt.BlankCursor) self.frame.evaluateJavaScript('document.body.style.cursor = "none"') else: From f090c5409f10fb534a491486e13e1c687b29c112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Mon, 17 Jan 2011 22:47:46 +0200 Subject: [PATCH 46/60] smart features removed, using objectify now --- openlp/plugins/songs/lib/easislidesimport.py | 257 ++++++++----------- 1 file changed, 105 insertions(+), 152 deletions(-) diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py index 11f4df1e2..c66d35847 100644 --- a/openlp/plugins/songs/lib/easislidesimport.py +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -26,7 +26,7 @@ import logging import os -from lxml import etree +from lxml import etree, objectify from lxml.etree import Error, LxmlError import re @@ -60,156 +60,107 @@ class EasiSlidesImport(SongImport): """ self.import_wizard.progressBar.setMaximum(1) - log.info(u'Direct import %s', self.filename) + log.info(u'Importing XML file %s', self.filename) + parser = etree.XMLParser(remove_blank_text=True) + file = etree.parse(self.filename, parser) + xml = unicode(etree.tostring(file)) + song_xml = objectify.fromstring(xml) + self.import_wizard.incrementProgressBar( unicode(translate('SongsPlugin.ImportWizardForm', u'Importing %s...')) % os.path.split(self.filename)[-1]) - file = open(self.filename) - count = file.read().count('') - file.seek(0) - self.import_wizard.progressBar.setMaximum(count) - return self.do_import_file(file) - - def do_import_file(self, file): - """ - Process the EasiSlides file - pass in a file-like object, - not a filename - """ - self.set_defaults() - success = True + self.import_wizard.progressBar.setMaximum(len(song_xml.Item)) - # determines, if ENTIRELY UPPERCASE lines should be converted to lower - self.toLower = False - # list of names, which have always to be Uppercase, like Jesus - # only used, when self.toLower is True - self.backToUpper = [u'Jesus', u'God'] - # determines, if title should be prepended to lyrics - self.titleIsLyrics = False - - try: - context = etree.iterparse(file) - except (Error, LxmlError): - log.exception(u'Error parsing XML') - return - - data = {} - for action, elem in context: - if not elem.text: - text = None - else: - text = unicode(elem.text) - - data[elem.tag.lower()] = text - - if elem.tag.lower() == u"item": - # just in case, it worked without set_defaults as well - self.set_defaults() - self.parse_song(data) - self.import_wizard.incrementProgressBar( - unicode(translate('SongsPlugin.ImportWizardForm', - u'Importing %s, song %s...')) % - (os.path.split(self.filename)[-1], self.title)) - if self.commit: - self.finish() - data = {} - # breakpoint here - if self.stop_import_flag: - success = False - break - return success - - def notCapsLock(self, string): - if self.toLower and string.upper() == string: - ret = string.lower() - if len(self.backToUpper) > 0: - for repl in self.backToUpper: - if repl == u'': - continue - ret = ret.replace(repl.lower(), repl) - return ret - else: - return string - - def notCapsLockTitle(self, string): - if self.toLower and string.upper() == string: - ret = string.lower() - if len(self.backToUpper) > 0: - for repl in self.backToUpper: - if repl == u'': - continue - ret = ret.replace(repl.lower(), repl) - return u"%s%s" % (ret[0].upper(), ret[1:]) - else: - return string - - def listHas(self, lst, subitems): - for i in subitems: - if type(lst) == type({}) and lst.has_key(i): - lst = lst[i] - elif type(lst) == type([]) and i in lst: - lst = lst[i] - else: + for song in song_xml.Item: + self.import_wizard.incrementProgressBar( + unicode(translate('SongsPlugin.ImportWizardForm', + u'Importing %s, song %s...')) % + (os.path.split(self.filename)[-1], song.Title1)) + success = self._parse_song(song) + if not success or self.stop_import_flag: return False + if self.commit: + self.finish() return True - def extractRegion(self, line): - # this was true already: thisline[0:7] == u'[region': - right_bracket = line.find(u']') - return line[7:right_bracket].strip() + def _parse_song(self, song): + self._success = True + self._add_title(song) + self._add_alttitle(song) + self._add_number(song) + self._add_authors(song) + self._add_copyright(song) + self._add_book(song) + self._parse_and_add_lyrics(song) + return self._success - def parse_song(self, data): - self.title = self.notCapsLockTitle(data['title1']) + def _add_title(self, song): + try: + self.title = unicode(song.Title1).strip() + except: + log.info(u'no Title1') + self._success = False - if data['title2'] != None: - self.alternate_title = self.notCapsLockTitle(data['title2']) - - # EasiSlides tends to set all not changed song numbers to 0, - # so this hardly ever carries any information - if data['songnumber'] != None and data['songnumber'] != u'0': - self.song_number = int(data['songnumber']) - - if data['writer'] != None: - authors = data['writer'].split(u',') + def _add_alttitle(self, song): + try: + self.alternate_title = unicode(self.song.Title2).strip() + except: + pass + + def _add_number(self, song): + try: + number = int(song.SongNumber) + if number != 0: + self.song_number = number + print number + except: + pass + + def _add_authors(self, song): + try: + authors = unicode(song.Writer).strip().split(u',') for author in authors: self.authors.append(author.strip()) - - # licenceadmins may contain Public Domain or CCLI, as shown in examples - # let's just concatenate these fields + except: + pass + + def _add_copyright(self, song): copyright = [] - if data['copyright']: - copyright.append(data['copyright'].strip()) - if data['licenceadmin1']: - copyright.append(data['licenceadmin1'].strip()) - if data['licenceadmin2']: - copyright.append(data['licenceadmin2'].strip()) + try: + copyright.append(unicode(song.Copyright).strip()) + except: + pass + try: + copyright.append(unicode(song.LicenceAdmin1).strip()) + except: + pass + try: + copyright.append(unicode(song.LicenceAdmin2).strip()) + except: + pass self.add_copyright(u' '.join(copyright)) - - # I was not able to find place to set categories in easislides - # but then again, it does not hurt either - if data['category']: - for topic in data['category'].split(u','): - self.topics.append(topic.strip()) - if data['bookreference']: - self.song_book_name = data['bookreference'].strip() + def _add_book(self, song): + try: + self.song_book_name = unicode(song.BookReference).strip() + except: + pass - # LYRICS LYRICS LYRICS - lyrics = data['contents'] - - # we add title to first line, if supposed to do so - if self.titleIsLyrics: - lyrics = u"%s\n%s" % (data['title1'], lyrics) - + def _parse_and_add_lyrics(self, song): + try: + lyrics = unicode(song.Contents).strip() + except: + log.info(u'no Contents') + self._success = False + lines = lyrics.split(u'\n') length = len(lines) - # we go over all lines first, to determine some information, + # we go over all lines first, to determine information, # which tells us how to parse verses later emptylines = 0 regionlines = {} separatorlines = 0 - uppercaselines = 0 - notuppercaselines = 0 for i in range(length): lines[i] = lines[i].strip() thisline = lines[i] @@ -223,20 +174,14 @@ class EasiSlidesImport(SongImport): # to have [region 3] or more, we add a possiblity to # count these separately, yeah, rather stupid, but # count this as a programming exercise - region = self.extractRegion(thisline) + region = self._extractRegion(thisline) if regionlines.has_key(region): regionlines[region] = regionlines[region] + 1 else: regionlines[region] = 1 else: separatorlines = separatorlines + 1 - elif thisline == thisline.upper(): - uppercaselines = uppercaselines + 1 - else: - notuppercaselines = notuppercaselines + 1 - # if the whole song is entirely UPPERCASE - allUpperCase = (notuppercaselines == 0) # if the song has separators separators = (separatorlines > 0) # the number of different regions in song - 1 @@ -280,18 +225,11 @@ class EasiSlidesImport(SongImport): if separators: # separators are used, so empty line means slide break # inside verse - if self.listHas(verses, [reg, vt, vn, inst]): + if self._listHas(verses, [reg, vt, vn, inst]): inst = inst + 1 else: # separators are not used, so empty line starts a new verse - if not allUpperCase and nextline and \ - nextline is nextline.upper(): - # the next line is all uppercase, it must be chorus - vt = u'C' - else: - # if the next line is not uppercase, - # or whole song is uppercase, this must be verse - vt = u'V' + vt = u'V' if verses[reg].has_key(vt): vn = len(verses[reg][vt].keys())+1 @@ -305,7 +243,7 @@ class EasiSlidesImport(SongImport): continue elif thisline[0:7] == u'[region': - reg = self.extractRegion(thisline) + reg = self._extractRegion(thisline) if not verses.has_key(reg): verses[reg] = {} if i == 0: @@ -345,7 +283,7 @@ class EasiSlidesImport(SongImport): region = defaultregion inst = 1 - if self.listHas(verses, [reg, vt, vn, inst]): + if self._listHas(verses, [reg, vt, vn, inst]): inst = len(verses[reg][vt][vn])+1 if not [reg, vt, vn, inst] in our_verse_order: @@ -369,8 +307,6 @@ class EasiSlidesImport(SongImport): verses[reg][vt][vn][inst] = [] words = self.tidy_text(thisline) - words = self.notCapsLock(words) - verses[reg][vt][vn][inst].append(words) # done parsing @@ -385,7 +321,7 @@ class EasiSlidesImport(SongImport): vn = tag[2] inst = tag[3] - if not self.listHas(verses, [reg, vt, vn, inst]): + if not self._listHas(verses, [reg, vt, vn, inst]): continue versetag = u'%s%s' % (vt, vn) versetags.append(versetag) @@ -401,8 +337,8 @@ class EasiSlidesImport(SongImport): u'w': u'B2', u'e': u'E1'} # Make use of Sequence data, determining the order of verses - if data['sequence'] != None: - order = data['sequence'].split(u',') + try: + order = unicode(song.Sequence).strip().split(u',') for tag in order: if tag[0].isdigit(): # it's a verse if it has no prefix, but has a number @@ -417,3 +353,20 @@ class EasiSlidesImport(SongImport): u'dropping item from presentation order', tag) else: self.verse_order_list.append(tag) + except: + pass + + def _listHas(self, lst, subitems): + for i in subitems: + if type(lst) == type({}) and lst.has_key(i): + lst = lst[i] + elif type(lst) == type([]) and i in lst: + lst = lst[i] + else: + return False + return True + + def _extractRegion(self, line): + # this was true already: thisline[0:7] == u'[region': + right_bracket = line.find(u']') + return line[7:right_bracket].strip() From 0ccb0f4fddd7c0f2cda02d3a8fa957a4b97db093 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Mon, 17 Jan 2011 21:52:27 +0000 Subject: [PATCH 47/60] Few small cleanups --- openlp/plugins/songs/lib/__init__.py | 2 +- openlp/plugins/songs/lib/mediaitem.py | 3 +-- openlp/plugins/songs/lib/songbeamerimport.py | 2 +- openlp/plugins/songs/lib/wowimport.py | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index 462dac89a..4124cc252 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -163,7 +163,7 @@ def retrieve_windows_encoding(recommendation=None): translate('SongsPlugin', 'Character Encoding'), translate('SongsPlugin', 'The codepage setting is responsible\n' 'for the correct character representation.\n' - 'Usually you are fine with the preselected choise.'), + 'Usually you are fine with the preselected choice.'), [pair[1] for pair in encodings], recommended_index, False) else: choice = QtGui.QInputDialog.getItem(None, diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 93e40f58a..67021616b 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -194,8 +194,7 @@ class SongMediaItem(MediaManagerItem): elif search_type == 5: log.debug(u'Theme Search') search_results = self.parent.manager.get_all_objects(Song, - Song.theme_name == search_keywords, - Song.search_lyrics.asc()) + Song.theme_name == search_keywords, Song.search_lyrics.asc()) self.displayResultsSong(search_results) def onSongListLoad(self): diff --git a/openlp/plugins/songs/lib/songbeamerimport.py b/openlp/plugins/songs/lib/songbeamerimport.py index c783793db..a4d53ec08 100644 --- a/openlp/plugins/songs/lib/songbeamerimport.py +++ b/openlp/plugins/songs/lib/songbeamerimport.py @@ -83,7 +83,7 @@ class SongBeamerImport(SongImport): def do_import(self): """ - Recieve a single file, or a list of files to import. + Receive a single file or a list of files to import. """ if isinstance(self.import_source, list): self.import_wizard.progressBar.setMaximum( diff --git a/openlp/plugins/songs/lib/wowimport.py b/openlp/plugins/songs/lib/wowimport.py index d0c308413..a8acb6266 100644 --- a/openlp/plugins/songs/lib/wowimport.py +++ b/openlp/plugins/songs/lib/wowimport.py @@ -107,7 +107,7 @@ class WowImport(SongImport): def do_import(self): """ - Recieve a single file, or a list of files to import. + Receive a single file or a list of files to import. """ if isinstance(self.import_source, list): From 0c38bccd45a40143e10343bc13daa5db7bd6c5c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Tue, 18 Jan 2011 00:27:25 +0200 Subject: [PATCH 48/60] more exceptions and a few other changes --- openlp/plugins/songs/lib/easislidesimport.py | 159 +++++++++---------- openlp/plugins/songs/lib/opensongimport.py | 2 +- 2 files changed, 77 insertions(+), 84 deletions(-) diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py index c66d35847..7974a8842 100644 --- a/openlp/plugins/songs/lib/easislidesimport.py +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -79,7 +79,7 @@ class EasiSlidesImport(SongImport): success = self._parse_song(song) if not success or self.stop_import_flag: return False - if self.commit: + elif self.commit: self.finish() return True @@ -97,14 +97,18 @@ class EasiSlidesImport(SongImport): def _add_title(self, song): try: self.title = unicode(song.Title1).strip() - except: - log.info(u'no Title1') + except UnicodeDecodeError: + log.exception(u'Title1 unicode decode error') + except AttributeError: + log.exception(u'no Title1') self._success = False def _add_alttitle(self, song): try: - self.alternate_title = unicode(self.song.Title2).strip() - except: + self.alternate_title = unicode(song.Title2).strip() + except UnicodeDecodeError: + log.exception(u'Title2 unicode decode error') + except AttributeError: pass def _add_number(self, song): @@ -112,75 +116,81 @@ class EasiSlidesImport(SongImport): number = int(song.SongNumber) if number != 0: self.song_number = number - print number - except: + except UnicodeDecodeError: + log.exception(u'SongNumber unicode decode error') + except AttributeError: pass def _add_authors(self, song): try: - authors = unicode(song.Writer).strip().split(u',') + authors = unicode(song.Writer).split(u',') for author in authors: - self.authors.append(author.strip()) - except: + author = author.strip() + if len(author) > 0: + self.authors.append(author) + except UnicodeDecodeError: + log.exception(u'Writer unicode decode error') + except AttributeError: pass def _add_copyright(self, song): copyright = [] try: copyright.append(unicode(song.Copyright).strip()) - except: + except UnicodeDecodeError: + log.exception(u'Copyright unicode decode error') + except AttributeError: pass try: copyright.append(unicode(song.LicenceAdmin1).strip()) - except: + except UnicodeDecodeError: + log.exception(u'LicenceAdmin1 unicode decode error') + except AttributeError: pass try: copyright.append(unicode(song.LicenceAdmin2).strip()) - except: + except UnicodeDecodeError: + log.exception(u'LicenceAdmin2 unicode decode error') + except AttributeError: pass self.add_copyright(u' '.join(copyright)) def _add_book(self, song): try: self.song_book_name = unicode(song.BookReference).strip() - except: + except UnicodeDecodeError: + log.exception(u'BookReference unicode decode error') + except AttributeError: pass def _parse_and_add_lyrics(self, song): try: lyrics = unicode(song.Contents).strip() - except: - log.info(u'no Contents') + except UnicodeDecodeError: + log.exception(u'Contents unicode decode error') + except AttributeError: + log.exception(u'no Contents') self._success = False lines = lyrics.split(u'\n') - length = len(lines) # we go over all lines first, to determine information, # which tells us how to parse verses later - emptylines = 0 regionlines = {} separatorlines = 0 - for i in range(length): - lines[i] = lines[i].strip() - thisline = lines[i] - if len(thisline) == 0: - emptylines = emptylines + 1 - elif thisline[0] == u'[': - if thisline[1:7] == u'region': - # this is region separator [region 2] - # Easislides song can have only one extra region zone, - # at least by now, but just in case the file happens - # to have [region 3] or more, we add a possiblity to - # count these separately, yeah, rather stupid, but - # count this as a programming exercise - region = self._extractRegion(thisline) - if regionlines.has_key(region): - regionlines[region] = regionlines[region] + 1 - else: - regionlines[region] = 1 + for line in lines: + line = line.strip() + if len(line) == 0: + continue + elif line[1:7] == u'region': + # this is region separator, probably [region 2] + region = self._extractRegion(line) + if regionlines.has_key(region): + regionlines[region] = regionlines[region] + 1 else: - separatorlines = separatorlines + 1 + regionlines[region] = 1 + elif line[0] == u'[': + separatorlines = separatorlines + 1 # if the song has separators separators = (separatorlines > 0) @@ -196,6 +206,14 @@ class EasiSlidesImport(SongImport): regionsInVerses = (regions and \ regionlines[regionlines.keys()[0]] > 1) + MarkTypes = { + u'chorus': u'C', + u'verse': u'V', + u'intro': u'I', + u'ending': u'E', + u'bridge': u'B', + u'prechorus': u'P'} + verses = {} # list as [region, versetype, versenum, instance] our_verse_order = [] @@ -204,24 +222,13 @@ class EasiSlidesImport(SongImport): verses[reg] = {} # instance differentiates occurrences of same verse tag inst = 1 - - MarkTypes = { - u'chorus': u'C', - u'verse': u'V', - u'intro': u'I', - u'ending': u'E', - u'bridge': u'B', - u'prechorus': u'P'} + vt = u'V' + vn = u'1' - for i in range(length): - thisline = lines[i] - if i < length-1: - nextline = lines[i+1].strip() - else: - # there is no nextline at the last line - nextline = False + for line in lines: + line = line.strip() - if len(thisline) == 0: + if len(line) == 0: if separators: # separators are used, so empty line means slide break # inside verse @@ -237,43 +244,32 @@ class EasiSlidesImport(SongImport): vn = u'1' inst = 1 - if not [reg, vt, vn, inst] in our_verse_order: - our_verse_order.append([reg, vt, vn, inst]) continue continue - elif thisline[0:7] == u'[region': - reg = self._extractRegion(thisline) + elif line[0:7] == u'[region': + reg = self._extractRegion(line) if not verses.has_key(reg): verses[reg] = {} - if i == 0: - # the file started with [region 2] - vt = u'V' - vn = u'1' - our_verse_order.append([reg, vt, vn, inst]) continue - elif thisline[0] == u'[': + elif line[0] == u'[': # this is a normal section marker # drop the square brackets - right_bracket = thisline.find(u']') - marker = thisline[1:right_bracket].upper() + right_bracket = line.find(u']') + marker = line[1:right_bracket].upper() # have we got any digits? # If so, versenumber is everything from the digits to the end match = re.match(u'(.*)(\d+.*)', marker) if match is not None: vt = match.group(1).strip() vn = match.group(2) - if vt == u'': - vt = u'V' - elif MarkTypes.has_key(vt.lower()): + if MarkTypes.has_key(vt.lower()): vt = MarkTypes[vt.lower()] else: vt = u'O' else: - if marker == u'': - vt = u'V' - elif MarkTypes.has_key(marker.lower()): + if MarkTypes.has_key(marker.lower()): vt = MarkTypes[marker.lower()] else: vt = u'O' @@ -285,16 +281,9 @@ class EasiSlidesImport(SongImport): inst = 1 if self._listHas(verses, [reg, vt, vn, inst]): inst = len(verses[reg][vt][vn])+1 - - if not [reg, vt, vn, inst] in our_verse_order: - our_verse_order.append([reg, vt, vn, inst]) continue - if i == 0: - # this is the first line, but no separator is found, - # we say it's V1 - vt = u'V' - vn = u'1' + if not [reg, vt, vn, inst] in our_verse_order: our_verse_order.append([reg, vt, vn, inst]) # We have versetype/number data, if it was there, now @@ -306,7 +295,7 @@ class EasiSlidesImport(SongImport): if not verses[reg][vt][vn].has_key(inst): verses[reg][vt][vn][inst] = [] - words = self.tidy_text(thisline) + words = self.tidy_text(line) verses[reg][vt][vn][inst].append(words) # done parsing @@ -340,7 +329,9 @@ class EasiSlidesImport(SongImport): try: order = unicode(song.Sequence).strip().split(u',') for tag in order: - if tag[0].isdigit(): + if len(tag) == 0: + continue + elif tag[0].isdigit(): # it's a verse if it has no prefix, but has a number tag = u'V' + tag elif SeqTypes.has_key(tag.lower()): @@ -353,7 +344,9 @@ class EasiSlidesImport(SongImport): u'dropping item from presentation order', tag) else: self.verse_order_list.append(tag) - except: + except UnicodeDecodeError: + log.exception(u'Sequence unicode decode error') + except AttributeError: pass def _listHas(self, lst, subitems): @@ -367,6 +360,6 @@ class EasiSlidesImport(SongImport): return True def _extractRegion(self, line): - # this was true already: thisline[0:7] == u'[region': + # this was true already: line[0:7] == u'[region': right_bracket = line.find(u']') return line[7:right_bracket].strip() diff --git a/openlp/plugins/songs/lib/opensongimport.py b/openlp/plugins/songs/lib/opensongimport.py index 6a60fcc6c..eb16f4ba4 100644 --- a/openlp/plugins/songs/lib/opensongimport.py +++ b/openlp/plugins/songs/lib/opensongimport.py @@ -129,7 +129,7 @@ class OpenSongImport(SongImport): else: numfiles += 1 log.debug(u'Total number of files: %d', numfiles) - self.import_wizard.importProgressBar.setMaximum(numfiles) + self.import_wizard.progressBar.setMaximum(numfiles) for filename in self.filenames: if self.stop_import_flag: success = False From 1c1e66bba87ed80f772bfbd73a37e033735c5909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Tue, 18 Jan 2011 01:16:30 +0200 Subject: [PATCH 49/60] refurbished, added self._success = False to exceptions --- openlp/plugins/songs/lib/easislidesimport.py | 106 +++++++++---------- 1 file changed, 49 insertions(+), 57 deletions(-) diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py index 7974a8842..26bb105af 100644 --- a/openlp/plugins/songs/lib/easislidesimport.py +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -98,7 +98,8 @@ class EasiSlidesImport(SongImport): try: self.title = unicode(song.Title1).strip() except UnicodeDecodeError: - log.exception(u'Title1 unicode decode error') + log.exception(u'Unicode decode error while decoding Title1') + self._success = False except AttributeError: log.exception(u'no Title1') self._success = False @@ -107,7 +108,8 @@ class EasiSlidesImport(SongImport): try: self.alternate_title = unicode(song.Title2).strip() except UnicodeDecodeError: - log.exception(u'Title2 unicode decode error') + log.exception(u'Unicode decode error while decoding Title2') + self._success = False except AttributeError: pass @@ -117,7 +119,8 @@ class EasiSlidesImport(SongImport): if number != 0: self.song_number = number except UnicodeDecodeError: - log.exception(u'SongNumber unicode decode error') + log.exception(u'Unicode decode error while decoding SongNumber') + self._success = False except AttributeError: pass @@ -129,7 +132,8 @@ class EasiSlidesImport(SongImport): if len(author) > 0: self.authors.append(author) except UnicodeDecodeError: - log.exception(u'Writer unicode decode error') + log.exception(u'Unicode decode error while decoding Writer') + self._success = False except AttributeError: pass @@ -138,19 +142,22 @@ class EasiSlidesImport(SongImport): try: copyright.append(unicode(song.Copyright).strip()) except UnicodeDecodeError: - log.exception(u'Copyright unicode decode error') + log.exception(u'Unicode decode error while decoding Copyright') + self._success = False except AttributeError: pass try: copyright.append(unicode(song.LicenceAdmin1).strip()) except UnicodeDecodeError: - log.exception(u'LicenceAdmin1 unicode decode error') + log.exception(u'Unicode decode error while decoding LicenceAdmin1') + self._success = False except AttributeError: pass try: copyright.append(unicode(song.LicenceAdmin2).strip()) except UnicodeDecodeError: - log.exception(u'LicenceAdmin2 unicode decode error') + log.exception(u'Unicode decode error while decoding LicenceAdmin2') + self._success = False except AttributeError: pass self.add_copyright(u' '.join(copyright)) @@ -159,7 +166,8 @@ class EasiSlidesImport(SongImport): try: self.song_book_name = unicode(song.BookReference).strip() except UnicodeDecodeError: - log.exception(u'BookReference unicode decode error') + log.exception(u'Unicode decode error while decoding BookReference') + self._success = False except AttributeError: pass @@ -167,7 +175,8 @@ class EasiSlidesImport(SongImport): try: lyrics = unicode(song.Contents).strip() except UnicodeDecodeError: - log.exception(u'Contents unicode decode error') + log.exception(u'Unicode decode error while decoding Contents') + self._success = False except AttributeError: log.exception(u'no Contents') self._success = False @@ -207,12 +216,12 @@ class EasiSlidesImport(SongImport): regionlines[regionlines.keys()[0]] > 1) MarkTypes = { - u'chorus': u'C', - u'verse': u'V', - u'intro': u'I', - u'ending': u'E', - u'bridge': u'B', - u'prechorus': u'P'} + u'CHORUS': u'C', + u'VERSE': u'V', + u'INTRO': u'I', + u'ENDING': u'E', + u'BRIDGE': u'B', + u'PRECHORUS': u'P'} verses = {} # list as [region, versetype, versenum, instance] @@ -221,9 +230,9 @@ class EasiSlidesImport(SongImport): reg = defaultregion verses[reg] = {} # instance differentiates occurrences of same verse tag - inst = 1 vt = u'V' vn = u'1' + inst = 1 for line in lines: line = line.strip() @@ -237,47 +246,39 @@ class EasiSlidesImport(SongImport): else: # separators are not used, so empty line starts a new verse vt = u'V' - if verses[reg].has_key(vt): vn = len(verses[reg][vt].keys())+1 else: vn = u'1' - inst = 1 - continue continue - elif line[0:7] == u'[region': reg = self._extractRegion(line) if not verses.has_key(reg): verses[reg] = {} + if not regionsInVerses: + vt = u'V' + vn = u'1' + inst = 1 continue - elif line[0] == u'[': # this is a normal section marker - # drop the square brackets - right_bracket = line.find(u']') - marker = line[1:right_bracket].upper() + marker = line[1:line.find(u']')].upper() + vn = u'1' # have we got any digits? # If so, versenumber is everything from the digits to the end match = re.match(u'(.*)(\d+.*)', marker) - if match is not None: - vt = match.group(1).strip() + if match: + marker = match.group(1).strip() vn = match.group(2) - if MarkTypes.has_key(vt.lower()): - vt = MarkTypes[vt.lower()] - else: - vt = u'O' + if len(marker) == 0: + vt = u'V' + elif MarkTypes.has_key(marker): + vt = MarkTypes[marker] else: - if MarkTypes.has_key(marker.lower()): - vt = MarkTypes[marker.lower()] - else: - vt = u'O' - vn = u'1' - + vt = u'O' if regionsInVerses: region = defaultregion - inst = 1 if self._listHas(verses, [reg, vt, vn, inst]): inst = len(verses[reg][vt][vn])+1 @@ -286,8 +287,6 @@ class EasiSlidesImport(SongImport): if not [reg, vt, vn, inst] in our_verse_order: our_verse_order.append([reg, vt, vn, inst]) - # We have versetype/number data, if it was there, now - # we parse text if not verses[reg].has_key(vt): verses[reg][vt] = {} if not verses[reg][vt].has_key(vn): @@ -303,19 +302,12 @@ class EasiSlidesImport(SongImport): # we use our_verse_order to ensure, we insert lyrics in the same order # as these appeared originally in the file - - for tag in our_verse_order: - reg = tag[0] - vt = tag[1] - vn = tag[2] - inst = tag[3] - - if not self._listHas(verses, [reg, vt, vn, inst]): - continue - versetag = u'%s%s' % (vt, vn) - versetags.append(versetag) - lines = u'\n'.join(verses[reg][vt][vn][inst]) - self.verses.append([versetag, lines]) + for [reg, vt, vn, inst] in our_verse_order: + if self._listHas(verses, [reg, vt, vn, inst]): + versetag = u'%s%s' % (vt, vn) + versetags.append(versetag) + lines = u'\n'.join(verses[reg][vt][vn][inst]) + self.verses.append([versetag, lines]) SeqTypes = { u'p': u'P1', @@ -332,20 +324,20 @@ class EasiSlidesImport(SongImport): if len(tag) == 0: continue elif tag[0].isdigit(): - # it's a verse if it has no prefix, but has a number tag = u'V' + tag elif SeqTypes.has_key(tag.lower()): tag = SeqTypes[tag.lower()] else: continue - if not tag in versetags: + if tag in versetags: + self.verse_order_list.append(tag) + else: log.info(u'Got order item %s, which is not in versetags,' u'dropping item from presentation order', tag) - else: - self.verse_order_list.append(tag) except UnicodeDecodeError: - log.exception(u'Sequence unicode decode error') + log.exception(u'Unicode decode error while decoding Sequence') + self._success = False except AttributeError: pass From c12ada7da2ad35bd07df440cdab479ece08bb8ad Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Tue, 18 Jan 2011 04:32:24 +0000 Subject: [PATCH 50/60] Refactors and cleanups --- openlp/core/lib/spelltextedit.py | 8 +- openlp/core/utils/__init__.py | 140 ++++++++++--------- openlp/plugins/songs/lib/__init__.py | 42 ++---- openlp/plugins/songs/lib/importer.py | 30 ++-- openlp/plugins/songs/lib/songbeamerimport.py | 12 +- openlp/plugins/songs/lib/songimport.py | 9 +- openlp/plugins/songs/lib/wowimport.py | 75 +++++----- openlp/plugins/songs/lib/xml.py | 2 +- 8 files changed, 148 insertions(+), 170 deletions(-) diff --git a/openlp/core/lib/spelltextedit.py b/openlp/core/lib/spelltextedit.py index 30811e08b..82391a0b3 100644 --- a/openlp/core/lib/spelltextedit.py +++ b/openlp/core/lib/spelltextedit.py @@ -28,9 +28,9 @@ import re try: import enchant from enchant import DictNotFoundError - enchant_available = True + ENCHANT_AVAILABLE = True except ImportError: - enchant_available = False + ENCHANT_AVAILABLE = False # based on code from # http://john.nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check @@ -45,7 +45,7 @@ class SpellTextEdit(QtGui.QPlainTextEdit): def __init__(self, *args): QtGui.QPlainTextEdit.__init__(self, *args) # Default dictionary based on the current locale. - if enchant_available: + if ENCHANT_AVAILABLE: try: self.dict = enchant.Dict() except DictNotFoundError: @@ -72,7 +72,7 @@ class SpellTextEdit(QtGui.QPlainTextEdit): self.setTextCursor(cursor) # Check if the selected word is misspelled and offer spelling # suggestions if it is. - if enchant_available and self.textCursor().hasSelection(): + if ENCHANT_AVAILABLE and self.textCursor().hasSelection(): text = unicode(self.textCursor().selectedText()) if not self.dict.check(text): spell_menu = QtGui.QMenu(translate('OpenLP.SpellTextEdit', diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index b7d95a46d..9117a8e19 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -26,7 +26,6 @@ """ The :mod:`utils` module provides the utility libraries for OpenLP """ - import logging import os import re @@ -36,12 +35,18 @@ import urllib2 from datetime import datetime from PyQt4 import QtGui, QtCore +if sys.platform != u'win32' and sys.platform != u'darwin': + try: + from xdg import BaseDirectory + XDG_BASE_AVAILABLE = True + except ImportError: + XDG_BASE_AVAILABLE = False import openlp from openlp.core.lib import Receiver, translate log = logging.getLogger(__name__) -images_filter = None +IMAGES_FILTER = None class VersionThread(QtCore.QThread): """ @@ -113,77 +118,46 @@ class AppLocation(object): The directory type you want, for instance the data directory. """ if dir_type == AppLocation.AppDir: - if hasattr(sys, u'frozen') and sys.frozen == 1: - app_path = os.path.abspath(os.path.split(sys.argv[0])[0]) - else: - app_path = os.path.split(openlp.__file__)[0] - return app_path + return _get_frozen_path( + os.path.abspath(os.path.split(sys.argv[0])[0]), + os.path.split(openlp.__file__)[0]) elif dir_type == AppLocation.ConfigDir: - if sys.platform == u'win32': - path = os.path.join(os.getenv(u'APPDATA'), u'openlp') - elif sys.platform == u'darwin': - path = os.path.join(os.getenv(u'HOME'), u'Library', - u'Application Support', u'openlp') - else: - try: - from xdg import BaseDirectory - path = os.path.join( - BaseDirectory.xdg_config_home, u'openlp') - except ImportError: - path = os.path.join(os.getenv(u'HOME'), u'.openlp') - return path + return _get_os_dir_path(u'openlp', + os.path.join(os.getenv(u'HOME'), u'Library', + u'Application Support', u'openlp'), + os.path.join(BaseDirectory.xdg_config_home, u'openlp'), + os.path.join(os.getenv(u'HOME'), u'.openlp')) elif dir_type == AppLocation.DataDir: - if sys.platform == u'win32': - path = os.path.join(os.getenv(u'APPDATA'), u'openlp', u'data') - elif sys.platform == u'darwin': - path = os.path.join(os.getenv(u'HOME'), u'Library', - u'Application Support', u'openlp', u'Data') - else: - try: - from xdg import BaseDirectory - path = os.path.join(BaseDirectory.xdg_data_home, u'openlp') - except ImportError: - path = os.path.join(os.getenv(u'HOME'), u'.openlp', u'data') - return path + return _get_os_dir_path(os.path.join(u'openlp', u'data'), + os.path.join(os.getenv(u'HOME'), u'Library', + u'Application Support', u'openlp', u'Data'), + os.path.join(BaseDirectory.xdg_data_home, u'openlp'), + os.path.join(os.getenv(u'HOME'), u'.openlp', u'data')) elif dir_type == AppLocation.PluginsDir: - plugin_path = None app_path = os.path.abspath(os.path.split(sys.argv[0])[0]) - if hasattr(sys, u'frozen') and sys.frozen == 1: - plugin_path = os.path.join(app_path, u'plugins') - else: - plugin_path = os.path.join( - os.path.split(openlp.__file__)[0], u'plugins') - return plugin_path + return _get_frozen_path(os.path.join(app_path, u'plugins'), + os.path.join(os.path.split(openlp.__file__)[0], u'plugins')) elif dir_type == AppLocation.VersionDir: - if hasattr(sys, u'frozen') and sys.frozen == 1: - version_path = os.path.abspath(os.path.split(sys.argv[0])[0]) - else: - version_path = os.path.split(openlp.__file__)[0] - return version_path + return _get_frozen_path( + os.path.abspath(os.path.split(sys.argv[0])[0]), + os.path.split(openlp.__file__)[0]) elif dir_type == AppLocation.CacheDir: - if sys.platform == u'win32': - path = os.path.join(os.getenv(u'APPDATA'), u'openlp') - elif sys.platform == u'darwin': - path = os.path.join(os.getenv(u'HOME'), u'Library', - u'Application Support', u'openlp') - else: - try: - from xdg import BaseDirectory - path = os.path.join( - BaseDirectory.xdg_cache_home, u'openlp') - except ImportError: - path = os.path.join(os.getenv(u'HOME'), u'.openlp') - return path + return _get_os_dir_path(u'openlp', + os.path.join(os.getenv(u'HOME'), u'Library', + u'Application Support', u'openlp'), + os.path.join(BaseDirectory.xdg_cache_home, u'openlp'), + os.path.join(os.getenv(u'HOME'), u'.openlp')) if dir_type == AppLocation.LanguageDir: - if hasattr(sys, u'frozen') and sys.frozen == 1: - app_path = os.path.abspath(os.path.split(sys.argv[0])[0]) - else: - app_path = os.path.split(openlp.__file__)[0] + app_path = _get_frozen_path( + os.path.abspath(os.path.split(sys.argv[0])[0]), + os.path.split(openlp.__file__)[0]) return os.path.join(app_path, u'i18n') - @staticmethod def get_data_path(): + """ + Return the path OpenLP stores all its data under. + """ path = AppLocation.get_directory(AppLocation.DataDir) if not os.path.exists(path): os.makedirs(path) @@ -191,12 +165,38 @@ class AppLocation(object): @staticmethod def get_section_data_path(section): + """ + Return the path a particular module stores its data under. + """ data_path = AppLocation.get_data_path() path = os.path.join(data_path, section) if not os.path.exists(path): os.makedirs(path) return path +def _get_os_dir_path(win_option, darwin_option, base_dir_option, + non_base_dir_option): + """ + Return a path based on which OS and environment we are running in. + """ + if sys.platform == u'win32': + return os.path.join(os.getenv(u'APPDATA'), win_option) + elif sys.platform == u'darwin': + return darwin_option + else: + if XDG_BASE_AVAILABLE: + return base_dir_option + else: + return non_base_dir_option + +def _get_frozen_path(frozen_option, non_frozen_option): + """ + Return a path based on the system status. + """ + if hasattr(sys, u'frozen') and sys.frozen == 1: + return frozen_option + else: + return non_frozen_option def check_latest_version(current_version): """ @@ -225,9 +225,8 @@ def check_latest_version(current_version): remote_version = None try: remote_version = unicode(urllib2.urlopen(req, None).read()).strip() - except IOError, e: - if hasattr(e, u'reason'): - log.exception(u'Reason for failure: %s', e.reason) + except IOError: + log.exception(u'Failed to download the latest OpenLP version file') if remote_version: version_string = remote_version return version_string @@ -264,18 +263,21 @@ def get_images_filter(): Returns a filter string for a file dialog containing all the supported image formats. """ - global images_filter - if not images_filter: + global IMAGES_FILTER + if not IMAGES_FILTER: log.debug(u'Generating images filter.') formats = [unicode(fmt) for fmt in QtGui.QImageReader.supportedImageFormats()] visible_formats = u'(*.%s)' % u'; *.'.join(formats) actual_formats = u'(*.%s)' % u' *.'.join(formats) - images_filter = u'%s %s %s' % (translate('OpenLP', 'Image Files'), + IMAGES_FILTER = u'%s %s %s' % (translate('OpenLP', 'Image Files'), visible_formats, actual_formats) - return images_filter + return IMAGES_FILTER def split_filename(path): + """ + Return a list of the parts in a given path. + """ path = os.path.abspath(path) if not os.path.isfile(path): return path, u'' diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index 4124cc252..af8b71795 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -48,49 +48,27 @@ class VerseType(object): ``verse_type`` The type to return a string for """ - if verse_type == VerseType.Verse: - return translate('SongsPlugin.VerseType', 'Verse') - elif verse_type == VerseType.Chorus: - return translate('SongsPlugin.VerseType', 'Chorus') - elif verse_type == VerseType.Bridge: - return translate('SongsPlugin.VerseType', 'Bridge') - elif verse_type == VerseType.PreChorus: - return translate('SongsPlugin.VerseType', 'Pre-Chorus') - elif verse_type == VerseType.Intro: - return translate('SongsPlugin.VerseType', 'Intro') - elif verse_type == VerseType.Ending: - return translate('SongsPlugin.VerseType', 'Ending') - elif verse_type == VerseType.Other: - return translate('SongsPlugin.VerseType', 'Other') - - @staticmethod - def expand_string(verse_type): - """ - Return the VerseType for a given string - - ``verse_type`` - The string to return a VerseType for - """ - verse_type = verse_type.lower() - if verse_type == \ + if not isinstance(verse_type, int): + verse_type = verse_type.lower() + if verse_type == VerseType.Verse or verse_type == \ unicode(VerseType.to_string(VerseType.Verse)).lower()[0]: return translate('SongsPlugin.VerseType', 'Verse') - elif verse_type == \ + elif verse_type == VerseType.Chorus or verse_type == \ unicode(VerseType.to_string(VerseType.Chorus)).lower()[0]: return translate('SongsPlugin.VerseType', 'Chorus') - elif verse_type == \ + elif verse_type == VerseType.Bridge or verse_type == \ unicode(VerseType.to_string(VerseType.Bridge)).lower()[0]: return translate('SongsPlugin.VerseType', 'Bridge') - elif verse_type == \ + elif verse_type == VerseType.PreChorus or verse_type == \ unicode(VerseType.to_string(VerseType.PreChorus)).lower()[0]: - return translate('SongsPlugin.VerseType', 'PreChorus') - elif verse_type == \ + return translate('SongsPlugin.VerseType', 'Pre-Chorus') + elif verse_type == VerseType.Intro or verse_type == \ unicode(VerseType.to_string(VerseType.Intro)).lower()[0]: return translate('SongsPlugin.VerseType', 'Intro') - elif verse_type == \ + elif verse_type == VerseType.Ending or verse_type == \ unicode(VerseType.to_string(VerseType.Ending)).lower()[0]: return translate('SongsPlugin.VerseType', 'Ending') - elif verse_type == \ + elif verse_type == VerseType.Other or verse_type == \ unicode(VerseType.to_string(VerseType.Other)).lower()[0]: return translate('SongsPlugin.VerseType', 'Other') diff --git a/openlp/plugins/songs/lib/importer.py b/openlp/plugins/songs/lib/importer.py index 128d80138..120f47738 100644 --- a/openlp/plugins/songs/lib/importer.py +++ b/openlp/plugins/songs/lib/importer.py @@ -23,7 +23,9 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### - +""" +The :mod:`importer` modules provides the general song import functionality. +""" from opensongimport import OpenSongImport from olpimport import OpenLPSongImport from openlyricsimport import OpenLyricsImport @@ -34,19 +36,19 @@ from songbeamerimport import SongBeamerImport # Imports that might fail try: from olp1import import OpenLP1SongImport - has_openlp1 = True + HAS_OPENLP1 = True except ImportError: - has_openlp1 = False + HAS_OPENLP1 = False try: from sofimport import SofImport - has_sof = True + HAS_SOF = True except ImportError: - has_sof = False + HAS_SOF = False try: from oooimport import OooImport - has_ooo = True + HAS_OOO = True except ImportError: - has_ooo = False + HAS_OOO = False class SongFormat(object): """ @@ -118,14 +120,20 @@ class SongFormat(object): @staticmethod def set_availability(format, available): + """ + Set the availability for a given song format. + """ SongFormat._format_availability[format] = available @staticmethod def get_availability(format): + """ + Return the availability of a given song format. + """ return SongFormat._format_availability.get(format, True) -SongFormat.set_availability(SongFormat.OpenLP1, has_openlp1) -SongFormat.set_availability(SongFormat.SongsOfFellowship, has_sof) -SongFormat.set_availability(SongFormat.Generic, has_ooo) +SongFormat.set_availability(SongFormat.OpenLP1, HAS_OPENLP1) +SongFormat.set_availability(SongFormat.SongsOfFellowship, HAS_SOF) +SongFormat.set_availability(SongFormat.Generic, HAS_OOO) -__all__ = [u'SongFormat'] \ No newline at end of file +__all__ = [u'SongFormat'] diff --git a/openlp/plugins/songs/lib/songbeamerimport.py b/openlp/plugins/songs/lib/songbeamerimport.py index a4d53ec08..47290bfbd 100644 --- a/openlp/plugins/songs/lib/songbeamerimport.py +++ b/openlp/plugins/songs/lib/songbeamerimport.py @@ -94,21 +94,21 @@ class SongBeamerImport(SongImport): self.current_verse = u'' self.current_verse_type = u'V' read_verses = False - self.file_name = os.path.split(file)[1] + file_name = os.path.split(file)[1] self.import_wizard.incrementProgressBar( - u'Importing %s' % (self.file_name), 0) + u'Importing %s' % (file_name), 0) if os.path.isfile(file): detect_file = open(file, u'r') details = chardet.detect(detect_file.read(2048)) detect_file.close() infile = codecs.open(file, u'r', details['encoding']) - self.songData = infile.readlines() + songData = infile.readlines() infile.close() else: return False - self.title = self.file_name.split('.sng')[0] + self.title = file_name.split('.sng')[0] read_verses = False - for line in self.songData: + for line in songData: # Just make sure that the line is of the type 'Unicode'. line = unicode(line).strip() if line.startswith(u'#') and not read_verses: @@ -136,7 +136,7 @@ class SongBeamerImport(SongImport): self.finish() self.import_wizard.incrementProgressBar(unicode(translate( 'SongsPlugin.SongBeamerImport', 'Importing %s...')) % - self.file_name) + file_name) return True def replace_html_tags(self): diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index c1105a578..b4f64f9b4 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -62,7 +62,6 @@ class SongImport(QtCore.QObject): Create defaults for properties - call this before each song if importing many songs at once to ensure a clean beginning """ - self.authors = [] self.title = u'' self.song_number = u'' self.alternate_title = u'' @@ -251,17 +250,11 @@ class SongImport(QtCore.QObject): def finish(self): """ - All fields have been set to this song. Write it away + All fields have been set to this song. Write the song to disk. """ if not self.authors: self.authors.append(unicode(translate('SongsPlugin.SongImport', 'Author unknown'))) - self.commit_song() - - def commit_song(self): - """ - Write the song and its fields to disk - """ log.info(u'commiting song %s to database', self.title) song = Song() song.title = self.title diff --git a/openlp/plugins/songs/lib/wowimport.py b/openlp/plugins/songs/lib/wowimport.py index a8acb6266..b90a47de6 100644 --- a/openlp/plugins/songs/lib/wowimport.py +++ b/openlp/plugins/songs/lib/wowimport.py @@ -109,61 +109,58 @@ class WowImport(SongImport): """ Receive a single file or a list of files to import. """ - if isinstance(self.import_source, list): self.import_wizard.progressBar.setMaximum(len(self.import_source)) for file in self.import_source: - self.author = u'' - self.copyright = u'' - self.file_name = os.path.split(file)[1] + author = u'' + copyright = u'' + file_name = os.path.split(file)[1] self.import_wizard.incrementProgressBar( - u'Importing %s' % (self.file_name), 0) + u'Importing %s' % (file_name), 0) # Get the song title - self.title = self.file_name.rpartition(u'.')[0] - self.songData = open(file, 'rb') - if self.songData.read(19) != u'WoW File\nSong Words': + self.title = file_name.rpartition(u'.')[0] + songData = open(file, 'rb') + if songData.read(19) != u'WoW File\nSong Words': continue # Seek to byte which stores number of blocks in the song - self.songData.seek(56) - self.no_of_blocks = ord(self.songData.read(1)) + songData.seek(56) + no_of_blocks = ord(songData.read(1)) # Seek to the beging of the first block - self.songData.seek(82) - for block in range(self.no_of_blocks): - self.lines_to_read = ord(self.songData.read(1)) + songData.seek(82) + for block in range(no_of_blocks): + self.lines_to_read = ord(songData.read(1)) # Skip 3 nulls to the beginnig of the 1st line - self.songData.seek(3, os.SEEK_CUR) - self.block_text = u'' + songData.seek(3, os.SEEK_CUR) + block_text = u'' while self.lines_to_read: - self.length_of_line = ord(self.songData.read(1)) self.line_text = unicode( - self.songData.read(self.length_of_line), u'cp1252') - self.songData.seek(1, os.SEEK_CUR) - if self.block_text != u'': - self.block_text += u'\n' - self.block_text += self.line_text + songData.read(ord(songData.read(1))), u'cp1252') + songData.seek(1, os.SEEK_CUR) + if block_text != u'': + block_text += u'\n' + block_text += self.line_text self.lines_to_read -= 1 - self.block_type = BLOCK_TYPES[ord(self.songData.read(1))] + block_type = BLOCK_TYPES[ord(songData.read(1))] # Skip 3 nulls at the end of the block - self.songData.seek(3, os.SEEK_CUR) + songData.seek(3, os.SEEK_CUR) # Blocks are seperated by 2 bytes, skip them, but not if # this is the last block! - if (block + 1) < self.no_of_blocks: - self.songData.seek(2, os.SEEK_CUR) - self.add_verse(self.block_text, self.block_type) - # Now to extact the author - self.author_length = ord(self.songData.read(1)) - if self.author_length != 0: - self.author = unicode( - self.songData.read(self.author_length), u'cp1252') + if (block + 1) < no_of_blocks: + songData.seek(2, os.SEEK_CUR) + self.add_verse(block_text, block_type) + # Now to extract the author + author_length = ord(songData.read(1)) + if author_length != 0: + author = unicode(songData.read(author_length), u'cp1252') # Finally the copyright - self.copyright_length = ord(self.songData.read(1)) - if self.copyright_length != 0: - self.copyright = unicode( - self.songData.read(self.copyright_length), u'cp1252') - self.parse_author(self.author) - self.add_copyright(self.copyright) - self.songData.close() + copyright_length = ord(songData.read(1)) + if copyright_length != 0: + copyright = unicode( + songData.read(copyright_length), u'cp1252') + self.parse_author(author) + self.add_copyright(copyright) + songData.close() self.finish() self.import_wizard.incrementProgressBar( - u'Importing %s' % (self.file_name)) + u'Importing %s' % (file_name)) return True diff --git a/openlp/plugins/songs/lib/xml.py b/openlp/plugins/songs/lib/xml.py index cbe313212..88459b797 100644 --- a/openlp/plugins/songs/lib/xml.py +++ b/openlp/plugins/songs/lib/xml.py @@ -435,7 +435,7 @@ class OpenLyrics(object): text += u'\n' text += u'\n'.join([unicode(line) for line in lines.line]) verse_name = self._get(verse, u'name') - verse_type = unicode(VerseType.expand_string(verse_name[0]))[0] + verse_type = unicode(VerseType.to_string(verse_name[0]))[0] verse_number = re.compile(u'[a-zA-Z]*').sub(u'', verse_name) verse_part = re.compile(u'[0-9]*').sub(u'', verse_name[1:]) # OpenLyrics allows e. g. "c", but we need "c1". From ff80150fc171ca629c61c5925af625ab149071c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Tue, 18 Jan 2011 11:09:00 +0200 Subject: [PATCH 51/60] removed extra empty lines, removed leading spaces --- openlp/plugins/songs/lib/easislidesimport.py | 61 ++++++++------------ openlp/plugins/songs/lib/importer.py | 1 + 2 files changed, 24 insertions(+), 38 deletions(-) diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py index 26bb105af..571f9d047 100644 --- a/openlp/plugins/songs/lib/easislidesimport.py +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -59,18 +59,15 @@ class EasiSlidesImport(SongImport): import will not be committed to the database (useful for test scripts). """ self.import_wizard.progressBar.setMaximum(1) - - log.info(u'Importing XML file %s', self.filename) + log.info(u'Importing EasiSlides XML file %s', self.filename) parser = etree.XMLParser(remove_blank_text=True) file = etree.parse(self.filename, parser) xml = unicode(etree.tostring(file)) song_xml = objectify.fromstring(xml) - self.import_wizard.incrementProgressBar( unicode(translate('SongsPlugin.ImportWizardForm', u'Importing %s...')) % os.path.split(self.filename)[-1]) self.import_wizard.progressBar.setMaximum(len(song_xml.Item)) - for song in song_xml.Item: self.import_wizard.incrementProgressBar( unicode(translate('SongsPlugin.ImportWizardForm', @@ -82,7 +79,7 @@ class EasiSlidesImport(SongImport): elif self.commit: self.finish() return True - + def _parse_song(self, song): self._success = True self._add_title(song) @@ -93,7 +90,7 @@ class EasiSlidesImport(SongImport): self._add_book(song) self._parse_and_add_lyrics(song) return self._success - + def _add_title(self, song): try: self.title = unicode(song.Title1).strip() @@ -103,7 +100,7 @@ class EasiSlidesImport(SongImport): except AttributeError: log.exception(u'no Title1') self._success = False - + def _add_alttitle(self, song): try: self.alternate_title = unicode(song.Title2).strip() @@ -112,7 +109,7 @@ class EasiSlidesImport(SongImport): self._success = False except AttributeError: pass - + def _add_number(self, song): try: number = int(song.SongNumber) @@ -136,7 +133,7 @@ class EasiSlidesImport(SongImport): self._success = False except AttributeError: pass - + def _add_copyright(self, song): copyright = [] try: @@ -161,7 +158,7 @@ class EasiSlidesImport(SongImport): except AttributeError: pass self.add_copyright(u' '.join(copyright)) - + def _add_book(self, song): try: self.song_book_name = unicode(song.BookReference).strip() @@ -170,7 +167,7 @@ class EasiSlidesImport(SongImport): self._success = False except AttributeError: pass - + def _parse_and_add_lyrics(self, song): try: lyrics = unicode(song.Contents).strip() @@ -180,9 +177,7 @@ class EasiSlidesImport(SongImport): except AttributeError: log.exception(u'no Contents') self._success = False - lines = lyrics.split(u'\n') - # we go over all lines first, to determine information, # which tells us how to parse verses later regionlines = {} @@ -200,7 +195,6 @@ class EasiSlidesImport(SongImport): regionlines[region] = 1 elif line[0] == u'[': separatorlines = separatorlines + 1 - # if the song has separators separators = (separatorlines > 0) # the number of different regions in song - 1 @@ -214,7 +208,6 @@ class EasiSlidesImport(SongImport): # if the regions are inside verses regionsInVerses = (regions and \ regionlines[regionlines.keys()[0]] > 1) - MarkTypes = { u'CHORUS': u'C', u'VERSE': u'V', @@ -222,7 +215,6 @@ class EasiSlidesImport(SongImport): u'ENDING': u'E', u'BRIDGE': u'B', u'PRECHORUS': u'P'} - verses = {} # list as [region, versetype, versenum, instance] our_verse_order = [] @@ -236,7 +228,6 @@ class EasiSlidesImport(SongImport): for line in lines: line = line.strip() - if len(line) == 0: if separators: # separators are used, so empty line means slide break @@ -251,7 +242,6 @@ class EasiSlidesImport(SongImport): else: vn = u'1' inst = 1 - continue elif line[0:7] == u'[region': reg = self._extractRegion(line) if not verses.has_key(reg): @@ -260,7 +250,6 @@ class EasiSlidesImport(SongImport): vt = u'V' vn = u'1' inst = 1 - continue elif line[0] == u'[': # this is a normal section marker marker = line[1:line.find(u']')].upper() @@ -282,24 +271,20 @@ class EasiSlidesImport(SongImport): inst = 1 if self._listHas(verses, [reg, vt, vn, inst]): inst = len(verses[reg][vt][vn])+1 - continue - - if not [reg, vt, vn, inst] in our_verse_order: - our_verse_order.append([reg, vt, vn, inst]) - - if not verses[reg].has_key(vt): - verses[reg][vt] = {} - if not verses[reg][vt].has_key(vn): - verses[reg][vt][vn] = {} - if not verses[reg][vt][vn].has_key(inst): - verses[reg][vt][vn][inst] = [] - - words = self.tidy_text(line) - verses[reg][vt][vn][inst].append(words) + else: + if not [reg, vt, vn, inst] in our_verse_order: + our_verse_order.append([reg, vt, vn, inst]) + if not verses[reg].has_key(vt): + verses[reg][vt] = {} + if not verses[reg][vt].has_key(vn): + verses[reg][vt][vn] = {} + if not verses[reg][vt][vn].has_key(inst): + verses[reg][vt][vn][inst] = [] + words = self.tidy_text(line) + verses[reg][vt][vn][inst].append(words) # done parsing - + versetags = [] - # we use our_verse_order to ensure, we insert lyrics in the same order # as these appeared originally in the file for [reg, vt, vn, inst] in our_verse_order: @@ -308,7 +293,7 @@ class EasiSlidesImport(SongImport): versetags.append(versetag) lines = u'\n'.join(verses[reg][vt][vn][inst]) self.verses.append([versetag, lines]) - + SeqTypes = { u'p': u'P1', u'q': u'P2', @@ -340,7 +325,7 @@ class EasiSlidesImport(SongImport): self._success = False except AttributeError: pass - + def _listHas(self, lst, subitems): for i in subitems: if type(lst) == type({}) and lst.has_key(i): @@ -350,7 +335,7 @@ class EasiSlidesImport(SongImport): else: return False return True - + def _extractRegion(self, line): # this was true already: line[0:7] == u'[region': right_bracket = line.find(u']') diff --git a/openlp/plugins/songs/lib/importer.py b/openlp/plugins/songs/lib/importer.py index 038eaa2a2..9e35c6204 100644 --- a/openlp/plugins/songs/lib/importer.py +++ b/openlp/plugins/songs/lib/importer.py @@ -134,3 +134,4 @@ SongFormat.set_availability(SongFormat.SongsOfFellowship, has_sof) SongFormat.set_availability(SongFormat.Generic, has_ooo) __all__ = [u'SongFormat'] + From ddcda85090c0f49de13767048fbc277f51759b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Tue, 18 Jan 2011 17:18:04 +0200 Subject: [PATCH 52/60] indentation fix, songbook number back to unicode, these sometimes contain letters like 104a --- openlp/plugins/songs/lib/easislidesimport.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py index 571f9d047..fac376134 100644 --- a/openlp/plugins/songs/lib/easislidesimport.py +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -112,8 +112,8 @@ class EasiSlidesImport(SongImport): def _add_number(self, song): try: - number = int(song.SongNumber) - if number != 0: + number = unicode(song.SongNumber) + if number != u'0': self.song_number = number except UnicodeDecodeError: log.exception(u'Unicode decode error while decoding SongNumber') @@ -206,8 +206,7 @@ class EasiSlidesImport(SongImport): # if the song has regions regions = (len(regionlines) > 0) # if the regions are inside verses - regionsInVerses = (regions and \ - regionlines[regionlines.keys()[0]] > 1) + regionsInVerses = (regions and regionlines[regionlines.keys()[0]] > 1) MarkTypes = { u'CHORUS': u'C', u'VERSE': u'V', From 4dec90a419898a1c93fa4893ba3e8715942d78c2 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 18 Jan 2011 17:09:34 +0100 Subject: [PATCH 53/60] added line --- openlp/core/ui/serviceitemeditform.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlp/core/ui/serviceitemeditform.py b/openlp/core/ui/serviceitemeditform.py index 807b8dfb7..edd4ee29f 100644 --- a/openlp/core/ui/serviceitemeditform.py +++ b/openlp/core/ui/serviceitemeditform.py @@ -148,3 +148,4 @@ class ServiceItemEditForm(QtGui.QDialog, Ui_ServiceItemEditDialog): else: self.upButton.setEnabled(True) self.deleteButton.setEnabled(True) + From 628a5bd755a627ff4436ec2cb7d543b228fd76f0 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 18 Jan 2011 19:49:47 +0100 Subject: [PATCH 55/60] removed obsolete attribute doc --- openlp/core/lib/mediamanageritem.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 6fb834e05..de2b2327c 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -168,9 +168,6 @@ class MediaManagerItem(QtGui.QWidget): ``slot`` The method to call when the button is clicked. - - ``objectname`` - The name of the button. """ # NB different order (when I broke this out, I didn't want to # break compatability), but it makes sense for the icon to From 608dbd2537c76af1782ddc8f42d4438884da268a Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 18 Jan 2011 19:53:09 +0100 Subject: [PATCH 56/60] removed white spaces --- openlp/core/ui/pluginform.py | 2 +- openlp/core/ui/wizard.py | 4 ++-- openlp/plugins/songs/forms/songimportform.py | 4 ++-- openlp/plugins/songs/lib/easislidesimport.py | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/openlp/core/ui/pluginform.py b/openlp/core/ui/pluginform.py index 8e82f0003..d6ffc69f0 100644 --- a/openlp/core/ui/pluginform.py +++ b/openlp/core/ui/pluginform.py @@ -85,7 +85,7 @@ class PluginForm(QtGui.QDialog, Ui_PluginViewDialog): item.setIcon(plugin.icon) self.pluginListWidget.addItem(item) pluginListWidth = max(pluginListWidth, self.fontMetrics().width( - unicode(translate('OpenLP.PluginForm', '%s (Inactive)')) % + unicode(translate('OpenLP.PluginForm', '%s (Inactive)')) % name_string[u'singular'])) self.pluginListWidget.setFixedWidth(pluginListWidth + self.pluginListWidget.iconSize().width() + 48) diff --git a/openlp/core/ui/wizard.py b/openlp/core/ui/wizard.py index 3b221455b..d3a0255b4 100644 --- a/openlp/core/ui/wizard.py +++ b/openlp/core/ui/wizard.py @@ -95,7 +95,7 @@ class OpenLPWizard(QtGui.QWizard): def addProgressPage(self): """ - Add the progress page for the wizard. This page informs the user how + Add the progress page for the wizard. This page informs the user how the wizard is progressing with its task. """ self.progressPage = QtGui.QWizardPage() @@ -125,7 +125,7 @@ class OpenLPWizard(QtGui.QWizard): log.debug(u'Wizard cancelled by user.') if self.currentPage() == self.progressPage: Receiver.send_message(u'openlp_stop_wizard') - self.done(QtGui.QDialog.Rejected) + self.done(QtGui.QDialog.Rejected) def onCurrentIdChanged(self, pageId): """ diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index 433c9abfc..d14ab9c36 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -322,7 +322,7 @@ class SongImportForm(OpenLPWizard): QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) self.openLP1FormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) - self.easiSlidesFormLabelSpacer.changeSize(width, 0, + self.easiSlidesFormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) self.ewFormLabelSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) @@ -654,7 +654,7 @@ class SongImportForm(OpenLPWizard): 'Select EasiSlides songfile'), self.easiSlidesFilenameEdit ) - + def onEWBrowseButtonClicked(self): """ Get EasyWorship song database files diff --git a/openlp/plugins/songs/lib/easislidesimport.py b/openlp/plugins/songs/lib/easislidesimport.py index fac376134..8685b6934 100644 --- a/openlp/plugins/songs/lib/easislidesimport.py +++ b/openlp/plugins/songs/lib/easislidesimport.py @@ -39,7 +39,7 @@ class EasiSlidesImport(SongImport): """ Import songs exported from EasiSlides - The format example is here: + The format example is here: http://wiki.openlp.org/Development:EasiSlides_-_Song_Data_Format """ def __init__(self, manager, **kwargs): @@ -71,7 +71,7 @@ class EasiSlidesImport(SongImport): for song in song_xml.Item: self.import_wizard.incrementProgressBar( unicode(translate('SongsPlugin.ImportWizardForm', - u'Importing %s, song %s...')) % + u'Importing %s, song %s...')) % (os.path.split(self.filename)[-1], song.Title1)) success = self._parse_song(song) if not success or self.stop_import_flag: @@ -313,7 +313,7 @@ class EasiSlidesImport(SongImport): tag = SeqTypes[tag.lower()] else: continue - + if tag in versetags: self.verse_order_list.append(tag) else: From 14d45a001166f9bca5e6835265704ae064c5b695 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Tue, 18 Jan 2011 19:11:46 +0000 Subject: [PATCH 57/60] Fix verse order saving --- openlp/core/ui/maindisplay.py | 3 ++- openlp/plugins/songs/forms/editsongform.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 6ddd2544f..ec5ab7b3f 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -437,7 +437,8 @@ class MainDisplay(DisplayWidget): self.hideDisplay(self.hideMode) # Hide mouse cursor when moved over display if enabled in settings settings = QtCore.QSettings() - if settings.value(u'advanced/hide mouse', QtCore.QVariant(False)).toBool(): + if settings.value(u'advanced/hide mouse', + QtCore.QVariant(False)).toBool(): self.setCursor(QtCore.Qt.BlankCursor) self.frame.evaluateJavaScript('document.body.style.cursor = "none"') else: diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 8a7157e29..43fba6dd9 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -553,7 +553,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): return False if self.verseOrderEdit.text(): order = [] - order_names = self.verseOrderEdit.text().split() + order_names = str(self.verseOrderEdit.text()).split() for item in order_names: if len(item) == 1: order.append(item.lower() + u'1') From 091d604901289d76083646abd3cfd1f493314a81 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Tue, 18 Jan 2011 19:31:03 +0000 Subject: [PATCH 58/60] Better string fix --- openlp/plugins/songs/forms/editsongform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 43fba6dd9..b36ea55e1 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -553,7 +553,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): return False if self.verseOrderEdit.text(): order = [] - order_names = str(self.verseOrderEdit.text()).split() + order_names = unicode(self.verseOrderEdit.text()).split() for item in order_names: if len(item) == 1: order.append(item.lower() + u'1') From d567bb12ad13fc7fe43bd3abfe827dd63e5fd772 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 18 Jan 2011 21:14:44 +0100 Subject: [PATCH 59/60] more doc fixes --- openlp/core/lib/mediamanageritem.py | 4 ++++ openlp/core/lib/toolbar.py | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index de2b2327c..bb98c9db8 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -168,6 +168,10 @@ class MediaManagerItem(QtGui.QWidget): ``slot`` The method to call when the button is clicked. + + ``checkable`` + If *True* the button has two, *off* and *on*, states. Default is + *False*, which means the buttons has only one state. """ # NB different order (when I broke this out, I didn't want to # break compatability), but it makes sense for the icon to diff --git a/openlp/core/lib/toolbar.py b/openlp/core/lib/toolbar.py index 93aed62e5..763e6bf67 100644 --- a/openlp/core/lib/toolbar.py +++ b/openlp/core/lib/toolbar.py @@ -69,8 +69,9 @@ class OpenLPToolbar(QtGui.QToolBar): ``slot`` The method to run when this button is clicked. - ``objectname`` - The name of the object, as used in `