← Back to team overview

openlp-core team mailing list archive

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

 

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

Commit message:
Update projector UI strings to Python3 format

Requested reviews:
  OpenLP Core (openlp-core)

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

- Update string format to Python3 style
- Added projector multiple lamp values test

Convert string format from Python2
     '%s %s' % (value1, value2)
to Python3
     '{key1} {key2}'.format(key1=value1, key2=value2)

-- 
Your team OpenLP Core is requested to review the proposed merge of lp:~alisonken1/openlp/strings_projector_ui into lp:openlp.
=== modified file 'openlp/core/ui/projector/editform.py'
--- openlp/core/ui/projector/editform.py	2016-01-09 16:26:14 +0000
+++ openlp/core/ui/projector/editform.py	2016-04-17 09:40:04 +0000
@@ -182,9 +182,10 @@
             QtWidgets.QMessageBox.warning(self,
                                           translate('OpenLP.ProjectorEdit', 'Duplicate Name'),
                                           translate('OpenLP.ProjectorEdit',
-                                                    'There is already an entry with name "%s" in '
-                                                    'the database as ID "%s". <br />'
-                                                    'Please enter a different name.' % (name, record.id)))
+                                                    'There is already an entry with name "{name}" in '
+                                                    'the database as ID "{record}". <br />'
+                                                    'Please enter a different name.'.format(name=name,
+                                                                                            record=record.id)))
             valid = False
             return
         adx = self.ip_text.text()
@@ -198,17 +199,17 @@
                 QtWidgets.QMessageBox.warning(self,
                                               translate('OpenLP.ProjectorWizard', 'Duplicate IP Address'),
                                               translate('OpenLP.ProjectorWizard',
-                                                        'IP address "%s"<br />is already in the database as ID %s.'
-                                                        '<br /><br />Please Enter a different IP address.' %
-                                                        (adx, ip.id)))
+                                                        'IP address "{ip}"<br />is already in the database '
+                                                        'as ID {data}.<br /><br />Please Enter a different '
+                                                        'IP address.'.format(ip=adx, data=ip.id)))
                 valid = False
                 return
         else:
             QtWidgets.QMessageBox.warning(self,
                                           translate('OpenLP.ProjectorWizard', 'Invalid IP Address'),
                                           translate('OpenLP.ProjectorWizard',
-                                                    'IP address "%s"<br>is not a valid IP address.'
-                                                    '<br /><br />Please enter a valid IP address.' % adx))
+                                                    'IP address "{ip}"<br>is not a valid IP address.'
+                                                    '<br /><br />Please enter a valid IP address.'.format(ip=adx)))
             valid = False
             return
         port = int(self.port_text.text())
@@ -219,8 +220,8 @@
                                                     'Port numbers below 1000 are reserved for admin use only, '
                                                     '<br />and port numbers above 32767 are not currently usable.'
                                                     '<br /><br />Please enter a valid port number between '
-                                                    ' 1000 and 32767.'
-                                                    '<br /><br />Default PJLink port is %s' % PJLINK_PORT))
+                                                    '1000 and 32767.<br /><br />'
+                                                    'Default PJLink port is {port}'.format(port=PJLINK_PORT)))
             valid = False
         if valid:
             self.projector.ip = self.ip_text.text()

=== modified file 'openlp/core/ui/projector/manager.py'
--- openlp/core/ui/projector/manager.py	2016-03-03 17:53:29 +0000
+++ openlp/core/ui/projector/manager.py	2016-04-17 09:40:04 +0000
@@ -344,7 +344,7 @@
         real_projector = item.data(QtCore.Qt.UserRole)
         projector_name = str(item.text())
         visible = real_projector.link.status_connect >= S_CONNECTED
-        log.debug('(%s) Building menu - visible = %s' % (projector_name, visible))
+        log.debug('({name}) Building menu - visible = {visible}'.format(name=projector_name, visible=visible))
         self.delete_action.setVisible(True)
         self.edit_action.setVisible(True)
         self.connect_action.setVisible(not visible)
@@ -394,7 +394,7 @@
                                                         projectordb=self.projectordb,
                                                         edit=edit)
             source = source_select_form.exec(projector.link)
-        log.debug('(%s) source_select_form() returned %s' % (projector.link.ip, source))
+        log.debug('({ip}) source_select_form() returned {data}'.format(ip=projector.link.ip, data=source))
         if source is not None and source > 0:
             projector.link.set_input_source(str(source))
         return
@@ -473,8 +473,9 @@
             return
         projector = list_item.data(QtCore.Qt.UserRole)
         msg = QtWidgets.QMessageBox()
-        msg.setText(translate('OpenLP.ProjectorManager', 'Delete projector (%s) %s?') % (projector.link.ip,
-                                                                                         projector.link.name))
+        msg.setText(translate('OpenLP.ProjectorManager',
+                              'Delete projector ({ip}) {name}?'.format(ip=projector.link.ip,
+                                                                       name=projector.link.name)))
         msg.setInformativeText(translate('OpenLP.ProjectorManager', 'Are you sure you want to delete this projector?'))
         msg.setStandardButtons(msg.Cancel | msg.Ok)
         msg.setDefaultButton(msg.Cancel)
@@ -522,7 +523,7 @@
         list_item = None
         deleted = self.projectordb.delete_projector(projector.db_item)
         for item in self.projector_list:
-            log.debug('New projector list - item: %s %s' % (item.link.ip, item.link.name))
+            log.debug('New projector list - item: {ip} {name}'.format(ip=item.link.ip, name=item.link.name))
 
     def on_disconnect_projector(self, opt=None):
         """
@@ -627,53 +628,58 @@
         """
         lwi = self.projector_list_widget.item(self.projector_list_widget.currentRow())
         projector = lwi.data(QtCore.Qt.UserRole)
-        message = '<b>%s</b>: %s<BR />' % (translate('OpenLP.ProjectorManager', 'Name'),
-                                           projector.link.name)
-        message = '%s<b>%s</b>: %s<br />' % (message, translate('OpenLP.ProjectorManager', 'IP'),
-                                             projector.link.ip)
-        message = '%s<b>%s</b>: %s<br />' % (message, translate('OpenLP.ProjectorManager', 'Port'),
-                                             projector.link.port)
-        message = '%s<b>%s</b>: %s<br />' % (message, translate('OpenLP.ProjectorManager', 'Notes'),
-                                             projector.link.notes)
-        message = '%s<hr /><br >' % message
+        message = '<b>{title}</b>: {data}<BR />'.format(title=translate('OpenLP.ProjectorManager', 'Name'),
+                                                        data=projector.link.name)
+        message += '<b>{title}</b>: {data}<br />'.format(title=translate('OpenLP.ProjectorManager', 'IP'),
+                                                         data=projector.link.ip)
+        message += '<b>{title}</b>: {data}<br />'.format(title=translate('OpenLP.ProjectorManager', 'Port'),
+                                                         data=projector.link.port)
+        message += '<b>{title}</b>: {data}<br />'.format(title=translate('OpenLP.ProjectorManager', 'Notes'),
+                                                         data=projector.link.notes)
+        message += '<hr /><br >'
         if projector.link.manufacturer is None:
-            message = '%s%s' % (message, translate('OpenLP.ProjectorManager',
-                                                   'Projector information not available at this time.'))
+            message += translate('OpenLP.ProjectorManager', 'Projector information not available at this time.')
         else:
-            message = '%s<b>%s</b>: %s<BR />' % (message, translate('OpenLP.ProjectorManager', 'Projector Name'),
-                                                 projector.link.pjlink_name)
-            message = '%s<b>%s</b>: %s<br />' % (message, translate('OpenLP.ProjectorManager', 'Manufacturer'),
-                                                 projector.link.manufacturer)
-            message = '%s<b>%s</b>: %s<br />' % (message, translate('OpenLP.ProjectorManager', 'Model'),
-                                                 projector.link.model)
-            message = '%s<b>%s</b>: %s<br /><br />' % (message, translate('OpenLP.ProjectorManager', 'Other info'),
-                                                       projector.link.other_info)
-            message = '%s<b>%s</b>: %s<br />' % (message, translate('OpenLP.ProjectorManager', 'Power status'),
-                                                 ERROR_MSG[projector.link.power])
-            message = '%s<b>%s</b>: %s<br />' % (message, translate('OpenLP.ProjectorManager', 'Shutter is'),
-                                                 translate('OpenLP.ProjectorManager', 'Closed')
-                                                 if projector.link.shutter else translate('OpenLP', 'Open'))
+            message += '<b>{title}</b>: {data}<br />'.format(title=translate('OpenLP.ProjectorManager',
+                                                                             'Projector Name'),
+                                                             data=projector.link.pjlink_name)
+            message += '<b>{title}</b>: {data}<br />'.format(title=translate('OpenLP.ProjectorManager', 'Manufacturer'),
+                                                             data=projector.link.manufacturer)
+            message += '<b>{title}</b>: {data}<br />'.format(title=translate('OpenLP.ProjectorManager', 'Model'),
+                                                             data=projector.link.model)
+            message += '<b>{title}</b>: {data}<br /><br />'.format(title=translate('OpenLP.ProjectorManager',
+                                                                                   'Other info'),
+                                                                   data=projector.link.other_info)
+            message += '<b>{title}</b>: {data}<br />'.format(title=translate('OpenLP.ProjectorManager', 'Power status'),
+                                                             data=ERROR_MSG[projector.link.power])
+            message += '<b>{title}</b>: {data}<br />'.format(title=translate('OpenLP.ProjectorManager', 'Shutter is'),
+                                                             data=translate('OpenLP.ProjectorManager', 'Closed')
+                                                             if projector.link.shutter
+                                                             else translate('OpenLP', 'Open'))
             message = '%s<b>%s</b>: %s<br />' % (message,
                                                  translate('OpenLP.ProjectorManager', 'Current source input is'),
                                                  projector.link.source)
             count = 1
             for item in projector.link.lamp:
-                message = '%s <b>%s %s</b> (%s) %s: %s<br />' % (message,
-                                                                 translate('OpenLP.ProjectorManager', 'Lamp'),
-                                                                 count,
-                                                                 translate('OpenLP.ProjectorManager', 'On')
-                                                                 if item['On']
-                                                                 else translate('OpenLP.ProjectorManager', 'Off'),
-                                                                 translate('OpenLP.ProjectorManager', 'Hours'),
-                                                                 item['Hours'])
-                count = count + 1
-            message = '%s<hr /><br />' % message
+                message += '<b>{title} {count}</b> {status} '.format(title=translate('OpenLP.ProjectorManager',
+                                                                                     'Lamp'),
+                                                                     count=count,
+                                                                     status=translate('OpenLP.ProjectorManager',
+                                                                                      ' is on')
+                                                                     if item['On']
+                                                                     else translate('OpenLP.ProjectorManager',
+                                                                                    'is off'))
+
+                message += '<b>{title}</b>: {hours}<br />'.format(title=translate('OpenLP.ProjectorManager', 'Hours'),
+                                                                  hours=item['Hours'])
+                count += 1
+            message += '<hr /><br />'
             if projector.link.projector_errors is None:
-                message = '%s%s' % (message, translate('OpenLP.ProjectorManager', 'No current errors or warnings'))
+                message += translate('OpenLP.ProjectorManager', 'No current errors or warnings')
             else:
-                message = '%s<b>%s</b>' % (message, translate('OpenLP.ProjectorManager', 'Current errors/warnings'))
+                message += '<b>{data}</b>'.format(data=translate('OpenLP.ProjectorManager', 'Current errors/warnings'))
                 for (key, val) in projector.link.projector_errors.items():
-                    message = '%s<b>%s</b>: %s<br />' % (message, key, ERROR_MSG[val])
+                    message += '<b>{key}</b>: {data}<br />'.format(key=key, data=ERROR_MSG[val])
         QtWidgets.QMessageBox.information(self, translate('OpenLP.ProjectorManager', 'Projector Information'), message)
 
     def _add_projector(self, projector):
@@ -743,7 +749,7 @@
         if start:
             item.link.connect_to_host()
         for item in self.projector_list:
-            log.debug('New projector list - item: (%s) %s' % (item.link.ip, item.link.name))
+            log.debug('New projector list - item: ({ip}) {name}'.format(ip=item.link.ip, name=item.link.name))
 
     @pyqtSlot(str)
     def add_projector_from_wizard(self, ip, opts=None):
@@ -753,7 +759,7 @@
         :param ip: IP address of new record item to find
         :param opts: Needed by PyQt5
         """
-        log.debug('add_projector_from_wizard(ip=%s)' % ip)
+        log.debug('add_projector_from_wizard(ip={ip})'.format(ip=ip))
         item = self.projectordb.get_projector_by_ip(ip)
         self.add_projector(item)
 
@@ -764,7 +770,7 @@
 
         :param projector: Projector() instance of projector with updated information
         """
-        log.debug('edit_projector_from_wizard(ip=%s)' % projector.ip)
+        log.debug('edit_projector_from_wizard(ip={ip})'.format(ip=projector.ip))
         self.old_projector.link.name = projector.name
         self.old_projector.link.ip = projector.ip
         self.old_projector.link.pin = None if projector.pin == '' else projector.pin
@@ -816,7 +822,9 @@
         else:
             status_code = status
             message = ERROR_MSG[status] if msg is None else msg
-        log.debug('(%s) updateStatus(status=%s) message: "%s"' % (item.link.name, status_code, message))
+        log.debug('({name}) updateStatus(status={status}) message: "{message}"'.format(name=item.link.name,
+                                                                                       status=status_code,
+                                                                                       message=message))
         if status in STATUS_ICONS:
             if item.status == status:
                 return
@@ -826,14 +834,14 @@
                 status_code = ERROR_STRING[status]
             elif status in STATUS_STRING:
                 status_code = STATUS_STRING[status]
-            log.debug('(%s) Updating icon with %s' % (item.link.name, status_code))
+            log.debug('({name}) Updating icon with {code}'.format(name=item.link.name, code=status_code))
             item.widget.setIcon(item.icon)
             self.update_icons()
 
     def get_toolbar_item(self, name, enabled=False, hidden=False):
         item = self.one_toolbar.findChild(QtWidgets.QAction, name)
         if item == 0:
-            log.debug('No item found with name "%s"' % name)
+            log.debug('No item found with name "{name}"'.format(name=name))
             return
         item.setVisible(False if hidden else True)
         item.setEnabled(True if enabled else False)
@@ -918,11 +926,13 @@
 
         :param name: Name from QListWidgetItem
         """
-        QtWidgets.QMessageBox.warning(self, translate('OpenLP.ProjectorManager',
-                                                      '"%s" Authentication Error' % name),
+        # Build the title separately so we can make it easier for translators
+        title = '"{name}" '.format(name=name)
+        title += translate('OpenLP.ProjectorManager', 'Authentication Error')
+        QtWidgets.QMessageBox.warning(self, title,
                                       '<br />There was an authentication error while trying to connect.'
                                       '<br /><br />Please verify your PIN setting '
-                                      'for projector item "%s"' % name)
+                                      'for projector item "{name}"'.format(name=name))
 
     @pyqtSlot(str)
     def no_authentication_error(self, name):
@@ -932,11 +942,13 @@
 
         :param name: Name from QListWidgetItem
         """
-        QtWidgets.QMessageBox.warning(self, translate('OpenLP.ProjectorManager',
-                                                      '"%s" No Authentication Error' % name),
+        # Build the title separately so we can make it easier for translators
+        title = '"{name}" '.format(name=name)
+        title += translate('OpenLP.ProjectorManager', 'No Authentication Error')
+        QtWidgets.QMessageBox.warning(self, title,
                                       '<br />PIN is set and projector does not require authentication.'
                                       '<br /><br />Please verify your PIN setting '
-                                      'for projector item "%s"' % name)
+                                      'for projector item "{name}"'.format(name=name))
 
 
 class ProjectorItem(QObject):
@@ -972,5 +984,5 @@
     QtWidgets.QMessageBox.information(None,
                                       translate('OpenLP.ProjectorManager', 'Not Implemented Yet'),
                                       translate('OpenLP.ProjectorManager',
-                                                'Function "%s"<br />has not been implemented yet.'
-                                                '<br />Please check back again later.' % function))
+                                                'Function "{function}"<br />has not been implemented yet.'
+                                                '<br />Please check back again later.'.format(function=function)))

=== modified file 'openlp/core/ui/projector/sourceselectform.py'
--- openlp/core/ui/projector/sourceselectform.py	2016-01-09 16:26:14 +0000
+++ openlp/core/ui/projector/sourceselectform.py	2016-04-17 09:40:04 +0000
@@ -115,7 +115,7 @@
     if edit:
         for key in sourcelist:
             item = QLineEdit()
-            item.setObjectName('source_key_%s' % key)
+            item.setObjectName('source_key_{key}'.format(key=key))
             source_item = projectordb.get_source_by_code(code=key, projector_id=projector.db_item.id)
             if source_item is None:
                 item.setText(PJLINK_DEFAULT_CODES[key])
@@ -161,7 +161,7 @@
             button.setToolTip(translate('OpenLP.SourceSelectForm',
                                         'Save changes and return to OpenLP'))
         else:
-            log.debug('No tooltip for button {}'.format(button.text()))
+            log.debug('No tooltip for button {text}'.format(text=button.text()))
 
 
 class FingerTabBarWidget(QTabBar):
@@ -359,16 +359,20 @@
                     continue
                 item = self.projectordb.get_source_by_code(code=code, projector_id=projector.id)
                 if item is None:
-                    log.debug("(%s) Adding new source text %s: %s" % (projector.ip, code, text))
+                    log.debug("({ip}) Adding new source text {code}: {text}".format(ip=projector.ip,
+                                                                                    code=code,
+                                                                                    text=text))
                     item = ProjectorSource(projector_id=projector.id, code=code, text=text)
                 else:
                     item.text = text
-                    log.debug('(%s) Updating source code %s with text="%s"' % (projector.ip, item.code, item.text))
+                    log.debug('({ip}) Updating source code {code} with text="{text}"'.format(ip=projector.ip,
+                                                                                             code=item.code,
+                                                                                             text=item.text))
                 self.projectordb.add_source(item)
             selected = 0
         else:
             selected = self.button_group.checkedId()
-            log.debug('SourceSelectTabs().accepted() Setting source to %s' % selected)
+            log.debug('SourceSelectTabs().accepted() Setting source to {selected}'.format(selected=selected))
         self.done(selected)
 
 
@@ -417,7 +421,7 @@
         if self.edit:
             for key in keys:
                 item = QLineEdit()
-                item.setObjectName('source_key_%s' % key)
+                item.setObjectName('source_key_{key}'.format(key=key))
                 source_item = self.projectordb.get_source_by_code(code=key, projector_id=self.projector.db_item.id)
                 if source_item is None:
                     item.setText(PJLINK_DEFAULT_CODES[key])
@@ -498,14 +502,18 @@
                     continue
                 item = self.projectordb.get_source_by_code(code=code, projector_id=projector.id)
                 if item is None:
-                    log.debug("(%s) Adding new source text %s: %s" % (projector.ip, code, text))
+                    log.debug("({ip}) Adding new source text {code}: {text}".format(ip=projector.ip,
+                                                                                    code=code,
+                                                                                    text=text))
                     item = ProjectorSource(projector_id=projector.id, code=code, text=text)
                 else:
                     item.text = text
-                    log.debug('(%s) Updating source code %s with text="%s"' % (projector.ip, item.code, item.text))
+                    log.debug('({ip}) Updating source code {code} with text="{text}"'.format(ip=projector.ip,
+                                                                                             code=item.code,
+                                                                                             text=item.text))
                 self.projectordb.add_source(item)
             selected = 0
         else:
             selected = self.button_group.checkedId()
-            log.debug('SourceSelectDialog().accepted() Setting source to %s' % selected)
+            log.debug('SourceSelectDialog().accepted() Setting source to {selected}'.format(selected=selected))
         self.done(selected)

=== modified file 'tests/functional/openlp_core_lib/test_projector_pjlink1.py'
--- tests/functional/openlp_core_lib/test_projector_pjlink1.py	2016-04-02 03:04:15 +0000
+++ tests/functional/openlp_core_lib/test_projector_pjlink1.py	2016-04-17 09:40:04 +0000
@@ -107,3 +107,30 @@
         # THEN: process_inpt method should have been called with 31
         mock_process_inpt.called_with('31',
                                       "process_inpt should have been called with 31")
+
+    @patch.object(pjlink_test, 'projectorReceivedData')
+    def projector_process_multiple_lamp_test(self, mock_projectorReceivedData):
+        """
+        Test setting multiple lamp on/off and hours
+        """
+        # GIVEN: Test object
+        pjlink = pjlink_test
+
+        # WHEN: Call process_command with lamp data
+        pjlink.process_command('LAMP', '11111 1 22222 0 33333 1')
+
+        # THEN: Lamp should have been set with proper lamp status
+        self.assertEquals(len(pjlink.lamp), 3,
+                          'Projector should have 3 lamps specified')
+        self.assertEquals(pjlink.lamp[0]['On'], True,
+                          'Lamp 1 power status should have been set to TRUE')
+        self.assertEquals(pjlink.lamp[0]['Hours'], 11111,
+                          'Lamp 1 hours should have been set to 11111')
+        self.assertEquals(pjlink.lamp[1]['On'], False,
+                          'Lamp 2 power status should have been set to FALSE')
+        self.assertEquals(pjlink.lamp[1]['Hours'], 22222,
+                          'Lamp 2 hours should have been set to 22222')
+        self.assertEquals(pjlink.lamp[2]['On'], True,
+                          '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')


Follow ups