diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index b13056b32..08246a544 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -87,7 +87,7 @@ class SongImportForm(OpenLPWizard): Song wizard specific initialisation. """ for format in SongFormat.get_format_list(): - if not SongFormat.get(format, SongFormat.Availability): + if not SongFormat.get(format, u'availability'): self.formatWidgets[format][u'disabledWidget'].setVisible(True) self.formatWidgets[format][u'importWidget'].setVisible(False) @@ -96,7 +96,7 @@ class SongImportForm(OpenLPWizard): Song wizard specific signals. """ for format in SongFormat.get_format_list(): - select_mode = SongFormat.get(format, SongFormat.SelectMode) + select_mode = SongFormat.get(format, u'selectMode') if select_mode == SongFormatSelect.MultipleFiles: QtCore.QObject.connect(self.formatWidgets[format][u'addButton'], QtCore.SIGNAL(u'clicked()'), self.onAddButtonClicked) @@ -161,8 +161,7 @@ class SongImportForm(OpenLPWizard): self.formatLabel.setText(WizardStrings.FormatLabel) for format in SongFormat.get_format_list(): format_name, custom_combo_text, select_mode = SongFormat.get( - format, SongFormat.Name, SongFormat.ComboBoxText, - SongFormat.SelectMode) + format, u'name', u'comboBoxText', u'selectMode') combo_box_text = custom_combo_text if custom_combo_text \ else format_name self.formatComboBox.setItemText(format, combo_box_text) @@ -181,7 +180,7 @@ class SongImportForm(OpenLPWizard): translate('SongsPlugin.ImportWizardForm', f_label)) for format in self.disablableFormats: self.formatWidgets[format][u'disabledLabel'].setText( - SongFormat.get(format, SongFormat.DisabledLabelText)) + SongFormat.get(format, u'disabledLabelText')) self.progressPage.setTitle(WizardStrings.Importing) self.progressPage.setSubTitle( translate('SongsPlugin.ImportWizardForm', @@ -227,8 +226,7 @@ class SongImportForm(OpenLPWizard): QtCore.QSettings().setValue(u'songs/last import type', format) select_mode, class_, error_msg = SongFormat.get(format, - SongFormat.SelectMode, SongFormat.Class, - SongFormat.InvalidSourceMsg) + u'selectMode', u'class', u'invalidSourceMsg') if select_mode == SongFormatSelect.MultipleFiles: import_source = self.getListOfFiles( self.formatWidgets[format][u'fileListWidget']) @@ -291,8 +289,8 @@ class SongImportForm(OpenLPWizard): def onBrowseButtonClicked(self): format = self.currentFormat - select_mode, format_name, filter = SongFormat.get(format, - SongFormat.SelectMode, SongFormat.Name, SongFormat.Filter) + select_mode, format_name, filter = SongFormat.get(format, u'selectMode', + u'name', u'filter') filepathEdit = self.formatWidgets[format][u'filepathEdit'] if select_mode == SongFormatSelect.SingleFile: self.getFileName(WizardStrings.OpenTypeFile % format_name, @@ -304,8 +302,8 @@ class SongImportForm(OpenLPWizard): def onAddButtonClicked(self): format = self.currentFormat select_mode, format_name, filter, custom_title = SongFormat.get(format, - SongFormat.SelectMode, SongFormat.Name, SongFormat.Filter, - SongFormat.GetFilesTitle) + u'selectMode', u'name', u'filter', + u'getFilesTitle') title = custom_title if custom_title \ else WizardStrings.OpenTypeFile % format_name if select_mode == SongFormatSelect.MultipleFiles: @@ -338,7 +336,7 @@ class SongImportForm(OpenLPWizard): last_import_type = 0 self.formatComboBox.setCurrentIndex(last_import_type) for format in SongFormat.get_format_list(): - select_mode = SongFormat.get(format, SongFormat.SelectMode) + select_mode = SongFormat.get(format, u'selectMode') if select_mode == SongFormatSelect.MultipleFiles: self.formatWidgets[format][u'fileListWidget'].clear() else: @@ -363,7 +361,7 @@ class SongImportForm(OpenLPWizard): the actual importing. """ source_format = self.currentFormat - select_mode = SongFormat.get(source_format, SongFormat.SelectMode) + select_mode = SongFormat.get(source_format, u'selectMode') if select_mode == SongFormatSelect.SingleFile: importer = self.plugin.importSongs(source_format, filename=unicode( self.formatWidgets[source_format][u'filepathEdit'].text())) @@ -397,8 +395,8 @@ class SongImportForm(OpenLPWizard): def addFileSelectItem(self): format = self.currentFormat - prefix, can_disable, select_mode = SongFormat.get(format, - SongFormat.Prefix, SongFormat.CanDisable, SongFormat.SelectMode) + prefix, can_disable, select_mode = SongFormat.get(format, u'prefix', + u'canDisable', u'selectMode') page = QtGui.QWidget() page.setObjectName(prefix + u'Page') if can_disable: @@ -505,8 +503,8 @@ class SongImportSourcePage(QtGui.QWizardPage): """ wizard = self.wizard() format = wizard.currentFormat - select_mode, format_available = SongFormat.get(format, - SongFormat.SelectMode, SongFormat.Availability) + select_mode, format_available = SongFormat.get(format, u'selectMode', + u'availability') if format_available: if select_mode == SongFormatSelect.MultipleFiles: if wizard.formatWidgets[format][u'fileListWidget'].count() > 0: diff --git a/openlp/plugins/songs/lib/importer.py b/openlp/plugins/songs/lib/importer.py index 11169813b..870a65e60 100644 --- a/openlp/plugins/songs/lib/importer.py +++ b/openlp/plugins/songs/lib/importer.py @@ -81,45 +81,40 @@ class SongFormat(object): Required attributes for each song format: - ``Class`` + ``u'class'`` Import class, e.g. ``OpenLyricsImport`` - ``Name`` + ``u'name'`` Name of the format, e.g. ``u'OpenLyrics'`` - ``Prefix`` + ``u'prefix'`` Prefix for Qt objects. Use mixedCase, e.g. ``u'openLyrics'`` See ``SongImportForm.addFileSelectItem()`` Optional attributes for each song format: - ``CanDisable`` + ``u'canDisable'`` Whether song format importer is disablable. - ``Availability`` + ``u'availability'`` Whether song format importer is available. - ``SelectMode`` + ``u'selectMode'`` Whether format accepts single file, multiple files, or single folder (as per ``SongFormatSelect`` options). - ``Filter`` + ``u'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`` + ``u'comboBoxText'`` + Combo box selector (default value is the format's ``u'name'``). + ``u'disabledLabelText'`` Required for disablable song formats. - ``GetFilesTitle`` - Title for ``QFileDialog`` (default includes the format's ``Name``). - ``InvalidSourceMsg`` - Message displayed if ``Class.isValidSource()`` returns ``False``. + ``u'getFilesTitle'`` + Title for ``QFileDialog`` (default includes the format's ``u'name'``). + ``u'invalidSourceMsg'`` + Message displayed if ``isValidSource()`` returns ``False``. """ - # Enumeration of song formats and their attributes + # Song formats (ordered alphabetically after Generic) # * 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 @@ -138,158 +133,143 @@ class SongFormat(object): WordsOfWorship = 14 #CSV = 15 - # Required attributes - Class = -10 - Name = -11 - Prefix = -12 - # Optional attributes - CanDisable = -20 - Availability = -21 - SelectMode = -22 - Filter = -23 - # Optional/custom text values - ComboBoxText = -30 - DisabledLabelText = -31 - GetFilesTitle = -32 - InvalidSourceMsg = -33 - # Set optional attribute defaults - _defaults = { - CanDisable: False, - Availability: True, - SelectMode: SongFormatSelect.MultipleFiles, - Filter: u'', - ComboBoxText: None, - DisabledLabelText: u'', - GetFilesTitle: None, - InvalidSourceMsg: None + __defaults__ = { + u'canDisable': False, + u'availability': True, + u'selectMode': SongFormatSelect.MultipleFiles, + u'filter': u'', + u'comboBoxText': None, + u'disabledLabelText': u'', + u'getFilesTitle': None, + u'invalidSourceMsg': None } # Set attribute values for each Song Format - _attributes = { + __attributes__ = { OpenLyrics: { - Class: OpenLyricsImport, - Name: u'OpenLyrics', - Prefix: u'openLyrics', - Filter: u'%s (*.xml)' % translate('SongsPlugin.ImportWizardForm', + u'class': OpenLyricsImport, + u'name': u'OpenLyrics', + u'prefix': u'openLyrics', + u'filter': u'%s (*.xml)' % translate('SongsPlugin.ImportWizardForm', 'OpenLyrics Files'), - ComboBoxText: translate('SongsPlugin.ImportWizardForm', + u'comboBoxText': translate('SongsPlugin.ImportWizardForm', 'OpenLyrics or OpenLP 2.0 Exported Song') }, OpenLP2: { - Class: OpenLPSongImport, - Name: UiStrings().OLPV2, - Prefix: u'openLP2', - SelectMode: SongFormatSelect.SingleFile, - Filter: u'%s (*.sqlite)' % (translate( + u'class': OpenLPSongImport, + u'name': UiStrings().OLPV2, + u'prefix': u'openLP2', + u'selectMode': SongFormatSelect.SingleFile, + u'filter': u'%s (*.sqlite)' % (translate( 'SongsPlugin.ImportWizardForm', 'OpenLP 2.0 Databases')) }, OpenLP1: { - Name: UiStrings().OLPV1, - Prefix: u'openLP1', - CanDisable: True, - SelectMode: SongFormatSelect.SingleFile, - Filter: u'%s (*.olp)' % translate('SongsPlugin.ImportWizardForm', + u'name': UiStrings().OLPV1, + u'prefix': u'openLP1', + u'canDisable': True, + u'selectMode': SongFormatSelect.SingleFile, + u'filter': u'%s (*.olp)' % translate('SongsPlugin.ImportWizardForm', 'openlp.org v1.x Databases'), - DisabledLabelText: WizardStrings.NoSqlite + u'disabledLabelText': WizardStrings.NoSqlite }, Generic: { - Name: translate('SongsPlugin.ImportWizardForm', + u'name': translate('SongsPlugin.ImportWizardForm', 'Generic Document/Presentation'), - Prefix: u'generic', - CanDisable: True, - DisabledLabelText: translate('SongsPlugin.ImportWizardForm', + u'prefix': u'generic', + u'canDisable': True, + u'disabledLabelText': translate('SongsPlugin.ImportWizardForm', 'The generic document/presentation importer has been disabled ' 'because OpenLP cannot access OpenOffice or LibreOffice.'), - GetFilesTitle: translate('SongsPlugin.ImportWizardForm', + u'getFilesTitle': translate('SongsPlugin.ImportWizardForm', 'Select Document/Presentation Files') }, CCLI: { - Class: CCLIFileImport, - Name: u'CCLI/SongSelect', - Prefix: u'ccli', - Filter: u'%s (*.usr *.txt)' % translate( + u'class': CCLIFileImport, + u'name': u'CCLI/SongSelect', + u'prefix': u'ccli', + u'filter': u'%s (*.usr *.txt)' % translate( 'SongsPlugin.ImportWizardForm', 'CCLI SongSelect Files') }, DreamBeam: { - Class: DreamBeamImport, - Name: u'DreamBeam', - Prefix: u'dreamBeam', - Filter: u'%s (*.xml)' % translate('SongsPlugin.ImportWizardForm', + u'class': DreamBeamImport, + u'name': u'DreamBeam', + u'prefix': u'dreamBeam', + u'filter': u'%s (*.xml)' % translate('SongsPlugin.ImportWizardForm', 'DreamBeam Song Files') }, EasySlides: { - Class: EasySlidesImport, - Name: u'EasySlides', - Prefix: u'easySlides', - SelectMode: SongFormatSelect.SingleFile, - Filter: u'%s (*.xml)' % translate('SongsPlugin.ImportWizardForm', + u'class': EasySlidesImport, + u'name': u'EasySlides', + u'prefix': u'easySlides', + u'selectMode': SongFormatSelect.SingleFile, + u'filter': u'%s (*.xml)' % translate('SongsPlugin.ImportWizardForm', 'EasySlides XML File') }, EasyWorship: { - Class: EasyWorshipSongImport, - Name: u'EasyWorship', - Prefix: u'ew', - SelectMode: SongFormatSelect.SingleFile, - Filter: u'%s (*.db)' % translate('SongsPlugin.ImportWizardForm', + u'class': EasyWorshipSongImport, + u'name': u'EasyWorship', + u'prefix': u'ew', + u'selectMode': SongFormatSelect.SingleFile, + u'filter': u'%s (*.db)' % translate('SongsPlugin.ImportWizardForm', 'EasyWorship Song Database') }, FoilPresenter: { - Class: FoilPresenterImport, - Name: u'Foilpresenter', - Prefix: u'foilPresenter', - Filter: u'%s (*.foil)' % translate('SongsPlugin.ImportWizardForm', - 'Foilpresenter Song Files') + u'class': FoilPresenterImport, + u'name': u'Foilpresenter', + u'prefix': u'foilPresenter', + u'filter': u'%s (*.foil)' % translate( + 'SongsPlugin.ImportWizardForm', 'Foilpresenter Song Files') }, OpenSong: { - Class: OpenSongImport, - Name: WizardStrings.OS, - Prefix: u'openSong' + u'class': OpenSongImport, + u'name': WizardStrings.OS, + u'prefix': u'openSong' }, PowerSong: { - Class: PowerSongImport, - Name: u'PowerSong 1.0', - Prefix: u'powerSong', - SelectMode: SongFormatSelect.SingleFolder, - InvalidSourceMsg: translate('SongsPlugin.ImportWizardForm', + u'class': PowerSongImport, + u'name': u'PowerSong 1.0', + u'prefix': u'powerSong', + u'selectMode': SongFormatSelect.SingleFolder, + u'invalidSourceMsg': translate('SongsPlugin.ImportWizardForm', 'You need to specify a valid PowerSong 1.0 database folder.') }, SongBeamer: { - Class: SongBeamerImport, - Name: u'SongBeamer', - Prefix: u'songBeamer', - Filter: u'%s (*.sng)' % translate('SongsPlugin.ImportWizardForm', + u'class': SongBeamerImport, + u'name': u'SongBeamer', + u'prefix': u'songBeamer', + u'filter': u'%s (*.sng)' % translate('SongsPlugin.ImportWizardForm', 'SongBeamer Files') }, SongShowPlus: { - Class: SongShowPlusImport, - Name: u'SongShow Plus', - Prefix: u'songShowPlus', - Filter: u'%s (*.sbsong)' % translate('SongsPlugin.ImportWizardForm', - 'SongShow Plus Song Files') + u'class': SongShowPlusImport, + u'name': u'SongShow Plus', + u'prefix': u'songShowPlus', + u'filter': u'%s (*.sbsong)' % translate( + 'SongsPlugin.ImportWizardForm', 'SongShow Plus Song Files') }, SongsOfFellowship: { - Name: u'Songs of Fellowship', - Prefix: u'songsOfFellowship', - CanDisable: True, - Filter: u'%s (*.rtf)' % translate('SongsPlugin.ImportWizardForm', + u'name': u'Songs of Fellowship', + u'prefix': u'songsOfFellowship', + u'canDisable': True, + u'filter': u'%s (*.rtf)' % translate('SongsPlugin.ImportWizardForm', 'Songs Of Fellowship Song Files'), - DisabledLabelText: translate('SongsPlugin.ImportWizardForm', + u'disabledLabelText': translate('SongsPlugin.ImportWizardForm', 'The Songs of Fellowship importer has been disabled because ' 'OpenLP cannot access OpenOffice or LibreOffice.') }, WordsOfWorship: { - Class: WowImport, - Name: u'Words of Worship', - Prefix: u'wordsOfWorship', - Filter: u'%s (*.wsg *.wow-song)' % translate( + u'class': WowImport, + u'name': u'Words of Worship', + u'prefix': u'wordsOfWorship', + u'filter': u'%s (*.wsg *.wow-song)' % translate( 'SongsPlugin.ImportWizardForm', 'Words Of Worship Song Files') # }, # CSV: { -# class_: CSVImport, -# name: WizardStrings.CSV, -# prefix: u'csv', -# select_mode: SongFormatSelect.SingleFile +# u'class': CSVImport, +# u'name': WizardStrings.CSV, +# u'prefix': u'csv', +# u'selectMode': SongFormatSelect.SingleFile } } @@ -333,16 +313,16 @@ class SongFormat(object): :>1: Return tuple of requested attribute values. """ if not attributes: - return SongFormat._attributes.get(format) + return SongFormat.__attributes__.get(format) elif len(attributes) == 1: - default = SongFormat._defaults.get(attributes[0]) - return SongFormat._attributes[format].get(attributes[0], + default = SongFormat.__defaults__.get(attributes[0]) + return SongFormat.__attributes__[format].get(attributes[0], default) else: values = [] for attr in attributes: - default = SongFormat._defaults.get(attr) - values.append(SongFormat._attributes[format].get(attr, + default = SongFormat.__defaults__.get(attr) + values.append(SongFormat.__attributes__[format].get(attr, default)) return tuple(values) @@ -351,16 +331,16 @@ class SongFormat(object): """ Set specified song format attribute to the supplied value. """ - SongFormat._attributes[format][attribute] = value + SongFormat.__attributes__[format][attribute] = value -SongFormat.set(SongFormat.OpenLP1, SongFormat.Availability, HAS_OPENLP1) +SongFormat.set(SongFormat.OpenLP1, u'availability', HAS_OPENLP1) if HAS_OPENLP1: - SongFormat.set(SongFormat.OpenLP1, SongFormat.Class, OpenLP1SongImport) -SongFormat.set(SongFormat.SongsOfFellowship, SongFormat.Availability, HAS_SOF) + SongFormat.set(SongFormat.OpenLP1, u'class', OpenLP1SongImport) +SongFormat.set(SongFormat.SongsOfFellowship, u'availability', HAS_SOF) if HAS_SOF: - SongFormat.set(SongFormat.SongsOfFellowship, SongFormat.Class, SofImport) -SongFormat.set(SongFormat.Generic, SongFormat.Availability, HAS_OOO) + SongFormat.set(SongFormat.SongsOfFellowship, u'class', SofImport) +SongFormat.set(SongFormat.Generic, u'availability', HAS_OOO) if HAS_OOO: - SongFormat.set(SongFormat.Generic, SongFormat.Class, OooImport) + SongFormat.set(SongFormat.Generic, u'class', OooImport) __all__ = [u'SongFormat', u'SongFormatSelect'] diff --git a/openlp/plugins/songs/lib/powersongimport.py b/openlp/plugins/songs/lib/powersongimport.py index d22d2a26b..d3ac766f9 100644 --- a/openlp/plugins/songs/lib/powersongimport.py +++ b/openlp/plugins/songs/lib/powersongimport.py @@ -88,7 +88,7 @@ class PowerSongImport(SongImport): Receive either a list of files or a folder (unicode) to import. """ from importer import SongFormat - PS_string = SongFormat.get(SongFormat.PowerSong, SongFormat.Name) + PS_string = SongFormat.get(SongFormat.PowerSong, u'name') if isinstance(self.importSource, unicode): if os.path.isdir(self.importSource): dir = self.importSource diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index cff68f83e..d7b36414a 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -194,7 +194,7 @@ class SongsPlugin(Plugin): self.manager.save_object(song) def importSongs(self, format, **kwargs): - class_ = SongFormat.get(format, SongFormat.Class) + class_ = SongFormat.get(format, u'class') importer = class_(self.manager, **kwargs) importer.register(self.mediaItem.importWizard) return importer