From 7f5096d0f9426b92f297cdedd769813efddb03d7 Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Fri, 20 May 2016 09:22:06 -0700 Subject: [PATCH] core_lib files string conversions --- openlp/core/lib/projector/db.py | 2 +- openlp/core/ui/aboutform.py | 2 +- openlp/core/ui/advancedtab.py | 26 +++--- openlp/core/ui/exceptionform.py | 34 ++++--- openlp/core/ui/firsttimeform.py | 91 +++++++++++-------- openlp/core/ui/firsttimewizard.py | 20 ++-- openlp/core/ui/formattingtagcontroller.py | 23 +++-- openlp/core/ui/formattingtagform.py | 7 +- openlp/core/ui/generaltab.py | 2 +- openlp/core/ui/mainwindow.py | 9 +- openlp/core/ui/plugindialog.py | 2 +- openlp/core/ui/pluginform.py | 4 +- openlp/core/ui/servicemanager.py | 52 ++++++----- openlp/core/ui/settingsform.py | 2 +- openlp/core/ui/shortcutlistform.py | 9 +- openlp/core/ui/slidecontroller.py | 80 +++++++++------- openlp/core/ui/starttimeform.py | 6 +- openlp/core/ui/themeform.py | 10 +- openlp/core/ui/thememanager.py | 55 ++++++----- openlp/core/ui/themewizard.py | 8 +- .../openlp_core_lib/test_projectordb.py | 18 +++- 21 files changed, 263 insertions(+), 199 deletions(-) diff --git a/openlp/core/lib/projector/db.py b/openlp/core/lib/projector/db.py index 2b41ea69c..98778e695 100644 --- a/openlp/core/lib/projector/db.py +++ b/openlp/core/lib/projector/db.py @@ -131,7 +131,7 @@ class Source(CommonBase, Base): """ Return basic representation of Source table entry. """ - return ''.format(name=self.pjlink_name, + return ''.format(name=self.pjlink_name, code=self.pjlink_code, text=self.text) model_id = Column(Integer, ForeignKey('model.id')) diff --git a/openlp/core/ui/aboutform.py b/openlp/core/ui/aboutform.py index fc29f968c..3b509bdbd 100644 --- a/openlp/core/ui/aboutform.py +++ b/openlp/core/ui/aboutform.py @@ -52,7 +52,7 @@ class AboutForm(QtWidgets.QDialog, UiAboutDialog): about_text = self.about_text_edit.toPlainText() about_text = about_text.replace('', application_version['version']) if application_version['build']: - build_text = translate('OpenLP.AboutForm', ' build %s') % application_version['build'] + build_text = translate('OpenLP.AboutForm', ' build {version}').format(version=application_version['build']) else: build_text = '' about_text = about_text.replace('', build_text) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index 97e2d3617..e6f2dee49 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -308,8 +308,8 @@ class AdvancedTab(SettingsTab): self.service_name_label.setText(translate('OpenLP.AdvancedTab', 'Name:')) self.service_name_edit.setToolTip(translate('OpenLP.AdvancedTab', 'Consult the OpenLP manual for usage.')) self.service_name_revert_button.setToolTip( - translate('OpenLP.AdvancedTab', 'Revert to the default service name "%s".') % - UiStrings().DefaultServiceName) + translate('OpenLP.AdvancedTab', + 'Revert to the default service name "{name}".').format(name=UiStrings().DefaultServiceName)) self.service_name_example_label.setText(translate('OpenLP.AdvancedTab', 'Example:')) self.hide_mouse_group_box.setTitle(translate('OpenLP.AdvancedTab', 'Mouse Cursor')) self.hide_mouse_check_box.setText(translate('OpenLP.AdvancedTab', 'Hide mouse cursor when over display window')) @@ -391,16 +391,16 @@ class AdvancedTab(SettingsTab): # Since data location can be changed, make sure the path is present. self.current_data_path = AppLocation.get_data_path() if not os.path.exists(self.current_data_path): - log.error('Data path not found %s' % self.current_data_path) + log.error('Data path not found {path}'.format(path=self.current_data_path)) answer = QtWidgets.QMessageBox.critical( self, translate('OpenLP.AdvancedTab', 'Data Directory Error'), - translate('OpenLP.AdvancedTab', 'OpenLP data directory was not found\n\n%s\n\n' + translate('OpenLP.AdvancedTab', 'OpenLP data directory was not found\n\n{path}\n\n' 'This data directory was previously changed from the OpenLP ' 'default location. If the new location was on removable ' 'media, that media needs to be made available.\n\n' 'Click "No" to stop loading OpenLP. allowing you to fix the the problem.\n\n' 'Click "Yes" to reset the data directory to the default ' - 'location.').replace('%s', self.current_data_path), + 'location.').format(path=self.current_data_path), QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No), QtWidgets.QMessageBox.No) if answer == QtWidgets.QMessageBox.No: @@ -410,7 +410,7 @@ class AdvancedTab(SettingsTab): # Set data location to default. settings.remove('advanced/data path') self.current_data_path = AppLocation.get_data_path() - log.warning('User requested data path set to default %s' % self.current_data_path) + log.warning('User requested data path set to default {path}'.format(path=self.current_data_path)) self.data_directory_label.setText(os.path.abspath(self.current_data_path)) # Don't allow data directory move if running portable. if settings.value('advanced/is portable'): @@ -542,9 +542,9 @@ class AdvancedTab(SettingsTab): # Make sure they want to change the data. answer = QtWidgets.QMessageBox.question(self, translate('OpenLP.AdvancedTab', 'Confirm Data Directory Change'), translate('OpenLP.AdvancedTab', 'Are you sure you want to change the ' - 'location of the OpenLP data directory to:\n\n%s\n\nThe data ' - 'directory will be changed when OpenLP is closed.'). - replace('%s', new_data_path), + 'location of the OpenLP data directory to:\n\n{path}' + '\n\nThe data directory will be changed when OpenLP is ' + 'closed.').format(path=new_data_path), QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No), QtWidgets.QMessageBox.No) @@ -608,10 +608,10 @@ class AdvancedTab(SettingsTab): answer = QtWidgets.QMessageBox.warning(self, translate('OpenLP.AdvancedTab', 'Overwrite Existing Data'), translate('OpenLP.AdvancedTab', - 'WARNING: \n\nThe location you have selected \n\n%s\n\n' - 'appears to contain OpenLP data files. Do you wish to ' - 'replace these files with the current data files?'). - replace('%s', os.path.abspath(data_path,)), + 'WARNING: \n\nThe location you have selected \n\n{path}' + '\n\nappears to contain OpenLP data files. Do you wish to ' + 'replace these files with the current data ' + 'files?').format(path=os.path.abspath(data_path,)), QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No), QtWidgets.QMessageBox.No) diff --git a/openlp/core/ui/exceptionform.py b/openlp/core/ui/exceptionform.py index 68dd9705f..216780584 100644 --- a/openlp/core/ui/exceptionform.py +++ b/openlp/core/ui/exceptionform.py @@ -91,6 +91,7 @@ class ExceptionForm(QtWidgets.QDialog, Ui_ExceptionDialog, RegistryProperties): super(ExceptionForm, self).__init__(None, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint) self.setupUi(self) self.settings_section = 'crashreport' + # TODO: Need to see how to format strings when string with tags is actually a variable self.report_text = '**OpenLP Bug Report**\n' \ 'Version: %s\n\n' \ '--- Details of the Exception. ---\n\n%s\n\n ' \ @@ -114,21 +115,17 @@ class ExceptionForm(QtWidgets.QDialog, Ui_ExceptionDialog, RegistryProperties): openlp_version = get_application_version() description = self.description_text_edit.toPlainText() traceback = self.exception_text_edit.toPlainText() - system = translate('OpenLP.ExceptionForm', 'Platform: %s\n') % platform.platform() - libraries = 'Python: %s\n' % platform.python_version() + \ - 'Qt5: %s\n' % Qt.qVersion() + \ - 'PyQt5: %s\n' % Qt.PYQT_VERSION_STR + \ - 'QtWebkit: %s\n' % WEBKIT_VERSION + \ - 'SQLAlchemy: %s\n' % sqlalchemy.__version__ + \ - 'SQLAlchemy Migrate: %s\n' % MIGRATE_VERSION + \ - 'BeautifulSoup: %s\n' % bs4.__version__ + \ - 'lxml: %s\n' % etree.__version__ + \ - 'Chardet: %s\n' % CHARDET_VERSION + \ - 'PyEnchant: %s\n' % ENCHANT_VERSION + \ - 'Mako: %s\n' % MAKO_VERSION + \ - 'pyICU: %s\n' % ICU_VERSION + \ - 'pyUNO bridge: %s\n' % self._pyuno_import() + \ - 'VLC: %s\n' % VLC_VERSION + system = translate('OpenLP.ExceptionForm', 'Platform: {platform}\n').format(platform=platform.platform()) + libraries = ('Python: {python}\nQt5: {qt5}\nPyQt5: {pyqt5}\nQtWebkit: {qtwebkit}\nSQLAlchemy: {sqalchemy}\n' + 'SQLAlchemy Migrate: {migrate}\nBeautifulSoup: {soup}\nlxml: {etree}\nChardet: {chardet}\n' + 'PyEnchant: {enchant}\nMako: {mako}\npyICU: {icu}\npyUNO bridge: {uno}\n' + 'VLC: {vlc}\n').format(python=platform.python_version(), qt5=Qt.qVersion(), + pyqt5=Qt.PYQT_VERSION_STR, qtwebkit=WEBKIT_VERSION, + sqalchemy=sqlalchemy.__version__, migrate=MIGRATE_VERSION, + soup=bs4.__version__, etree=etree.__version__, chardet=CHARDET_VERSION, + enchant=ENCHANT_VERSION, mako=MAKO_VERSION, icu=ICU_VERSION, + uno=self._pyuno_import(), vlc=VLC_VERSION) + if is_linux(): if os.environ.get('KDE_FULL_SESSION') == 'true': system += 'Desktop: KDE SC\n' @@ -178,9 +175,10 @@ class ExceptionForm(QtWidgets.QDialog, Ui_ExceptionDialog, RegistryProperties): source = re.sub(r'.*[/\\]openlp[/\\](.*)".*', r'\1', line) if ':' in line: exception = line.split('\n')[-1].split(':')[0] - subject = 'Bug report: %s in %s' % (exception, source) + subject = 'Bug report: {error} in {source}'.format(error=exception, source=source) mail_urlquery = QtCore.QUrlQuery() mail_urlquery.addQueryItem('subject', subject) + # TODO: Find out how to format() text that is in a variable mail_urlquery.addQueryItem('body', self.report_text % content) if self.file_attachment: mail_urlquery.addQueryItem('attach', self.file_attachment) @@ -199,7 +197,7 @@ class ExceptionForm(QtWidgets.QDialog, Ui_ExceptionDialog, RegistryProperties): else: self.__button_state(False) self.description_word_count.setText( - translate('OpenLP.ExceptionDialog', 'Description characters to enter : %s') % count) + translate('OpenLP.ExceptionDialog', 'Description characters to enter : {count}').format(count=count)) def on_attach_file_button_clicked(self): """ @@ -210,7 +208,7 @@ class ExceptionForm(QtWidgets.QDialog, Ui_ExceptionDialog, RegistryProperties): 'Select Attachment'), Settings().value(self.settings_section + '/last directory'), - '%s (*)' % UiStrings().AllFiles) + '{text} (*)'.format(text=UiStrings().AllFiles)) log.info('New files(s) %s', str(files)) if files: self.file_attachment = str(files) diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index f2be3b29c..cadb4814f 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -72,7 +72,7 @@ class ThemeScreenshotWorker(QtCore.QObject): if self.was_download_cancelled: return try: - urllib.request.urlretrieve('%s%s' % (self.themes_url, self.screenshot), + urllib.request.urlretrieve('{host}{name}'.format(host=self.themes_url, name=self.screenshot), os.path.join(gettempdir(), 'openlp', self.screenshot)) # Signal that the screenshot has been downloaded self.screenshot_downloaded.emit(self.title, self.filename, self.sha256) @@ -180,11 +180,13 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): user_agent = 'OpenLP/' + Registry().get('application').applicationVersion() self.application.process_events() try: - web_config = get_web_page('%s%s' % (self.web, 'download.cfg'), header=('User-Agent', user_agent)) + web_config = get_web_page('{host}{name}'.format(host=self.web, name='download.cfg'), + header=('User-Agent', user_agent)) except (urllib.error.URLError, ConnectionError) as err: msg = QtWidgets.QMessageBox() title = translate('OpenLP.FirstTimeWizard', 'Network Error') - msg.setText('{} {}'.format(title, err.code if hasattr(err, 'code') else '')) + msg.setText('{title} {error}'.format(title=title, + error=err.code if hasattr(err, 'code') else '')) msg.setInformativeText(translate('OpenLP.FirstTimeWizard', 'There was a network error attempting to ' 'connect to retrieve initial configuration information')) @@ -205,6 +207,7 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): trace_error_handler(log) self.update_screen_list_combo() self.application.process_events() + # TODO: Figure out how to use a variable with format() self.downloading = translate('OpenLP.FirstTimeWizard', 'Downloading %s...') if self.has_run_wizard: self.songs_check_box.setChecked(self.plugin_manager.get_plugin_by_name('songs').is_active()) @@ -223,9 +226,9 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): songs = songs.split(',') for song in songs: self.application.process_events() - title = self.config.get('songs_%s' % song, 'title') - filename = self.config.get('songs_%s' % song, 'filename') - sha256 = self.config.get('songs_%s' % song, 'sha256', fallback='') + title = self.config.get('songs_{song}'.format(song=song), 'title') + filename = self.config.get('songs_{song}'.format(song=song), 'filename') + sha256 = self.config.get('songs_{song}'.format(song=song), 'sha256', fallback='') item = QtWidgets.QListWidgetItem(title, self.songs_list_widget) item.setData(QtCore.Qt.UserRole, (filename, sha256)) item.setCheckState(QtCore.Qt.Unchecked) @@ -234,15 +237,15 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): bible_languages = bible_languages.split(',') for lang in bible_languages: self.application.process_events() - language = self.config.get('bibles_%s' % lang, 'title') + language = self.config.get('bibles_{lang}'.format(lang=lang), 'title') lang_item = QtWidgets.QTreeWidgetItem(self.bibles_tree_widget, [language]) - bibles = self.config.get('bibles_%s' % lang, 'translations') + bibles = self.config.get('bibles_{lang}'.format(lang=lang), 'translations') bibles = bibles.split(',') for bible in bibles: self.application.process_events() - title = self.config.get('bible_%s' % bible, 'title') - filename = self.config.get('bible_%s' % bible, 'filename') - sha256 = self.config.get('bible_%s' % bible, 'sha256', fallback='') + title = self.config.get('bible_{bible}'.format(bible=bible), 'title') + filename = self.config.get('bible_{bible}'.format(bible=bible), 'filename') + sha256 = self.config.get('bible_{bible}'.format(bible=bible), 'sha256', fallback='') item = QtWidgets.QTreeWidgetItem(lang_item, [title]) item.setData(0, QtCore.Qt.UserRole, (filename, sha256)) item.setCheckState(0, QtCore.Qt.Unchecked) @@ -252,10 +255,10 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): # Download the theme screenshots themes = self.config.get('themes', 'files').split(',') for theme in themes: - title = self.config.get('theme_%s' % theme, 'title') - filename = self.config.get('theme_%s' % theme, 'filename') - sha256 = self.config.get('theme_%s' % theme, 'sha256', fallback='') - screenshot = self.config.get('theme_%s' % theme, 'screenshot') + title = self.config.get('theme_{theme}'.format(theme=theme), 'title') + filename = self.config.get('theme_{theme}'.format(theme=theme), 'filename') + sha256 = self.config.get('theme_{theme}'.format(theme=theme), 'sha256', fallback='') + screenshot = self.config.get('theme_{theme}'.format(theme=theme), 'screenshot') worker = ThemeScreenshotWorker(self.themes_url, title, filename, sha256, screenshot) self.theme_screenshot_workers.append(worker) worker.screenshot_downloaded.connect(self.on_screenshot_downloaded) @@ -421,7 +424,7 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): self._download_progress(block_count, block_size) filename.close() if sha256 and hasher.hexdigest() != sha256: - log.error('sha256 sums did not match for file: {}'.format(f_path)) + log.error('sha256 sums did not match for file: {file}'.format(file=f_path)) os.remove(f_path) return False except (urllib.error.URLError, socket.timeout) as err: @@ -447,7 +450,7 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): themes = self.config.get('themes', 'files') themes = themes.split(',') for index, theme in enumerate(themes): - screenshot = self.config.get('theme_%s' % theme, 'screenshot') + screenshot = self.config.get('theme_{theme}'.format(theme=theme), 'screenshot') item = self.themes_list_widget.item(index) if item: item.setIcon(build_icon(os.path.join(gettempdir(), 'openlp', screenshot))) @@ -507,7 +510,7 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): item = self.songs_list_widget.item(i) if item.checkState() == QtCore.Qt.Checked: filename, sha256 = item.data(QtCore.Qt.UserRole) - size = self._get_file_size('%s%s' % (self.songs_url, filename)) + size = self._get_file_size('{path}{name}'.format(path=self.songs_url, name=filename)) self.max_progress += size # Loop through the Bibles list and increase for each selected item iterator = QtWidgets.QTreeWidgetItemIterator(self.bibles_tree_widget) @@ -516,7 +519,7 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): item = iterator.value() if item.parent() and item.checkState(0) == QtCore.Qt.Checked: filename, sha256 = item.data(0, QtCore.Qt.UserRole) - size = self._get_file_size('%s%s' % (self.bibles_url, filename)) + size = self._get_file_size('{path}{name}'.format(path=self.bibles_url, name=filename)) self.max_progress += size iterator += 1 # Loop through the themes list and increase for each selected item @@ -525,7 +528,7 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): item = self.themes_list_widget.item(i) if item.checkState() == QtCore.Qt.Checked: filename, sha256 = item.data(QtCore.Qt.UserRole) - size = self._get_file_size('%s%s' % (self.themes_url, filename)) + size = self._get_file_size('{path}{name}'.format(path=self.themes_url, name=filename)) self.max_progress += size except urllib.error.URLError: trace_error_handler(log) @@ -560,22 +563,26 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): if self.max_progress: self.progress_bar.setValue(self.progress_bar.maximum()) if self.has_run_wizard: - self.progress_label.setText(translate('OpenLP.FirstTimeWizard', - 'Download complete. Click the %s button to return to OpenLP.') % - clean_button_text(self.buttonText(QtWidgets.QWizard.FinishButton))) + text = translate('OpenLP.FirstTimeWizard', + 'Download complete. Click the {button} button to return to OpenLP.' + ).format(text=clean_button_text(self.buttonText(QtWidgets.QWizard.FinishButton))) + self.progress_label.setText(text) else: - self.progress_label.setText(translate('OpenLP.FirstTimeWizard', - 'Download complete. Click the %s button to start OpenLP.') % - clean_button_text(self.buttonText(QtWidgets.QWizard.FinishButton))) + text = translate('OpenLP.FirstTimeWizard', + 'Download complete. Click the {button} button to start OpenLP.' + ).format(button=clean_button_text(self.buttonText(QtWidgets.QWizard.FinishButton))) + self.progress_label.setText() else: if self.has_run_wizard: - self.progress_label.setText(translate('OpenLP.FirstTimeWizard', - 'Click the %s button to return to OpenLP.') % - clean_button_text(self.buttonText(QtWidgets.QWizard.FinishButton))) + text = translate('OpenLP.FirstTimeWizard', + 'Click the {button} button to return to OpenLP.' + ).format(button=clean_button_text(self.buttonText(QtWidgets.QWizard.FinishButton))) + self.progress_label.setText(text) else: - self.progress_label.setText(translate('OpenLP.FirstTimeWizard', - 'Click the %s button to start OpenLP.') % - clean_button_text(self.buttonText(QtWidgets.QWizard.FinishButton))) + text = translate('OpenLP.FirstTimeWizard', + 'Click the {button} button to start OpenLP.' + ).format(button=clean_button_text(self.buttonText(QtWidgets.QWizard.FinishButton))) + self.progress_label.setText() self.finish_button.setVisible(True) self.finish_button.setEnabled(True) self.cancel_button.setVisible(False) @@ -628,8 +635,9 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): self._increment_progress_bar(self.downloading % filename, 0) self.previous_size = 0 destination = os.path.join(songs_destination, str(filename)) - if not self.url_get_file('%s%s' % (self.songs_url, filename), destination, sha256): - missed_files.append('Song: {}'.format(filename)) + if not self.url_get_file('{path}{name}'.format(path=self.songs_url, name=filename), + destination, sha256): + missed_files.append('Song: {name}'.format(name=filename)) # Download Bibles bibles_iterator = QtWidgets.QTreeWidgetItemIterator(self.bibles_tree_widget) while bibles_iterator.value(): @@ -638,31 +646,34 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): bible, sha256 = item.data(0, QtCore.Qt.UserRole) self._increment_progress_bar(self.downloading % bible, 0) self.previous_size = 0 - if not self.url_get_file('%s%s' % (self.bibles_url, bible), os.path.join(bibles_destination, bible), + if not self.url_get_file('{path}{name}'.format(path=self.bibles_url, name=bible), + os.path.join(bibles_destination, bible), sha256): - missed_files.append('Bible: {}'.format(bible)) + missed_files.append('Bible: {name}'.format(name=bible)) bibles_iterator += 1 # Download themes for i in range(self.themes_list_widget.count()): item = self.themes_list_widget.item(i) if item.checkState() == QtCore.Qt.Checked: theme, sha256 = item.data(QtCore.Qt.UserRole) + # TODO: Verify how to use format() with strings in a variable self._increment_progress_bar(self.downloading % theme, 0) self.previous_size = 0 - if not self.url_get_file('%s%s' % (self.themes_url, theme), os.path.join(themes_destination, theme), + if not self.url_get_file('{path}{name}'.format(path=self.themes_url, name=theme), + os.path.join(themes_destination, theme), sha256): - missed_files.append('Theme: {}'.format(theme)) + missed_files.append('Theme: {name}'.format(name=theme)) if missed_files: file_list = '' for entry in missed_files: - file_list += '{}
'.format(entry) + file_list += '{text}
'.format(text=entry) msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setWindowTitle(translate('OpenLP.FirstTimeWizard', 'Network Error')) msg.setText(translate('OpenLP.FirstTimeWizard', 'Unable to download some files')) msg.setInformativeText(translate('OpenLP.FirstTimeWizard', 'The following files were not able to be ' - 'downloaded:
{}'.format(file_list))) + 'downloaded:
{text}'.format(text=file_list))) msg.setStandardButtons(msg.Ok) ans = msg.exec() return True diff --git a/openlp/core/ui/firsttimewizard.py b/openlp/core/ui/firsttimewizard.py index 9f740e5cf..7b93c1680 100644 --- a/openlp/core/ui/firsttimewizard.py +++ b/openlp/core/ui/firsttimewizard.py @@ -228,12 +228,13 @@ class UiFirstTimeWizard(object): :param first_time_wizard: The wizard form """ first_time_wizard.setWindowTitle(translate('OpenLP.FirstTimeWizard', 'First Time Wizard')) - first_time_wizard.title_label.setText('%s' % - translate('OpenLP.FirstTimeWizard', 'Welcome to the First Time Wizard')) + text = translate('OpenLP.FirstTimeWizard', 'Welcome to the First Time Wizard') + first_time_wizard.title_label.setText('{text}' + ''.format(text=text)) + button = clean_button_text(first_time_wizard.buttonText(QtWidgets.QWizard.NextButton)) first_time_wizard.information_label.setText( translate('OpenLP.FirstTimeWizard', 'This wizard will help you to configure OpenLP for initial use. ' - 'Click the %s button below to start.') % - clean_button_text(first_time_wizard.buttonText(QtWidgets.QWizard.NextButton))) + 'Click the {button} button below to start.').format(button=button)) self.download_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Downloading Resource Index')) self.download_page.setSubTitle(translate('OpenLP.FirstTimeWizard', 'Please wait while the resource index is ' 'downloaded.')) @@ -264,18 +265,19 @@ class UiFirstTimeWizard(object): self.no_internet_page.setTitle(translate('OpenLP.FirstTimeWizard', 'No Internet Connection')) self.no_internet_page.setSubTitle( translate('OpenLP.FirstTimeWizard', 'Unable to detect an Internet connection.')) + button = clean_button_text(first_time_wizard.buttonText(QtWidgets.QWizard.FinishButton)) self.no_internet_text = translate('OpenLP.FirstTimeWizard', 'No Internet connection was found. The First Time Wizard needs an Internet ' 'connection in order to be able to download sample songs, Bibles and themes.' - ' Click the %s button now to start OpenLP with initial settings and ' + ' Click the {button} button now to start OpenLP with initial settings and ' 'no sample data.\n\nTo re-run the First Time Wizard and import this sample ' 'data at a later time, check your Internet connection and re-run this ' - 'wizard by selecting "Tools/Re-run First Time Wizard" from OpenLP.') % \ - clean_button_text(first_time_wizard.buttonText(QtWidgets.QWizard.FinishButton)) + 'wizard by selecting "Tools/Re-run First Time Wizard" from OpenLP.' + ).format(button=button) + button = clean_button_text(first_time_wizard.buttonText(QtWidgets.QWizard.CancelButton)) self.cancel_wizard_text = translate('OpenLP.FirstTimeWizard', '\n\nTo cancel the First Time Wizard completely (and not start OpenLP), ' - 'click the %s button now.') % \ - clean_button_text(first_time_wizard.buttonText(QtWidgets.QWizard.CancelButton)) + 'click the {button} button now.').format(button=button) self.songs_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Sample Songs')) self.songs_page.setSubTitle(translate('OpenLP.FirstTimeWizard', 'Select and download public domain songs.')) self.bibles_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Sample Bibles')) diff --git a/openlp/core/ui/formattingtagcontroller.py b/openlp/core/ui/formattingtagcontroller.py index b56f5009c..161930cb6 100644 --- a/openlp/core/ui/formattingtagcontroller.py +++ b/openlp/core/ui/formattingtagcontroller.py @@ -72,19 +72,19 @@ class FormattingTagController(object): """ for line_number, html1 in enumerate(self.protected_tags): if self._strip(html1['start tag']) == tag: - return translate('OpenLP.FormattingTagForm', 'Tag %s already defined.') % tag + return translate('OpenLP.FormattingTagForm', 'Tag {tag} already defined.').format(tag=tag) if self._strip(html1['desc']) == desc: - return translate('OpenLP.FormattingTagForm', 'Description %s already defined.') % tag + return translate('OpenLP.FormattingTagForm', 'Description {tag} already defined.').format(tag=tag) for line_number, html1 in enumerate(self.custom_tags): if self._strip(html1['start tag']) == tag: - return translate('OpenLP.FormattingTagForm', 'Tag %s already defined.') % tag + return translate('OpenLP.FormattingTagForm', 'Tag {tag} already defined.').format(tag=tag) if self._strip(html1['desc']) == desc: - return translate('OpenLP.FormattingTagForm', 'Description %s already defined.') % tag + return translate('OpenLP.FormattingTagForm', 'Description {tag} already defined.').format(tag=tag) tag = { 'desc': desc, - 'start tag': '{%s}' % tag, + 'start tag': '{{{tag}}}'.format(tag=tag), 'start html': start_html, - 'end tag': '{/%s}' % tag, + 'end tag': '{/{tag}}}'.format(tag=tag), 'end html': end_html, 'protected': False, 'temporary': False @@ -130,6 +130,7 @@ class FormattingTagController(object): elif not match.group('empty'): end_tags.append(tag) match = self.html_tag_regex.search(start_html, match.end()) + # TODO: Verify format() works with lambda return ''.join(map(lambda tag: '' % tag, reversed(end_tags))) def start_tag_changed(self, start_html, end_html): @@ -146,7 +147,8 @@ class FormattingTagController(object): end = self.start_html_to_end_html(start_html) if not end_html: if not end: - return translate('OpenLP.FormattingTagForm', 'Start tag %s is not valid HTML') % start_html, None + return translate('OpenLP.FormattingTagForm', + 'Start tag {tag} is not valid HTML').format(tag=start_html), None return None, end return None, None @@ -165,7 +167,8 @@ class FormattingTagController(object): if not end_html: return None, end if end and end != end_html: - return translate('OpenLP.FormattingTagForm', - 'End tag %(end)s does not match end tag for start tag %(start)s') % \ - {'end': end, 'start': start_html}, None + return (translate('OpenLP.FormattingTagForm', + 'End tag {end} does not match end tag for start tag {start}').format(end=end, + start=start_html), + None) return None, None diff --git a/openlp/core/ui/formattingtagform.py b/openlp/core/ui/formattingtagform.py index 6fb658f06..658653875 100644 --- a/openlp/core/ui/formattingtagform.py +++ b/openlp/core/ui/formattingtagform.py @@ -90,9 +90,10 @@ class FormattingTagForm(QtWidgets.QDialog, Ui_FormattingTagDialog, FormattingTag """ new_row = self.tag_table_widget.rowCount() self.tag_table_widget.insertRow(new_row) - self.tag_table_widget.setItem(new_row, 0, QtWidgets.QTableWidgetItem(translate('OpenLP.FormattingTagForm', - 'New Tag %d' % new_row))) - self.tag_table_widget.setItem(new_row, 1, QtWidgets.QTableWidgetItem('n%d' % new_row)) + self.tag_table_widget.setItem(new_row, 0, + QtWidgets.QTableWidgetItem(translate('OpenLP.FormattingTagForm', + 'New Tag {row:d}').format(row=new_row))) + self.tag_table_widget.setItem(new_row, 1, QtWidgets.QTableWidgetItem('n{row:d}'.format(row=new_row))) self.tag_table_widget.setItem(new_row, 2, QtWidgets.QTableWidgetItem(translate('OpenLP.FormattingTagForm', ''))) self.tag_table_widget.setItem(new_row, 3, QtWidgets.QTableWidgetItem('')) diff --git a/openlp/core/ui/generaltab.py b/openlp/core/ui/generaltab.py index 816e947ba..9fdc7d297 100644 --- a/openlp/core/ui/generaltab.py +++ b/openlp/core/ui/generaltab.py @@ -400,7 +400,7 @@ class GeneralTab(SettingsTab): """ Select the logo file """ - file_filters = '%s;;%s (*.*)' % (get_images_filter(), UiStrings().AllFiles) + file_filters = '{text};;{names} (*.*)'.format(text=get_images_filter(), names=UiStrings().AllFiles) filename, filter_used = QtWidgets.QFileDialog.getOpenFileName(self, translate('OpenLP.AdvancedTab', 'Open File'), '', file_filters) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index a0235bb9b..ccd12727c 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -471,7 +471,8 @@ class Ui_MainWindow(object): self.web_site_item.setText(translate('OpenLP.MainWindow', '&Web Site')) for item in self.language_group.actions(): item.setText(item.objectName()) - item.setStatusTip(translate('OpenLP.MainWindow', 'Set the interface language to %s') % item.objectName()) + item.setStatusTip(translate('OpenLP.MainWindow', + 'Set the interface language to {name}').format(name=item.objectName())) self.auto_language_item.setText(translate('OpenLP.MainWindow', '&Autodetect')) self.auto_language_item.setStatusTip(translate('OpenLP.MainWindow', 'Use the system language, if available.')) self.tools_add_tool_item.setText(translate('OpenLP.MainWindow', 'Add &Tool...')) @@ -1334,8 +1335,10 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, RegistryProperties): for file_id, filename in enumerate(recent_files_to_display): log.debug('Recent file name: {name}'.format(name=filename)) # TODO: Verify ''.format() before committing - action = create_action(self, '', text='&%d %s' % (file_id + 1, - os.path.splitext(os.path.basename(str(filename)))[0]), data=filename, + action = create_action(self, '', + text='&{n} {name}'.format(n=file_id + 1, + name=os.path.splitext(os.path.basename(str(filename)))[0]), + data=filename, triggers=self.service_manager_contents.on_recent_service_clicked) self.recent_files_menu.addAction(action) clear_recent_files_action = create_action(self, '', diff --git a/openlp/core/ui/plugindialog.py b/openlp/core/ui/plugindialog.py index 583728fcd..ad461cd44 100644 --- a/openlp/core/ui/plugindialog.py +++ b/openlp/core/ui/plugindialog.py @@ -74,6 +74,6 @@ class Ui_PluginViewDialog(object): """ plugin_view_dialog.setWindowTitle(translate('OpenLP.PluginForm', 'Manage Plugins')) self.plugin_info_group_box.setTitle(translate('OpenLP.PluginForm', 'Plugin Details')) - self.about_label.setText('%s:' % UiStrings().About) + self.about_label.setText('{about}:'.format(about=UiStrings().About)) self.status_label.setText(translate('OpenLP.PluginForm', 'Status:')) self.status_checkbox.setText(translate('OpenLP.PluginForm', 'Active')) diff --git a/openlp/core/ui/pluginform.py b/openlp/core/ui/pluginform.py index cb6dd70aa..4280bcd25 100644 --- a/openlp/core/ui/pluginform.py +++ b/openlp/core/ui/pluginform.py @@ -60,6 +60,7 @@ class PluginForm(QtWidgets.QDialog, Ui_PluginViewDialog, RegistryProperties): self._clear_details() self.programatic_change = True plugin_list_width = 0 + # TODO: See how to use format() with variables for plugin in self.plugin_manager.plugins: item = QtWidgets.QListWidgetItem(self.plugin_list_widget) # We do this just to make 100% sure the status is an integer as @@ -94,7 +95,7 @@ class PluginForm(QtWidgets.QDialog, Ui_PluginViewDialog, RegistryProperties): """ Set the details of the currently selected plugin """ - log.debug('PluginStatus: %s', str(self.active_plugin.status)) + log.debug('PluginStatus: {status}'.format(status=str(self.active_plugin.status))) self.about_text_browser.setHtml(self.active_plugin.about()) self.programatic_change = True if self.active_plugin.status != PluginStatus.Disabled: @@ -136,6 +137,7 @@ class PluginForm(QtWidgets.QDialog, Ui_PluginViewDialog, RegistryProperties): self.active_plugin.app_startup() else: self.active_plugin.toggle_status(PluginStatus.Inactive) + # TODO: Verify using format() with a variable status_text = translate('OpenLP.PluginForm', '%s (Inactive)') if self.active_plugin.status == PluginStatus.Active: status_text = translate('OpenLP.PluginForm', '%s (Active)') diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 35ec1bb9e..907cb49a6 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -118,7 +118,7 @@ class Ui_ServiceManager(object): tooltip=translate('OpenLP.ServiceManager', 'Save this service.'), triggers=self.decide_save_method) self.toolbar.addSeparator() - self.theme_label = QtWidgets.QLabel('%s:' % UiStrings().Theme, widget) + self.theme_label = QtWidgets.QLabel('{theme}:'.format(theme=UiStrings().Theme), widget) self.theme_label.setContentsMargins(3, 3, 3, 3) self.theme_label.setObjectName('theme_label') self.toolbar.add_toolbar_widget(self.theme_label) @@ -503,8 +503,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa path_file_name = str(self.file_name()) path, file_name = os.path.split(path_file_name) base_name = os.path.splitext(file_name)[0] - service_file_name = '%s.osj' % base_name - self.log_debug('ServiceManager.save_file - %s' % path_file_name) + service_file_name = '{name}.osj'.format(name=base_name) + self.log_debug('ServiceManager.save_file - {name}'.format(name=path_file_name)) Settings().setValue(self.main_window.service_manager_settings_section + '/last directory', path) service = self.create_basic_service() write_list = [] @@ -530,8 +530,9 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa self.application.set_normal_cursor() title = translate('OpenLP.ServiceManager', 'Service File(s) Missing') message = translate('OpenLP.ServiceManager', - 'The following file(s) in the service are missing: %s\n\n' - 'These files will be removed if you continue to save.') % "\n\t".join(missing_list) + 'The following file(s) in the service are missing: {name}\n\n' + 'These files will be removed if you continue to save.' + ).format(name="\n\t".join(missing_list)) answer = QtWidgets.QMessageBox.critical(self, title, message, QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)) @@ -561,7 +562,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa service_content = json.dumps(service) # Usual Zip file cannot exceed 2GiB, file with Zip64 cannot be extracted using unzip in UNIX. allow_zip_64 = (total_size > 2147483648 + len(service_content)) - self.log_debug('ServiceManager.save_file - allowZip64 is %s' % allow_zip_64) + self.log_debug('ServiceManager.save_file - allowZip64 is {text}'.format(text=allow_zip_64)) zip_file = None success = True self.main_window.increment_progress_bar() @@ -584,7 +585,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa shutil.copy(audio_from, save_file) zip_file.write(audio_from, audio_to) except IOError: - self.log_exception('Failed to save service to disk: %s' % temp_file_name) + self.log_exception('Failed to save service to disk: {name}'.format(name=temp_file_name)) self.main_window.error_message(translate('OpenLP.ServiceManager', 'Error Saving File'), translate('OpenLP.ServiceManager', 'There was an error saving your file.')) success = False @@ -601,7 +602,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa except OSError as ose: QtWidgets.QMessageBox.critical(self, translate('OpenLP.ServiceManager', 'Error Saving File'), translate('OpenLP.ServiceManager', 'An error occurred while writing the ' - 'service file: %s') % ose.strerror, + 'service file: {error}').format(error=ose.strerror), QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Ok)) success = False self.main_window.add_recent_file(path_file_name) @@ -623,8 +624,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa path_file_name = str(self.file_name()) path, file_name = os.path.split(path_file_name) base_name = os.path.splitext(file_name)[0] - service_file_name = '%s.osj' % base_name - self.log_debug('ServiceManager.save_file - %s' % path_file_name) + service_file_name = '{name}.osj'.format(name=base_name) + self.log_debug('ServiceManager.save_file - {name}'.format(name=path_file_name)) Settings().setValue(self.main_window.service_manager_settings_section + '/last directory', path) service = self.create_basic_service() self.application.set_busy_cursor() @@ -645,7 +646,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa # First we add service contents. zip_file.writestr(service_file_name, service_content) except IOError: - self.log_exception('Failed to save service to disk: %s', temp_file_name) + self.log_exception('Failed to save service to disk: {name}'.format(name=temp_file_name)) self.main_window.error_message(translate('OpenLP.ServiceManager', 'Error Saving File'), translate('OpenLP.ServiceManager', 'There was an error saving your file.')) success = False @@ -740,13 +741,13 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa try: ucs_file = zip_info.filename except UnicodeDecodeError: - self.log_exception('file_name "%s" is not valid UTF-8' % zip_info.file_name) + self.log_exception('file_name "{name}" is not valid UTF-8'.format(name=zip_info.file_name)) critical_error_message_box(message=translate('OpenLP.ServiceManager', 'File is not a valid service.\n The content encoding is not UTF-8.')) continue os_file = ucs_file.replace('/', os.path.sep) os_file = os.path.basename(os_file) - self.log_debug('Extract file: %s' % os_file) + self.log_debug('Extract file: {name}'.format(name=os_file)) zip_info.filename = os_file zip_file.extract(zip_info, self.service_path) if os_file.endswith('osj') or os_file.endswith('osd'): @@ -774,18 +775,18 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa critical_error_message_box(message=translate('OpenLP.ServiceManager', 'File is not a valid service.')) self.log_error('File contains no service data') except (IOError, NameError, zipfile.BadZipfile): - self.log_exception('Problem loading service file %s' % file_name) + self.log_exception('Problem loading service file {name}'.format(name=file_name)) critical_error_message_box(message=translate('OpenLP.ServiceManager', 'File could not be opened because it is corrupt.')) except zipfile.BadZipfile: if os.path.getsize(file_name) == 0: - self.log_exception('Service file is zero sized: %s' % file_name) + self.log_exception('Service file is zero sized: {name}'.format(name=file_name)) QtWidgets.QMessageBox.information(self, translate('OpenLP.ServiceManager', 'Empty File'), translate('OpenLP.ServiceManager', 'This service file does not contain ' 'any data.')) else: - self.log_exception('Service file is cannot be extracted as zip: %s' % file_name) + self.log_exception('Service file is cannot be extracted as zip: {name}'.format(name=file_name)) QtWidgets.QMessageBox.information(self, translate('OpenLP.ServiceManager', 'Corrupt File'), translate('OpenLP.ServiceManager', 'This file is either corrupt or it is not an OpenLP 2 ' @@ -874,7 +875,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa self.auto_play_slides_loop.setChecked(service_item['service_item'].auto_play_slides_loop) self.timed_slide_interval.setChecked(service_item['service_item'].timed_slide_interval > 0) if service_item['service_item'].timed_slide_interval > 0: - delay_suffix = ' %s s' % str(service_item['service_item'].timed_slide_interval) + delay_suffix = ' {text} s'.format(text=str(service_item['service_item'].timed_slide_interval)) else: delay_suffix = ' ...' self.timed_slide_interval.setText( @@ -1268,14 +1269,17 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa tree_widget_item.setText(0, service_item_from_item.get_display_title()) tips = [] if service_item_from_item.temporary_edit: - tips.append('%s: %s' % (translate('OpenLP.ServiceManager', 'Edit'), - (translate('OpenLP.ServiceManager', 'Service copy only')))) + text1 = translate('OpenLP.ServiceManager', 'Edit') + text2 = translate('OpenLP.ServiceManager', 'Service copy only') + tips.append('{text1}: {text2}'.format(text1=text1, text2=text2)) if service_item_from_item.theme and service_item_from_item.theme != -1: - tips.append('%s: %s' % - (translate('OpenLP.ServiceManager', 'Slide theme'), service_item_from_item.theme)) + text = translate('OpenLP.ServiceManager', 'Slide theme') + tips.append('{text1}: {text2}'.format(text1=text, + text2=service_item_from_item.theme)) if service_item_from_item.notes: - tips.append('%s: %s' % - (translate('OpenLP.ServiceManager', 'Notes'), html.escape(service_item_from_item.notes))) + text1 = translate('OpenLP.ServiceManager', 'Notes') + text2 = html.escape(service_item_from_item.notes) + tips.append('{text1}: {text2}'.format(text1=text1, text2=text2)) if item['service_item'].is_capable(ItemCapabilities.HasVariableStartTime): tips.append(item['service_item'].get_media_time()) tree_widget_item.setToolTip(0, '
'.join(tips)) @@ -1637,7 +1641,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa replace = True else: self.drop_position = get_parent_item_data(item) - 1 - Registry().execute('%s_add_service_item' % plugin, replace) + Registry().execute('{plugin}_add_service_item'.format(plugin=plugin), replace) def update_theme_list(self, theme_list): """ diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index 82d72694c..42558b830 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -85,7 +85,7 @@ class SettingsForm(QtWidgets.QDialog, Ui_SettingsDialog, RegistryProperties): :param tab_widget: The widget to add :param is_visible: If this tab should be visible """ - log.debug('Inserting %s tab' % tab_widget.tab_title) + log.debug('Inserting {text} tab'.format(text=tab_widget.tab_title)) # add the tab to get it to display in the correct part of the screen self.stacked_layout.addWidget(tab_widget) if is_visible: diff --git a/openlp/core/ui/shortcutlistform.py b/openlp/core/ui/shortcutlistform.py index e0d72d9e1..1266d1cc4 100644 --- a/openlp/core/ui/shortcutlistform.py +++ b/openlp/core/ui/shortcutlistform.py @@ -425,11 +425,12 @@ class ShortcutListForm(QtWidgets.QDialog, Ui_ShortcutListDialog, RegistryPropert if changing_action.shortcutContext() in [QtCore.Qt.WindowShortcut, QtCore.Qt.ApplicationShortcut]: is_valid = False if not is_valid: + text = translate('OpenLP.ShortcutListDialog', + 'The shortcut "{key}" is already assigned to another action, please' + ' use a different shortcut.' + ).format(key=self.get_shortcut_string(key_sequence)) self.main_window.warning_message(translate('OpenLP.ShortcutListDialog', 'Duplicate Shortcut'), - translate('OpenLP.ShortcutListDialog', - 'The shortcut "%s" is already assigned to another action, please' - ' use a different shortcut.') % - self.get_shortcut_string(key_sequence, for_display=True)) + text, for_display=True) self.dialog_was_shown = True return is_valid diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index c06860057..9379bb96f 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -98,7 +98,7 @@ class DisplayController(QtWidgets.QWidget): """ sender = self.sender().objectName() if self.sender().objectName() else self.sender().text() controller = self - Registry().execute('%s' % sender, [controller, args]) + Registry().execute('{text}'.format(text=sender), [controller, args]) class InfoLabel(QtWidgets.QLabel): @@ -395,7 +395,7 @@ class SlideController(DisplayController, RegistryProperties): {'key': 'O', 'configurable': True, 'text': translate('OpenLP.SlideController', 'Go to "Other"')} ] shortcuts.extend([{'key': str(number)} for number in range(10)]) - self.controller.addActions([create_action(self, 'shortcutAction_%s' % s['key'], + self.controller.addActions([create_action(self, 'shortcutAction_{key}'.format(key=s['key']), text=s.get('text'), can_shortcuts=True, context=QtCore.Qt.WidgetWithChildrenShortcut, @@ -417,14 +417,20 @@ class SlideController(DisplayController, RegistryProperties): self.preview_widget.doubleClicked.connect(self.on_preview_double_click) self.toolbar.set_widget_visible(['editSong'], False) self.controller.addActions([self.next_item, self.previous_item]) - Registry().register_function('slidecontroller_%s_stop_loop' % self.type_prefix, self.on_stop_loop) - Registry().register_function('slidecontroller_%s_change' % self.type_prefix, self.on_slide_change) - Registry().register_function('slidecontroller_%s_blank' % self.type_prefix, self.on_slide_blank) - Registry().register_function('slidecontroller_%s_unblank' % self.type_prefix, self.on_slide_unblank) + Registry().register_function('slidecontroller_{text}_stop_loop'.format(text=self.type_prefix), + self.on_stop_loop) + Registry().register_function('slidecontroller_{text}_change'.format(text=self.type_prefix), + self.on_slide_change) + Registry().register_function('slidecontroller_{text}_blank'.format(text=self.type_prefix), + self.on_slide_blank) + Registry().register_function('slidecontroller_{text}_unblank'.format(text=self.type_prefix), + self.on_slide_unblank) Registry().register_function('slidecontroller_update_slide_limits', self.update_slide_limits) - getattr(self, 'slidecontroller_%s_set' % self.type_prefix).connect(self.on_slide_selected_index) - getattr(self, 'slidecontroller_%s_next' % self.type_prefix).connect(self.on_slide_selected_next) - getattr(self, 'slidecontroller_%s_previous' % self.type_prefix).connect(self.on_slide_selected_previous) + getattr(self, 'slidecontroller_{text}_set'.format(text=self.type_prefix)).connect(self.on_slide_selected_index) + getattr(self, 'slidecontroller_{text}_next'.format(text=self.type_prefix)).connect(self.on_slide_selected_next) + # NOTE: {t} used to keep line length < maxline + getattr(self, + 'slidecontroller_{t}_previous'.format(t=self.type_prefix)).connect(self.on_slide_selected_previous) def _slide_shortcut_activated(self): """ @@ -841,7 +847,8 @@ class SlideController(DisplayController, RegistryProperties): self.service_item = copy.copy(service_item) if self.service_item.is_command(): Registry().execute( - '%s_start' % service_item.name.lower(), [self.service_item, self.is_live, self.hide_mode(), slide_no]) + '{text}_start'.format(text=service_item.name.lower()), + [self.service_item, self.is_live, self.hide_mode(), slide_no]) # Reset blanking if needed if old_item and self.is_live and (old_item.is_capable(ItemCapabilities.ProvidesOwnDisplay) or self.service_item.is_capable(ItemCapabilities.ProvidesOwnDisplay)): @@ -879,8 +886,8 @@ class SlideController(DisplayController, RegistryProperties): if frame['verseTag']: # These tags are already translated. verse_def = frame['verseTag'] - verse_def = '%s%s' % (verse_def[0], verse_def[1:]) - two_line_def = '%s\n%s' % (verse_def[0], verse_def[1:]) + verse_def = '{def1}{def2}'.format(def1=verse_def[0], def2=verse_def[1:]) + two_line_def = '{def1}\n{def2}'.format(def1=verse_def[0], def2=verse_def[1:]) row = two_line_def if verse_def not in self.slide_list: self.slide_list[verse_def] = frame_number @@ -915,10 +922,10 @@ class SlideController(DisplayController, RegistryProperties): # close the previous, so make sure we don't close the new one. if old_item.is_command() and not self.service_item.is_command() or \ old_item.is_command() and not old_item.is_media() and self.service_item.is_media(): - Registry().execute('%s_stop' % old_item.name.lower(), [old_item, self.is_live]) + Registry().execute('{name}_stop'.format(name=old_item.name.lower()), [old_item, self.is_live]) if old_item.is_media() and not self.service_item.is_media(): self.on_media_close() - Registry().execute('slidecontroller_%s_started' % self.type_prefix, [self.service_item]) + Registry().execute('slidecontroller_{item}_started'.format(item=self.type_prefix), [self.service_item]) def on_slide_selected_index(self, message): """ @@ -930,7 +937,8 @@ class SlideController(DisplayController, RegistryProperties): if not self.service_item: return if self.service_item.is_command(): - Registry().execute('%s_slide' % self.service_item.name.lower(), [self.service_item, self.is_live, index]) + Registry().execute('{name}_slide'.format(name=self.service_item.name.lower()), + [self.service_item, self.is_live, index]) self.update_preview() self.selected_row = index else: @@ -975,7 +983,7 @@ class SlideController(DisplayController, RegistryProperties): """ if checked is None: checked = self.blank_screen.isChecked() - self.log_debug('on_blank_display %s' % checked) + self.log_debug('on_blank_display {text}'.format(text=checked)) self.hide_menu.setDefaultAction(self.blank_screen) self.blank_screen.setChecked(checked) self.theme_screen.setChecked(False) @@ -996,7 +1004,7 @@ class SlideController(DisplayController, RegistryProperties): """ if checked is None: checked = self.theme_screen.isChecked() - self.log_debug('on_theme_display %s' % checked) + self.log_debug('on_theme_display {text}'.format(text=checked)) self.hide_menu.setDefaultAction(self.theme_screen) self.blank_screen.setChecked(False) self.theme_screen.setChecked(checked) @@ -1017,7 +1025,7 @@ class SlideController(DisplayController, RegistryProperties): """ if checked is None: checked = self.desktop_screen.isChecked() - self.log_debug('on_hide_display %s' % checked) + self.log_debug('on_hide_display {text}'.format(text=checked)) self.hide_menu.setDefaultAction(self.desktop_screen) self.blank_screen.setChecked(False) self.theme_screen.setChecked(False) @@ -1035,17 +1043,18 @@ class SlideController(DisplayController, RegistryProperties): Blank/Hide the display screen within a plugin if required. """ hide_mode = self.hide_mode() - self.log_debug('blank_plugin %s ' % hide_mode) + self.log_debug('blank_plugin {text}'.format(text=hide_mode)) if self.service_item is not None: if hide_mode: if not self.service_item.is_command(): Registry().execute('live_display_hide', hide_mode) - Registry().execute('%s_blank' % - self.service_item.name.lower(), [self.service_item, self.is_live, hide_mode]) + Registry().execute('{text}_blank'.format(text=self.service_item.name.lower()), + [self.service_item, self.is_live, hide_mode]) else: if not self.service_item.is_command(): Registry().execute('live_display_show') - Registry().execute('%s_unblank' % self.service_item.name.lower(), [self.service_item, self.is_live]) + Registry().execute('{text}_unblank'.format(text=self.service_item.name.lower()), + [self.service_item, self.is_live]) else: if hide_mode: Registry().execute('live_display_hide', hide_mode) @@ -1056,15 +1065,17 @@ class SlideController(DisplayController, RegistryProperties): """ Tell the plugin to hide the display screen. """ - self.log_debug('hide_plugin %s ' % hide) + self.log_debug('hide_plugin {text}'.format(text=hide)) if self.service_item is not None: if hide: Registry().execute('live_display_hide', HideMode.Screen) - Registry().execute('%s_hide' % self.service_item.name.lower(), [self.service_item, self.is_live]) + Registry().execute('{text}_hide'.format(text=self.service_item.name.lower()), + [self.service_item, self.is_live]) else: if not self.service_item.is_command(): Registry().execute('live_display_show') - Registry().execute('%s_unblank' % self.service_item.name.lower(), [self.service_item, self.is_live]) + Registry().execute('{text}_unblank'.format(text=self.service_item.name.lower()), + [self.service_item, self.is_live]) else: if hide: Registry().execute('live_display_hide', HideMode.Screen) @@ -1099,8 +1110,8 @@ class SlideController(DisplayController, RegistryProperties): if -1 < row < self.preview_widget.slide_count(): if self.service_item.is_command(): if self.is_live and not start: - Registry().execute('%s_slide' % - self.service_item.name.lower(), [self.service_item, self.is_live, row]) + Registry().execute('{text}_slide'.format(text=self.service_item.name.lower()), + [self.service_item, self.is_live, row]) else: to_display = self.service_item.get_rendered_frame(row) if self.service_item.is_text(): @@ -1133,7 +1144,7 @@ class SlideController(DisplayController, RegistryProperties): """ This updates the preview frame, for example after changing a slide or using *Blank to Theme*. """ - self.log_debug('update_preview %s ' % self.screens.current['primary']) + self.log_debug('update_preview {text} '.format(text=self.screens.current['primary'])) if self.service_item and self.service_item.is_capable(ItemCapabilities.ProvidesOwnDisplay): if self.is_live: # If live, grab screen-cap of main display now @@ -1185,7 +1196,8 @@ class SlideController(DisplayController, RegistryProperties): if not self.service_item: return if self.service_item.is_command(): - Registry().execute('%s_next' % self.service_item.name.lower(), [self.service_item, self.is_live]) + Registry().execute('{text}_next'.format(text=self.service_item.name.lower()), + [self.service_item, self.is_live]) if self.is_live: self.update_preview() else: @@ -1213,7 +1225,8 @@ class SlideController(DisplayController, RegistryProperties): if not self.service_item: return if self.service_item.is_command(): - Registry().execute('%s_previous' % self.service_item.name.lower(), [self.service_item, self.is_live]) + Registry().execute('{text}_previous'.format(text=self.service_item.name.lower()), + [self.service_item, self.is_live]) if self.is_live: self.update_preview() else: @@ -1265,7 +1278,7 @@ class SlideController(DisplayController, RegistryProperties): checked = self.play_slides_loop.isChecked() else: self.play_slides_loop.setChecked(checked) - self.log_debug('on_play_slides_loop %s' % checked) + self.log_debug('on_play_slides_loop {text}'.format(text=checked)) if checked: self.play_slides_loop.setIcon(build_icon(':/media/media_stop.png')) self.play_slides_loop.setText(UiStrings().StopPlaySlidesInLoop) @@ -1288,7 +1301,7 @@ class SlideController(DisplayController, RegistryProperties): checked = self.play_slides_once.isChecked() else: self.play_slides_once.setChecked(checked) - self.log_debug('on_play_slides_once %s' % checked) + self.log_debug('on_play_slides_once {text}'.format(text=checked)) if checked: self.play_slides_once.setIcon(build_icon(':/media/media_stop.png')) self.play_slides_once.setText(UiStrings().StopPlaySlidesToEnd) @@ -1354,7 +1367,8 @@ class SlideController(DisplayController, RegistryProperties): # Live and Preview have issues if we have video or presentations # playing in both at the same time. if self.service_item.is_command(): - Registry().execute('%s_stop' % self.service_item.name.lower(), [self.service_item, self.is_live]) + Registry().execute('{text}_stop'.format(text=self.service_item.name.lower()), + [self.service_item, self.is_live]) if self.service_item.is_media(): self.on_media_close() self.on_go_live() diff --git a/openlp/core/ui/starttimeform.py b/openlp/core/ui/starttimeform.py index f6238a340..386608970 100644 --- a/openlp/core/ui/starttimeform.py +++ b/openlp/core/ui/starttimeform.py @@ -56,9 +56,9 @@ class StartTimeForm(QtWidgets.QDialog, Ui_StartTimeDialog, RegistryProperties): self.hour_finish_spin_box.setValue(hours) self.minute_finish_spin_box.setValue(minutes) self.second_finish_spin_box.setValue(seconds) - self.hour_finish_label.setText('%s%s' % (str(hour), UiStrings().Hours)) - self.minute_finish_label.setText('%s%s' % (str(minutes), UiStrings().Minutes)) - self.second_finish_label.setText('%s%s' % (str(seconds), UiStrings().Seconds)) + self.hour_finish_label.setText('{val:d}{text}'.format(val=hour, text=UiStrings().Hours)) + self.minute_finish_label.setText('{val:d}{text}'.format(val=minutes, text=UiStrings().Minutes)) + self.second_finish_label.setText('{val:d}{text}'.format(val=seconds, text=UiStrings().Seconds)) return QtWidgets.QDialog.exec(self) def accept(self): diff --git a/openlp/core/ui/themeform.py b/openlp/core/ui/themeform.py index 2ec733629..475bfc0b7 100644 --- a/openlp/core/ui/themeform.py +++ b/openlp/core/ui/themeform.py @@ -263,7 +263,7 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties): """ Run the wizard. """ - log.debug('Editing theme %s' % self.theme.theme_name) + log.debug('Editing theme {name}'.format(name=self.theme.theme_name)) self.temp_background_filename = '' self.update_theme_allowed = False self.set_defaults() @@ -272,7 +272,8 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties): self.theme_name_edit.setVisible(not edit) self.edit_mode = edit if edit: - self.setWindowTitle(translate('OpenLP.ThemeWizard', 'Edit Theme - %s') % self.theme.theme_name) + self.setWindowTitle(translate('OpenLP.ThemeWizard', 'Edit Theme - {name}' + ).format(name=self.theme.theme_name)) self.next() else: self.setWindowTitle(UiStrings().NewTheme) @@ -282,7 +283,7 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties): """ Set up the pages for Initial run through dialog """ - log.debug('initializePage %s' % page_id) + log.debug('initializePage {page}'.format(page=page_id)) wizard_page = self.page(page_id) if wizard_page == self.background_page: self.set_background_page_values() @@ -445,7 +446,7 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties): Background Image button pushed. """ images_filter = get_images_filter() - images_filter = '%s;;%s (*.*)' % (images_filter, UiStrings().AllFiles) + images_filter = '{name};;{text} (*.*)'.format(name=images_filter, text=UiStrings().AllFiles) filename, filter_used = QtWidgets.QFileDialog.getOpenFileName( self, translate('OpenLP.ThemeWizard', 'Select Image'), self.image_file_edit.text(), images_filter) @@ -463,6 +464,7 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties): """ Background video button pushed. """ + # TODO: Check this before converting visible_formats = '(%s)' % '; '.join(VIDEO_EXT) actual_formats = '(%s)' % ' '.join(VIDEO_EXT) video_filter = '{trans} {visible} {actual}'.format(trans=translate('OpenLP', 'Video Files'), diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 14a4663f4..70ca9fd88 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -203,7 +203,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage Change the global theme when it is changed through the Themes settings tab """ self.global_theme = Settings().value(self.settings_section + '/global theme') - self.log_debug('change_global_from_tab %s' % self.global_theme) + self.log_debug('change_global_from_tab {text}'.format(text=self.global_theme)) for count in range(0, self.theme_list_widget.count()): # reset the old name item = self.theme_list_widget.item(count) @@ -213,7 +213,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage self.theme_list_widget.item(count).setText(new_name) # Set the new name if self.global_theme == new_name: - name = translate('OpenLP.ThemeManager', '%s (default)') % new_name + name = translate('OpenLP.ThemeManager', '{text} (default)').format(text=new_name) self.theme_list_widget.item(count).setText(name) self.delete_toolbar_action.setVisible(item not in self.theme_list_widget.selectedItems()) @@ -233,7 +233,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage # Set the new name if count == selected_row: self.global_theme = self.theme_list_widget.item(count).text() - name = translate('OpenLP.ThemeManager', '%s (default)') % self.global_theme + name = translate('OpenLP.ThemeManager', '{text} (default)').format(text=self.global_theme) self.theme_list_widget.item(count).setText(name) Settings().setValue(self.settings_section + '/global theme', self.global_theme) Registry().execute('theme_update_global') @@ -256,6 +256,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage Renames an existing theme to a new name :param field: """ + # TODO: Check for delayed format() conversions if self._validate_theme_action(translate('OpenLP.ThemeManager', 'You must select a theme to rename.'), translate('OpenLP.ThemeManager', 'Rename Confirmation'), translate('OpenLP.ThemeManager', 'Rename %s theme?'), False, False): @@ -284,7 +285,8 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage item = self.theme_list_widget.currentItem() old_theme_name = item.data(QtCore.Qt.UserRole) self.file_rename_form.file_name_edit.setText(translate('OpenLP.ThemeManager', - 'Copy of %s', 'Copy of ') % old_theme_name) + 'Copy of {name}', + 'Copy of ').format(name=old_theme_name)) if self.file_rename_form.exec(True): new_theme_name = self.file_rename_form.file_name_edit.text() if self.check_if_theme_exists(new_theme_name): @@ -331,6 +333,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage Delete a theme triggered by the UI. :param field: """ + # TODO: Verify delayed format() conversions if self._validate_theme_action(translate('OpenLP.ThemeManager', 'You must select a theme to delete.'), translate('OpenLP.ThemeManager', 'Delete Confirmation'), translate('OpenLP.ThemeManager', 'Delete %s theme?')): @@ -351,7 +354,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage :param theme: The theme to delete. """ self.theme_list.remove(theme) - thumb = '%s.png' % theme + thumb = '{name}.png'.format(name=theme) delete_file(os.path.join(self.path, thumb)) delete_file(os.path.join(self.thumb_path, thumb)) try: @@ -363,7 +366,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage shutil.rmtree(os.path.join(self.path, theme).encode(encoding)) except OSError as os_error: shutil.Error = os_error - self.log_exception('Error deleting theme %s' % theme) + self.log_exception('Error deleting theme {name}'.format(name=theme)) def on_export_theme(self, field=None): """ @@ -376,7 +379,8 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage return theme = item.data(QtCore.Qt.UserRole) path = QtWidgets.QFileDialog.getExistingDirectory(self, - translate('OpenLP.ThemeManager', 'Save Theme - (%s)') % theme, + translate('OpenLP.ThemeManager', + 'Save Theme - ({name})').format(name=theme), Settings().value(self.settings_section + '/last directory export')) self.application.set_busy_cursor() @@ -409,7 +413,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage self.log_exception('Export Theme Failed') critical_error_message_box(translate('OpenLP.ThemeManager', 'Theme Export Failed'), translate('OpenLP.ThemeManager', 'The theme export failed because this error ' - 'occurred: %s') % ose.strerror) + 'occurred: {err}').format(err=ose.strerror)) if theme_zip: theme_zip.close() shutil.rmtree(theme_path, True) @@ -425,7 +429,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage translate('OpenLP.ThemeManager', 'Select Theme Import File'), Settings().value(self.settings_section + '/last directory import'), translate('OpenLP.ThemeManager', 'OpenLP Themes (*.otz)')) - self.log_info('New Themes %s' % str(files)) + self.log_info('New Themes {name}'.format(name=str(files))) if not files: return self.application.set_busy_cursor() @@ -472,10 +476,10 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage if os.path.exists(theme): text_name = os.path.splitext(name)[0] if text_name == self.global_theme: - name = translate('OpenLP.ThemeManager', '%s (default)') % text_name + name = translate('OpenLP.ThemeManager', '{name} (default)').format(name=text_name) else: name = text_name - thumb = os.path.join(self.thumb_path, '%s.png' % text_name) + thumb = os.path.join(self.thumb_path, '{name}.png'.format(name=text_name)) item_name = QtWidgets.QListWidgetItem(name) if validate_thumb(theme, thumb): icon = build_icon(thumb) @@ -506,7 +510,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage :param theme_name: Name of the theme to load from file :return: The theme object. """ - self.log_debug('get theme data for theme %s' % theme_name) + self.log_debug('get theme data for theme {name}'.format(name=theme_name)) xml_file = os.path.join(self.path, str(theme_name), str(theme_name) + '.xml') xml = get_text_file_string(xml_file) if not xml: @@ -524,8 +528,8 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage """ ret = QtWidgets.QMessageBox.question(self, translate('OpenLP.ThemeManager', 'Theme Already Exists'), translate('OpenLP.ThemeManager', - 'Theme %s already exists. Do you want to replace it?') - .replace('%s', theme_name), + 'Theme {name} already exists. ' + 'Do you want to replace it?').format(name=theme_name), QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No), QtWidgets.QMessageBox.No) @@ -538,7 +542,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage :param file_name: :param directory: """ - self.log_debug('Unzipping theme %s' % file_name) + self.log_debug('Unzipping theme {name}'.format(name=file_name)) theme_zip = None out_file = None file_xml = None @@ -547,7 +551,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage theme_zip = zipfile.ZipFile(file_name) xml_file = [name for name in theme_zip.namelist() if os.path.splitext(name)[1].lower() == '.xml'] if len(xml_file) != 1: - self.log_error('Theme contains "%s" XML files' % len(xml_file)) + self.log_error('Theme contains "{val:d}" XML files'.format(val=len(xml_file))) raise ValidationError xml_tree = ElementTree(element=XML(theme_zip.read(xml_file[0]))).getroot() theme_version = xml_tree.get('version', default=None) @@ -579,7 +583,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage out_file.write(theme_zip.read(name)) out_file.close() except (IOError, zipfile.BadZipfile): - self.log_exception('Importing theme from zip failed %s' % file_name) + self.log_exception('Importing theme from zip failed {name|'.format(name=file_name)) raise ValidationError except ValidationError: critical_error_message_box(translate('OpenLP.ThemeManager', 'Validation Error'), @@ -601,7 +605,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage critical_error_message_box( translate('OpenLP.ThemeManager', 'Validation Error'), translate('OpenLP.ThemeManager', 'File is not a valid theme.')) - self.log_error('Theme file does not contain XML data %s' % file_name) + self.log_error('Theme file does not contain XML data {name}'.format(name=file_name)) def check_if_theme_exists(self, theme_name): """ @@ -682,7 +686,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage if os.path.exists(sample_path_name): os.unlink(sample_path_name) frame.save(sample_path_name, 'png') - thumb = os.path.join(self.thumb_path, '%s.png' % name) + thumb = os.path.join(self.thumb_path, '{name}.png'.format(name=name)) create_thumb(sample_path_name, thumb, False) def update_preview_images(self): @@ -760,14 +764,17 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage for plugin in self.plugin_manager.plugins: used_count = plugin.uses_theme(theme) if used_count: - plugin_usage = "%s%s" % (plugin_usage, (translate('OpenLP.ThemeManager', - '%(count)s time(s) by %(plugin)s') % - {'count': used_count, 'plugin': plugin.name})) + plugin_usage = "{plug}{text}".format(plug=plugin_usage, + text=(translate('OpenLP.ThemeManager', + '{count} time(s) by {plugin}' + ).format(name=used_count, + plugin=plugin.name))) plugin_usage = "%s\n" % plugin_usage if plugin_usage: critical_error_message_box(translate('OpenLP.ThemeManager', 'Unable to delete theme'), - translate('OpenLP.ThemeManager', 'Theme is currently used \n\n%s') % - plugin_usage) + translate('OpenLP.ThemeManager', + 'Theme is currently used \n\n{text}' + ).format(text=plugin_usage)) return False return True diff --git a/openlp/core/ui/themewizard.py b/openlp/core/ui/themewizard.py index b546c1872..e1ef1dd78 100644 --- a/openlp/core/ui/themewizard.py +++ b/openlp/core/ui/themewizard.py @@ -405,8 +405,8 @@ class Ui_ThemeWizard(object): Translate the UI on the fly """ theme_wizard.setWindowTitle(translate('OpenLP.ThemeWizard', 'Theme Wizard')) - self.title_label.setText('%s' % - translate('OpenLP.ThemeWizard', 'Welcome to the Theme Wizard')) + text = translate('OpenLP.ThemeWizard', 'Welcome to the Theme Wizard') + self.title_label.setText('{text}'.format(text=text)) self.information_label.setText( translate('OpenLP.ThemeWizard', 'This wizard will help you to create and edit your themes. Click the next ' 'button below to start the process by setting up your background.')) @@ -435,9 +435,9 @@ class Ui_ThemeWizard(object): self.gradient_combo_box.setItemText(BackgroundGradientType.LeftBottom, translate('OpenLP.ThemeWizard', 'Bottom Left - Top Right')) self.image_color_label.setText(translate('OpenLP.ThemeWizard', 'Background color:')) - self.image_label.setText('%s:' % UiStrings().Image) + self.image_label.setText('{text}:'.format(text=UiStrings().Image)) self.video_color_label.setText(translate('OpenLP.ThemeWizard', 'Background color:')) - self.video_label.setText('%s:' % UiStrings().Video) + self.video_label.setText('{text}:'.format(text=UiStrings().Video)) self.main_area_page.setTitle(translate('OpenLP.ThemeWizard', 'Main Area Font Details')) self.main_area_page.setSubTitle(translate('OpenLP.ThemeWizard', 'Define the font and display ' 'characteristics for the Display text')) diff --git a/tests/functional/openlp_core_lib/test_projectordb.py b/tests/functional/openlp_core_lib/test_projectordb.py index c1b9ce3d1..a6ecb617d 100644 --- a/tests/functional/openlp_core_lib/test_projectordb.py +++ b/tests/functional/openlp_core_lib/test_projectordb.py @@ -28,7 +28,7 @@ PREREQUISITE: add_record() and get_all() functions validated. import os from unittest import TestCase -from openlp.core.lib.projector.db import Manufacturer, Model, Projector, ProjectorDB, ProjectorSource +from openlp.core.lib.projector.db import Manufacturer, Model, Projector, ProjectorDB, ProjectorSource, Source from tests.functional import MagicMock, patch from tests.resources.projector.data import TEST_DB, TEST1_DATA, TEST2_DATA, TEST3_DATA @@ -220,3 +220,19 @@ class TestProjectorDB(TestCase): # THEN: __repr__ should return a proper string self.assertEqual(str(model), '', 'Model.__repr__() should have returned a proper representation string') + + def source_repr_test(self): + """ + Test source.__repr__ text + """ + # GIVEN: Test object + source = Source() + + # WHEN: Source() information is set + source.pjlink_name = 'Test object' + source.pjlink_code = '11' + source.text = 'Input text' + + # THEN: __repr__ should return a proper string + self.assertEqual(str(source), '', + 'Source.__repr__() should have returned a proper representation string')