openlp/openlp/plugins/songs/forms/songimportform.py

525 lines
24 KiB
Python
Raw Normal View History

2010-04-02 12:23:40 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2011-12-27 10:33:55 +00:00
# Copyright (c) 2008-2012 Raoul Snyman #
# Portions copyright (c) 2008-2012 Tim Bentley, Gerald Britton, Jonathan #
2011-05-26 16:25:54 +00:00
# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, #
2011-05-26 17:11:22 +00:00
# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias #
2011-06-12 16:02:52 +00:00
# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
2011-06-12 15:41:01 +00:00
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund #
2010-04-02 12:23:40 +00:00
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
2011-01-13 17:55:29 +00:00
"""
The song import functions for OpenLP.
"""
import codecs
2010-04-02 12:23:40 +00:00
import logging
2010-08-20 19:40:07 +00:00
import os
2010-04-02 12:23:40 +00:00
from PyQt4 import QtCore, QtGui
from openlp.core.lib import Receiver, SettingsManager, translate
2011-02-09 05:04:12 +00:00
from openlp.core.lib.ui import UiStrings, critical_error_message_box
2011-02-12 02:43:13 +00:00
from openlp.core.ui.wizard import OpenLPWizard, WizardStrings
from openlp.plugins.songs.lib.importer import SongFormat, SongFormatSelect
2010-04-02 12:23:40 +00:00
log = logging.getLogger(__name__)
2011-01-13 17:55:29 +00:00
class SongImportForm(OpenLPWizard):
2010-04-02 12:23:40 +00:00
"""
2010-08-08 14:38:51 +00:00
This is the Song Import Wizard, which allows easy importing of Songs
into OpenLP from other formats like OpenLyrics, OpenSong and CCLI.
2010-04-02 12:23:40 +00:00
"""
2010-08-08 14:38:51 +00:00
log.info(u'SongImportForm loaded')
2010-04-02 12:23:40 +00:00
def __init__(self, parent, plugin):
2010-04-02 12:23:40 +00:00
"""
Instantiate the wizard, and run any extra setup we need to.
``parent``
The QWidget-derived parent of the wizard.
2010-08-08 14:38:51 +00:00
``plugin``
The songs plugin.
2010-04-02 12:23:40 +00:00
"""
self.clipboard = plugin.formParent.clipboard
2011-01-13 17:55:29 +00:00
OpenLPWizard.__init__(self, parent, plugin, u'songImportWizard',
u':/wizards/wizard_importsong.bmp')
def setupUi(self, image):
"""
Set up the song wizard UI.
"""
self.formatWidgets = dict([(format, {}) for format in
SongFormat.get_format_list()])
2011-01-13 17:55:29 +00:00
OpenLPWizard.setupUi(self, image)
self.currentFormat = SongFormat.OpenLyrics
self.formatStack.setCurrentIndex(self.currentFormat)
2011-01-13 17:55:29 +00:00
QtCore.QObject.connect(self.formatComboBox,
QtCore.SIGNAL(u'currentIndexChanged(int)'),
self.onCurrentIndexChanged)
def onCurrentIndexChanged(self, index):
"""
Called when the format combo box's index changed.
"""
self.currentFormat = index
self.formatStack.setCurrentIndex(index)
self.sourcePage.emit(QtCore.SIGNAL(u'completeChanged()'))
2011-01-13 17:55:29 +00:00
def customInit(self):
"""
Song wizard specific initialisation.
"""
2012-05-30 09:11:44 +00:00
for format in SongFormat.get_format_list():
if not SongFormat.get(format, SongFormat.Availability):
self.formatWidgets[format][u'disabledWidget'].setVisible(True)
self.formatWidgets[format][u'importWidget'].setVisible(False)
2011-01-13 17:55:29 +00:00
def customSignals(self):
"""
Song wizard specific signals.
"""
2012-05-30 09:11:44 +00:00
for format in SongFormat.get_format_list():
select_mode = SongFormat.get(format, SongFormat.SelectMode)
if select_mode == SongFormatSelect.MultipleFiles:
QtCore.QObject.connect(self.formatWidgets[format][u'addButton'],
QtCore.SIGNAL(u'clicked()'), self.onAddButtonClicked)
QtCore.QObject.connect(
self.formatWidgets[format][u'removeButton'],
QtCore.SIGNAL(u'clicked()'), self.onRemoveButtonClicked)
else:
QtCore.QObject.connect(
self.formatWidgets[format][u'browseButton'],
QtCore.SIGNAL(u'clicked()'), self.onBrowseButtonClicked)
QtCore.QObject.connect(
self.formatWidgets[format][u'filepathEdit'],
QtCore.SIGNAL(u'textChanged (const QString&)'),
self.onFilepathEditTextChanged)
2010-04-02 12:23:40 +00:00
2011-01-13 17:55:29 +00:00
def addCustomPages(self):
2010-04-02 12:23:40 +00:00
"""
2011-01-13 17:55:29 +00:00
Add song wizard specific pages.
2010-04-02 12:23:40 +00:00
"""
2011-01-13 17:55:29 +00:00
# Source Page
self.sourcePage = SongImportSourcePage()
2011-01-13 17:55:29 +00:00
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)
2011-02-03 20:12:06 +00:00
self.stackSpacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed,
QtGui.QSizePolicy.Expanding)
2011-01-13 17:55:29 +00:00
self.formatStack = QtGui.QStackedLayout()
self.formatStack.setObjectName(u'FormatStack')
self.disablableFormats = []
for self.currentFormat in SongFormat.get_format_list():
self.addFileSelectItem()
2011-01-13 17:55:29 +00:00
self.sourceLayout.addLayout(self.formatStack)
self.addPage(self.sourcePage)
def retranslateUi(self):
2010-12-08 22:55:28 +00:00
"""
2011-01-13 17:55:29 +00:00
Song wizard localisation.
2010-12-08 22:55:28 +00:00
"""
2011-01-13 17:55:29 +00:00
self.setWindowTitle(
translate('SongsPlugin.ImportWizardForm', 'Song Import Wizard'))
self.titleLabel.setText(WizardStrings.HeaderStyle %
2011-02-16 03:06:34 +00:00
translate('OpenLP.Ui', 'Welcome to the Song Import Wizard'))
2011-01-13 17:55:29 +00:00
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.'))
2011-02-12 02:43:13 +00:00
self.sourcePage.setTitle(WizardStrings.ImportSelect)
self.sourcePage.setSubTitle(WizardStrings.ImportSelectLong)
self.formatLabel.setText(WizardStrings.FormatLabel)
2012-05-30 09:11:44 +00:00
for format in SongFormat.get_format_list():
format_name, custom_combo_text, select_mode = SongFormat.get(
format, SongFormat.Name, SongFormat.ComboBoxText,
SongFormat.SelectMode)
2012-05-30 09:11:44 +00:00
combo_box_text = custom_combo_text if custom_combo_text \
else format_name
self.formatComboBox.setItemText(format, combo_box_text)
if select_mode == SongFormatSelect.MultipleFiles:
self.formatWidgets[format][u'addButton'].setText(
translate('SongsPlugin.ImportWizardForm', 'Add Files...'))
self.formatWidgets[format][u'removeButton'].setText(
translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
else:
self.formatWidgets[format][u'browseButton'].setText(
UiStrings().Browse)
f_label = 'Filename:'
if select_mode == SongFormatSelect.SingleFolder:
2012-05-31 13:58:10 +00:00
f_label = 'Folder:'
self.formatWidgets[format][u'filepathLabel'].setText(
2012-05-30 09:11:44 +00:00
translate('SongsPlugin.ImportWizardForm', f_label))
for format in self.disablableFormats:
self.formatWidgets[format][u'disabledLabel'].setText(
SongFormat.get(format, SongFormat.DisabledLabelText))
2011-02-12 15:37:02 +00:00
self.progressPage.setTitle(WizardStrings.Importing)
2011-01-13 17:55:29 +00:00
self.progressPage.setSubTitle(
translate('SongsPlugin.ImportWizardForm',
'Please wait while your songs are imported.'))
2011-02-13 01:09:04 +00:00
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'))
2011-01-13 17:55:29 +00:00
# Align all QFormLayouts towards each other.
formats = filter(lambda f: u'filepathLabel' in self.formatWidgets[f],
SongFormat.get_format_list())
labels = [self.formatWidgets[f][u'filepathLabel'] for f in formats]
# Get max width of all labels
max_label_width = max(self.formatLabel.minimumSizeHint().width(),
max([label.minimumSizeHint().width() for label in labels]))
self.formatSpacer.changeSize(max_label_width, 0,
QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
spacers = [self.formatWidgets[f][u'filepathSpacer'] for f in formats]
for index, spacer in enumerate(spacers):
spacer.changeSize(
max_label_width - labels[index].minimumSizeHint().width(), 0,
QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
2010-12-08 22:55:28 +00:00
def customPageChanged(self, pageId):
"""
Called when changing to a page other than the progress page
"""
if self.page(pageId) == self.sourcePage:
self.onCurrentIndexChanged(self.formatStack.currentIndex())
2010-04-02 12:23:40 +00:00
def validateCurrentPage(self):
"""
Validate the current page before moving on to the next page.
Provides each song format class with a chance to validate its input by
overriding isValidSource().
2010-04-02 12:23:40 +00:00
"""
if self.currentPage() == self.welcomePage:
return True
elif self.currentPage() == self.sourcePage:
format = self.currentFormat
QtCore.QSettings().setValue(u'songs/last import type',
format)
select_mode, class_, error_msg = SongFormat.get(format,
SongFormat.SelectMode, SongFormat.Class,
SongFormat.InvalidSourceMsg)
if select_mode == SongFormatSelect.MultipleFiles:
import_source = self.getListOfFiles(
self.formatWidgets[format][u'fileListWidget'])
error_title = UiStrings().IFSp
focus_button = self.formatWidgets[format][u'addButton']
else:
import_source = \
self.formatWidgets[format][u'filepathEdit'].text()
error_title = UiStrings().IFSs if select_mode == \
SongFormatSelect.SingleFile else UiStrings().IFdSs
focus_button = self.formatWidgets[format][u'browseButton']
if not class_.isValidSource(import_source):
critical_error_message_box(error_title, error_msg)
focus_button.setFocus()
return False
return True
2011-01-13 17:55:29 +00:00
elif self.currentPage() == self.progressPage:
return True
2010-04-02 12:23:40 +00:00
2010-12-21 13:40:41 +00:00
def getFiles(self, title, listbox, filters=u''):
"""
Opens a QFileDialog and writes the filenames to the given listbox.
``title``
The title of the dialog (unicode).
``listbox``
A listbox (QListWidget).
``filters``
The file extension filters. It should contain the file descriptions
as well as the file extensions. For example::
2011-02-14 20:32:19 +00:00
u'SongBeamer Files (*.sng)'
2010-12-21 13:40:41 +00:00
"""
if filters:
filters += u';;'
filters += u'%s (*)' % UiStrings().AllFiles
2010-08-08 14:38:51 +00:00
filenames = QtGui.QFileDialog.getOpenFileNames(self, title,
2010-12-29 16:35:10 +00:00
SettingsManager.get_last_dir(self.plugin.settingsSection, 1),
filters)
2010-08-08 14:38:51 +00:00
if filenames:
listbox.addItems(filenames)
2011-02-16 03:06:34 +00:00
SettingsManager.set_last_dir(self.plugin.settingsSection,
2010-08-20 19:40:07 +00:00
os.path.split(unicode(filenames[0]))[0], 1)
2010-08-08 14:38:51 +00:00
def getListOfFiles(self, listbox):
2011-01-13 17:55:29 +00:00
"""
Return a list of file from the listbox
"""
return [unicode(listbox.item(i).text()) for i in range(listbox.count())]
2010-08-08 14:38:51 +00:00
def removeSelectedItems(self, listbox):
2011-01-13 17:55:29 +00:00
"""
Remove selected listbox items
"""
2010-08-08 14:38:51 +00:00
for item in listbox.selectedItems():
item = listbox.takeItem(listbox.row(item))
del item
def onBrowseButtonClicked(self):
format = self.currentFormat
select_mode, format_name, filter = SongFormat.get(format,
SongFormat.SelectMode, SongFormat.Name, SongFormat.Filter)
filepathEdit = self.formatWidgets[format][u'filepathEdit']
if select_mode == SongFormatSelect.SingleFile:
self.getFileName(WizardStrings.OpenTypeFile % format_name,
filepathEdit, filter)
elif select_mode == SongFormatSelect.SingleFolder:
self.getFolder(WizardStrings.OpenTypeFolder % format_name,
filepathEdit)
def onAddButtonClicked(self):
format = self.currentFormat
select_mode, format_name, filter, custom_title = SongFormat.get(format,
SongFormat.SelectMode, SongFormat.Name, SongFormat.Filter,
SongFormat.GetFilesTitle)
2012-05-30 09:11:44 +00:00
title = custom_title if custom_title \
else WizardStrings.OpenTypeFile % format_name
if select_mode == SongFormatSelect.MultipleFiles:
self.getFiles(title, self.formatWidgets[format][u'fileListWidget'],
2012-05-30 09:11:44 +00:00
filter)
self.sourcePage.emit(QtCore.SIGNAL(u'completeChanged()'))
def onRemoveButtonClicked(self):
self.removeSelectedItems(
self.formatWidgets[self.currentFormat][u'fileListWidget'])
self.sourcePage.emit(QtCore.SIGNAL(u'completeChanged()'))
def onFilepathEditTextChanged(self):
"""
Called when the content of the Filename/Folder edit box changes.
"""
self.sourcePage.emit(QtCore.SIGNAL(u'completeChanged()'))
2010-04-02 20:03:51 +00:00
def setDefaults(self):
2011-01-13 17:55:29 +00:00
"""
Set default form values for the song import wizard.
"""
self.restart()
self.finishButton.setVisible(False)
self.cancelButton.setVisible(True)
last_import_type = QtCore.QSettings().value(
u'songs/last import type').toInt()[0]
if last_import_type < 0 or \
last_import_type >= self.formatComboBox.count():
last_import_type = 0
self.formatComboBox.setCurrentIndex(last_import_type)
2012-05-30 09:11:44 +00:00
for format in SongFormat.get_format_list():
select_mode = SongFormat.get(format, SongFormat.SelectMode)
if select_mode == SongFormatSelect.MultipleFiles:
self.formatWidgets[format][u'fileListWidget'].clear()
else:
self.formatWidgets[format][u'filepathEdit'].setText(u'')
self.errorReportTextEdit.clear()
self.errorReportTextEdit.setHidden(True)
self.errorCopyToButton.setHidden(True)
self.errorSaveToButton.setHidden(True)
2010-04-02 12:23:40 +00:00
2011-01-13 17:55:29 +00:00
def preWizard(self):
"""
Perform pre import tasks
"""
OpenLPWizard.preWizard(self)
2011-02-13 01:09:04 +00:00
self.progressLabel.setText(WizardStrings.StartingImport)
Receiver.send_message(u'openlp_process_events')
2010-04-02 12:23:40 +00:00
2011-01-13 17:55:29 +00:00
def performWizard(self):
"""
Perform the actual import. This method pulls in the correct importer
class, and then runs the ``doImport`` method of the importer to do
the actual importing.
"""
source_format = self.currentFormat
select_mode = SongFormat.get(source_format, SongFormat.SelectMode)
if select_mode == SongFormatSelect.SingleFile:
importer = self.plugin.importSongs(source_format, filename=unicode(
self.formatWidgets[source_format][u'filepathEdit'].text()))
elif select_mode == SongFormatSelect.SingleFolder:
importer = self.plugin.importSongs(source_format, folder=unicode(
self.formatWidgets[source_format][u'filepathEdit'].text()))
else:
importer = self.plugin.importSongs(source_format,
filenames=self.getListOfFiles(
self.formatWidgets[source_format][u'fileListWidget']))
importer.doImport()
self.progressLabel.setText(WizardStrings.FinishedImport)
2010-04-02 12:23:40 +00:00
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
2011-06-01 05:42:56 +00:00
report_file = codecs.open(filename, u'w', u'utf-8')
report_file.write(self.errorReportTextEdit.toPlainText())
report_file.close()
def addFileSelectItem(self):
format = self.currentFormat
prefix, can_disable, select_mode = SongFormat.get(format,
SongFormat.Prefix, SongFormat.CanDisable, SongFormat.SelectMode)
2011-01-13 17:55:29 +00:00
page = QtGui.QWidget()
page.setObjectName(prefix + u'Page')
2011-01-13 17:55:29 +00:00
if can_disable:
importWidget = self.disablableWidget(page, prefix)
2011-01-13 17:55:29 +00:00
else:
importWidget = page
importLayout = QtGui.QVBoxLayout(importWidget)
importLayout.setMargin(0)
importLayout.setObjectName(prefix + u'ImportLayout')
if select_mode == SongFormatSelect.SingleFile or \
select_mode == SongFormatSelect.SingleFolder:
filepathLayout = QtGui.QHBoxLayout()
filepathLayout.setObjectName(prefix + u'FilepathLayout')
filepathLabel = QtGui.QLabel(importWidget)
filepathLabel.setObjectName(prefix + u'FilepathLabel')
filepathLayout.addWidget(filepathLabel)
filepathSpacer = QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Fixed,
QtGui.QSizePolicy.Fixed)
filepathLayout.addSpacerItem(filepathSpacer)
filepathEdit = QtGui.QLineEdit(importWidget)
filepathEdit.setObjectName(prefix + u'FilepathEdit')
filepathLayout.addWidget(filepathEdit)
2011-02-02 03:32:25 +00:00
browseButton = QtGui.QToolButton(importWidget)
browseButton.setIcon(self.openIcon)
browseButton.setObjectName(prefix + u'BrowseButton')
filepathLayout.addWidget(browseButton)
importLayout.addLayout(filepathLayout)
2011-02-03 20:12:06 +00:00
importLayout.addSpacerItem(self.stackSpacer)
2012-05-30 09:11:44 +00:00
self.formatWidgets[format][u'filepathLabel'] = filepathLabel
self.formatWidgets[format][u'filepathSpacer'] = filepathSpacer
2012-05-30 09:11:44 +00:00
self.formatWidgets[format][u'filepathLayout'] = filepathLayout
self.formatWidgets[format][u'filepathEdit'] = filepathEdit
self.formatWidgets[format][u'browseButton'] = browseButton
elif select_mode == SongFormatSelect.MultipleFiles:
2011-02-02 03:32:25 +00:00
fileListWidget = QtGui.QListWidget(importWidget)
fileListWidget.setSelectionMode(
QtGui.QAbstractItemView.ExtendedSelection)
fileListWidget.setObjectName(prefix + u'FileListWidget')
2011-02-02 03:32:25 +00:00
importLayout.addWidget(fileListWidget)
buttonLayout = QtGui.QHBoxLayout()
buttonLayout.setObjectName(prefix + u'ButtonLayout')
2011-02-02 03:32:25 +00:00
addButton = QtGui.QPushButton(importWidget)
addButton.setIcon(self.openIcon)
addButton.setObjectName(prefix + u'AddButton')
2011-02-02 03:32:25 +00:00
buttonLayout.addWidget(addButton)
buttonLayout.addStretch()
removeButton = QtGui.QPushButton(importWidget)
removeButton.setIcon(self.deleteIcon)
removeButton.setObjectName(prefix + u'RemoveButton')
2011-02-02 03:32:25 +00:00
buttonLayout.addWidget(removeButton)
importLayout.addLayout(buttonLayout)
self.formatWidgets[format][u'fileListWidget'] = fileListWidget
2012-05-30 09:11:44 +00:00
self.formatWidgets[format][u'buttonLayout'] = buttonLayout
self.formatWidgets[format][u'addButton'] = addButton
self.formatWidgets[format][u'removeButton'] = removeButton
2012-05-30 09:11:44 +00:00
self.formatStack.addWidget(page)
self.formatWidgets[format][u'page'] = page
self.formatWidgets[format][u'importLayout'] = importLayout
2011-01-13 17:55:29 +00:00
self.formatComboBox.addItem(u'')
def disablableWidget(self, page, prefix):
format = self.currentFormat
self.disablableFormats.append(format)
2011-01-13 17:55:29 +00:00
layout = QtGui.QVBoxLayout(page)
layout.setMargin(0)
layout.setSpacing(0)
layout.setObjectName(prefix + u'Layout')
2011-01-13 17:55:29 +00:00
disabledWidget = QtGui.QWidget(page)
disabledWidget.setVisible(False)
disabledWidget.setObjectName(prefix + u'DisabledWidget')
2011-01-13 17:55:29 +00:00
disabledLayout = QtGui.QVBoxLayout(disabledWidget)
disabledLayout.setMargin(0)
disabledLayout.setObjectName(prefix + u'DisabledLayout')
2011-01-13 17:55:29 +00:00
disabledLabel = QtGui.QLabel(disabledWidget)
disabledLabel.setWordWrap(True)
disabledLabel.setObjectName(prefix + u'DisabledLabel')
2011-01-13 17:55:29 +00:00
disabledLayout.addWidget(disabledLabel)
2011-02-03 20:12:06 +00:00
disabledLayout.addSpacerItem(self.stackSpacer)
2011-01-13 17:55:29 +00:00
layout.addWidget(disabledWidget)
importWidget = QtGui.QWidget(page)
importWidget.setObjectName(prefix + u'ImportWidget')
2011-01-13 17:55:29 +00:00
layout.addWidget(importWidget)
2012-05-30 09:11:44 +00:00
self.formatWidgets[format][u'layout'] = layout
self.formatWidgets[format][u'disabledWidget'] = disabledWidget
2012-05-30 09:11:44 +00:00
self.formatWidgets[format][u'disabledLayout'] = disabledLayout
self.formatWidgets[format][u'disabledLabel'] = disabledLabel
self.formatWidgets[format][u'importWidget'] = importWidget
2011-04-17 15:47:02 +00:00
return importWidget
class SongImportSourcePage(QtGui.QWizardPage):
"""
Subclass QtGui.QWizardPage in order to reimplement isComplete().
"""
def isComplete(self):
"""
Returns True if:
* an available format is selected, and
* if MultipleFiles mode, at least one file is selected
* or if SingleFile mode, the specified file exists
* or if SingleFolder mode, the specified folder exists
When this method returns True, the wizard's Next button is enabled.
"""
wizard = self.wizard()
format = wizard.currentFormat
select_mode, format_available = SongFormat.get(format,
SongFormat.SelectMode, SongFormat.Availability)
if format_available:
if select_mode == SongFormatSelect.MultipleFiles:
if wizard.formatWidgets[format][u'fileListWidget'].count() > 0:
return True
else:
filepath = wizard.formatWidgets[format][u'filepathEdit'].text()
if not filepath.isEmpty():
2012-06-05 14:14:50 +00:00
if select_mode == SongFormatSelect.SingleFile \
and os.path.isfile(filepath):
return True
2012-06-05 14:14:50 +00:00
elif select_mode == SongFormatSelect.SingleFolder \
and os.path.isdir(filepath):
return True
2012-05-31 12:45:00 +00:00
return False