Exemple #1
0
 def custom_init(self):
     """
     Song wizard specific initialisation.
     """
     for song_format in SongFormat.get_format_list():
         if not SongFormat.get(song_format, 'availability'):
             self.format_widgets[song_format]['disabled_widget'].setVisible(True)
             self.format_widgets[song_format]['import_widget'].setVisible(False)
 def custom_init(self):
     """
     Song wizard specific initialisation.
     """
     for song_format in SongFormat.get_format_list():
         if not SongFormat.get(song_format, 'availability'):
             self.format_widgets[song_format]['disabled_widget'].setVisible(True)
             self.format_widgets[song_format]['import_widget'].setVisible(False)
Exemple #3
0
 def test_get_attributed_no_attributes(self):
     """
     Test that SongFormat.get(song_format) returns all attributes associated with the given song_format
     """
     # GIVEN: A SongFormat
     # WHEN: Retrieving all attributes of a SongFormat
     for song_format in SongFormat.get_format_list():
         # THEN: All attributes associated with the SongFormat should be returned
         assert SongFormat.get(song_format) == SongFormat.__attributes__[song_format], \
             "The returned attributes don't match the stored ones"
Exemple #4
0
 def test_get_attributed_multiple_attributes(self):
     """
     Test that multiple attributes can be retrieved for a song_format
     """
     # GIVEN: A SongFormat
     # WHEN: Retrieving multiple attributes at the same time
     for song_format in SongFormat.get_format_list():
         # THEN: Return all attributes that were specified
         assert len(SongFormat.get(song_format, 'canDisable', 'availability')) == 2, \
             "Did not return the correct number of attributes when retrieving multiple attributes at once"
Exemple #5
0
 def test_get_format_list_returns_ordered_list(self):
     """
     Test that get_format_list() returns a list that is ordered
     according to the order specified in SongFormat
     """
     # GIVEN: The SongFormat class
     # WHEN: Retrieving all formats
     # THEN: The returned list should be sorted according to the ordering defined in SongFormat
     assert sorted(SongFormat.get_format_list()) == SongFormat.get_format_list(), \
         "The list returned should be sorted according to the ordering in SongFormat"
Exemple #6
0
 def custom_signals(self):
     """
     Song wizard specific signals.
     """
     for song_format in SongFormat.get_format_list():
         select_mode = SongFormat.get(song_format, 'selectMode')
         if select_mode == SongFormatSelect.MultipleFiles:
             self.format_widgets[song_format]['addButton'].clicked.connect(self.on_add_button_clicked)
             self.format_widgets[song_format]['removeButton'].clicked.connect(self.on_remove_button_clicked)
         else:
             self.format_widgets[song_format]['path_edit'].pathChanged.connect(self.on_path_edit_path_changed)
 def custom_signals(self):
     """
     Song wizard specific signals.
     """
     for song_format in SongFormat.get_format_list():
         select_mode = SongFormat.get(song_format, 'selectMode')
         if select_mode == SongFormatSelect.MultipleFiles:
             self.format_widgets[song_format]['addButton'].clicked.connect(self.on_add_button_clicked)
             self.format_widgets[song_format]['removeButton'].clicked.connect(self.onRemoveButtonClicked)
         else:
             self.format_widgets[song_format]['browseButton'].clicked.connect(self.on_browse_button_clicked)
             self.format_widgets[song_format]['file_path_edit'].textChanged.connect(self.onFilepathEditTextChanged)
    def isComplete(self):
        """
        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.
        """
        wizard = self.wizard()
        this_format = wizard.current_format
        select_mode, format_available = SongFormat.get(this_format, 'selectMode', 'availability')
        if format_available:
            if select_mode == SongFormatSelect.MultipleFiles:
                if wizard.format_widgets[this_format]['file_list_widget'].count() > 0:
                    return True
            else:
                file_path = str(wizard.format_widgets[this_format]['file_path_edit'].text())
                if file_path:
                    if select_mode == SongFormatSelect.SingleFile and os.path.isfile(file_path):
                        return True
                    elif select_mode == SongFormatSelect.SingleFolder and os.path.isdir(file_path):
                        return True
        return False
Exemple #9
0
 def add_custom_pages(self):
     """
     Add song wizard specific pages.
     """
     # Source Page
     self.source_page = SongImportSourcePage()
     self.source_page.setObjectName('source_page')
     self.source_layout = QtWidgets.QVBoxLayout(self.source_page)
     self.source_layout.setObjectName('source_layout')
     self.format_layout = QtWidgets.QFormLayout()
     self.format_layout.setObjectName('format_layout')
     self.format_label = QtWidgets.QLabel(self.source_page)
     self.format_label.setObjectName('format_label')
     self.format_combo_box = QtWidgets.QComboBox(self.source_page)
     self.format_combo_box.setObjectName('format_combo_box')
     self.format_layout.addRow(self.format_label, self.format_combo_box)
     self.format_spacer = QtWidgets.QSpacerItem(10, 0, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Minimum)
     self.format_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.format_spacer)
     self.source_layout.addLayout(self.format_layout)
     self.format_h_spacing = self.format_layout.horizontalSpacing()
     self.format_v_spacing = self.format_layout.verticalSpacing()
     self.format_layout.setVerticalSpacing(0)
     self.stack_spacer = QtWidgets.QSpacerItem(10, 0, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Expanding)
     self.format_stack = QtWidgets.QStackedLayout()
     self.format_stack.setObjectName('format_stack')
     self.disablable_formats = []
     for self.current_format in SongFormat.get_format_list():
         self.add_file_select_item()
     self.source_layout.addLayout(self.format_stack)
     self.addPage(self.source_page)
Exemple #10
0
    def isComplete(self):
        """
        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.

        :rtype: bool
        """
        wizard = self.wizard()
        this_format = wizard.current_format
        select_mode, format_available = SongFormat.get(this_format, 'selectMode', 'availability')
        if format_available:
            if select_mode == SongFormatSelect.MultipleFiles:
                if wizard.format_widgets[this_format]['file_list_widget'].count() > 0:
                    return True
            else:
                file_path = wizard.format_widgets[this_format]['path_edit'].path
                if file_path:
                    if select_mode == SongFormatSelect.SingleFile and file_path.is_file():
                        return True
                    elif select_mode == SongFormatSelect.SingleFolder and file_path.is_dir():
                        return True
        return False
 def validateCurrentPage(self):
     """
     Re-implement the validateCurrentPage() method. Validate the current page before moving on to the next page.
     Provide each song format class with a chance to validate its input by overriding is_valid_source().
     """
     if self.currentPage() == self.welcome_page:
         return True
     elif self.currentPage() == self.source_page:
         this_format = self.current_format
         Settings().setValue('songs/last import type', this_format)
         select_mode, class_, error_msg = SongFormat.get(this_format, 'selectMode', 'class', 'invalidSourceMsg')
         if select_mode == SongFormatSelect.MultipleFiles:
             import_source = self.get_list_of_files(self.format_widgets[this_format]['file_list_widget'])
             error_title = UiStrings().IFSp
             focus_button = self.format_widgets[this_format]['addButton']
         else:
             import_source = self.format_widgets[this_format]['file_path_edit'].text()
             error_title = (UiStrings().IFSs if select_mode == SongFormatSelect.SingleFile else UiStrings().IFdSs)
             focus_button = self.format_widgets[this_format]['browseButton']
         if not class_.is_valid_source(import_source):
             critical_error_message_box(error_title, error_msg)
             focus_button.setFocus()
             return False
         return True
     elif self.currentPage() == self.progress_page:
         return True
Exemple #12
0
 def validateCurrentPage(self):
     """
     Re-implement the validateCurrentPage() method. Validate the current page before moving on to the next page.
     Provide each song format class with a chance to validate its input by overriding is_valid_source().
     """
     if self.currentPage() == self.welcome_page:
         return True
     elif self.currentPage() == self.source_page:
         this_format = self.current_format
         self.settings.setValue('songs/last import type', this_format)
         select_mode, class_, error_msg = SongFormat.get(this_format, 'selectMode', 'class', 'invalidSourceMsg')
         if select_mode == SongFormatSelect.MultipleFiles:
             import_source = self.get_list_of_paths(self.format_widgets[this_format]['file_list_widget'])
             error_title = UiStrings().IFSp
             focus_button = self.format_widgets[this_format]['addButton']
         else:
             import_source = self.format_widgets[this_format]['path_edit'].path
             error_title = (UiStrings().IFSs if select_mode == SongFormatSelect.SingleFile else UiStrings().IFdSs)
             focus_button = self.format_widgets[this_format]['path_edit']
         if not class_.is_valid_source(import_source):
             critical_error_message_box(error_title, error_msg)
             focus_button.setFocus()
             return False
         return True
     elif self.currentPage() == self.progress_page:
         return True
 def add_custom_pages(self):
     """
     Add song wizard specific pages.
     """
     # Source Page
     self.source_page = SongImportSourcePage()
     self.source_page.setObjectName('source_page')
     self.source_layout = QtGui.QVBoxLayout(self.source_page)
     self.source_layout.setObjectName('source_layout')
     self.format_layout = QtGui.QFormLayout()
     self.format_layout.setObjectName('format_layout')
     self.format_label = QtGui.QLabel(self.source_page)
     self.format_label.setObjectName('format_label')
     self.format_combo_box = QtGui.QComboBox(self.source_page)
     self.format_combo_box.setObjectName('format_combo_box')
     self.format_layout.addRow(self.format_label, self.format_combo_box)
     self.format_spacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum)
     self.format_layout.setItem(1, QtGui.QFormLayout.LabelRole, self.format_spacer)
     self.source_layout.addLayout(self.format_layout)
     self.format_h_spacing = self.format_layout.horizontalSpacing()
     self.format_v_spacing = self.format_layout.verticalSpacing()
     self.format_layout.setVerticalSpacing(0)
     self.stack_spacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Expanding)
     self.format_stack = QtGui.QStackedLayout()
     self.format_stack.setObjectName('format_stack')
     self.disablable_formats = []
     for self.current_format in SongFormat.get_format_list():
         self.add_file_select_item()
     self.source_layout.addLayout(self.format_stack)
     self.addPage(self.source_page)
Exemple #14
0
 def setup_ui(self, image):
     """
     Set up the song wizard UI.
     """
     self.format_widgets = dict([(song_format, {}) for song_format in SongFormat.get_format_list()])
     super(SongImportForm, self).setup_ui(image)
     self.current_format = SongFormat.OpenLyrics
     self.format_stack.setCurrentIndex(self.current_format)
     self.format_combo_box.currentIndexChanged.connect(self.on_current_index_changed)
 def setupUi(self, image):
     """
     Set up the song wizard UI.
     """
     self.format_widgets = dict([(song_format, {}) for song_format in SongFormat.get_format_list()])
     super(SongImportForm, self).setupUi(image)
     self.current_format = SongFormat.OpenLyrics
     self.format_stack.setCurrentIndex(self.current_format)
     self.format_combo_box.currentIndexChanged.connect(self.on_current_index_changed)
Exemple #16
0
 def test_get_format_list(self):
     """
     Test that get_format_list() returns all available formats
     """
     # GIVEN: The SongFormat class
     # WHEN: Retrieving the format list
     # THEN: All SongFormats should be returned
     assert len(SongFormat.get_format_list()) == len(SongFormat.__attributes__), \
         "The returned SongFormats don't match the stored ones"
Exemple #17
0
 def set_defaults(self):
     """
     Set default form values for the song import wizard.
     """
     self.restart()
     self.finish_button.setVisible(False)
     self.cancel_button.setVisible(True)
     last_import_type = self.settings.value('songs/last import type')
     if last_import_type < 0 or last_import_type >= self.format_combo_box.count():
         last_import_type = 0
     self.format_combo_box.setCurrentIndex(last_import_type)
     for format_list in SongFormat.get_format_list():
         select_mode = SongFormat.get(format_list, 'selectMode')
         if select_mode == SongFormatSelect.MultipleFiles:
             self.format_widgets[format_list]['file_list_widget'].clear()
     self.error_report_text_edit.clear()
     self.error_report_text_edit.setHidden(True)
     self.error_copy_to_button.setHidden(True)
     self.error_save_to_button.setHidden(True)
 def on_add_button_clicked(self):
     """
     Add a file or directory.
     """
     this_format = self.current_format
     select_mode, format_name, ext_filter, custom_title = \
         SongFormat.get(this_format, 'selectMode', 'name', 'filter', 'getFilesTitle')
     title = custom_title if custom_title else WizardStrings.OpenTypeFile % format_name
     if select_mode == SongFormatSelect.MultipleFiles:
         self.get_files(title, self.format_widgets[this_format]['file_list_widget'], ext_filter)
         self.source_page.emit(QtCore.SIGNAL('completeChanged()'))
Exemple #19
0
 def on_add_button_clicked(self):
     """
     Add a file or directory.
     """
     this_format = self.current_format
     select_mode, format_name, ext_filter, custom_title = \
         SongFormat.get(this_format, 'selectMode', 'name', 'filter', 'getFilesTitle')
     title = custom_title if custom_title else WizardStrings.OpenTypeFile.format(file_type=format_name)
     if select_mode == SongFormatSelect.MultipleFiles:
         self.get_files(title, self.format_widgets[this_format]['file_list_widget'], ext_filter)
         self.source_page.completeChanged.emit()
Exemple #20
0
    def import_songs(self, import_format, **kwargs):
        """
        Add the correct importer class

        :param import_format: The import_format to be used
        :param kwargs: The arguments
        :return: the correct importer
        """
        class_ = SongFormat.get(import_format, 'class')
        importer = class_(self.manager, **kwargs)
        importer.register(self.media_item.import_wizard)
        return importer
 def set_defaults(self):
     """
     Set default form values for the song import wizard.
     """
     self.restart()
     self.finish_button.setVisible(False)
     self.cancel_button.setVisible(True)
     last_import_type = Settings().value('songs/last import type')
     if last_import_type < 0 or last_import_type >= self.format_combo_box.count():
         last_import_type = 0
     self.format_combo_box.setCurrentIndex(last_import_type)
     for format_list in SongFormat.get_format_list():
         select_mode = SongFormat.get(format_list, 'selectMode')
         if select_mode == SongFormatSelect.MultipleFiles:
             self.format_widgets[format_list]['file_list_widget'].clear()
         else:
             self.format_widgets[format_list]['file_path_edit'].setText('')
     self.error_report_text_edit.clear()
     self.error_report_text_edit.setHidden(True)
     self.error_copy_to_button.setHidden(True)
     self.error_save_to_button.setHidden(True)
Exemple #22
0
    def import_songs(self, import_format, **kwargs):
        """
        Add the correct importer class

        :param import_format: The import_format to be used
        :param kwargs: The arguments
        :return: the correct importer
        """
        class_ = SongFormat.get(import_format, 'class')
        importer = class_(self.manager, **kwargs)
        importer.register(self.media_item.import_wizard)
        return importer
 def on_browse_button_clicked(self):
     """
     Browse for files or a directory.
     """
     this_format = self.current_format
     select_mode, format_name, ext_filter = SongFormat.get(this_format, 'selectMode', 'name', 'filter')
     file_path_edit = self.format_widgets[this_format]['file_path_edit']
     if select_mode == SongFormatSelect.SingleFile:
         self.get_file_name(
             WizardStrings.OpenTypeFile % format_name, file_path_edit, 'last directory import', ext_filter)
     elif select_mode == SongFormatSelect.SingleFolder:
         self.get_folder(WizardStrings.OpenTypeFolder % format_name, file_path_edit, 'last directory import')
 def retranslateUi(self):
     """
     Song wizard localisation.
     """
     self.setWindowTitle(translate('SongsPlugin.ImportWizardForm', 'Song Import Wizard'))
     self.title_label.setText(WizardStrings.HeaderStyle % translate('OpenLP.Ui',
                                                                    'Welcome to the Song Import Wizard'))
     self.information_label.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.source_page.setTitle(WizardStrings.ImportSelect)
     self.source_page.setSubTitle(WizardStrings.ImportSelectLong)
     self.format_label.setText(WizardStrings.FormatLabel)
     for format_list in SongFormat.get_format_list():
         format_name, custom_combo_text, description_text, select_mode = \
             SongFormat.get(format_list, 'name', 'comboBoxText', 'descriptionText', 'selectMode')
         combo_box_text = (custom_combo_text if custom_combo_text else format_name)
         self.format_combo_box.setItemText(format_list, combo_box_text)
         if description_text is not None:
             self.format_widgets[format_list]['description_label'].setText(description_text)
         if select_mode == SongFormatSelect.MultipleFiles:
             self.format_widgets[format_list]['addButton'].setText(
                 translate('SongsPlugin.ImportWizardForm', 'Add Files...'))
             self.format_widgets[format_list]['removeButton'].setText(
                 translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
         else:
             self.format_widgets[format_list]['browseButton'].setText(UiStrings().Browse)
             f_label = 'Filename:'
             if select_mode == SongFormatSelect.SingleFolder:
                 f_label = 'Folder:'
             self.format_widgets[format_list]['filepathLabel'].setText(
                 translate('SongsPlugin.ImportWizardForm', f_label))
     for format_list in self.disablable_formats:
         self.format_widgets[format_list]['disabled_label'].setText(SongFormat.get(format_list, 'disabledLabelText'))
     self.progress_page.setTitle(WizardStrings.Importing)
     self.progress_page.setSubTitle(
         translate('SongsPlugin.ImportWizardForm', 'Please wait while your songs are imported.'))
     self.progress_label.setText(WizardStrings.Ready)
     self.progress_bar.setFormat(WizardStrings.PercentSymbolFormat)
     self.error_copy_to_button.setText(translate('SongsPlugin.ImportWizardForm', 'Copy'))
     self.error_save_to_button.setText(translate('SongsPlugin.ImportWizardForm', 'Save to File'))
     # Align all QFormLayouts towards each other.
     formats = [f for f in SongFormat.get_format_list() if 'filepathLabel' in self.format_widgets[f]]
     labels = [self.format_widgets[f]['filepathLabel'] for f in formats]
     # Get max width of all labels
     max_label_width = max(self.format_label.minimumSizeHint().width(),
                           max([label.minimumSizeHint().width() for label in labels]))
     self.format_spacer.changeSize(max_label_width, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
     spacers = [self.format_widgets[f]['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)
     # Align descriptionLabels with rest of layout
     for format_list in SongFormat.get_format_list():
         if SongFormat.get(format_list, 'descriptionText') is not None:
             self.format_widgets[format_list]['descriptionSpacer'].changeSize(
                 max_label_width + self.format_h_spacing, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
Exemple #25
0
 def on_browse_button_clicked(self):
     """
     Browse for files or a directory.
     """
     this_format = self.current_format
     select_mode, format_name, ext_filter = SongFormat.get(
         this_format, 'selectMode', 'name', 'filter')
     file_path_edit = self.format_widgets[this_format]['file_path_edit']
     if select_mode == SongFormatSelect.SingleFile:
         self.get_file_name(WizardStrings.OpenTypeFile % format_name,
                            file_path_edit, 'last directory import',
                            ext_filter)
     elif select_mode == SongFormatSelect.SingleFolder:
         self.get_folder(WizardStrings.OpenTypeFolder % format_name,
                         file_path_edit, 'last directory import')
Exemple #26
0
 def retranslate_ui(self):
     """
     Song wizard localisation.
     """
     self.setWindowTitle(translate('SongsPlugin.ImportWizardForm', 'Song Import Wizard'))
     self.title_label.setText(
         WizardStrings.HeaderStyle.format(text=translate('OpenLP.Ui', 'Welcome to the Song Import Wizard')))
     self.information_label.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.source_page.setTitle(WizardStrings.ImportSelect)
     self.source_page.setSubTitle(WizardStrings.ImportSelectLong)
     self.format_label.setText(WizardStrings.FormatLabel)
     for format_list in SongFormat.get_format_list():
         format_name, custom_combo_text, description_text, select_mode = \
             SongFormat.get(format_list, 'name', 'comboBoxText', 'descriptionText', 'selectMode')
         combo_box_text = (custom_combo_text if custom_combo_text else format_name)
         self.format_combo_box.setItemText(format_list, combo_box_text)
         if description_text is not None:
             self.format_widgets[format_list]['description_label'].setText(description_text)
         if select_mode == SongFormatSelect.MultipleFiles:
             self.format_widgets[format_list]['addButton'].setText(
                 translate('SongsPlugin.ImportWizardForm', 'Add Files...'))
             self.format_widgets[format_list]['removeButton'].setText(
                 translate('SongsPlugin.ImportWizardForm', 'Remove File(s)'))
         else:
             f_label = 'Filename:'
             if select_mode == SongFormatSelect.SingleFolder:
                 f_label = 'Folder:'
             self.format_widgets[format_list]['filepathLabel'].setText(
                 translate('SongsPlugin.ImportWizardForm', f_label))
     for format_list in self.disablable_formats:
         self.format_widgets[format_list]['disabled_label'].setText(SongFormat.get(format_list, 'disabledLabelText'))
     self.progress_page.setTitle(WizardStrings.Importing)
     self.progress_page.setSubTitle(
         translate('SongsPlugin.ImportWizardForm', 'Please wait while your songs are imported.'))
     self.progress_label.setText(WizardStrings.Ready)
     self.progress_bar.setFormat(WizardStrings.PercentSymbolFormat)
     self.error_copy_to_button.setText(translate('SongsPlugin.ImportWizardForm', 'Copy'))
     self.error_save_to_button.setText(translate('SongsPlugin.ImportWizardForm', 'Save to File'))
     # Align all QFormLayouts towards each other.
     formats = [f for f in SongFormat.get_format_list() if 'filepathLabel' in self.format_widgets[f]]
     labels = [self.format_widgets[f]['filepathLabel'] for f in formats] + [self.format_label]
     # Get max width of all labels
     max_label_width = max(labels, key=lambda label: label.minimumSizeHint().width()).minimumSizeHint().width()
     for label in labels:
         label.setFixedWidth(max_label_width)
     # Align descriptionLabels with rest of layout
     for format_list in SongFormat.get_format_list():
         if SongFormat.get(format_list, 'descriptionText') is not None:
             self.format_widgets[format_list]['descriptionSpacer'].changeSize(
                 max_label_width + self.format_h_spacing, 0, QtWidgets.QSizePolicy.Fixed,
                 QtWidgets.QSizePolicy.Fixed)
 def perform_wizard(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 the actual importing.
     """
     source_format = self.current_format
     select_mode = SongFormat.get(source_format, 'selectMode')
     if select_mode == SongFormatSelect.SingleFile:
         importer = self.plugin.import_songs(source_format,
                                             filename=self.format_widgets[source_format]['file_path_edit'].text())
     elif select_mode == SongFormatSelect.SingleFolder:
         importer = self.plugin.import_songs(source_format,
                                             folder=self.format_widgets[source_format]['file_path_edit'].text())
     else:
         importer = self.plugin.import_songs(
             source_format,
             filenames=self.get_list_of_files(self.format_widgets[source_format]['file_list_widget']))
     importer.do_import()
     self.progress_label.setText(WizardStrings.FinishedImport)
Exemple #28
0
 def perform_wizard(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 the actual importing.
     """
     source_format = self.current_format
     select_mode = SongFormat.get(source_format, 'selectMode')
     if select_mode == SongFormatSelect.SingleFile:
         importer = self.plugin.import_songs(source_format,
                                             file_path=self.format_widgets[source_format]['path_edit'].path)
     elif select_mode == SongFormatSelect.SingleFolder:
         importer = self.plugin.import_songs(source_format,
                                             folder_path=self.format_widgets[source_format]['path_edit'].path)
     else:
         importer = self.plugin.import_songs(
             source_format,
             file_paths=self.get_list_of_paths(self.format_widgets[source_format]['file_list_widget']))
     importer.do_import()
     self.progress_label.setText(WizardStrings.FinishedImport)
Exemple #29
0
 def test_get_attributed_single_attribute(self):
     """
     Test that SongFormat.get(song_format, attribute) returns only one -and the correct- attribute
     """
     # GIVEN: A SongFormat
     for song_format in SongFormat.get_format_list():
         # WHEN: Retrieving an attribute that overrides the default values
         for attribute in SongFormat.get(song_format).keys():
             # THEN: Return the attribute
             assert SongFormat.get(song_format, attribute) == SongFormat.get(song_format)[attribute], \
                 "The returned attribute doesn't match the stored one"
         # WHEN: Retrieving an attribute that was not overridden
         for attribute in SongFormat.__defaults__.keys():
             if attribute not in SongFormat.get(song_format).keys():
                 # THEN: Return the default value
                 assert SongFormat.get(song_format, attribute) == SongFormat.__defaults__[attribute], \
                     "The returned attribute does not match the default values stored"
Exemple #30
0
 def perform_wizard(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 the actual importing.
     """
     source_format = self.current_format
     select_mode = SongFormat.get(source_format, 'selectMode')
     if select_mode == SongFormatSelect.SingleFile:
         importer = self.plugin.import_songs(source_format,
                                             file_path=self.format_widgets[source_format]['path_edit'].path)
     elif select_mode == SongFormatSelect.SingleFolder:
         importer = self.plugin.import_songs(source_format,
                                             folder_path=self.format_widgets[source_format]['path_edit'].path)
     else:
         importer = self.plugin.import_songs(
             source_format,
             file_paths=self.get_list_of_paths(self.format_widgets[source_format]['file_list_widget']))
     try:
         importer.do_import()
         self.progress_label.setText(WizardStrings.FinishedImport)
     except OSError as e:
         log.exception('Importing songs failed')
         self.progress_label.setText(translate('SongsPlugin.ImportWizardForm',
                                               'Your Song import failed. {error}').format(error=e))
Exemple #31
0
 def add_file_select_item(self):
     """
     Add a file selection page.
     """
     this_format = self.current_format
     prefix, can_disable, description_text, select_mode = \
         SongFormat.get(this_format, 'prefix', 'canDisable', 'descriptionText', 'selectMode')
     page = QtWidgets.QWidget()
     page.setObjectName(prefix + 'Page')
     if can_disable:
         import_widget = self.disablable_widget(page, prefix)
     else:
         import_widget = page
     import_layout = QtWidgets.QVBoxLayout(import_widget)
     import_layout.setContentsMargins(0, 0, 0, 0)
     import_layout.setObjectName(prefix + 'ImportLayout')
     if description_text is not None:
         description_layout = QtWidgets.QHBoxLayout()
         description_layout.setObjectName(prefix + 'DescriptionLayout')
         description_spacer = QtWidgets.QSpacerItem(
             0, 0, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
         description_layout.addSpacerItem(description_spacer)
         description_label = QtWidgets.QLabel(import_widget)
         description_label.setWordWrap(True)
         description_label.setOpenExternalLinks(True)
         description_label.setObjectName(prefix + '_description_label')
         description_layout.addWidget(description_label)
         import_layout.addLayout(description_layout)
         self.format_widgets[this_format][
             'description_label'] = description_label
         self.format_widgets[this_format][
             'descriptionSpacer'] = description_spacer
     if select_mode == SongFormatSelect.SingleFile or select_mode == SongFormatSelect.SingleFolder:
         file_path_layout = QtWidgets.QHBoxLayout()
         file_path_layout.setObjectName(prefix + '_file_path_layout')
         file_path_layout.setContentsMargins(0, self.format_v_spacing, 0, 0)
         file_path_label = QtWidgets.QLabel(import_widget)
         file_path_label.setObjectName(prefix + 'FilepathLabel')
         file_path_layout.addWidget(file_path_label)
         file_path_spacer = QtWidgets.QSpacerItem(
             0, 0, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
         file_path_layout.addSpacerItem(file_path_spacer)
         file_path_edit = QtWidgets.QLineEdit(import_widget)
         file_path_edit.setObjectName(prefix + '_file_path_edit')
         file_path_layout.addWidget(file_path_edit)
         browse_button = QtWidgets.QToolButton(import_widget)
         browse_button.setIcon(self.open_icon)
         browse_button.setObjectName(prefix + 'BrowseButton')
         file_path_layout.addWidget(browse_button)
         import_layout.addLayout(file_path_layout)
         import_layout.addSpacerItem(self.stack_spacer)
         self.format_widgets[this_format]['filepathLabel'] = file_path_label
         self.format_widgets[this_format][
             'filepathSpacer'] = file_path_spacer
         self.format_widgets[this_format][
             'file_path_layout'] = file_path_layout
         self.format_widgets[this_format]['file_path_edit'] = file_path_edit
         self.format_widgets[this_format]['browseButton'] = browse_button
     elif select_mode == SongFormatSelect.MultipleFiles:
         file_list_widget = QtWidgets.QListWidget(import_widget)
         file_list_widget.setSelectionMode(
             QtWidgets.QAbstractItemView.ExtendedSelection)
         file_list_widget.setObjectName(prefix + 'FileListWidget')
         import_layout.addWidget(file_list_widget)
         button_layout = QtWidgets.QHBoxLayout()
         button_layout.setObjectName(prefix + '_button_layout')
         add_button = QtWidgets.QPushButton(import_widget)
         add_button.setIcon(self.open_icon)
         add_button.setObjectName(prefix + 'AddButton')
         button_layout.addWidget(add_button)
         button_layout.addStretch()
         remove_button = QtWidgets.QPushButton(import_widget)
         remove_button.setIcon(self.delete_icon)
         remove_button.setObjectName(prefix + 'RemoveButton')
         button_layout.addWidget(remove_button)
         import_layout.addLayout(button_layout)
         self.format_widgets[this_format][
             'file_list_widget'] = file_list_widget
         self.format_widgets[this_format]['button_layout'] = button_layout
         self.format_widgets[this_format]['addButton'] = add_button
         self.format_widgets[this_format]['removeButton'] = remove_button
     self.format_stack.addWidget(page)
     self.format_widgets[this_format]['page'] = page
     self.format_widgets[this_format]['importLayout'] = import_layout
     self.format_combo_box.addItem('')
Exemple #32
0
 def do_import(self):
     """
     Receive either a list of files or a folder (unicode) to import.
     """
     from openlp.plugins.songs.lib.importer import SongFormat
     ps_string = SongFormat.get(SongFormat.PowerSong, 'name')
     if isinstance(self.import_source, str):
         if os.path.isdir(self.import_source):
             dir = self.import_source
             self.import_source = []
             for file in os.listdir(dir):
                 if fnmatch.fnmatch(file, '*.song'):
                     self.import_source.append(os.path.join(dir, file))
         else:
             self.import_source = ''
     if not self.import_source or not isinstance(self.import_source, list):
         self.log_error(translate('SongsPlugin.PowerSongImport', 'No songs to import.'),
                        translate('SongsPlugin.PowerSongImport', 'No {text} files found.').format(text=ps_string))
         return
     self.import_wizard.progress_bar.setMaximum(len(self.import_source))
     for file in self.import_source:
         if self.stop_import_flag:
             return
         self.set_defaults()
         parse_error = False
         with open(file, 'rb') as song_data:
             while True:
                 try:
                     label = self._read_string(song_data)
                     if not label:
                         break
                     field = self._read_string(song_data)
                 except ValueError:
                     parse_error = True
                     self.log_error(os.path.basename(file),
                                    translate('SongsPlugin.PowerSongImport',
                                              'Invalid {text} file. Unexpected byte value.').format(text=ps_string))
                     break
                 else:
                     if label == 'TITLE':
                         self.title = field.replace('\n', ' ')
                     elif label == 'AUTHOR':
                         self.parse_author(field)
                     elif label == 'COPYRIGHTLINE':
                         found_copyright = True
                         self._parse_copyright_cCCLI(field)
                     elif label == 'PART':
                         self.add_verse(field)
         if parse_error:
             continue
         # Check that file had TITLE field
         if not self.title:
             self.log_error(os.path.basename(file),
                            translate('SongsPlugin.PowerSongImport',
                                      'Invalid {text} file. Missing "TITLE" header.').format(text=ps_string))
             continue
         # Check that file had COPYRIGHTLINE label
         if not found_copyright:
             self.log_error(self.title,
                            translate('SongsPlugin.PowerSongImport',
                                      'Invalid {text} file. Missing "COPYRIGHTLINE" header.').format(text=ps_string))
             continue
         # Check that file had at least one verse
         if not self.verses:
             self.log_error(self.title,
                            translate('SongsPlugin.PowerSongImport', 'Verses not found. Missing "PART" header.'))
             continue
         if not self.finish():
             self.log_error(self.title)
Exemple #33
0
 def add_file_select_item(self):
     """
     Add a file selection page.
     """
     this_format = self.current_format
     format_name, prefix, can_disable, description_text, select_mode, filters = \
         SongFormat.get(this_format, 'name', 'prefix', 'canDisable', 'descriptionText', 'selectMode', 'filter')
     page = QtWidgets.QWidget()
     page.setObjectName(prefix + 'Page')
     if can_disable:
         import_widget = self.disablable_widget(page, prefix)
     else:
         import_widget = page
     import_layout = QtWidgets.QVBoxLayout(import_widget)
     import_layout.setContentsMargins(0, 0, 0, 0)
     import_layout.setObjectName(prefix + 'ImportLayout')
     if description_text is not None:
         description_layout = QtWidgets.QHBoxLayout()
         description_layout.setObjectName(prefix + 'DescriptionLayout')
         description_spacer = QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
         description_layout.addSpacerItem(description_spacer)
         description_label = QtWidgets.QLabel(import_widget)
         description_label.setWordWrap(True)
         description_label.setOpenExternalLinks(True)
         description_label.setObjectName(prefix + '_description_label')
         description_layout.addWidget(description_label)
         import_layout.addLayout(description_layout)
         self.format_widgets[this_format]['description_label'] = description_label
         self.format_widgets[this_format]['descriptionSpacer'] = description_spacer
     if select_mode == SongFormatSelect.SingleFile or select_mode == SongFormatSelect.SingleFolder:
         file_path_layout = QtWidgets.QHBoxLayout()
         file_path_layout.setObjectName(prefix + '_file_path_layout')
         file_path_label = QtWidgets.QLabel(import_widget)
         file_path_layout.addWidget(file_path_label)
         if select_mode == SongFormatSelect.SingleFile:
             path_type = PathEditType.Files
             dialog_caption = WizardStrings.OpenTypeFile.format(file_type=format_name)
         else:
             path_type = PathEditType.Directories
             dialog_caption = WizardStrings.OpenTypeFolder.format(folder_name=format_name)
         path_edit = PathEdit(
             parent=import_widget, path_type=path_type, dialog_caption=dialog_caption, show_revert=False)
         if path_edit.filters:
             path_edit.filters = filters + ';;' + path_edit.filters
         else:
             path_edit.filters = filters
         path_edit.path = self.settings.value(self.plugin.settings_section + '/last directory import')
         file_path_layout.addWidget(path_edit)
         import_layout.addLayout(file_path_layout)
         import_layout.addSpacerItem(self.stack_spacer)
         self.format_widgets[this_format]['filepathLabel'] = file_path_label
         self.format_widgets[this_format]['path_edit'] = path_edit
     elif select_mode == SongFormatSelect.MultipleFiles:
         file_list_widget = QtWidgets.QListWidget(import_widget)
         file_list_widget.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
         file_list_widget.setObjectName(prefix + 'FileListWidget')
         import_layout.addWidget(file_list_widget)
         button_layout = QtWidgets.QHBoxLayout()
         button_layout.setObjectName(prefix + '_button_layout')
         add_button = QtWidgets.QPushButton(import_widget)
         add_button.setIcon(self.open_icon)
         add_button.setObjectName(prefix + 'AddButton')
         button_layout.addWidget(add_button)
         button_layout.addStretch()
         remove_button = QtWidgets.QPushButton(import_widget)
         remove_button.setIcon(self.delete_icon)
         remove_button.setObjectName(prefix + 'RemoveButton')
         button_layout.addWidget(remove_button)
         import_layout.addLayout(button_layout)
         self.format_widgets[this_format]['file_list_widget'] = file_list_widget
         self.format_widgets[this_format]['button_layout'] = button_layout
         self.format_widgets[this_format]['addButton'] = add_button
         self.format_widgets[this_format]['removeButton'] = remove_button
     self.format_stack.addWidget(page)
     self.format_widgets[this_format]['page'] = page
     self.format_widgets[this_format]['importLayout'] = import_layout
     self.format_combo_box.addItem('')
Exemple #34
0
 def do_import(self):
     """
     Receive either a list of files or a folder (unicode) to import.
     """
     from openlp.plugins.songs.lib.importer import SongFormat
     ps_string = SongFormat.get(SongFormat.PowerSong, 'name')
     if isinstance(self.import_source, str):
         if os.path.isdir(self.import_source):
             dir = self.import_source
             self.import_source = []
             for file in os.listdir(dir):
                 if fnmatch.fnmatch(file, '*.song'):
                     self.import_source.append(os.path.join(dir, file))
         else:
             self.import_source = ''
     if not self.import_source or not isinstance(self.import_source, list):
         self.log_error(
             translate('SongsPlugin.PowerSongImport',
                       'No songs to import.'),
             translate('SongsPlugin.PowerSongImport',
                       'No {text} files found.').format(text=ps_string))
         return
     self.import_wizard.progress_bar.setMaximum(len(self.import_source))
     for file in self.import_source:
         if self.stop_import_flag:
             return
         self.set_defaults()
         parse_error = False
         with open(file, 'rb') as song_data:
             while True:
                 try:
                     label = self._read_string(song_data)
                     if not label:
                         break
                     field = self._read_string(song_data)
                 except ValueError:
                     parse_error = True
                     self.log_error(
                         os.path.basename(file),
                         translate(
                             'SongsPlugin.PowerSongImport',
                             'Invalid {text} file. Unexpected byte value.').
                         format(text=ps_string))
                     break
                 else:
                     if label == 'TITLE':
                         self.title = field.replace('\n', ' ')
                     elif label == 'AUTHOR':
                         self.parse_author(field)
                     elif label == 'COPYRIGHTLINE':
                         found_copyright = True
                         self._parse_copyright_cCCLI(field)
                     elif label == 'PART':
                         self.add_verse(field)
         if parse_error:
             continue
         # Check that file had TITLE field
         if not self.title:
             self.log_error(
                 os.path.basename(file),
                 translate(
                     'SongsPlugin.PowerSongImport',
                     'Invalid {text} file. Missing "TITLE" header.').format(
                         text=ps_string))
             continue
         # Check that file had COPYRIGHTLINE label
         if not found_copyright:
             self.log_error(
                 self.title,
                 translate(
                     'SongsPlugin.PowerSongImport',
                     'Invalid {text} file. Missing "COPYRIGHTLINE" header.'
                 ).format(text=ps_string))
             continue
         # Check that file had at least one verse
         if not self.verses:
             self.log_error(
                 self.title,
                 translate('SongsPlugin.PowerSongImport',
                           'Verses not found. Missing "PART" header.'))
             continue
         if not self.finish():
             self.log_error(self.title)
 def add_file_select_item(self):
     """
     Add a file selection page.
     """
     this_format = self.current_format
     prefix, can_disable, description_text, select_mode = \
         SongFormat.get(this_format, 'prefix', 'canDisable', 'descriptionText', 'selectMode')
     page = QtGui.QWidget()
     page.setObjectName(prefix + 'Page')
     if can_disable:
         import_widget = self.disablable_widget(page, prefix)
     else:
         import_widget = page
     import_layout = QtGui.QVBoxLayout(import_widget)
     import_layout.setMargin(0)
     import_layout.setObjectName(prefix + 'ImportLayout')
     if description_text is not None:
         description_layout = QtGui.QHBoxLayout()
         description_layout.setObjectName(prefix + 'DescriptionLayout')
         description_spacer = QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
         description_layout.addSpacerItem(description_spacer)
         description_label = QtGui.QLabel(import_widget)
         description_label.setWordWrap(True)
         description_label.setOpenExternalLinks(True)
         description_label.setObjectName(prefix + '_description_label')
         description_layout.addWidget(description_label)
         import_layout.addLayout(description_layout)
         self.format_widgets[this_format]['description_label'] = description_label
         self.format_widgets[this_format]['descriptionSpacer'] = description_spacer
     if select_mode == SongFormatSelect.SingleFile or select_mode == SongFormatSelect.SingleFolder:
         file_path_layout = QtGui.QHBoxLayout()
         file_path_layout.setObjectName(prefix + '_file_path_layout')
         file_path_layout.setContentsMargins(0, self.format_v_spacing, 0, 0)
         file_path_label = QtGui.QLabel(import_widget)
         file_path_label.setObjectName(prefix + 'FilepathLabel')
         file_path_layout.addWidget(file_path_label)
         file_path_spacer = QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
         file_path_layout.addSpacerItem(file_path_spacer)
         file_path_edit = QtGui.QLineEdit(import_widget)
         file_path_edit.setObjectName(prefix + '_file_path_edit')
         file_path_layout.addWidget(file_path_edit)
         browse_button = QtGui.QToolButton(import_widget)
         browse_button.setIcon(self.open_icon)
         browse_button.setObjectName(prefix + 'BrowseButton')
         file_path_layout.addWidget(browse_button)
         import_layout.addLayout(file_path_layout)
         import_layout.addSpacerItem(self.stack_spacer)
         self.format_widgets[this_format]['filepathLabel'] = file_path_label
         self.format_widgets[this_format]['filepathSpacer'] = file_path_spacer
         self.format_widgets[this_format]['file_path_layout'] = file_path_layout
         self.format_widgets[this_format]['file_path_edit'] = file_path_edit
         self.format_widgets[this_format]['browseButton'] = browse_button
     elif select_mode == SongFormatSelect.MultipleFiles:
         file_list_widget = QtGui.QListWidget(import_widget)
         file_list_widget.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
         file_list_widget.setObjectName(prefix + 'FileListWidget')
         import_layout.addWidget(file_list_widget)
         button_layout = QtGui.QHBoxLayout()
         button_layout.setObjectName(prefix + '_button_layout')
         add_button = QtGui.QPushButton(import_widget)
         add_button.setIcon(self.open_icon)
         add_button.setObjectName(prefix + 'AddButton')
         button_layout.addWidget(add_button)
         button_layout.addStretch()
         remove_button = QtGui.QPushButton(import_widget)
         remove_button.setIcon(self.delete_icon)
         remove_button.setObjectName(prefix + 'RemoveButton')
         button_layout.addWidget(remove_button)
         import_layout.addLayout(button_layout)
         self.format_widgets[this_format]['file_list_widget'] = file_list_widget
         self.format_widgets[this_format]['button_layout'] = button_layout
         self.format_widgets[this_format]['addButton'] = add_button
         self.format_widgets[this_format]['removeButton'] = remove_button
     self.format_stack.addWidget(page)
     self.format_widgets[this_format]['page'] = page
     self.format_widgets[this_format]['importLayout'] = import_layout
     self.format_combo_box.addItem('')
Exemple #36
0
 def importSongs(self, format, **kwargs):
     class_ = SongFormat.get(format, 'class')
     importer = class_(self.manager, **kwargs)
     importer.register(self.media_item.import_wizard)
     return importer
Exemple #37
0
 def importSongs(self, format, **kwargs):
     class_ = SongFormat.get(format, u'class')
     kwargs[u'plugin'] = self
     importer = class_(self.manager, **kwargs)
     importer.register(self.mediaItem.importWizard)
     return importer