forked from openlp/openlp
added textEdit and buttons for better feedback
This commit is contained in:
parent
48d0d39a17
commit
8cd3742c87
@ -95,6 +95,10 @@ class OpenLPWizard(QtGui.QWizard):
|
||||
self.customSignals()
|
||||
QtCore.QObject.connect(self, QtCore.SIGNAL(u'currentIdChanged(int)'),
|
||||
self.onCurrentIdChanged)
|
||||
QtCore.QObject.connect(self.errorCopyToButton,
|
||||
QtCore.SIGNAL(u'clicked()'), self.onErrorCopyToButtonClicked)
|
||||
QtCore.QObject.connect(self.errorSaveToButton,
|
||||
QtCore.SIGNAL(u'clicked()'), self.onErrorSaveToButtonClicked)
|
||||
|
||||
def setupUi(self, image):
|
||||
"""
|
||||
@ -129,11 +133,36 @@ class OpenLPWizard(QtGui.QWizard):
|
||||
self.progressLayout.setObjectName(u'progressLayout')
|
||||
self.progressLabel = QtGui.QLabel(self.progressPage)
|
||||
self.progressLabel.setObjectName(u'progressLabel')
|
||||
self.progressLabel.setWordWrap(True)
|
||||
self.progressLayout.addWidget(self.progressLabel)
|
||||
self.progressBar = QtGui.QProgressBar(self.progressPage)
|
||||
self.progressBar.setObjectName(u'progressBar')
|
||||
self.progressLabel.setWordWrap(True)
|
||||
self.progressLayout.addWidget(self.progressBar)
|
||||
# Add a QTextEdit and a copy to file and copy to clipboard button to be
|
||||
# able to provide feedback to the user. Hidden by default.
|
||||
self.errorReportTextEdit = QtGui.QTextEdit(self.progressPage)
|
||||
self.errorReportTextEdit.setObjectName(u'progresserrorReportTextEdit')
|
||||
self.errorReportTextEdit.setHidden(True)
|
||||
self.errorReportTextEdit.setReadOnly(True)
|
||||
self.progressLayout.addWidget(self.errorReportTextEdit)
|
||||
self.errorButtonLayout = QtGui.QHBoxLayout()
|
||||
self.errorButtonLayout.setObjectName(u'errorButtonLayout')
|
||||
spacer = QtGui.QSpacerItem(40, 20,
|
||||
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
|
||||
self.errorButtonLayout.addItem(spacer)
|
||||
self.errorCopyToButton = QtGui.QPushButton(self.progressPage)
|
||||
self.errorCopyToButton.setObjectName(u'errorCopyToButton')
|
||||
self.errorCopyToButton.setHidden(True)
|
||||
self.errorCopyToButton.setIcon(
|
||||
build_icon(u':/system/system_edit_copy.png'))
|
||||
self.errorButtonLayout.addWidget(self.errorCopyToButton)
|
||||
self.errorSaveToButton = QtGui.QPushButton(self.progressPage)
|
||||
self.errorSaveToButton.setObjectName(u'errorSaveToButton')
|
||||
self.errorSaveToButton.setHidden(True)
|
||||
self.errorSaveToButton.setIcon(
|
||||
build_icon(u':/general/general_save.png'))
|
||||
self.errorButtonLayout.addWidget(self.errorSaveToButton)
|
||||
self.progressLayout.addLayout(self.errorButtonLayout)
|
||||
self.addPage(self.progressPage)
|
||||
|
||||
def exec_(self):
|
||||
@ -161,6 +190,18 @@ class OpenLPWizard(QtGui.QWizard):
|
||||
self.performWizard()
|
||||
self.postWizard()
|
||||
|
||||
def onErrorCopyToButtonClicked(self):
|
||||
"""
|
||||
Called when the ``onErrorCopyToButtonClicked`` has been clicked.
|
||||
"""
|
||||
pass
|
||||
|
||||
def onErrorSaveToButtonClicked(self):
|
||||
"""
|
||||
Called when the ``onErrorSaveToButtonClicked`` has been clicked.
|
||||
"""
|
||||
pass
|
||||
|
||||
def incrementProgressBar(self, status_text, increment=1):
|
||||
"""
|
||||
Update the wizard progress page.
|
||||
@ -221,3 +262,4 @@ class OpenLPWizard(QtGui.QWizard):
|
||||
editbox.setText(filename)
|
||||
SettingsManager.set_last_dir(self.plugin.settingsSection,
|
||||
filename, 1)
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
"""
|
||||
The song import functions for OpenLP.
|
||||
"""
|
||||
import codecs
|
||||
import logging
|
||||
import os
|
||||
|
||||
@ -55,6 +56,7 @@ class SongImportForm(OpenLPWizard):
|
||||
``plugin``
|
||||
The songs plugin.
|
||||
"""
|
||||
self.clipboard = plugin.formparent.clipboard
|
||||
OpenLPWizard.__init__(self, parent, plugin, u'songImportWizard',
|
||||
u':/wizards/wizard_importsong.bmp')
|
||||
|
||||
@ -330,6 +332,10 @@ class SongImportForm(OpenLPWizard):
|
||||
'Please wait while your songs are imported.'))
|
||||
self.progressLabel.setText(WizardStrings.Ready)
|
||||
self.progressBar.setFormat(WizardStrings.PercentSymbolFormat)
|
||||
self.errorCopyToButton.setText(translate('SongsPlugin.ImportWizardForm',
|
||||
'Copy'))
|
||||
self.errorSaveToButton.setText(translate('SongsPlugin.ImportWizardForm',
|
||||
'Save to File'))
|
||||
# Align all QFormLayouts towards each other.
|
||||
width = max(self.formatLabel.minimumSizeHint().width(),
|
||||
self.openLP2FilenameLabel.minimumSizeHint().width())
|
||||
@ -656,6 +662,10 @@ class SongImportForm(OpenLPWizard):
|
||||
self.songShowPlusFileListWidget.clear()
|
||||
self.foilPresenterFileListWidget.clear()
|
||||
#self.csvFilenameEdit.setText(u'')
|
||||
self.errorReportTextEdit.clear()
|
||||
self.errorReportTextEdit.setHidden(True)
|
||||
self.errorCopyToButton.setHidden(True)
|
||||
self.errorSaveToButton.setHidden(True)
|
||||
|
||||
def preWizard(self):
|
||||
"""
|
||||
@ -742,22 +752,29 @@ class SongImportForm(OpenLPWizard):
|
||||
)
|
||||
importer.do_import()
|
||||
if importer.error_log:
|
||||
self.progressLabel.setTextInteractionFlags(
|
||||
QtCore.Qt.TextSelectableByMouse)
|
||||
self.progressLabel.setText(translate(
|
||||
'SongsPlugin.SongImportForm', 'Your song import failed.'))
|
||||
if critical_error_message_box(translate('SongsPlugin.SongImportForm',
|
||||
'Song import failed.'), translate('SongsPlugin.SongImportForm',
|
||||
'Your song import failed. Do you want to create an error '
|
||||
'report?'), self, True) == QtGui.QMessageBox.No:
|
||||
return
|
||||
error_path = importer.write_error_report()
|
||||
self.progressLabel.setText(unicode(translate(
|
||||
'SongsPlugin.SongImportForm', 'Your song import failed. '
|
||||
'For more details see the error report:\n%s')) % error_path)
|
||||
else:
|
||||
self.progressLabel.setText(WizardStrings.FinishedImport)
|
||||
|
||||
def onErrorCopyToButtonClicked(self):
|
||||
"""
|
||||
Copy the error report to the clipboard.
|
||||
"""
|
||||
self.clipboard.setText(self.errorReportTextEdit.toPlainText())
|
||||
|
||||
def onErrorSaveToButtonClicked(self):
|
||||
"""
|
||||
Save the error report to a file.
|
||||
"""
|
||||
filename = QtGui.QFileDialog.getSaveFileName(self,
|
||||
SettingsManager.get_last_dir(self.plugin.settingsSection, 1))
|
||||
if not filename:
|
||||
return
|
||||
file = codecs.open(filename, u'w', u'utf-8')
|
||||
file.write(self.errorReportTextEdit.toPlainText())
|
||||
file.close()
|
||||
|
||||
def addFileSelectItem(self, prefix, obj_prefix=None, can_disable=False,
|
||||
single_select=False):
|
||||
if not obj_prefix:
|
||||
|
@ -32,7 +32,6 @@ from zipfile import ZipFile
|
||||
from lxml import objectify
|
||||
from lxml.etree import Error, LxmlError
|
||||
|
||||
from openlp.core.ui.wizard import WizardStrings
|
||||
from openlp.plugins.songs.lib import VerseType
|
||||
from openlp.plugins.songs.lib.songimport import SongImport
|
||||
from openlp.plugins.songs.lib.ui import SongStrings
|
||||
@ -142,8 +141,6 @@ class OpenSongImport(SongImport):
|
||||
# No final part => directory
|
||||
continue
|
||||
log.info(u'Zip importing %s', parts[-1])
|
||||
self.import_wizard.incrementProgressBar(
|
||||
WizardStrings.ImportingType % parts[-1])
|
||||
song_file = z.open(song)
|
||||
self.do_import_file(song_file)
|
||||
song_file.close()
|
||||
@ -151,8 +148,6 @@ class OpenSongImport(SongImport):
|
||||
else:
|
||||
# not a zipfile
|
||||
log.info(u'Direct import %s', filename)
|
||||
self.import_wizard.incrementProgressBar(
|
||||
WizardStrings.ImportingType % os.path.split(filename)[-1])
|
||||
song_file = open(filename)
|
||||
self.do_import_file(song_file)
|
||||
song_file.close()
|
||||
|
@ -23,12 +23,8 @@
|
||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
###############################################################################
|
||||
import codecs
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
from PyQt4 import QtCore
|
||||
|
||||
@ -114,29 +110,17 @@ class SongImport(QtCore.QObject):
|
||||
The reason, why the import failed. The string should be as
|
||||
informative as possible.
|
||||
"""
|
||||
self.error_log.append((filepath, unicode(reason)))
|
||||
|
||||
def write_error_report(self):
|
||||
"""
|
||||
Creates a error import containing all error messages.
|
||||
"""
|
||||
report_path = os.path.join(AppLocation.get_data_path(), unicode(translate(
|
||||
'SongsPlugin.SongImport','song_import_report (%s).txt')) %
|
||||
datetime.datetime.now().strftime(u'%Y-%m-%d %H:%M:%S'))
|
||||
report_file = codecs.open(report_path, u'w', u'utf-8')
|
||||
report_file.write(translate('SongsPlugin.SongImport',
|
||||
'The following songs could not be imported:\n'))
|
||||
for filepath, reason in self.error_log:
|
||||
report_file.write(u'- %s (%s)\n' % (filepath, reason))
|
||||
if not os.path.isfile(filepath):
|
||||
continue
|
||||
check_directory_exists(report_path[:-4])
|
||||
new_song_path = \
|
||||
os.path.join(report_path[:-4], os.path.basename(filepath))
|
||||
if not os.path.exists(new_song_path):
|
||||
shutil.copyfile(filepath, new_song_path)
|
||||
report_file.close()
|
||||
return report_path
|
||||
if self.import_wizard is None:
|
||||
return
|
||||
if self.import_wizard.errorReportTextEdit.isHidden():
|
||||
self.import_wizard.errorReportTextEdit.setText(
|
||||
translate('SongsPlugin.SongImport',
|
||||
'The following songs could not be imported:'))
|
||||
self.import_wizard.errorReportTextEdit.setVisible(True)
|
||||
self.import_wizard.errorCopyToButton.setVisible(True)
|
||||
self.import_wizard.errorSaveToButton.setVisible(True)
|
||||
self.import_wizard.errorReportTextEdit.append(
|
||||
u'- %s (%s)' % (filepath, reason))
|
||||
|
||||
def stop_import(self):
|
||||
"""
|
||||
@ -299,6 +283,7 @@ class SongImport(QtCore.QObject):
|
||||
log.info(u'committing song %s to database', self.title)
|
||||
song = Song()
|
||||
song.title = self.title
|
||||
if self.import_wizard is not None:
|
||||
self.import_wizard.incrementProgressBar(
|
||||
WizardStrings.ImportingType % song.title)
|
||||
song.alternate_title = self.alternate_title
|
||||
|
Loading…
Reference in New Issue
Block a user