diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index bcdb99109..d9b401368 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -45,7 +45,7 @@ log = logging.getLogger(__name__ + '.__init__') FIRST_CAMEL_REGEX = re.compile('(.)([A-Z][a-z]+)') SECOND_CAMEL_REGEX = re.compile('([a-z0-9])([A-Z])') CONTROL_CHARS = re.compile(r'[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]') -INVALID_FILE_CHARS = re.compile(r'[\\/:\*\?"<>\|\+\[\]%]') +INVALID_FILE_CHARS = re.compile(r'[\\/:*?"<>|+\[\]%]') IMAGES_FILTER = None REPLACMENT_CHARS_MAP = str.maketrans({'\u2018': '\'', '\u2019': '\'', '\u201c': '"', '\u201d': '"', '\u2026': '...', '\u2013': '-', '\u2014': '-', '\v': '\n\n', '\f': '\n\n'}) @@ -112,21 +112,21 @@ def trace_error_handler(logger): logger.error(log_string) -def extension_loader(glob_pattern, excluded_files=[]): +def extension_loader(glob_pattern, excluded_files=None): """ A utility function to find and load OpenLP extensions, such as plugins, presentation and media controllers and importers. :param str glob_pattern: A glob pattern used to find the extension(s) to be imported. Should be relative to the application directory. i.e. plugins/*/*plugin.py - :param list[str] excluded_files: A list of file names to exclude that the glob pattern may find. + :param list[str] | None excluded_files: A list of file names to exclude that the glob pattern may find. :rtype: None """ from openlp.core.common.applocation import AppLocation app_dir = AppLocation.get_directory(AppLocation.AppDir) for extension_path in app_dir.glob(glob_pattern): extension_path = extension_path.relative_to(app_dir) - if extension_path.name in excluded_files: + if extension_path.name in (excluded_files or []): continue log.debug('Attempting to import %s', extension_path) module_name = path_to_module(extension_path) diff --git a/openlp/core/common/i18n.py b/openlp/core/common/i18n.py index 85fe35e2f..5b2aabf20 100644 --- a/openlp/core/common/i18n.py +++ b/openlp/core/common/i18n.py @@ -338,8 +338,8 @@ class UiStrings(object): Override the default object creation method to return a single instance. """ if not cls.__instance__: - cls.__instance__ = object.__new__(cls) - cls.load(cls) + cls.__instance__ = super().__new__(cls) + cls.__instance__.load() return cls.__instance__ def load(self): @@ -503,7 +503,7 @@ def format_time(text, local_time): """ return local_time.strftime(match.group()) - return re.sub(r'\%[a-zA-Z]', match_formatting, text) + return re.sub(r'%[a-zA-Z]', match_formatting, text) def get_locale_key(string, numeric=False): diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index a0445730f..e2ef2e33e 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -265,7 +265,7 @@ def upgrade_db(url, upgrade): """ if not database_exists(url): log.warning("Database {db} doesn't exist - skipping upgrade checks".format(db=url)) - return (0, 0) + return 0, 0 log.debug('Checking upgrades for DB {db}'.format(db=url)) diff --git a/openlp/core/lib/formattingtags.py b/openlp/core/lib/formattingtags.py index 560cbb5f2..dc58cafd0 100644 --- a/openlp/core/lib/formattingtags.py +++ b/openlp/core/lib/formattingtags.py @@ -59,97 +59,98 @@ class FormattingTags(object): """ temporary_tags = [tag for tag in FormattingTags.html_expands if tag.get('temporary')] FormattingTags.html_expands = [] - base_tags = [] + base_tags = [ + { + 'desc': translate('OpenLP.FormattingTags', 'Red'), + 'start tag': '{r}', + 'start html': '', + 'end tag': '{/r}', 'end html': '', 'protected': True, + 'temporary': False + }, { + 'desc': translate('OpenLP.FormattingTags', 'Black'), + 'start tag': '{b}', + 'start html': '', + 'end tag': '{/b}', 'end html': '', 'protected': True, + 'temporary': False + }, { + 'desc': translate('OpenLP.FormattingTags', 'Blue'), + 'start tag': '{bl}', + 'start html': '', + 'end tag': '{/bl}', 'end html': '', 'protected': True, + 'temporary': False + }, { + 'desc': translate('OpenLP.FormattingTags', 'Yellow'), + 'start tag': '{y}', + 'start html': '', + 'end tag': '{/y}', 'end html': '', 'protected': True, + 'temporary': False + }, { + 'desc': translate('OpenLP.FormattingTags', 'Green'), + 'start tag': '{g}', + 'start html': '', + 'end tag': '{/g}', 'end html': '', 'protected': True, + 'temporary': False + }, { + 'desc': translate('OpenLP.FormattingTags', 'Pink'), + 'start tag': '{pk}', + 'start html': '', + 'end tag': '{/pk}', 'end html': '', 'protected': True, + 'temporary': False + }, { + 'desc': translate('OpenLP.FormattingTags', 'Orange'), + 'start tag': '{o}', + 'start html': '', + 'end tag': '{/o}', 'end html': '', 'protected': True, + 'temporary': False + }, { + 'desc': translate('OpenLP.FormattingTags', 'Purple'), + 'start tag': '{pp}', + 'start html': '', + 'end tag': '{/pp}', 'end html': '', 'protected': True, + 'temporary': False + }, { + 'desc': translate('OpenLP.FormattingTags', 'White'), + 'start tag': '{w}', + 'start html': '', + 'end tag': '{/w}', 'end html': '', 'protected': True, + 'temporary': False + }, { + 'desc': translate('OpenLP.FormattingTags', 'Superscript'), + 'start tag': '{su}', 'start html': '', + 'end tag': '{/su}', 'end html': '', 'protected': True, + 'temporary': False + }, { + 'desc': translate('OpenLP.FormattingTags', 'Subscript'), + 'start tag': '{sb}', 'start html': '', + 'end tag': '{/sb}', 'end html': '', 'protected': True, + 'temporary': False + }, { + 'desc': translate('OpenLP.FormattingTags', 'Paragraph'), + 'start tag': '{p}', 'start html': '

', 'end tag': '{/p}', + 'end html': '

', 'protected': True, + 'temporary': False + }, { + 'desc': translate('OpenLP.FormattingTags', 'Bold'), + 'start tag': '{st}', 'start html': '', + 'end tag': '{/st}', 'end html': '', + 'protected': True, 'temporary': False + }, { + 'desc': translate('OpenLP.FormattingTags', 'Italics'), + 'start tag': '{it}', 'start html': '', 'end tag': '{/it}', + 'end html': '', 'protected': True, 'temporary': False + }, { + 'desc': translate('OpenLP.FormattingTags', 'Underline'), + 'start tag': '{u}', + 'start html': '', + 'end tag': '{/u}', 'end html': '', 'protected': True, + 'temporary': False + }, { + 'desc': translate('OpenLP.FormattingTags', 'Break'), + 'start tag': '{br}', 'start html': '
', 'end tag': '', + 'end html': '', 'protected': True, + 'temporary': False + }] # Append the base tags. - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'Red'), - 'start tag': '{r}', - 'start html': '', - 'end tag': '{/r}', 'end html': '', 'protected': True, - 'temporary': False}) - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'Black'), - 'start tag': '{b}', - 'start html': '', - 'end tag': '{/b}', 'end html': '', 'protected': True, - 'temporary': False}) - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'Blue'), - 'start tag': '{bl}', - 'start html': '', - 'end tag': '{/bl}', 'end html': '', 'protected': True, - 'temporary': False}) - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'Yellow'), - 'start tag': '{y}', - 'start html': '', - 'end tag': '{/y}', 'end html': '', 'protected': True, - 'temporary': False}) - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'Green'), - 'start tag': '{g}', - 'start html': '', - 'end tag': '{/g}', 'end html': '', 'protected': True, - 'temporary': False}) - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'Pink'), - 'start tag': '{pk}', - 'start html': '', - 'end tag': '{/pk}', 'end html': '', 'protected': True, - 'temporary': False}) - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'Orange'), - 'start tag': '{o}', - 'start html': '', - 'end tag': '{/o}', 'end html': '', 'protected': True, - 'temporary': False}) - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'Purple'), - 'start tag': '{pp}', - 'start html': '', - 'end tag': '{/pp}', 'end html': '', 'protected': True, - 'temporary': False}) - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'White'), - 'start tag': '{w}', - 'start html': '', - 'end tag': '{/w}', 'end html': '', 'protected': True, - 'temporary': False}) - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'Superscript'), - 'start tag': '{su}', 'start html': '', - 'end tag': '{/su}', 'end html': '', 'protected': True, - 'temporary': False}) - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'Subscript'), - 'start tag': '{sb}', 'start html': '', - 'end tag': '{/sb}', 'end html': '', 'protected': True, - 'temporary': False}) - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'Paragraph'), - 'start tag': '{p}', 'start html': '

', 'end tag': '{/p}', - 'end html': '

', 'protected': True, - 'temporary': False}) - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'Bold'), - 'start tag': '{st}', 'start html': '', - 'end tag': '{/st}', 'end html': '', - 'protected': True, 'temporary': False}) - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'Italics'), - 'start tag': '{it}', 'start html': '', 'end tag': '{/it}', - 'end html': '', 'protected': True, 'temporary': False}) - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'Underline'), - 'start tag': '{u}', - 'start html': '', - 'end tag': '{/u}', 'end html': '', 'protected': True, - 'temporary': False}) - base_tags.append({ - 'desc': translate('OpenLP.FormattingTags', 'Break'), - 'start tag': '{br}', 'start html': '
', 'end tag': '', - 'end html': '', 'protected': True, - 'temporary': False}) FormattingTags.add_html_tags(base_tags) FormattingTags.add_html_tags(temporary_tags) user_expands_string = str(Settings().value('formattingTags/html_tags')) diff --git a/openlp/core/projectors/manager.py b/openlp/core/projectors/manager.py index 02b1c71f2..91b604b14 100644 --- a/openlp/core/projectors/manager.py +++ b/openlp/core/projectors/manager.py @@ -344,14 +344,14 @@ class ProjectorManager(QtWidgets.QWidget, RegistryBase, UiProjectorManager, LogM """ log.debug('Checking for UDP port {port} listener deletion'.format(port=port)) if port not in self.pjlink_udp: - log.warn('UDP listener for port {port} not there - skipping delete'.format(port=port)) + log.warning('UDP listener for port {port} not there - skipping delete'.format(port=port)) return keep_port = False for item in self.projector_list: if port == item.link.port: keep_port = True if keep_port: - log.warn('UDP listener for port {port} needed for other projectors - skipping delete'.format(port=port)) + log.warning('UDP listener for port {port} needed for other projectors - skipping delete'.format(port=port)) return Registry().execute('udp_broadcast_remove', port=port) del self.pjlink_udp[port] diff --git a/openlp/core/projectors/pjlink.py b/openlp/core/projectors/pjlink.py index 5ca3d9ba3..403b96b7c 100644 --- a/openlp/core/projectors/pjlink.py +++ b/openlp/core/projectors/pjlink.py @@ -552,7 +552,7 @@ class PJLink(QtNetwork.QTcpSocket): data = data_in.strip() self.receive_data_signal() # Initial packet checks - if (len(data) < 7): + if len(data) < 7: self._trash_buffer(msg='get_data(): Invalid packet - length') return elif len(data) > self.max_size: diff --git a/openlp/core/projectors/sourceselectform.py b/openlp/core/projectors/sourceselectform.py index 1d40436a2..f34439d33 100644 --- a/openlp/core/projectors/sourceselectform.py +++ b/openlp/core/projectors/sourceselectform.py @@ -177,7 +177,7 @@ class FingerTabBarWidget(QtWidgets.QTabBar): :param height: Remove default height parameter in kwargs """ self.tabSize = QtCore.QSize(kwargs.pop('width', 100), kwargs.pop('height', 25)) - QtWidgets.QTabBar.__init__(self, parent, *args, **kwargs) + super().__init__(parent) def paintEvent(self, event): """ @@ -215,11 +215,11 @@ class FingerTabWidget(QtWidgets.QTabWidget): Based on thread discussion http://www.riverbankcomputing.com/pipermail/pyqt/2005-December/011724.html """ - def __init__(self, parent, *args): + def __init__(self, parent): """ Initialize FingerTabWidget instance """ - QtWidgets.QTabWidget.__init__(self, parent, *args) + super().__init__(parent) self.setTabBar(FingerTabBarWidget(self)) diff --git a/openlp/core/ui/__init__.py b/openlp/core/ui/__init__.py index 220bda7ce..2e9a7a48c 100644 --- a/openlp/core/ui/__init__.py +++ b/openlp/core/ui/__init__.py @@ -93,4 +93,4 @@ class SingleColumnTableWidget(QtWidgets.QTableWidget): self.resizeRowsToContents() -__all__ = ['SingleColumnTableWidget', 'DisplayControllerType'] +__all__ = ['AlertLocation', 'DisplayControllerType', 'HideMode', 'SingleColumnTableWidget'] diff --git a/openlp/core/ui/formattingtagcontroller.py b/openlp/core/ui/formattingtagcontroller.py index 5b26851b5..0b88702aa 100644 --- a/openlp/core/ui/formattingtagcontroller.py +++ b/openlp/core/ui/formattingtagcontroller.py @@ -40,7 +40,7 @@ class FormattingTagController(object): """ self.html_tag_regex = re.compile( r'<(?:(?P/(?=[^\s/>]+>))?' - r'(?P[^\s/!\?>]+)(?:\s+[^\s=]+="[^"]*")*\s*(?P/)?' + r'(?P[^\s/!?>]+)(?:\s+[^\s=]+="[^"]*")*\s*(?P/)?' r'|(?P!\[CDATA\[(?:(?!\]\]>).)*\]\])' r'|(?P\?(?:(?!\?>).)*\?)' r'|(?P!--(?:(?!-->).)*--))>') diff --git a/openlp/core/ui/icons.py b/openlp/core/ui/icons.py index 925becf1f..701c25a09 100644 --- a/openlp/core/ui/icons.py +++ b/openlp/core/ui/icons.py @@ -45,8 +45,8 @@ class UiIcons(object): Override the default object creation method to return a single instance. """ if not cls.__instance__: - cls.__instance__ = object.__new__(cls) - cls.load(cls) + cls.__instance__ = super().__new__(cls) + cls.__instance__.load() return cls.__instance__ def load(self): @@ -164,7 +164,7 @@ class UiIcons(object): 'video': {'icon': 'fa.file-video-o'}, 'volunteer': {'icon': 'fa.group'} } - self.load_icons(self, icon_list) + self.load_icons(icon_list) def load_icons(self, icon_list): """ diff --git a/openlp/core/ui/shortcutlistdialog.py b/openlp/core/ui/shortcutlistdialog.py index efc795501..a6440b63f 100644 --- a/openlp/core/ui/shortcutlistdialog.py +++ b/openlp/core/ui/shortcutlistdialog.py @@ -101,7 +101,7 @@ class Ui_ShortcutListDialog(object): self.primary_push_button = CaptureShortcutButton(shortcutListDialog) self.primary_push_button.setObjectName('primary_push_button') self.primary_push_button.setMinimumSize(QtCore.QSize(84, 0)) - self.primary_push_button.setIcon(UiIcons.shortcuts) + self.primary_push_button.setIcon(UiIcons().shortcuts) self.primary_layout.addWidget(self.primary_push_button) self.clear_primary_button = QtWidgets.QToolButton(shortcutListDialog) self.clear_primary_button.setObjectName('clear_primary_button') diff --git a/openlp/core/ui/shortcutlistform.py b/openlp/core/ui/shortcutlistform.py index 360c631c0..6d37130ab 100644 --- a/openlp/core/ui/shortcutlistform.py +++ b/openlp/core/ui/shortcutlistform.py @@ -34,7 +34,7 @@ from openlp.core.common.settings import Settings from openlp.core.ui.shortcutlistdialog import Ui_ShortcutListDialog -REMOVE_AMPERSAND = re.compile(r'&{1}') +REMOVE_AMPERSAND = re.compile(r'&') log = logging.getLogger(__name__) diff --git a/openlp/core/widgets/views.py b/openlp/core/widgets/views.py index b5c07993c..c3f4be0ca 100644 --- a/openlp/core/widgets/views.py +++ b/openlp/core/widgets/views.py @@ -80,7 +80,7 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties): An empty ``ServiceItem`` is used by default. replace_service_manager_item() needs to be called to make this widget display something. """ - super(QtWidgets.QTableWidget, self).__init__(parent) + super().__init__(parent) self._setup(screen_ratio) def _setup(self, screen_ratio): @@ -124,7 +124,7 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties): max_img_row_height = Settings().value('advanced/slide max height') # Adjust for row height cap if in use. if isinstance(max_img_row_height, int): - if max_img_row_height > 0 and height > max_img_row_height: + if 0 < max_img_row_height < height: height = max_img_row_height elif max_img_row_height < 0: # If auto setting, show that number of slides, or if the resulting slides too small, 100px. @@ -219,7 +219,7 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties): slide_height = width // self.screen_ratio max_img_row_height = Settings().value('advanced/slide max height') if isinstance(max_img_row_height, int): - if max_img_row_height > 0 and slide_height > max_img_row_height: + if 0 < max_img_row_height < slide_height: slide_height = max_img_row_height elif max_img_row_height < 0: # If auto setting, show that number of slides, or if the resulting slides too small, 100px. diff --git a/openlp/core/widgets/widgets.py b/openlp/core/widgets/widgets.py index 0415d73a5..42f83511d 100644 --- a/openlp/core/widgets/widgets.py +++ b/openlp/core/widgets/widgets.py @@ -194,11 +194,11 @@ class ScreenButton(QtWidgets.QPushButton): class ScreenSelectionWidget(QtWidgets.QWidget): - def __init__(self, parent=None, screens=[]): + def __init__(self, parent=None, screens=None): super().__init__(parent) self.current_screen = None self.identify_labels = [] - self.screens = screens + self.screens = screens or [] self.timer = QtCore.QTimer() self.timer.setSingleShot(True) self.timer.setInterval(3000) diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 79f66cef4..53926d78b 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -401,4 +401,4 @@ class BibleManager(LogMixin, RegistryProperties): self.db_cache[bible].finalise() -__all__ = ['BibleFormat'] +__all__ = ['BibleFormat', 'BibleManager'] diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 185a6832e..b239defdd 100755 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -109,7 +109,7 @@ class BibleMediaItem(MediaManagerItem): :param kwargs: Keyword arguments to pass to the super method. (dict) """ self.clear_icon = UiIcons().square - self.save_results_icon = UiIcons.save + self.save_results_icon = UiIcons().save self.sort_icon = UiIcons().sort self.bible = None self.second_bible = None diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index 873e91b86..dd8ad9df4 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -55,7 +55,7 @@ if is_win(): class SlideShowListenerImport(XSlideShowListenerObj.__class__): pass except (AttributeError, pywintypes.com_error): - class SlideShowListenerImport(): + class SlideShowListenerImport(object): pass # Declare an empty exception to match the exception imported from UNO @@ -76,7 +76,7 @@ else: except ImportError: uno_available = False - class SlideShowListenerImport(): + class SlideShowListenerImport(object): pass log = logging.getLogger(__name__) @@ -233,9 +233,7 @@ class ImpressController(PresentationController): self.conf_provider = self.manager.createInstanceWithContext( 'com.sun.star.configuration.ConfigurationProvider', uno.getComponentContext()) # Setup lookup properties to get Impress settings - properties = [] - properties.append(self.create_property('nodepath', 'org.openoffice.Office.Impress')) - properties = tuple(properties) + properties = tuple(self.create_property('nodepath', 'org.openoffice.Office.Impress')) try: # Get an updateable configuration view impress_conf_props = self.conf_provider.createInstanceWithArguments( @@ -311,9 +309,7 @@ class ImpressDocument(PresentationDocument): if desktop is None: return False self.desktop = desktop - properties = [] - properties.append(self.controller.create_property('Hidden', True)) - properties = tuple(properties) + properties = tuple(self.controller.create_property('Hidden', True)) try: self.document = desktop.loadComponentFromURL(url, '_blank', 0, properties) except Exception: @@ -338,9 +334,7 @@ class ImpressDocument(PresentationDocument): return temp_folder_path = self.get_temp_folder() thumb_dir_url = temp_folder_path.as_uri() - properties = [] - properties.append(self.controller.create_property('FilterName', 'impress_png_Export')) - properties = tuple(properties) + properties = tuple(self.controller.create_property('FilterName', 'impress_png_Export')) doc = self.document pages = doc.getDrawPages() if not pages: diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index e79dbc95a..243eedcc8 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -615,14 +615,16 @@ def transpose_chord(chord, transpose_value, notation): :return: The transposed chord. """ # See https://en.wikipedia.org/wiki/Musical_note#12-tone_chromatic_scale - notes_sharp_notation = {} - notes_flat_notation = {} - notes_sharp_notation['german'] = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'H'] - notes_flat_notation['german'] = ['C', 'Db', 'D', 'Eb', 'Fb', 'F', 'Gb', 'G', 'Ab', 'A', 'B', 'H'] - notes_sharp_notation['english'] = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'] - notes_flat_notation['english'] = ['C', 'Db', 'D', 'Eb', 'Fb', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B'] - notes_sharp_notation['neo-latin'] = ['Do', 'Do#', 'Re', 'Re#', 'Mi', 'Fa', 'Fa#', 'Sol', 'Sol#', 'La', 'La#', 'Si'] - notes_flat_notation['neo-latin'] = ['Do', 'Reb', 'Re', 'Mib', 'Fab', 'Fa', 'Solb', 'Sol', 'Lab', 'La', 'Sib', 'Si'] + notes_sharp_notation = { + 'german': ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'H'], + 'english': ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'], + 'neo-latin': ['Do', 'Do#', 'Re', 'Re#', 'Mi', 'Fa', 'Fa#', 'Sol', 'Sol#', 'La', 'La#', 'Si'] + } + notes_flat_notation = { + 'german': ['C', 'Db', 'D', 'Eb', 'Fb', 'F', 'Gb', 'G', 'Ab', 'A', 'B', 'H'], + 'english': ['C', 'Db', 'D', 'Eb', 'Fb', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B'], + 'neo-latin': ['Do', 'Reb', 'Re', 'Mib', 'Fab', 'Fa', 'Solb', 'Sol', 'Lab', 'La', 'Sib', 'Si'] + } chord_split = chord.replace('♭', 'b').split('/') transposed_chord = '' last_chord = '' diff --git a/openlp/plugins/songs/lib/importers/easyworship.py b/openlp/plugins/songs/lib/importers/easyworship.py index 9468031fa..2061195d3 100644 --- a/openlp/plugins/songs/lib/importers/easyworship.py +++ b/openlp/plugins/songs/lib/importers/easyworship.py @@ -118,8 +118,8 @@ class EasyWorshipSongImport(SongImport): # 40/48/56 Entry count int32le 4 Number of items in the schedule # 44/52/60 Entry length int16le 2 Length of schedule entries: 0x0718 = 1816 # Get file version - type, = struct.unpack('<38s', self.ews_file.read(38)) - version = type.decode()[-3:] + file_type, = struct.unpack('<38s', self.ews_file.read(38)) + version = file_type.decode()[-3:] # Set fileposition based on filetype/version file_pos = 0 if version == ' 5': diff --git a/openlp/plugins/songs/lib/importers/foilpresenter.py b/openlp/plugins/songs/lib/importers/foilpresenter.py index da16c9b9e..ed64210b6 100644 --- a/openlp/plugins/songs/lib/importers/foilpresenter.py +++ b/openlp/plugins/songs/lib/importers/foilpresenter.py @@ -302,7 +302,7 @@ class FoilPresenter(object): break author_temp = [] for author in strings: - temp = re.split(r',(?=\D{2})|(?<=\D),|\/(?=\D{3,})|(?<=\D);', author) + temp = re.split(r',(?=\D{2})|(?<=\D),|/(?=\D{3,})|(?<=\D);', author) for tempx in temp: author_temp.append(tempx) for author in author_temp: diff --git a/openlp/plugins/songs/lib/importers/openoffice.py b/openlp/plugins/songs/lib/importers/openoffice.py index 2346dc039..0fc057e82 100644 --- a/openlp/plugins/songs/lib/importers/openoffice.py +++ b/openlp/plugins/songs/lib/importers/openoffice.py @@ -145,9 +145,7 @@ class OpenOfficeImport(SongImport): """ self.file_path = file_path url = file_path.as_uri() - properties = [] - properties.append(self.create_property('Hidden', True)) - properties = tuple(properties) + properties = tuple(self.create_property('Hidden', True)) try: self.document = self.desktop.loadComponentFromURL(url, '_blank', 0, properties) if not self.document.supportsService("com.sun.star.presentation.PresentationDocument") and not \ diff --git a/openlp/plugins/songs/lib/importers/opspro.py b/openlp/plugins/songs/lib/importers/opspro.py index ece7dc41e..2ad14487e 100644 --- a/openlp/plugins/songs/lib/importers/opspro.py +++ b/openlp/plugins/songs/lib/importers/opspro.py @@ -136,8 +136,8 @@ class OPSProImport(SongImport): verse_text = re.sub(r'^\d+\r\n', '', verse_text) verse_def = 'v' + verse_number.group(1) # Detect verse tags - elif re.match(r'^.+?\:\r\n', verse_text): - tag_match = re.match(r'^(.+?)\:\r\n(.*)', verse_text, flags=re.DOTALL) + elif re.match(r'^.+?:\r\n', verse_text): + tag_match = re.match(r'^(.+?):\r\n(.*)', verse_text, flags=re.DOTALL) tag = tag_match.group(1).lower() tag = tag.split(' ')[0] verse_text = tag_match.group(2) diff --git a/openlp/plugins/songs/lib/importers/propresenter.py b/openlp/plugins/songs/lib/importers/propresenter.py index 0d666e449..05ac8aff5 100644 --- a/openlp/plugins/songs/lib/importers/propresenter.py +++ b/openlp/plugins/songs/lib/importers/propresenter.py @@ -80,7 +80,7 @@ class ProPresenterImport(SongImport): self.parse_author(author) # ProPresenter 4 - if(self.version >= 400 and self.version < 500): + if 400 <= self.version < 500: self.copyright = root.get('CCLICopyrightInfo') self.ccli_number = root.get('CCLILicenseNumber') count = 0 @@ -95,7 +95,7 @@ class ProPresenterImport(SongImport): self.add_verse(words, "v{count}".format(count=count)) # ProPresenter 5 - elif(self.version >= 500 and self.version < 600): + elif 500 <= self.version < 600: self.copyright = root.get('CCLICopyrightInfo') self.ccli_number = root.get('CCLILicenseNumber') count = 0 @@ -111,7 +111,7 @@ class ProPresenterImport(SongImport): self.add_verse(words, "v{count:d}".format(count=count)) # ProPresenter 6 - elif(self.version >= 600 and self.version < 700): + elif 600 <= self.version < 700: self.copyright = root.get('CCLICopyrightYear') self.ccli_number = root.get('CCLISongNumber') count = 0 @@ -128,7 +128,7 @@ class ProPresenterImport(SongImport): b64Data = contents.text data = base64.standard_b64decode(b64Data) words = None - if(contents.get('rvXMLIvarName') == "RTFData"): + if contents.get('rvXMLIvarName') == "RTFData": words, encoding = strip_rtf(data.decode()) break if words: diff --git a/openlp/plugins/songs/lib/importers/videopsalm.py b/openlp/plugins/songs/lib/importers/videopsalm.py index bc0e06093..ff3eec52b 100644 --- a/openlp/plugins/songs/lib/importers/videopsalm.py +++ b/openlp/plugins/songs/lib/importers/videopsalm.py @@ -75,7 +75,7 @@ class VideoPsalmImport(SongImport): c = next(file_content_it) processed_content += '"' + c # Remove control characters - elif (c < chr(32)): + elif c < chr(32): processed_content += ' ' # Handle escaped characters elif c == '\\': diff --git a/openlp/plugins/songs/lib/openlyricsxml.py b/openlp/plugins/songs/lib/openlyricsxml.py index efa3103d2..7cb1f7a38 100644 --- a/openlp/plugins/songs/lib/openlyricsxml.py +++ b/openlp/plugins/songs/lib/openlyricsxml.py @@ -221,7 +221,7 @@ class OpenLyrics(object): """ IMPLEMENTED_VERSION = '0.8' START_TAGS_REGEX = re.compile(r'\{(\w+)\}') - END_TAGS_REGEX = re.compile(r'\{\/(\w+)\}') + END_TAGS_REGEX = re.compile(r'\{/(\w+)\}') VERSE_TAG_SPLITTER = re.compile('([a-zA-Z]+)([0-9]*)([a-zA-Z]?)') def __init__(self, manager): diff --git a/tests/functional/openlp_core/lib/test_image_manager.py b/tests/functional/openlp_core/lib/test_image_manager.py index 10470f0f6..1f6e0e326 100644 --- a/tests/functional/openlp_core/lib/test_image_manager.py +++ b/tests/functional/openlp_core/lib/test_image_manager.py @@ -32,7 +32,7 @@ from PyQt5 import QtGui from openlp.core.common.registry import Registry from openlp.core.display.screens import ScreenList -from openlp.core.lib.imagemanager import ImageManager, ImageWorker, Priority, PriorityQueue +from openlp.core.lib.imagemanager import Image, ImageManager, ImageWorker, Priority, PriorityQueue from tests.helpers.testmixin import TestMixin from tests.utils.constants import RESOURCE_PATH diff --git a/tests/functional/openlp_core/lib/test_theme.py b/tests/functional/openlp_core/lib/test_theme.py index f53d4367c..e7f935918 100644 --- a/tests/functional/openlp_core/lib/test_theme.py +++ b/tests/functional/openlp_core/lib/test_theme.py @@ -25,7 +25,78 @@ Package to test the openlp.core.lib.theme package. from pathlib import Path from unittest import TestCase -from openlp.core.lib.theme import Theme +from openlp.core.lib.theme import BackgroundType + + +class TestBackgroundType(TestCase): + """ + Test the BackgroundType enum methods. + """ + def test_solid_to_string(self): + """ + Test the to_string method of :class:`BackgroundType` + """ + # GIVEN: A BackgroundType member + background_type = BackgroundType.Solid + + # WHEN: Calling BackgroundType.to_string + # THEN: The string equivalent should have been returned + assert BackgroundType.to_string(background_type) == 'solid' + + def test_gradient_to_string(self): + """ + Test the to_string method of :class:`BackgroundType` + """ + # GIVEN: A BackgroundType member + background_type = BackgroundType.Gradient + + # WHEN: Calling BackgroundType.to_string + # THEN: The string equivalent should have been returned + assert BackgroundType.to_string(background_type) == 'gradient' + + def test_image_to_string(self): + """ + Test the to_string method of :class:`BackgroundType` + """ + # GIVEN: A BackgroundType member + background_type = BackgroundType.Image + + # WHEN: Calling BackgroundType.to_string + # THEN: The string equivalent should have been returned + assert BackgroundType.to_string(background_type) == 'image' + + def test_transparent_to_string(self): + """ + Test the to_string method of :class:`BackgroundType` + """ + # GIVEN: A BackgroundType member + background_type = BackgroundType.Transparent + + # WHEN: Calling BackgroundType.to_string + # THEN: The string equivalent should have been returned + assert BackgroundType.to_string(background_type) == 'transparent' + + def test_video_to_string(self): + """ + Test the to_string method of :class:`BackgroundType` + """ + # GIVEN: A BackgroundType member + background_type = BackgroundType.Video + + # WHEN: Calling BackgroundType.to_string + # THEN: The string equivalent should have been returned + assert BackgroundType.to_string(background_type) == 'video' + + def test_stream_to_string(self): + """ + Test the to_string method of :class:`BackgroundType` + """ + # GIVEN: A BackgroundType member + background_type = BackgroundType.Stream + + # WHEN: Calling BackgroundType.to_string + # THEN: The string equivalent should have been returned + assert BackgroundType.to_string(background_type) == 'stream' class TestTheme(TestCase):