← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~knightrider0xd/openlp/better-sm-preview into lp:openlp

 

Ian Knight has proposed merging lp:~knightrider0xd/openlp/better-sm-preview into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~knightrider0xd/openlp/better-sm-preview/+merge/283142

Added single click preview for service manager (see attached blueprint)
- Checkbox appears in advanced settings tab.
- When enabled, items will be sent to preview when clicked in service manager, but NOT if double-clicked.
-- 
Your team OpenLP Core is requested to review the proposed merge of lp:~knightrider0xd/openlp/better-sm-preview into lp:openlp.
=== modified file 'openlp/core/common/settings.py'
--- openlp/core/common/settings.py	2016-01-10 16:01:43 +0000
+++ openlp/core/common/settings.py	2016-01-19 14:08:14 +0000
@@ -131,6 +131,7 @@
         'advanced/save current plugin': False,
         'advanced/slide limits': SlideLimits.End,
         'advanced/single click preview': False,
+        'advanced/single click service preview': False,
         'advanced/x11 bypass wm': X11_BYPASS_DEFAULT,
         'advanced/search as type': True,
         'crashreport/last directory': '',

=== modified file 'openlp/core/ui/advancedtab.py'
--- openlp/core/ui/advancedtab.py	2015-12-31 22:46:06 +0000
+++ openlp/core/ui/advancedtab.py	2016-01-19 14:08:14 +0000
@@ -77,6 +77,9 @@
         self.single_click_preview_check_box = QtWidgets.QCheckBox(self.ui_group_box)
         self.single_click_preview_check_box.setObjectName('single_click_preview_check_box')
         self.ui_layout.addRow(self.single_click_preview_check_box)
+        self.single_click_service_preview_check_box = QtWidgets.QCheckBox(self.ui_group_box)
+        self.single_click_service_preview_check_box.setObjectName('single_click_service_preview_check_box')
+        self.ui_layout.addRow(self.single_click_service_preview_check_box)
         self.expand_service_item_check_box = QtWidgets.QCheckBox(self.ui_group_box)
         self.expand_service_item_check_box.setObjectName('expand_service_item_check_box')
         self.ui_layout.addRow(self.expand_service_item_check_box)
@@ -270,6 +273,8 @@
                                                            'Double-click to send items straight to live'))
         self.single_click_preview_check_box.setText(translate('OpenLP.AdvancedTab',
                                                               'Preview items when clicked in Media Manager'))
+        self.single_click_service_preview_check_box.setText(translate('OpenLP.AdvancedTab',
+                                                                      'Preview items when clicked in Service Manager'))
         self.expand_service_item_check_box.setText(translate('OpenLP.AdvancedTab',
                                                              'Expand new service items on creation'))
         self.enable_auto_close_check_box.setText(translate('OpenLP.AdvancedTab',
@@ -339,6 +344,7 @@
         self.media_plugin_check_box.setChecked(settings.value('save current plugin'))
         self.double_click_live_check_box.setChecked(settings.value('double click live'))
         self.single_click_preview_check_box.setChecked(settings.value('single click preview'))
+        self.single_click_service_preview_check_box.setChecked(settings.value('single click service preview'))
         self.expand_service_item_check_box.setChecked(settings.value('expand service item'))
         self.enable_auto_close_check_box.setChecked(settings.value('enable exit confirmation'))
         self.hide_mouse_check_box.setChecked(settings.value('hide mouse'))
@@ -420,6 +426,7 @@
         settings.setValue('save current plugin', self.media_plugin_check_box.isChecked())
         settings.setValue('double click live', self.double_click_live_check_box.isChecked())
         settings.setValue('single click preview', self.single_click_preview_check_box.isChecked())
+        settings.setValue('single click service preview', self.single_click_service_preview_check_box.isChecked())
         settings.setValue('expand service item', self.expand_service_item_check_box.isChecked())
         settings.setValue('enable exit confirmation', self.enable_auto_close_check_box.isChecked())
         settings.setValue('hide mouse', self.hide_mouse_check_box.isChecked())

=== modified file 'openlp/core/ui/servicemanager.py'
--- openlp/core/ui/servicemanager.py	2016-01-12 21:29:20 +0000
+++ openlp/core/ui/servicemanager.py	2016-01-19 14:08:14 +0000
@@ -211,7 +211,8 @@
         self.layout.addWidget(self.order_toolbar)
         # Connect up our signals and slots
         self.theme_combo_box.activated.connect(self.on_theme_combo_box_selected)
-        self.service_manager_list.doubleClicked.connect(self.on_make_live)
+        self.service_manager_list.doubleClicked.connect(self.on_double_click_live)
+        self.service_manager_list.clicked.connect(self.on_single_click_preview)
         self.service_manager_list.itemCollapsed.connect(self.collapsed)
         self.service_manager_list.itemExpanded.connect(self.expanded)
         # Last little bits of setting up
@@ -319,6 +320,7 @@
         self._modified = False
         self._file_name = ''
         self.service_has_all_original_files = True
+        self.list_double_clicked = False
 
     def bootstrap_initialise(self):
         """
@@ -1454,13 +1456,38 @@
         else:
             return self.service_items[item]['service_item']
 
-    def on_make_live(self, field=None):
+    def on_double_click_live(self, field=None):
         """
         Send the current item to the Live slide controller but triggered by a tablewidget click event.
         :param field:
         """
+        self.list_double_clicked = True
         self.make_live()
 
+    def on_single_click_preview(self, field=None):
+        """
+        If single click previewing is enabled, and triggered by a tablewidget click event,
+        start a timeout to verify a double-click hasn't triggered.
+        :param field:
+        """
+        if Settings().value('advanced/single click service preview'):
+            if not self.list_double_clicked:
+                # If a double click has not registered start a timer, otherwise wait for the existing timer to finish.
+                QtCore.QTimer.singleShot(QtWidgets.QApplication.instance().doubleClickInterval(),
+                                         self.on_single_click_preview_timeout)
+
+    def on_single_click_preview_timeout(self):
+        """
+        If a single click ok, but double click not triggered, send the current item to the Preview slide controller.
+        :param field:
+        """
+        if self.list_double_clicked:
+            # If a double click has registered, clear it.
+            self.list_double_clicked = False
+        else:
+            # Otherwise preview the item.
+            self.make_preview()
+
     def make_live(self, row=-1):
         """
         Send the current item to the Live slide controller

=== modified file 'tests/functional/openlp_core_ui/test_servicemanager.py'
--- tests/functional/openlp_core_ui/test_servicemanager.py	2015-12-31 22:46:06 +0000
+++ tests/functional/openlp_core_ui/test_servicemanager.py	2016-01-19 14:08:14 +0000
@@ -22,13 +22,14 @@
 """
 Package to test the openlp.core.ui.slidecontroller package.
 """
+import PyQt5
 from unittest import TestCase
 
-from openlp.core.common import Registry, ThemeLevel
+from openlp.core.common import Registry, ThemeLevel, Settings
 from openlp.core.lib import ServiceItem, ServiceItemType, ItemCapabilities
 from openlp.core.ui import ServiceManager
 
-from tests.functional import MagicMock
+from tests.functional import MagicMock, patch
 
 
 class TestServiceManager(TestCase):
@@ -540,3 +541,80 @@
         self.assertEquals(service_manager.timed_slide_interval.setChecked.call_count, 0, 'Should not be called')
         self.assertEquals(service_manager.theme_menu.menuAction().setVisible.call_count, 1,
                           'Should have be called once')
+
+    @patch(u'openlp.core.ui.servicemanager.Settings')
+    @patch(u'PyQt5.QtCore.QTimer.singleShot')
+    def single_click_preview_test_true(self, mocked_singleShot, MockedSettings):
+        """
+        Test that when "Preview items when clicked in Service Manager" enabled the preview timer starts
+        """
+        # GIVEN: A setting to enable "Preview items when clicked in Service Manager" and a service manager.
+        mocked_settings = MagicMock()
+        mocked_settings.value.return_value = True
+        MockedSettings.return_value = mocked_settings
+        service_manager = ServiceManager(None)
+        # WHEN: on_single_click_preview() is called
+        service_manager.on_single_click_preview()
+        # THEN: timer should have been started
+        mocked_singleShot.assert_called_with(PyQt5.QtWidgets.QApplication.instance().doubleClickInterval(),
+                                             service_manager.on_single_click_preview_timeout)
+
+    @patch(u'openlp.core.ui.servicemanager.Settings')
+    @patch(u'PyQt5.QtCore.QTimer.singleShot')
+    def single_click_preview_test_false(self, mocked_singleShot, MockedSettings):
+        """
+        Test that when "Preview items when clicked in Service Manager" disabled the preview timer doesn't start
+        """
+        # GIVEN: A setting to enable "Preview items when clicked in Service Manager" and a service manager.
+        mocked_settings = MagicMock()
+        mocked_settings.value.return_value = False
+        MockedSettings.return_value = mocked_settings
+        service_manager = ServiceManager(None)
+        # WHEN: on_single_click_preview() is called
+        service_manager.on_single_click_preview()
+        # THEN: timer should not be started
+        self.assertEquals(mocked_singleShot.call_count, 0, 'Should not be called')
+
+    @patch(u'openlp.core.ui.servicemanager.Settings')
+    @patch(u'PyQt5.QtCore.QTimer.singleShot')
+    @patch(u'openlp.core.ui.servicemanager.ServiceManager.make_live')
+    def single_click_preview_test_double(self, mocked_make_live, mocked_singleShot, MockedSettings):
+        """
+        Test that when a double click has registered the preview timer doesn't start
+        """
+        # GIVEN: A setting to enable "Preview items when clicked in Service Manager" and a service manager.
+        mocked_settings = MagicMock()
+        mocked_settings.value.return_value = True
+        MockedSettings.return_value = mocked_settings
+        service_manager = ServiceManager(None)
+        # WHEN: on_single_click_preview() is called following a double click
+        service_manager.on_double_click_live()
+        service_manager.on_single_click_preview()
+        # THEN: timer should not be started
+        self.assertEquals(mocked_singleShot.call_count, 0, 'Should not be called')
+
+    @patch(u'openlp.core.ui.servicemanager.ServiceManager.make_preview')
+    def single_click_timeout_test_single(self, mocked_make_preview):
+        """
+        Test that when a single click has been registered, the item is sent to preview
+        """
+        # GIVEN: A service manager.
+        service_manager = ServiceManager(None)
+        # WHEN: on_single_click_preview() is called
+        service_manager.on_single_click_preview_timeout()
+        # THEN: make_preview() should have been called
+        self.assertEquals(mocked_make_preview.call_count, 1, 'Should have been called once')
+
+    @patch(u'openlp.core.ui.servicemanager.ServiceManager.make_preview')
+    @patch(u'openlp.core.ui.servicemanager.ServiceManager.make_live')
+    def single_click_timeout_test_double(self, mocked_make_live, mocked_make_preview):
+        """
+        Test that when a double click has been registered, the item does not goes to preview
+        """
+        # GIVEN: A service manager.
+        service_manager = ServiceManager(None)
+        # WHEN: on_single_click_preview() is called after a double click
+        service_manager.on_double_click_live()
+        service_manager.on_single_click_preview_timeout()
+        # THEN: make_preview() should have been called
+        self.assertEquals(mocked_make_preview.call_count, 0, 'Should not be called')


Follow ups