← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~alisonken1/openlp/strings_mainwindow into lp:openlp

 

Ken Roberts has proposed merging lp:~alisonken1/openlp/strings_mainwindow into lp:openlp.

Commit message:
Convert strings to Python3 format in mainwindow.py and maindisplay.py

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~alisonken1/openlp/strings_mainwindow/+merge/293446

- Convert strings in mainwindow.py
- Convert strings in maindisplay.py
- Added test for projector Manufacturer.__repr__()
- pep8 in tests/functional/openlp_plugins/songs/test_openlpimporter.py

--------------------------------
lp:~alisonken1/openlp/strings_mainwindow (revision 2656)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/1512/
[SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/1423/
[SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1361/
[SUCCESS] https://ci.openlp.io/job/Branch-04a-Windows_Functional_Tests/1157/
[SUCCESS] https://ci.openlp.io/job/Branch-04b-Windows_Interface_Tests/748/
[SUCCESS] https://ci.openlp.io/job/Branch-05a-Code_Analysis/815/
[SUCCESS] https://ci.openlp.io/job/Branch-05b-Test_Coverage/683/

-- 
Your team OpenLP Core is requested to review the proposed merge of lp:~alisonken1/openlp/strings_mainwindow into lp:openlp.
=== modified file 'openlp/core/ui/maindisplay.py'
--- openlp/core/ui/maindisplay.py	2016-04-01 02:32:36 +0000
+++ openlp/core/ui/maindisplay.py	2016-04-29 20:41:28 +0000
@@ -247,7 +247,7 @@
         """
         Set up and build the output screen
         """
-        self.log_debug('Start MainDisplay setup (live = %s)' % self.is_live)
+        self.log_debug('Start MainDisplay setup (live = {islive})'.format(islive=self.is_live))
         self.screen = self.screens.current
         self.setVisible(False)
         Display.setup(self)
@@ -288,7 +288,9 @@
             self.application.process_events()
         self.setGeometry(self.screen['size'])
         if animate:
-            self.frame.evaluateJavaScript('show_text("%s")' % slide.replace('\\', '\\\\').replace('\"', '\\\"'))
+            # NOTE: Verify this works with ''.format()
+            _text = slide.replace('\\', '\\\\').replace('\"', '\\\"')
+            self.frame.evaluateJavaScript('show_text("{text}")'.format(text=_text))
         else:
             # This exists for https://bugs.launchpad.net/openlp/+bug/1016843
             # For unknown reasons if evaluateJavaScript is called
@@ -309,10 +311,10 @@
         text_prepared = expand_tags(html.escape(text)).replace('\\', '\\\\').replace('\"', '\\\"')
         if self.height() != self.screen['size'].height() or not self.isVisible():
             shrink = True
-            js = 'show_alert("%s", "%s")' % (text_prepared, 'top')
+            js = 'show_alert("{text}", "{top}")'.format(text=text_prepared, top='top')
         else:
             shrink = False
-            js = 'show_alert("%s", "")' % text_prepared
+            js = 'show_alert("{text}", "")'.format(text=text_prepared)
         height = self.frame.evaluateJavaScript(js)
         if shrink:
             if text:
@@ -368,7 +370,7 @@
         """
         self.setGeometry(self.screen['size'])
         if image:
-            js = 'show_image("data:image/png;base64,%s");' % image
+            js = 'show_image("data:image/png;base64,{image}");'.format(image=image)
         else:
             js = 'show_image("");'
         self.frame.evaluateJavaScript(js)
@@ -492,7 +494,7 @@
 
         :param mode: How the screen is to be hidden
         """
-        self.log_debug('hide_display mode = %d' % mode)
+        self.log_debug('hide_display mode = {mode:d}'.format(mode=mode))
         if self.screens.display_count == 1:
             # Only make visible if setting enabled.
             if not Settings().value('core/display on monitor'):

=== modified file 'openlp/core/ui/mainwindow.py'
--- openlp/core/ui/mainwindow.py	2016-04-23 13:46:59 +0000
+++ openlp/core/ui/mainwindow.py	2016-04-29 20:41:28 +0000
@@ -622,11 +622,10 @@
         :param version: The Version to be displayed.
         """
         log.debug('version_notice')
-        version_text = translate('OpenLP.MainWindow', 'Version %s of OpenLP is now available for download (you are '
-                                 'currently running version %s). \n\nYou can download the latest version from '
-                                 'http://openlp.org/.')
-        QtWidgets.QMessageBox.question(self, translate('OpenLP.MainWindow', 'OpenLP Version Updated'),
-                                       version_text % (version, get_application_version()[u'full']))
+        version_text = translate('OpenLP.MainWindow', 'Version {new} of OpenLP is now available for download (you are '
+                                 'currently running version {current}). \n\nYou can download the latest version from '
+                                 'http://openlp.org/.').format(new=version, current=get_application_version()[u'full'])
+        QtWidgets.QMessageBox.question(self, translate('OpenLP.MainWindow', 'OpenLP Version Updated'), version_text)
 
     def show(self):
         """
@@ -642,7 +641,7 @@
             self.service_manager_contents.load_last_file()
         # This will store currently used layout preset so it remains enabled on next startup.
         # If any panel is enabled/disabled after preset is set, this setting is not saved.
-        view_mode = Settings().value('%s/view mode' % self.general_settings_section)
+        view_mode = Settings().value('{section}/view mode'.format(section=self.general_settings_section))
         if view_mode == 'default' and Settings().value('user interface/is preset layout'):
             self.mode_default_item.setChecked(True)
         elif view_mode == 'setup' and Settings().value('user interface/is preset layout'):
@@ -731,8 +730,8 @@
         """
         settings = Settings()
         self.live_controller.main_display_set_background()
-        if settings.value('%s/screen blank' % self.general_settings_section):
-            if settings.value('%s/blank warning' % self.general_settings_section):
+        if settings.value('{section}/screen blank'.format(section=self.general_settings_section)):
+            if settings.value('{section}/blank warning'.format(section=self.general_settings_section)):
                 QtWidgets.QMessageBox.question(self, translate('OpenLP.MainWindow', 'OpenLP Main Display Blanked'),
                                                translate('OpenLP.MainWindow', 'The Main Display has been blanked out'))
 
@@ -924,9 +923,9 @@
             try:
                 value = import_settings.value(section_key)
             except KeyError:
-                log.warning('The key "%s" does not exist (anymore), so it will be skipped.' % section_key)
+                log.warning('The key "{key}" does not exist (anymore), so it will be skipped.'.format(key=section_key))
             if value is not None:
-                settings.setValue('%s' % (section_key), value)
+                settings.setValue('{key}'.format(key=section_key), value)
         now = datetime.now()
         settings.beginGroup(self.header_section)
         settings.setValue('file_imported', import_file_name)
@@ -1003,9 +1002,9 @@
                 key_value = settings.value(section_key)
             except KeyError:
                 QtWidgets.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'Export setting error'),
-                                               translate('OpenLP.MainWindow', 'The key "%s" does not have a default '
+                                               translate('OpenLP.MainWindow', 'The key "{key}" does not have a default '
                                                                               'value so it will be skipped in this '
-                                                                              'export.') % section_key,
+                                                                              'export.').format(key=section_key),
                                                QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Ok))
                 key_value = None
             if key_value is not None:
@@ -1027,8 +1026,9 @@
             os.remove(temp_file)
         except OSError as ose:
                 QtWidgets.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'Export setting error'),
-                                               translate('OpenLP.MainWindow', 'An error occurred while exporting the '
-                                                                              'settings: %s') % ose.strerror,
+                                               translate('OpenLP.MainWindow',
+                                                         'An error occurred while exporting the '
+                                                         'settings: {err}').format(err=ose.strerror),
                                                QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Ok))
 
     def on_mode_default_item_clicked(self):
@@ -1061,7 +1061,7 @@
         """
         if mode:
             settings = Settings()
-            settings.setValue('%s/view mode' % self.general_settings_section, mode)
+            settings.setValue('{section}/view mode'.format(section=self.general_settings_section), mode)
         self.media_manager_dock.setVisible(media)
         self.service_manager_dock.setVisible(service)
         self.theme_manager_dock.setVisible(theme)
@@ -1168,9 +1168,9 @@
         :param file_name: The file name of the service file.
         """
         if modified:
-            title = '%s - %s*' % (UiStrings().OLPV2x, file_name)
+            title = '{title} - {name}*'.format(title=UiStrings().OLPV2x, name=file_name)
         else:
-            title = '%s - %s' % (UiStrings().OLPV2x, file_name)
+            title = '{title} - {name}'.format(title=UiStrings().OLPV2x, name=file_name)
         self.setWindowTitle(title)
 
     def show_status_message(self, message):
@@ -1183,8 +1183,9 @@
         """
         Update the default theme indicator in the status bar
         """
-        self.default_theme_label.setText(translate('OpenLP.MainWindow', 'Default Theme: %s') %
-                                         Settings().value('themes/global theme'))
+        theme_name = Settings().value('themes/global theme')
+        self.default_theme_label.setText(translate('OpenLP.MainWindow',
+                                                   'Default Theme: {theme}').format(theme=theme_name))
 
     def toggle_media_manager(self):
         """
@@ -1331,7 +1332,8 @@
         recent_files_to_display = existing_recent_files[0:recent_file_count]
         self.recent_files_menu.clear()
         for file_id, filename in enumerate(recent_files_to_display):
-            log.debug('Recent file name: %s', filename)
+            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,
                                    triggers=self.service_manager_contents.on_recent_service_clicked)
@@ -1424,7 +1426,7 @@
         """
         Change the data directory.
         """
-        log.info('Changing data path to %s' % self.new_data_path)
+        log.info('Changing data path to {newpath}'.format(newpath=self.new_data_path))
         old_data_path = str(AppLocation.get_data_path())
         # Copy OpenLP data to new location if requested.
         self.application.set_busy_cursor()
@@ -1432,17 +1434,17 @@
             log.info('Copying data to new path')
             try:
                 self.show_status_message(
-                    translate('OpenLP.MainWindow', 'Copying OpenLP data to new data directory location - %s '
-                              '- Please wait for copy to finish').replace('%s', self.new_data_path))
+                    translate('OpenLP.MainWindow', 'Copying OpenLP data to new data directory location - {path} '
+                              '- Please wait for copy to finish').format(path=self.new_data_path))
                 dir_util.copy_tree(old_data_path, self.new_data_path)
                 log.info('Copy successful')
             except (IOError, os.error, DistutilsFileError) as why:
                 self.application.set_normal_cursor()
-                log.exception('Data copy failed %s' % str(why))
+                log.exception('Data copy failed {err}'.format(err=str(why)))
+                err_text = translate('OpenLP.MainWindow',
+                                     'OpenLP Data directory copy failed\n\n{err}').format(err=str(why)),
                 QtWidgets.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'New Data Directory Error'),
-                                               translate('OpenLP.MainWindow',
-                                                         'OpenLP Data directory copy failed\n\n%s').
-                                               replace('%s', str(why)),
+                                               err_text,
                                                QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Ok))
                 return False
         else:

=== modified file 'tests/functional/openlp_core_lib/test_projectordb.py'
--- tests/functional/openlp_core_lib/test_projectordb.py	2016-01-15 19:41:14 +0000
+++ tests/functional/openlp_core_lib/test_projectordb.py	2016-04-29 20:41:28 +0000
@@ -28,7 +28,7 @@
 import os
 from unittest import TestCase
 
-from openlp.core.lib.projector.db import Projector, ProjectorDB, ProjectorSource
+from openlp.core.lib.projector.db import Manufacturer, Model, Projector, ProjectorDB, ProjectorSource
 
 from tests.functional import MagicMock, patch
 from tests.resources.projector.data import TEST_DB, TEST1_DATA, TEST2_DATA, TEST3_DATA
@@ -82,13 +82,13 @@
     """
     Test case for ProjectorDB
     """
-    def setUp(self):
+    @patch('openlp.core.lib.projector.db.init_url')
+    def setUp(self, mocked_init_url):
         """
         Set up anything necessary for all tests
         """
-        with patch('openlp.core.lib.projector.db.init_url') as mocked_init_url:
-            mocked_init_url.return_value = 'sqlite:///%s' % TEST_DB
-            self.projector = ProjectorDB()
+        mocked_init_url.return_value = 'sqlite:///{db}'.format(db=TEST_DB)
+        self.projector = ProjectorDB()
 
     def tearDown(self):
         """
@@ -192,3 +192,17 @@
         # THEN: Projector should have the same source entry
         item = self.projector.get_projector_by_id(item_id)
         self.assertTrue(compare_source(item.source_list[0], source))
+
+    def manufacturer_repr_test(self):
+        """
+        Test manufacturer class __repr__ text
+        """
+        # GIVEN: Test object
+        manufacturer = Manufacturer()
+
+        # WHEN: Name is set
+        manufacturer.name = 'OpenLP Test'
+
+        # THEN: __repr__ should return a proper string
+        self.assertEqual(str(manufacturer), '<Manufacturer(name="OpenLP Test")>',
+                         'Manufacturer.__repr__() should have returned a proper representation string')


Follow ups