Merge refactor-song-import r1994

This commit is contained in:
Samuel Findlay 2012-06-07 00:55:42 +10:00
commit 837fc1c726
2 changed files with 47 additions and 29 deletions

View File

@ -217,8 +217,7 @@ class SongImportForm(OpenLPWizard):
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
Provide each song format class with a chance to validate its input by
overriding isValidSource().
"""
if self.currentPage() == self.welcomePage:
@ -491,16 +490,16 @@ class SongImportForm(OpenLPWizard):
class SongImportSourcePage(QtGui.QWizardPage):
"""
Subclass QtGui.QWizardPage in order to reimplement isComplete().
Subclass of QtGui.QWizardPage to override isComplete() for Source Page.
"""
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
Return 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.
"""

View File

@ -80,28 +80,47 @@ class SongFormat(object):
song formats handled by the importer, the attributes of each song format,
and a few helper functions.
Required attributes for each song format:
* ``Class`` Import class, e.g. OpenLyricsImport
* ``Name`` Name of the format, e.g. u'OpenLyrics'
* ``Prefix`` Prefix for Qt objects. Use camelCase, e.g. u'openLyrics'
See ``SongImportForm.addFileSelectItem()``.
``Class``
Import class, e.g. ``OpenLyricsImport``
``Name``
Name of the format, e.g. ``u'OpenLyrics'``
``Prefix``
Prefix for Qt objects. Use mixedCase, e.g. ``u'openLyrics'``
See ``SongImportForm.addFileSelectItem()``
Optional attributes for each song format:
* ``CanDisable`` Whether song format importer is disablable.
* ``Availability`` Whether song format importer is available.
* ``SelectMode`` Whether format accepts single file, multiple files, or
single folder (as per SongFormatSelect options).
* ``Filter`` File extension filter for QFileDialog.
Optional/custom text Strings for SongImportForm widgets:
* ``ComboBoxText`` Combo box selector (default value is format Name).
* ``DisabledLabelText`` Required for disablable song formats.
* ``GetFilesTitle`` Title for QFileDialog (default includes format Name).
* ``InvalidSourceMsg`` Message displayed when source does not validate with
Class.isValidSource().
``CanDisable``
Whether song format importer is disablable.
``Availability``
Whether song format importer is available.
``SelectMode``
Whether format accepts single file, multiple files, or single folder
(as per ``SongFormatSelect`` options).
``Filter``
File extension filter for ``QFileDialog``.
Optional/custom text Strings for ``SongImportForm`` widgets:
``ComboBoxText``
Combo box selector (default value is the format's ``Name``).
``DisabledLabelText``
Required for disablable song formats.
``GetFilesTitle``
Title for ``QFileDialog`` (default includes the format's ``Name``).
``InvalidSourceMsg``
Message displayed if ``Class.isValidSource()`` returns ``False``.
"""
# Song Formats
# Enumeration of song formats and their attributes
# * Numerical order of song formats is significant as it determines the
# order used by formatComboBox.
# * Attribute ints are negative so they don't clash with song format ints.
# * Each group of attribute values increments by 10 to facilitate addition
# of more attributes in future.
# Song formats (ordered alphabetically after Generic)
Unknown = -1
OpenLyrics = 0
OpenLP2 = 1
@ -320,9 +339,9 @@ class SongFormat(object):
Zero or more song format attributes from SongFormat.
Return type depends on number of supplied attributes:
* 0 : Return dict containing all defined attributes for the format.
* 1 : Return the attribute value.
* >1 : Return tuple of requested attribute values.
:0: Return dict containing all defined attributes for the format.
:1: Return the attribute value.
:>1: Return tuple of requested attribute values.
"""
if not attributes:
return SongFormat._attributes.get(format)