From c1222dc2bb8dd3845c606bc9a6726deffddddb22 Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Fri, 22 Apr 2016 17:40:59 -0700 Subject: [PATCH 01/17] Convert strings to python3 in __init__ files --- openlp/core/__init__.py | 17 +++++++++-------- openlp/core/common/__init__.py | 23 ++++++++++++++--------- openlp/core/lib/__init__.py | 4 +++- openlp/core/ui/media/__init__.py | 11 +++++++---- openlp/plugins/bibles/lib/__init__.py | 22 +++++++++++++--------- tests/utils/__init__.py | 2 +- 6 files changed, 47 insertions(+), 32 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index db135ef10..5ed016309 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -222,10 +222,11 @@ class OpenLP(OpenLPMixin, QtWidgets.QApplication): QtWidgets.QMessageBox.warning(None, translate('OpenLP', 'Backup'), translate('OpenLP', 'Backup of the data folder failed!')) return - QtWidgets.QMessageBox.information(None, translate('OpenLP', 'Backup'), - translate('OpenLP', - 'A backup of the data folder has been created at %s') - % data_folder_backup_path) + message = translate('OpenLP', + 'A backup of the data folder has been created' + 'at {text}'.format(text=data_folder_backup_path)) + QtWidgets.QMessageBox.information(None, translate('OpenLP', 'Backup'), message) + # Update the version in the settings Settings().setValue('core/application version', openlp_version) @@ -257,7 +258,7 @@ class OpenLP(OpenLPMixin, QtWidgets.QApplication): """ if event.type() == QtCore.QEvent.FileOpen: file_name = event.file() - log.debug('Got open file event for %s!', file_name) + log.debug('Got open file event for {name}!'.format(name=file_name)) self.args.insert(0, file_name) return True # Mac OS X should restore app window when user clicked on the OpenLP icon @@ -311,7 +312,7 @@ def set_up_logging(log_path): logfile.setFormatter(logging.Formatter('%(asctime)s %(name)-55s %(levelname)-8s %(message)s')) log.addHandler(logfile) if log.isEnabledFor(logging.DEBUG): - print('Logging to: %s' % filename) + print('Logging to: {name}'.format(name=filename)) def main(args=None): @@ -351,12 +352,12 @@ def main(args=None): log.info('Running portable') portable_settings_file = os.path.abspath(os.path.join(application_path, '..', '..', 'Data', 'OpenLP.ini')) # Make this our settings file - log.info('INI file: %s', portable_settings_file) + log.info('INI file: {name}'.format(name=portable_settings_file)) Settings.set_filename(portable_settings_file) portable_settings = Settings() # Set our data path data_path = os.path.abspath(os.path.join(application_path, '..', '..', 'Data',)) - log.info('Data path: %s', data_path) + log.info('Data path: {name}'.format(name=data_path)) # Point to our data path portable_settings.setValue('advanced/data path', data_path) portable_settings.setValue('advanced/is portable', True) diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index b8a1a4d2e..6a111d97d 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -53,7 +53,10 @@ def trace_error_handler(logger): """ log_string = "OpenLP Error trace" for tb in traceback.extract_stack(): - log_string = '%s\n File %s at line %d \n\t called %s' % (log_string, tb[0], tb[1], tb[3]) + log_string = '{text}\n File {file} at line {line} \n\t called {data}'.format(text=log_string, + file=tb[0], + line=tb[1], + data=tb[3]) logger.error(log_string) @@ -65,7 +68,7 @@ def check_directory_exists(directory, do_not_log=False): :param do_not_log: To not log anything. This is need for the start up, when the log isn't ready. """ if not do_not_log: - log.debug('check_directory_exists %s' % directory) + log.debug('check_directory_exists {text}'.format(text=directory)) try: if not os.path.exists(directory): os.makedirs(directory) @@ -200,13 +203,13 @@ def md5_hash(salt, data=None): :param data: OPTIONAL Data to hash :returns: str """ - log.debug('md5_hash(salt="%s")' % salt) + log.debug('md5_hash(salt="{text}")'.format(text=salt)) hash_obj = hashlib.new('md5') hash_obj.update(salt) if data: hash_obj.update(data) hash_value = hash_obj.hexdigest() - log.debug('md5_hash() returning "%s"' % hash_value) + log.debug('md5_hash() returning "{text}"'.format(text=hash_value)) return hash_value @@ -219,12 +222,12 @@ def qmd5_hash(salt, data=None): :param data: OPTIONAL Data to hash :returns: str """ - log.debug('qmd5_hash(salt="%s"' % salt) + log.debug('qmd5_hash(salt="{text}"'.format(text=salt)) hash_obj = QHash(QHash.Md5) hash_obj.addData(salt) hash_obj.addData(data) hash_value = hash_obj.result().toHex() - log.debug('qmd5_hash() returning "%s"' % hash_value) + log.debug('qmd5_hash() returning "{text}"'.format(text=hash_value)) return hash_value.data() @@ -340,9 +343,11 @@ def get_images_filter(): if not IMAGES_FILTER: log.debug('Generating images filter.') formats = list(map(bytes.decode, list(map(bytes, QtGui.QImageReader.supportedImageFormats())))) - visible_formats = '(*.%s)' % '; *.'.join(formats) - actual_formats = '(*.%s)' % ' *.'.join(formats) - IMAGES_FILTER = '%s %s %s' % (translate('OpenLP', 'Image Files'), visible_formats, actual_formats) + visible_formats = '(*.{text})'.format(text='; *.'.join(formats)) + actual_formats = '(*.{text})'.format(text=' *.'.join(formats)) + IMAGES_FILTER = '{text} {visible} {actual}'.format(text=translate('OpenLP', 'Image Files'), + visible=visible_formats, + actual=actual_formats) return IMAGES_FILTER diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 6e62bbf9c..5769a3626 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -97,7 +97,7 @@ def get_text_file_string(text_file): file_handle.seek(0) content = file_handle.read() except (IOError, UnicodeError): - log.exception('Failed to open text file %s' % text_file) + log.exception('Failed to open text file {text}'.format(text=text_file)) finally: if file_handle: file_handle.close() @@ -300,6 +300,8 @@ def create_separated_list(string_list): return '' elif len(string_list) == 1: return string_list[0] + # TODO: + # Cannot convert these strings to python3 yet until I can figure out how to mock translate() with the new format elif len(string_list) == 2: return translate('OpenLP.core.lib', '%s and %s', 'Locale list separator: 2 items') % (string_list[0], string_list[1]) diff --git a/openlp/core/ui/media/__init__.py b/openlp/core/ui/media/__init__.py index 07e2a73fb..9e2f61ae8 100644 --- a/openlp/core/ui/media/__init__.py +++ b/openlp/core/ui/media/__init__.py @@ -83,7 +83,7 @@ def get_media_players(): reg_ex = QtCore.QRegExp(".*\[(.*)\].*") if Settings().value('media/override player') == QtCore.Qt.Checked: if reg_ex.exactMatch(saved_players): - overridden_player = '%s' % reg_ex.cap(1) + overridden_player = '{text}'.format(text=reg_ex.cap(1)) else: overridden_player = 'auto' else: @@ -102,7 +102,7 @@ def set_media_players(players_list, overridden_player='auto'): log.debug('set_media_players') players = ','.join(players_list) if Settings().value('media/override player') == QtCore.Qt.Checked and overridden_player != 'auto': - players = players.replace(overridden_player, '[%s]' % overridden_player) + players = players.replace(overridden_player, '[{text}]'.format(text=overridden_player)) Settings().setValue('media/players', players) @@ -113,7 +113,7 @@ def parse_optical_path(input_string): :param input_string: The string to parse :return: The elements extracted from the string: filename, title, audio_track, subtitle_track, start, end """ - log.debug('parse_optical_path, about to parse: "%s"' % input_string) + log.debug('parse_optical_path, about to parse: "{text}"'.format(text=input_string)) clip_info = input_string.split(sep=':') title = int(clip_info[1]) audio_track = int(clip_info[2]) @@ -137,7 +137,10 @@ def format_milliseconds(milliseconds): seconds, millis = divmod(milliseconds, 1000) minutes, seconds = divmod(seconds, 60) hours, minutes = divmod(minutes, 60) - return "%02d:%02d:%02d,%03d" % (hours, minutes, seconds, millis) + return "{hours:02d}:{minutes:02d}:{seconds:02d},{millis:03d}".format(hours=hours, + minutes=minutes, + seconds=seconds, + millis=millis) from .mediacontroller import MediaController from .playertab import PlayerTab diff --git a/openlp/plugins/bibles/lib/__init__.py b/openlp/plugins/bibles/lib/__init__.py index 0bba1e387..52f400c24 100644 --- a/openlp/plugins/bibles/lib/__init__.py +++ b/openlp/plugins/bibles/lib/__init__.py @@ -211,22 +211,24 @@ def update_reference_separators(): while '||' in source_string: source_string = source_string.replace('||', '|') if role != 'e': - REFERENCE_SEPARATORS['sep_%s_display' % role] = source_string.split('|')[0] + REFERENCE_SEPARATORS['sep_{text}_display'.format(text=role)] = source_string.split('|')[0] # escape reserved characters for character in '\\.^$*+?{}[]()': source_string = source_string.replace(character, '\\' + character) # add various unicode alternatives source_string = source_string.replace('-', '(?:[-\u00AD\u2010\u2011\u2012\u2014\u2014\u2212\uFE63\uFF0D])') source_string = source_string.replace(',', '(?:[,\u201A])') - REFERENCE_SEPARATORS['sep_%s' % role] = '\s*(?:%s)\s*' % source_string - REFERENCE_SEPARATORS['sep_%s_default' % role] = default_separators[index] + REFERENCE_SEPARATORS['sep_{text}'.format(text=role)] = '\s*(?:{text})\s*'.format(text=source_string) + REFERENCE_SEPARATORS['sep_{text}_default'.format(text=role)] = default_separators[index] # verse range match: (:)?(-((:)?|end)?)? - range_regex = '(?:(?P[0-9]+)%(sep_v)s)?' \ - '(?P[0-9]+)(?P%(sep_r)s(?:(?:(?P' \ - '[0-9]+)%(sep_v)s)?(?P[0-9]+)|%(sep_e)s)?)?' % REFERENCE_SEPARATORS - REFERENCE_MATCHES['range'] = re.compile('^\s*%s\s*$' % range_regex, re.UNICODE) + range_regex = '(?:(?P[0-9]+){sep_v})?' \ + '(?P[0-9]+)(?P{sep_r}(?:(?:(?P' \ + '[0-9]+){sep_v})?(?P[0-9]+)|{sep_e})?)?'.format(**REFERENCE_SEPARATORS) + REFERENCE_MATCHES['range'] = re.compile('^\s*{text}\s*$'.format(text=range_regex), re.UNICODE) REFERENCE_MATCHES['range_separator'] = re.compile(REFERENCE_SEPARATORS['sep_l'], re.UNICODE) # full reference match: ((,(?!$)|(?=$)))+ + # NOTE: + # Need to research a little more before converting this to python3 string format REFERENCE_MATCHES['full'] = \ re.compile('^\s*(?!\s)(?P[\d]*[^\d]+)(?(?:%(range_regex)s(?:%(sep_l)s(?!\s*$)|(?=\s*$)))+)\s*$' @@ -331,10 +333,12 @@ def parse_reference(reference, bible, language_selection, book_ref_id=False): separator. """ + # TODO: + # Verify convertsion here before committing format change log.debug('parse_reference("%s")', reference) match = get_reference_match('full').match(reference) if match: - log.debug('Matched reference %s' % reference) + log.debug('Matched reference {text}'.format(text=reference)) book = match.group('book') if not book_ref_id: book_ref_id = bible.get_book_ref_id_by_localised_name(book, language_selection) @@ -400,7 +404,7 @@ def parse_reference(reference, bible, language_selection, book_ref_id=False): ref_list.append((book_ref_id, from_chapter, 1, -1)) return ref_list else: - log.debug('Invalid reference: %s' % reference) + log.warn('Invalid reference: {text}'.format(text=reference)) return None diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py index 86d73bf85..9c106a728 100644 --- a/tests/utils/__init__.py +++ b/tests/utils/__init__.py @@ -26,7 +26,7 @@ import json def assert_length(expected, iterable, msg=None): if len(iterable) != expected: if not msg: - msg = 'Expected length %s, got %s' % (expected, len(iterable)) + msg = 'Expected length {expected}, got {got}'.format(expected=expected, got=len(iterable)) raise AssertionError(msg) From d5b98b73081130626428f69b4be70d1718236a7f Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Sat, 23 Apr 2016 12:55:47 -0700 Subject: [PATCH 02/17] Added projector power test --- openlp/core/lib/projector/constants.py | 6 +++- .../openlp_core_lib/test_projector_pjlink1.py | 33 ++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/openlp/core/lib/projector/constants.py b/openlp/core/lib/projector/constants.py index 6bfc88a6f..5c0d6c6c2 100644 --- a/openlp/core/lib/projector/constants.py +++ b/openlp/core/lib/projector/constants.py @@ -297,7 +297,11 @@ PJLINK_ERST_STATUS = {'0': ERROR_STRING[E_OK], PJLINK_POWR_STATUS = {'0': S_STANDBY, '1': S_ON, '2': S_COOLDOWN, - '3': S_WARMUP} + '3': S_WARMUP, + S_STANDBY: '0', + S_ON: '1', + S_COOLDOWN: '2', + S_WARMUP: '3'} PJLINK_DEFAULT_SOURCES = {'1': translate('OpenLP.DB', 'RGB'), '2': translate('OpenLP.DB', 'Video'), diff --git a/tests/functional/openlp_core_lib/test_projector_pjlink1.py b/tests/functional/openlp_core_lib/test_projector_pjlink1.py index 5d0d26ceb..95d86efe9 100644 --- a/tests/functional/openlp_core_lib/test_projector_pjlink1.py +++ b/tests/functional/openlp_core_lib/test_projector_pjlink1.py @@ -26,7 +26,8 @@ Package to test the openlp.core.lib.projector.pjlink1 package. from unittest import TestCase from openlp.core.lib.projector.pjlink1 import PJLink1 -from openlp.core.lib.projector.constants import E_PARAMETER, ERROR_STRING +from openlp.core.lib.projector.constants import E_PARAMETER, ERROR_STRING, S_OFF, S_STANDBY, S_WARMUP, S_ON, \ + S_COOLDOWN, PJLINK_POWR_STATUS from tests.functional import patch from tests.resources.projector.data import TEST_PIN, TEST_SALT, TEST_CONNECT_AUTHENTICATE @@ -151,3 +152,33 @@ class TestPJLink(TestCase): 'Lamp 3 power status should have been set to TRUE') self.assertEquals(pjlink.lamp[2]['Hours'], 33333, 'Lamp 3 hours should have been set to 33333') + + @patch.object(pjlink_test, 'projectorReceivedData') + def projector_process_power_on_test(self, mock_projectorReceivedData): + """ + Test setting power on + """ + # GIVEN: Test object and preset + pjlink = pjlink_test + pjlink.power = S_STANDBY + + # WHEN: Call process_command with turn power on command + pjlink.process_command('POWR', PJLINK_POWR_STATUS[S_ON]) + + # THEN: Power should be set to ON + self.assertEquals(pjlink.power, S_ON, 'Power should have been set to ON') + + @patch.object(pjlink_test, 'projectorReceivedData') + def projector_process_power_off_test(self, mock_projectorReceivedData): + """ + Test setting power off + """ + # GIVEN: Test object and preset + pjlink = pjlink_test + pjlink.power = S_ON + + # WHEN: Call process_command with turn power on command + pjlink.process_command('POWR', PJLINK_POWR_STATUS[S_STANDBY]) + + # THEN: Power should be set to ON + self.assertEquals(pjlink.power, S_STANDBY, 'Power should have been set to STANDBY') From 3e0769d946bfe8ce81f31a1cb9b0a1b78ac0aa01 Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Sat, 23 Apr 2016 14:12:28 -0700 Subject: [PATCH 03/17] Fix extraneous print() in media plugin --- openlp/plugins/media/mediaplugin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index 1d5529084..bb8a4f6a5 100644 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -160,7 +160,8 @@ def process_check_binary(program_path): """ program_type = None runlog = check_binary_exists(program_path) - print(runlog, type(runlog)) + # NOTE: Unneeded print statement - let originator clear it out if needed + # print(runlog, type(runlog)) # Analyse the output to see it the program is mediainfo for line in runlog.splitlines(): decoded_line = line.decode() From 292606ba38ac7007426c4409cc5ca4373a7fd22a Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Sat, 23 Apr 2016 14:38:43 -0700 Subject: [PATCH 04/17] Fix translate() string format and some missed conversions --- openlp/core/__init__.py | 4 ++-- openlp/core/common/__init__.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 5ed016309..68dd772be 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -223,8 +223,8 @@ class OpenLP(OpenLPMixin, QtWidgets.QApplication): translate('OpenLP', 'Backup of the data folder failed!')) return message = translate('OpenLP', - 'A backup of the data folder has been created' - 'at {text}'.format(text=data_folder_backup_path)) + 'A backup of the data folder has been created ' + 'at {text}').format(text=data_folder_backup_path) QtWidgets.QMessageBox.information(None, translate('OpenLP', 'Backup'), message) # Update the version in the settings diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index 1f5ca0c30..3946ee0b0 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -286,7 +286,7 @@ def get_uno_command(connection_type='pipe'): CONNECTION = '"--accept=pipe,name=openlp_pipe;urp;"' else: CONNECTION = '"--accept=socket,host=localhost,port=2002;urp;"' - return '%s %s %s' % (command, OPTIONS, CONNECTION) + return '{cmd} {opt} {conn}'.format(cmd=command, opt=OPTIONS, conn=CONNECTION) def get_uno_instance(resolver, connection_type='pipe'): @@ -336,7 +336,7 @@ def delete_file(file_path_name): os.remove(file_path_name) return True except (IOError, OSError): - log.exception("Unable to delete file %s" % file_path_name) + log.exception("Unable to delete file {name}".format(name=file_path_name)) return False @@ -390,7 +390,7 @@ def check_binary_exists(program_path): :param program_path:The full path to the binary to check. :return: program output to be parsed """ - log.debug('testing program_path: %s', program_path) + log.debug('testing program_path: {text}'.format(text=program_path)) try: # Setup startupinfo options for check_output to avoid console popping up on windows if is_win(): @@ -404,5 +404,5 @@ def check_binary_exists(program_path): except Exception: trace_error_handler(log) runlog = '' - log.debug('check_output returned: %s' % runlog) + log.debug('check_output returned: {text}'.format(text=runlog)) return runlog From 28e14012a8c25d9838dd8e14fa194b3d221280d6 Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Sun, 24 Apr 2016 04:04:32 -0700 Subject: [PATCH 05/17] Remove unneeded print statement --- openlp/core/__init__.py | 4 ++-- openlp/core/common/__init__.py | 4 ++-- openlp/plugins/media/mediaplugin.py | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 68dd772be..5ed016309 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -223,8 +223,8 @@ class OpenLP(OpenLPMixin, QtWidgets.QApplication): translate('OpenLP', 'Backup of the data folder failed!')) return message = translate('OpenLP', - 'A backup of the data folder has been created ' - 'at {text}').format(text=data_folder_backup_path) + 'A backup of the data folder has been created' + 'at {text}'.format(text=data_folder_backup_path)) QtWidgets.QMessageBox.information(None, translate('OpenLP', 'Backup'), message) # Update the version in the settings diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index 3946ee0b0..8b6a935c4 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -336,7 +336,7 @@ def delete_file(file_path_name): os.remove(file_path_name) return True except (IOError, OSError): - log.exception("Unable to delete file {name}".format(name=file_path_name)) + log.exception("Unable to delete file {text}".format(text=file_path_name)) return False @@ -404,5 +404,5 @@ def check_binary_exists(program_path): except Exception: trace_error_handler(log) runlog = '' - log.debug('check_output returned: {text}'.format(text=runlog)) + log.debug('check_output returned: {text}'.format(text=runlog) return runlog diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index bb8a4f6a5..e258b5809 100644 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -160,8 +160,6 @@ def process_check_binary(program_path): """ program_type = None runlog = check_binary_exists(program_path) - # NOTE: Unneeded print statement - let originator clear it out if needed - # print(runlog, type(runlog)) # Analyse the output to see it the program is mediainfo for line in runlog.splitlines(): decoded_line = line.decode() From 884f060dea2795be1387dd0b0f7561787cad398d Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Sun, 24 Apr 2016 04:22:04 -0700 Subject: [PATCH 06/17] Oops and text in projector test --- openlp/core/common/__init__.py | 2 +- tests/functional/openlp_core_lib/test_projector_pjlink1.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index 8b6a935c4..17fdf027b 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -404,5 +404,5 @@ def check_binary_exists(program_path): except Exception: trace_error_handler(log) runlog = '' - log.debug('check_output returned: {text}'.format(text=runlog) + log.debug('check_output returned: {text}'.format(text=runlog)) return runlog diff --git a/tests/functional/openlp_core_lib/test_projector_pjlink1.py b/tests/functional/openlp_core_lib/test_projector_pjlink1.py index 95d86efe9..4f81b2660 100644 --- a/tests/functional/openlp_core_lib/test_projector_pjlink1.py +++ b/tests/functional/openlp_core_lib/test_projector_pjlink1.py @@ -156,7 +156,7 @@ class TestPJLink(TestCase): @patch.object(pjlink_test, 'projectorReceivedData') def projector_process_power_on_test(self, mock_projectorReceivedData): """ - Test setting power on + Test setting power to ON """ # GIVEN: Test object and preset pjlink = pjlink_test @@ -171,7 +171,7 @@ class TestPJLink(TestCase): @patch.object(pjlink_test, 'projectorReceivedData') def projector_process_power_off_test(self, mock_projectorReceivedData): """ - Test setting power off + Test setting power to STANDBY """ # GIVEN: Test object and preset pjlink = pjlink_test @@ -180,5 +180,5 @@ class TestPJLink(TestCase): # WHEN: Call process_command with turn power on command pjlink.process_command('POWR', PJLINK_POWR_STATUS[S_STANDBY]) - # THEN: Power should be set to ON + # THEN: Power should be set to STANDBY self.assertEquals(pjlink.power, S_STANDBY, 'Power should have been set to STANDBY') From d3d6e6c620933803eed5435576e80321cc813820 Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Wed, 27 Apr 2016 05:49:55 -0700 Subject: [PATCH 07/17] Missed translate() string format --- openlp/core/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 5ed016309..6f6addbbd 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -224,7 +224,7 @@ class OpenLP(OpenLPMixin, QtWidgets.QApplication): return message = translate('OpenLP', 'A backup of the data folder has been created' - 'at {text}'.format(text=data_folder_backup_path)) + 'at {text}').format(text=data_folder_backup_path) QtWidgets.QMessageBox.information(None, translate('OpenLP', 'Backup'), message) # Update the version in the settings From 6158a0672c389cd8bb5d3bc1f9a9f26c62e101fd Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 30 Apr 2016 10:34:37 +0100 Subject: [PATCH 08/17] background videos --- openlp/core/ui/maindisplay.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 079235c2d..7e7929fd6 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -31,13 +31,15 @@ Some of the code for this form is based on the examples at: import html import logging +import os from PyQt5 import QtCore, QtWidgets, QtWebKit, QtWebKitWidgets, QtOpenGL, QtGui, QtMultimedia -from openlp.core.common import Registry, RegistryProperties, OpenLPMixin, Settings, translate, is_macosx, is_win +from openlp.core.common import AppLocation, Registry, RegistryProperties, OpenLPMixin, Settings, translate,\ + is_macosx, is_win from openlp.core.lib import ServiceItem, ImageSource, ScreenList, build_html, expand_tags, image_to_byte from openlp.core.lib.theme import BackgroundType -from openlp.core.ui import HideMode, AlertLocation +from openlp.core.ui import HideMode, AlertLocation, DisplayControllerType if is_macosx(): from ctypes import pythonapi, c_void_p, c_char_p, py_object @@ -437,6 +439,7 @@ class MainDisplay(OpenLPMixin, Display, RegistryProperties): :param service_item: The Service item to be used :param image_path: Where the image resides. + :param is_love: Are we the live controller assume not. """ self.web_loaded = False self.initial_fame = None @@ -457,13 +460,13 @@ class MainDisplay(OpenLPMixin, Display, RegistryProperties): background = self.image_manager.get_image_bytes(self.override['image'], ImageSource.ImagePlugin) self.set_transparency(self.service_item.theme_data.background_type == BackgroundType.to_string(BackgroundType.Transparent)) - if self.service_item.theme_data.background_filename: - self.service_item.bg_image_bytes = self.image_manager.get_image_bytes( - self.service_item.theme_data.background_filename, ImageSource.Theme) - if image_path: - image_bytes = self.image_manager.get_image_bytes(image_path, ImageSource.ImagePlugin) - else: - image_bytes = None + image_bytes = None + if self.service_item.theme_data.background_type == 'image': + if self.service_item.theme_data.background_filename: + self.service_item.bg_image_bytes = self.image_manager.get_image_bytes( + self.service_item.theme_data.background_filename, ImageSource.Theme) + if image_path: + image_bytes = self.image_manager.get_image_bytes(image_path, ImageSource.ImagePlugin) html = build_html(self.service_item, self.screen, self.is_live, background, image_bytes, plugins=self.plugin_manager.plugins) self.web_view.setHtml(html) @@ -475,6 +478,17 @@ class MainDisplay(OpenLPMixin, Display, RegistryProperties): Registry().execute('slidecontroller_live_unblank') else: self.hide_display(self.hide_mode) + if self.service_item.theme_data.background_type == 'video' and self.is_live: + if self.service_item.theme_data.background_filename: + service_item = ServiceItem() + service_item.title = 'webkit' + service_item.processor = 'webkit' + path = os.path.join(AppLocation.get_section_data_path('themes'), + self.service_item.theme_data.theme_name) + service_item.add_from_command(path, + self.service_item.theme_data.background_filename, + ':/media/slidecontroller_multimedia.png') + self.media_controller.video(DisplayControllerType.Live, service_item, video_behind_text=True) self._hide_mouse() def footer(self, text): From c80f45320b84a4b56559500adf2437aaf4c20814 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 30 Apr 2016 16:40:23 +0100 Subject: [PATCH 09/17] video theme creation --- openlp/core/common/uistrings.py | 1 + openlp/core/lib/theme.py | 25 +++++++++++++++- openlp/core/ui/media/webkitplayer.py | 3 -- openlp/core/ui/themeform.py | 43 ++++++++++++++++++++++++++-- openlp/core/ui/thememanager.py | 4 +-- openlp/core/ui/themewizard.py | 37 ++++++++++++++++++++---- 6 files changed, 99 insertions(+), 14 deletions(-) diff --git a/openlp/core/common/uistrings.py b/openlp/core/common/uistrings.py index f26b41fc5..c7e29415d 100644 --- a/openlp/core/common/uistrings.py +++ b/openlp/core/common/uistrings.py @@ -152,3 +152,4 @@ class UiStrings(object): self.Version = translate('OpenLP.Ui', 'Version') self.View = translate('OpenLP.Ui', 'View') self.ViewMode = translate('OpenLP.Ui', 'View Mode') + self.Video = translate('OpenLP.Ui', 'Video') diff --git a/openlp/core/lib/theme.py b/openlp/core/lib/theme.py index 0ef0065a7..bd35c4bdb 100644 --- a/openlp/core/lib/theme.py +++ b/openlp/core/lib/theme.py @@ -44,6 +44,7 @@ class BackgroundType(object): Gradient = 1 Image = 2 Transparent = 3 + Video = 4 @staticmethod def to_string(background_type): @@ -58,6 +59,8 @@ class BackgroundType(object): return 'image' elif background_type == BackgroundType.Transparent: return 'transparent' + elif background_type == BackgroundType.Video: + return 'video' @staticmethod def from_string(type_string): @@ -72,6 +75,8 @@ class BackgroundType(object): return BackgroundType.Image elif type_string == 'transparent': return BackgroundType.Transparent + elif type_string == 'video': + return BackgroundType.Video class BackgroundGradientType(object): @@ -184,7 +189,7 @@ class ThemeXML(object): :param path: The path name to be added. """ - if self.background_type == 'image': + if self.background_type == 'image' or self.background_type == 'video': if self.background_filename and path: self.theme_name = self.theme_name.strip() self.background_filename = self.background_filename.strip() @@ -255,6 +260,21 @@ class ThemeXML(object): # Create endColor element self.child_element(background, 'borderColor', str(border_color)) + def add_background_video(self, filename, border_color): + """ + Add a video background. + + :param filename: The file name of the video. + :param border_color: + """ + background = self.theme_xml.createElement('background') + background.setAttribute('type', 'video') + self.theme.appendChild(background) + # Create Filename element + self.child_element(background, 'filename', filename) + # Create endColor element + self.child_element(background, 'borderColor', str(border_color)) + def add_font(self, name, color, size, override, fonttype='main', bold='False', italics='False', line_adjustment=0, xpos=0, ypos=0, width=0, height=0, outline='False', outline_color='#ffffff', outline_pixel=2, shadow='False', shadow_color='#ffffff', shadow_pixel=5): @@ -512,6 +532,9 @@ class ThemeXML(object): elif self.background_type == BackgroundType.to_string(BackgroundType.Image): filename = os.path.split(self.background_filename)[1] self.add_background_image(filename, self.background_border_color) + elif self.background_type == BackgroundType.to_string(BackgroundType.Video): + filename = os.path.split(self.background_filename)[1] + self.add_background_video(filename, self.background_border_color) elif self.background_type == BackgroundType.to_string(BackgroundType.Transparent): self.add_background_transparent() self.add_font( diff --git a/openlp/core/ui/media/webkitplayer.py b/openlp/core/ui/media/webkitplayer.py index cc8c7f55c..0b9b90a6e 100644 --- a/openlp/core/ui/media/webkitplayer.py +++ b/openlp/core/ui/media/webkitplayer.py @@ -55,9 +55,6 @@ VIDEO_JS = """ switch(state){ case 'load': video.src = 'file:///' + path; - if(loop == true) { - video.loop = true; - } video.load(); break; case 'play': diff --git a/openlp/core/ui/themeform.py b/openlp/core/ui/themeform.py index fc231a859..d18914411 100644 --- a/openlp/core/ui/themeform.py +++ b/openlp/core/ui/themeform.py @@ -31,7 +31,7 @@ from openlp.core.common import Registry, RegistryProperties, UiStrings, translat from openlp.core.lib.theme import BackgroundType, BackgroundGradientType from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui import ThemeLayoutForm -from openlp.core.ui.lib.colorbutton import ColorButton +from openlp.core.ui.media.webkitplayer import VIDEO_EXT from .themewizard import Ui_ThemeWizard log = logging.getLogger(__name__) @@ -66,10 +66,13 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties): self.gradient_combo_box.currentIndexChanged.connect(self.on_gradient_combo_box_current_index_changed) self.color_button.colorChanged.connect(self.on_color_changed) self.image_color_button.colorChanged.connect(self.on_image_color_changed) + self.video_color_button.colorChanged.connect(self.on_video_color_changed) self.gradient_start_button.colorChanged.connect(self.on_gradient_start_color_changed) self.gradient_end_button.colorChanged.connect(self.on_gradient_end_color_changed) self.image_browse_button.clicked.connect(self.on_image_browse_button_clicked) self.image_file_edit.editingFinished.connect(self.on_image_file_edit_editing_finished) + self.video_browse_button.clicked.connect(self.on_video_browse_button_clicked) + self.video_file_edit.editingFinished.connect(self.on_video_file_edit_editing_finished) self.main_color_button.colorChanged.connect(self.on_main_color_changed) self.outline_color_button.colorChanged.connect(self.on_outline_color_changed) self.shadow_color_button.colorChanged.connect(self.on_shadow_color_changed) @@ -307,6 +310,10 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties): self.image_color_button.color = self.theme.background_border_color self.image_file_edit.setText(self.theme.background_filename) self.setField('background_type', 2) + elif self.theme.background_type == BackgroundType.to_string(BackgroundType.Video): + self.video_color_button.color = self.theme.background_border_color + self.video_file_edit.setText(self.theme.background_filename) + self.setField('background_type', 4) elif self.theme.background_type == BackgroundType.to_string(BackgroundType.Transparent): self.setField('background_type', 3) if self.theme.background_direction == BackgroundGradientType.to_string(BackgroundGradientType.Horizontal): @@ -384,10 +391,12 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties): if self.update_theme_allowed: self.theme.background_type = BackgroundType.to_string(index) if self.theme.background_type != BackgroundType.to_string(BackgroundType.Image) and \ + self.theme.background_type != BackgroundType.to_string(BackgroundType.Video) and \ self.temp_background_filename == '': self.temp_background_filename = self.theme.background_filename self.theme.background_filename = '' - if self.theme.background_type == BackgroundType.to_string(BackgroundType.Image) and \ + if (self.theme.background_type == BackgroundType.to_string(BackgroundType.Image) or + self.theme.background_type != BackgroundType.to_string(BackgroundType.Video)) and \ self.temp_background_filename != '': self.theme.background_filename = self.temp_background_filename self.temp_background_filename = '' @@ -413,6 +422,12 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties): """ self.theme.background_border_color = color + def on_video_color_changed(self, color): + """ + Background / Gradient 1 _color button pushed. + """ + self.theme.background_border_color = color + def on_gradient_start_color_changed(self, color): """ Gradient 2 _color button pushed. @@ -444,6 +459,27 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties): """ self.theme.background_filename = str(self.image_file_edit.text()) + def on_video_browse_button_clicked(self): + """ + Background video button pushed. + """ + visible_formats = '(%s)' % '; '.join(VIDEO_EXT) + actual_formats = '(%s)' % ' '.join(VIDEO_EXT) + video_filter = '%s %s %s' % (translate('OpenLP', 'Video Files'), visible_formats, actual_formats) + video_filter = '%s;;%s (*.*)' % (video_filter, UiStrings().AllFiles) + filename, filter_used = QtWidgets.QFileDialog.getOpenFileName( + self, translate('OpenLP.ThemeWizard', 'Select Video'), + self.video_file_edit.text(), video_filter) + if filename: + self.theme.background_filename = filename + self.set_background_page_values() + + def on_video_file_edit_editing_finished(self): + """ + Background video path edited + """ + self.theme.background_filename = str(self.image_file_edit.text()) + def on_main_color_changed(self, color): """ Set the main colour value @@ -519,7 +555,8 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties): return save_from = None save_to = None - if self.theme.background_type == BackgroundType.to_string(BackgroundType.Image): + if self.theme.background_type == BackgroundType.to_string(BackgroundType.Image) or \ + self.theme.background_type == BackgroundType.to_string(BackgroundType.Video): filename = os.path.split(str(self.theme.background_filename))[1] save_to = os.path.join(self.path, self.theme.theme_name, filename) save_from = self.theme.background_filename diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 32975e9aa..14a4663f4 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -300,7 +300,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage """ save_to = None save_from = None - if theme_data.background_type == 'image': + if theme_data.background_type == 'image' or theme_data.background_type == 'video': save_to = os.path.join(self.path, new_theme_name, os.path.split(str(theme_data.background_filename))[1]) save_from = theme_data.background_filename theme_data.theme_name = new_theme_name @@ -318,7 +318,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage translate('OpenLP.ThemeManager', 'You must select a theme to edit.')): item = self.theme_list_widget.currentItem() theme = self.get_theme_data(item.data(QtCore.Qt.UserRole)) - if theme.background_type == 'image': + if theme.background_type == 'image' or theme.background_type == 'video': self.old_background_image = theme.background_filename self.theme_form.theme = theme self.theme_form.exec(True) diff --git a/openlp/core/ui/themewizard.py b/openlp/core/ui/themewizard.py index ab8854ef2..ac596440c 100644 --- a/openlp/core/ui/themewizard.py +++ b/openlp/core/ui/themewizard.py @@ -62,7 +62,7 @@ class Ui_ThemeWizard(object): self.background_label = QtWidgets.QLabel(self.background_page) self.background_label.setObjectName('background_label') self.background_combo_box = QtWidgets.QComboBox(self.background_page) - self.background_combo_box.addItems(['', '', '', '']) + self.background_combo_box.addItems(['', '', '', '', '']) self.background_combo_box.setObjectName('background_combo_box') self.background_type_layout.addRow(self.background_label, self.background_combo_box) self.background_type_layout.setItem(1, QtWidgets.QFormLayout.LabelRole, self.spacer) @@ -135,6 +135,32 @@ class Ui_ThemeWizard(object): self.transparent_layout.setObjectName('Transparent_layout') self.background_stack.addWidget(self.transparent_widget) self.background_layout.addLayout(self.background_stack) + + self.video_widget = QtWidgets.QWidget(self.background_page) + self.video_widget.setObjectName('video_widget') + self.video_layout = QtWidgets.QFormLayout(self.video_widget) + self.video_layout.setContentsMargins(0, 0, 0, 0) + self.video_layout.setObjectName('video_layout') + self.video_color_label = QtWidgets.QLabel(self.color_widget) + self.video_color_label.setObjectName('video_color_label') + self.video_color_button = ColorButton(self.color_widget) + self.video_color_button.setObjectName('video_color_button') + self.video_layout.addRow(self.video_color_label, self.video_color_button) + self.video_label = QtWidgets.QLabel(self.video_widget) + self.video_label.setObjectName('video_label') + self.video_file_layout = QtWidgets.QHBoxLayout() + self.video_file_layout.setObjectName('video_file_layout') + self.video_file_edit = QtWidgets.QLineEdit(self.video_widget) + self.video_file_edit.setObjectName('video_file_edit') + self.video_file_layout.addWidget(self.video_file_edit) + self.video_browse_button = QtWidgets.QToolButton(self.video_widget) + self.video_browse_button.setObjectName('video_browse_button') + self.video_browse_button.setIcon(build_icon(':/general/general_open.png')) + self.video_file_layout.addWidget(self.video_browse_button) + self.video_layout.addRow(self.video_label, self.video_file_layout) + self.video_layout.setItem(2, QtWidgets.QFormLayout.LabelRole, self.spacer) + self.background_stack.addWidget(self.video_widget) + theme_wizard.addPage(self.background_page) # Main Area Page self.main_area_page = QtWidgets.QWizardPage() @@ -390,11 +416,10 @@ class Ui_ThemeWizard(object): self.background_page.setSubTitle(translate('OpenLP.ThemeWizard', 'Set up your theme\'s background ' 'according to the parameters below.')) self.background_label.setText(translate('OpenLP.ThemeWizard', 'Background type:')) - self.background_combo_box.setItemText(BackgroundType.Solid, - translate('OpenLP.ThemeWizard', 'Solid color')) - self.background_combo_box.setItemText(BackgroundType.Gradient, - translate('OpenLP.ThemeWizard', 'Gradient')) + self.background_combo_box.setItemText(BackgroundType.Solid, translate('OpenLP.ThemeWizard', 'Solid color')) + self.background_combo_box.setItemText(BackgroundType.Gradient, translate('OpenLP.ThemeWizard', 'Gradient')) self.background_combo_box.setItemText(BackgroundType.Image, UiStrings().Image) + self.background_combo_box.setItemText(BackgroundType.Video, UiStrings().Video) self.background_combo_box.setItemText(BackgroundType.Transparent, translate('OpenLP.ThemeWizard', 'Transparent')) self.color_label.setText(translate('OpenLP.ThemeWizard', 'color:')) @@ -413,6 +438,8 @@ class Ui_ThemeWizard(object): 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.video_color_label.setText(translate('OpenLP.ThemeWizard', 'Background color:')) + self.video_label.setText('%s:' % 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')) From 162f1ecbe9efd79fd6523d91dab8e71c44001984 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 30 Apr 2016 16:49:06 +0100 Subject: [PATCH 10/17] remove old loop --- openlp/core/ui/media/webkitplayer.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/openlp/core/ui/media/webkitplayer.py b/openlp/core/ui/media/webkitplayer.py index 0b9b90a6e..4524d4cc7 100644 --- a/openlp/core/ui/media/webkitplayer.py +++ b/openlp/core/ui/media/webkitplayer.py @@ -45,7 +45,7 @@ VIDEO_CSS = """ """ VIDEO_JS = """ - function show_video(state, path, volume, loop, variable_value){ + function show_video(state, path, volume, variable_value){ // Sometimes video.currentTime stops slightly short of video.duration and video.ended is intermittent! var video = document.getElementById('video'); @@ -177,12 +177,8 @@ class WebkitPlayer(MediaPlayer): else: vol = 0 path = controller.media_info.file_info.absoluteFilePath() - if controller.media_info.is_background: - loop = 'true' - else: - loop = 'false' display.web_view.setVisible(True) - js = 'show_video("load", "%s", %s, %s);' % (path.replace('\\', '\\\\'), str(vol), loop) + js = 'show_video("load", "%s", %s, %s);' % (path.replace('\\', '\\\\'), str(vol)) display.frame.evaluateJavaScript(js) return True From 38cd4b1f67dcc5ab8c116b3dbe7d41f9a82abd88 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 30 Apr 2016 18:12:40 +0100 Subject: [PATCH 11/17] with tests --- scripts/translation_utils.py | 4 +- .../openlp_core_ui/test_maindisplay.py | 61 ++++++++++++++++++- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/scripts/translation_utils.py b/scripts/translation_utils.py index 221948acc..c355089fd 100755 --- a/scripts/translation_utils.py +++ b/scripts/translation_utils.py @@ -60,7 +60,7 @@ import webbrowser from PyQt5 import QtCore from lxml import etree, objectify -SERVER_URL = 'http://www.transifex.net/api/2/project/openlp/resource/openlp-24x/' +SERVER_URL = 'http://www.transifex.net/api/2/project/openlp/resource/openlp-26x/' IGNORED_PATHS = ['scripts'] IGNORED_FILES = ['setup.py'] @@ -270,7 +270,7 @@ def update_translations(): return else: os.chdir(os.path.abspath('..')) - run('pylupdate4 -verbose -noobsolete openlp.pro') + run('pylupdate5 -verbose -noobsolete openlp.pro') os.chdir(os.path.abspath('scripts')) diff --git a/tests/functional/openlp_core_ui/test_maindisplay.py b/tests/functional/openlp_core_ui/test_maindisplay.py index fc7ae4910..1eb92e93e 100644 --- a/tests/functional/openlp_core_ui/test_maindisplay.py +++ b/tests/functional/openlp_core_ui/test_maindisplay.py @@ -27,8 +27,9 @@ from unittest import TestCase, skipUnless from PyQt5 import QtCore from openlp.core.common import Registry, is_macosx, Settings -from openlp.core.lib import ScreenList +from openlp.core.lib import ScreenList, PluginManager from openlp.core.ui import MainDisplay +from openlp.core.ui.media import MediaController from openlp.core.ui.maindisplay import TRANSPARENT_STYLESHEET, OPAQUE_STYLESHEET from tests.helpers.testmixin import TestMixin @@ -223,3 +224,61 @@ class TestMainDisplay(TestCase, TestMixin): # THEN: setVisible should had not been called main_display.setVisible.assert_not_called() + + @patch(u'openlp.core.ui.maindisplay.Settings') + @patch(u'openlp.core.ui.maindisplay.build_html') + def build_html_no_video_test(self, MockedSettings, Mocked_build_html): + # GIVEN: Mocked display + display = MagicMock() + mocked_media_controller = MagicMock() + Registry.create() + Registry().register('media_controller', mocked_media_controller) + main_display = MainDisplay(display) + main_display.frame = MagicMock() + mocked_settings = MagicMock() + mocked_settings.value.return_value = False + MockedSettings.return_value = mocked_settings + main_display.shake_web_view = MagicMock() + service_item = MagicMock() + mocked_plugin = MagicMock() + display.plugin_manager = PluginManager() + display.plugin_manager.plugins = [mocked_plugin] + main_display.web_view = MagicMock() + + # WHEN: build_html is called with a normal service item and a non video theme. + main_display.build_html(service_item) + + # THEN: the following should had not been called + self.assertEquals(main_display.web_view.setHtml.call_count, 1, 'setHTML should be called once') + self.assertEquals(main_display.media_controller.video.call_count, 0, + 'Media Controller video should not have been called') + + @patch(u'openlp.core.ui.maindisplay.Settings') + @patch(u'openlp.core.ui.maindisplay.build_html') + def build_html_video_test(self, MockedSettings, Mocked_build_html): + # GIVEN: Mocked display + display = MagicMock() + mocked_media_controller = MagicMock() + Registry.create() + Registry().register('media_controller', mocked_media_controller) + main_display = MainDisplay(display) + main_display.frame = MagicMock() + mocked_settings = MagicMock() + mocked_settings.value.return_value = False + MockedSettings.return_value = mocked_settings + main_display.shake_web_view = MagicMock() + service_item = MagicMock() + service_item.theme_data = MagicMock() + service_item.theme_data.background_type = 'video' + mocked_plugin = MagicMock() + display.plugin_manager = PluginManager() + display.plugin_manager.plugins = [mocked_plugin] + main_display.web_view = MagicMock() + + # WHEN: build_html is called with a normal service item and a video theme. + main_display.build_html(service_item) + + # THEN: the following should had not been called + self.assertEquals(main_display.web_view.setHtml.call_count, 1, 'setHTML should be called once') + self.assertEquals(main_display.media_controller.video.call_count, 1, + 'Media Controller video should have been called once') From 6d7039ed41786a43f1665816fad614dcf722bbd6 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 30 Apr 2016 18:19:55 +0100 Subject: [PATCH 12/17] minor fixes --- openlp/core/ui/maindisplay.py | 1 - openlp/core/ui/themewizard.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 7e7929fd6..ccad0071e 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -439,7 +439,6 @@ class MainDisplay(OpenLPMixin, Display, RegistryProperties): :param service_item: The Service item to be used :param image_path: Where the image resides. - :param is_love: Are we the live controller assume not. """ self.web_loaded = False self.initial_fame = None diff --git a/openlp/core/ui/themewizard.py b/openlp/core/ui/themewizard.py index ac596440c..b546c1872 100644 --- a/openlp/core/ui/themewizard.py +++ b/openlp/core/ui/themewizard.py @@ -135,7 +135,6 @@ class Ui_ThemeWizard(object): self.transparent_layout.setObjectName('Transparent_layout') self.background_stack.addWidget(self.transparent_widget) self.background_layout.addLayout(self.background_stack) - self.video_widget = QtWidgets.QWidget(self.background_page) self.video_widget.setObjectName('video_widget') self.video_layout = QtWidgets.QFormLayout(self.video_widget) @@ -160,7 +159,6 @@ class Ui_ThemeWizard(object): self.video_layout.addRow(self.video_label, self.video_file_layout) self.video_layout.setItem(2, QtWidgets.QFormLayout.LabelRole, self.spacer) self.background_stack.addWidget(self.video_widget) - theme_wizard.addPage(self.background_page) # Main Area Page self.main_area_page = QtWidgets.QWizardPage() From 51613fd32d500270c62629a6c9c25e52cf600ee1 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 2 May 2016 09:12:39 +0100 Subject: [PATCH 13/17] fix strings --- openlp/core/ui/media/webkitplayer.py | 2 +- openlp/core/ui/themeform.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/openlp/core/ui/media/webkitplayer.py b/openlp/core/ui/media/webkitplayer.py index 4524d4cc7..19221ace0 100644 --- a/openlp/core/ui/media/webkitplayer.py +++ b/openlp/core/ui/media/webkitplayer.py @@ -178,7 +178,7 @@ class WebkitPlayer(MediaPlayer): vol = 0 path = controller.media_info.file_info.absoluteFilePath() display.web_view.setVisible(True) - js = 'show_video("load", "%s", %s, %s);' % (path.replace('\\', '\\\\'), str(vol)) + js = 'show_video("load", "{path}", {vol});'.format(path=path.replace('\\', '\\\\'), vol=str(vol)) display.frame.evaluateJavaScript(js) return True diff --git a/openlp/core/ui/themeform.py b/openlp/core/ui/themeform.py index d18914411..2ec733629 100644 --- a/openlp/core/ui/themeform.py +++ b/openlp/core/ui/themeform.py @@ -465,8 +465,9 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties): """ visible_formats = '(%s)' % '; '.join(VIDEO_EXT) actual_formats = '(%s)' % ' '.join(VIDEO_EXT) - video_filter = '%s %s %s' % (translate('OpenLP', 'Video Files'), visible_formats, actual_formats) - video_filter = '%s;;%s (*.*)' % (video_filter, UiStrings().AllFiles) + video_filter = '{trans} {visible} {actual}'.format(trans=translate('OpenLP', 'Video Files'), + visible=visible_formats, actual=actual_formats) + video_filter = '{video};;{ui} (*.*)'.format(video=video_filter, ui=UiStrings().AllFiles) filename, filter_used = QtWidgets.QFileDialog.getOpenFileName( self, translate('OpenLP.ThemeWizard', 'Select Video'), self.video_file_edit.text(), video_filter) From 16c0ebfcdac1c6fee563c860fbebf0c62df5ef95 Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Thu, 5 May 2016 08:41:48 -0700 Subject: [PATCH 14/17] Revert regex string conversion until more testing --- openlp/plugins/bibles/lib/__init__.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/openlp/plugins/bibles/lib/__init__.py b/openlp/plugins/bibles/lib/__init__.py index 52f400c24..804755d18 100644 --- a/openlp/plugins/bibles/lib/__init__.py +++ b/openlp/plugins/bibles/lib/__init__.py @@ -211,24 +211,24 @@ def update_reference_separators(): while '||' in source_string: source_string = source_string.replace('||', '|') if role != 'e': - REFERENCE_SEPARATORS['sep_{text}_display'.format(text=role)] = source_string.split('|')[0] + REFERENCE_SEPARATORS['sep_{role}_display'.format(role=role)] = source_string.split('|')[0] # escape reserved characters for character in '\\.^$*+?{}[]()': source_string = source_string.replace(character, '\\' + character) # add various unicode alternatives source_string = source_string.replace('-', '(?:[-\u00AD\u2010\u2011\u2012\u2014\u2014\u2212\uFE63\uFF0D])') source_string = source_string.replace(',', '(?:[,\u201A])') - REFERENCE_SEPARATORS['sep_{text}'.format(text=role)] = '\s*(?:{text})\s*'.format(text=source_string) - REFERENCE_SEPARATORS['sep_{text}_default'.format(text=role)] = default_separators[index] + REFERENCE_SEPARATORS['sep_{role}'.format(role=role)] = '\s*(?:{source})\s*'.format(source=source_string) + REFERENCE_SEPARATORS['sep_{role}_default'.format(role=role)] = default_separators[index] # verse range match: (:)?(-((:)?|end)?)? - range_regex = '(?:(?P[0-9]+){sep_v})?' \ - '(?P[0-9]+)(?P{sep_r}(?:(?:(?P' \ - '[0-9]+){sep_v})?(?P[0-9]+)|{sep_e})?)?'.format(**REFERENCE_SEPARATORS) - REFERENCE_MATCHES['range'] = re.compile('^\s*{text}\s*$'.format(text=range_regex), re.UNICODE) + # TODO: Check before converting this string + range_regex = '(?:(?P[0-9]+)%(sep_v)s)?' \ + '(?P[0-9]+)(?P%(sep_r)s(?:(?:(?P' \ + '[0-9]+)%(sep_v)s)?(?P[0-9]+)|%(sep_e)s)?)?' % REFERENCE_SEPARATORS + # TODO: Test before converting re.compile strings + REFERENCE_MATCHES['range'] = re.compile('^\s*%s\s*$' % range_regex, re.UNICODE) REFERENCE_MATCHES['range_separator'] = re.compile(REFERENCE_SEPARATORS['sep_l'], re.UNICODE) # full reference match: ((,(?!$)|(?=$)))+ - # NOTE: - # Need to research a little more before converting this to python3 string format REFERENCE_MATCHES['full'] = \ re.compile('^\s*(?!\s)(?P[\d]*[^\d]+)(?(?:%(range_regex)s(?:%(sep_l)s(?!\s*$)|(?=\s*$)))+)\s*$' @@ -333,9 +333,7 @@ def parse_reference(reference, bible, language_selection, book_ref_id=False): separator. """ - # TODO: - # Verify convertsion here before committing format change - log.debug('parse_reference("%s")', reference) + log.debug('parse_reference("{text}")'.format(text=reference)) match = get_reference_match('full').match(reference) if match: log.debug('Matched reference {text}'.format(text=reference)) @@ -404,7 +402,7 @@ def parse_reference(reference, bible, language_selection, book_ref_id=False): ref_list.append((book_ref_id, from_chapter, 1, -1)) return ref_list else: - log.warn('Invalid reference: {text}'.format(text=reference)) + log.debug('Invalid reference: {text}'.format(text=reference)) return None From 9ac95cf66553659d893bf69ddff56c2e62043a2b Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Thu, 5 May 2016 12:37:48 -0700 Subject: [PATCH 15/17] Skip crosswalk.com test while server down --- openlp/core/common/__init__.py | 7 +++---- tests/interfaces/openlp_plugins/bibles/test_lib_http.py | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index 17fdf027b..f1abd8fe6 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -55,10 +55,9 @@ def trace_error_handler(logger): """ log_string = "OpenLP Error trace" for tb in traceback.extract_stack(): - log_string = '{text}\n File {file} at line {line} \n\t called {data}'.format(text=log_string, - file=tb[0], - line=tb[1], - data=tb[3]) + log_string += '\n File {file} at line {line} \n\t called {data}'.format(file=tb[0], + line=tb[1], + data=tb[3]) logger.error(log_string) diff --git a/tests/interfaces/openlp_plugins/bibles/test_lib_http.py b/tests/interfaces/openlp_plugins/bibles/test_lib_http.py index ca2269aa4..5d73d01e8 100644 --- a/tests/interfaces/openlp_plugins/bibles/test_lib_http.py +++ b/tests/interfaces/openlp_plugins/bibles/test_lib_http.py @@ -22,7 +22,7 @@ """ Package to test the openlp.plugin.bible.lib.https package. """ -from unittest import TestCase +from unittest import TestCase, skip from openlp.core.common import Registry from openlp.plugins.bibles.lib.http import BGExtract, CWExtract, BSExtract @@ -146,6 +146,7 @@ class TestBibleHTTP(TestCase): self.assertIsNotNone(bibles) self.assertIn(('Holman Christian Standard Bible', 'HCSB', 'en'), bibles) + @skip("Waiting for Crosswalk to fix their server") def crosswalk_get_bibles_test(self): """ Test getting list of bibles from Crosswalk.com From df654d72fb1ca4c1a69f0f37da83845ee6eaab7e Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 10 May 2016 05:36:25 +0100 Subject: [PATCH 16/17] change net to com --- openlp/core/ui/servicemanager.py | 2 +- scripts/translation_utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 82b489344..a59f94377 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -1323,7 +1323,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa """ The theme may have changed in the settings dialog so make sure the theme combo box is in the correct state. """ - visible = self.renderer.theme_level == ThemeLevel.Global + visible = not self.renderer.theme_level == ThemeLevel.Global self.theme_label.setVisible(visible) self.theme_combo_box.setVisible(visible) diff --git a/scripts/translation_utils.py b/scripts/translation_utils.py index c355089fd..a82ac44cf 100755 --- a/scripts/translation_utils.py +++ b/scripts/translation_utils.py @@ -60,7 +60,7 @@ import webbrowser from PyQt5 import QtCore from lxml import etree, objectify -SERVER_URL = 'http://www.transifex.net/api/2/project/openlp/resource/openlp-26x/' +SERVER_URL = 'http://www.transifex.com/api/2/project/openlp/resource/openlp-26x/' IGNORED_PATHS = ['scripts'] IGNORED_FILES = ['setup.py'] From 33eb1ba274110b9023623b54ff30959538746bc0 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 10 May 2016 05:40:59 +0100 Subject: [PATCH 17/17] remove rogue print --- openlp/plugins/media/mediaplugin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index 1d5529084..e258b5809 100644 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -160,7 +160,6 @@ def process_check_binary(program_path): """ program_type = None runlog = check_binary_exists(program_path) - print(runlog, type(runlog)) # Analyse the output to see it the program is mediainfo for line in runlog.splitlines(): decoded_line = line.decode()