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)
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"
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 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)
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)
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 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"
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)
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 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"
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"
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 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"
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 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)