From 524d8f3acbe36f8cc6ce9978427c88039c7251fa Mon Sep 17 00:00:00 2001 From: VirBinarus Date: Tue, 13 Jun 2017 16:49:48 +0100 Subject: [PATCH] fixed bug #1238385, but no tests Fixes: https://launchpad.net/bugs/1238385 --- openlp/core/ui/servicemanager.py | 37 ++++++++++++++++++ .../openlp_core_ui/test_servicemanager.py | 39 ++++++++++++++++++- 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index cf30245bf..8e6c6fd6b 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -66,6 +66,12 @@ class ServiceManagerList(QtWidgets.QTreeWidget): elif event.key() == QtCore.Qt.Key_Down: self.service_manager.on_move_selection_down() event.accept() + elif event.key() == QtCore.Qt.Key_Right: + self.service_manager.on_expand_selection() + event.accept() + elif event.key() == QtCore.Qt.Key_Left: + self.service_manager.on_collapse_selection() + event.accept() elif event.key() == QtCore.Qt.Key_Delete: self.service_manager.on_delete_from_service() event.accept() @@ -1119,6 +1125,37 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa return self.service_manager_list.setCurrentItem(item_after) + def on_expand_selection(self): + """ + Expands cursor selection on the window. Called by the right arrow + """ + item = self.service_manager_list.currentItem() + + if item.childCount(): # Since we only have 2 levels we find them by checking for children + if not self.service_manager_list.isExpanded(self.service_manager_list.currentIndex()): + self.service_manager_list.expandItem(item) + self.service_manager.expanded(item) + # If not expanded, Expand it + + self.service_manager_list.setCurrentItem(self.service_manager_list.itemBelow(item)) + # Then move selection down to child whether it needed to be expanded or not + + def on_collapse_selection(self): + """ + Collapses cursor selection on the window Called by the left arrow + """ + item = self.service_manager_list.currentItem() + + if item.childCount(): # Since we only have 2 levels we find them by checking for children + if self.service_manager_list.isExpanded(self.service_manager_list.currentIndex()): + self.service_manager_list.collapseItem(item) + self.service_manager.collapsed(item) + + else: # If selection is lower level + self.service_manager_list.collapseItem(item.parent()) + self.service_manager.collapsed(item.parent()) + self.service_manager_list.setCurrentItem(item.parent()) + def on_collapse_all(self, field=None): """ Collapse all the service items. diff --git a/tests/interfaces/openlp_core_ui/test_servicemanager.py b/tests/interfaces/openlp_core_ui/test_servicemanager.py index 10e928bc2..4e84e4035 100644 --- a/tests/interfaces/openlp_core_ui/test_servicemanager.py +++ b/tests/interfaces/openlp_core_ui/test_servicemanager.py @@ -28,9 +28,11 @@ from unittest.mock import MagicMock, patch from openlp.core.common import Registry from openlp.core.lib import ScreenList, ServiceItem, ItemCapabilities from openlp.core.ui.mainwindow import MainWindow +from openlp.core.ui.servicemanager import ServiceManagerList +from openlp.core.lib.serviceitem import ServiceItem from tests.helpers.testmixin import TestMixin - +from PyQt5 import QtCore, QtGui, QtTest class TestServiceManager(TestCase, TestMixin): @@ -351,3 +353,38 @@ class TestServiceManager(TestCase, TestMixin): new_service.trigger() assert mocked_event.call_count == 1, 'The on_new_service_clicked method should have been called once' + + def test_keyboard_expand_selection(self): + """ + Test on on_expand_selection method caused by keyboard + """ + # GIVEN A collapsed song selected on the service manager. + self.service_manager.setup_ui(self.service_manager) + ServiceManagerList(self.service_manager) + + item = ServiceItem() + item.title = "test" + item.add_from_text("slide 1") + item.add_from_text("slide 2") + item.add_icon(":/plugins/plugin_songs.png") + #SongMediaItem.generate_slide_data(item) + self.service_manager.add_service_item(item) + + print(item._raw_frames) + + song_to_expand = self.service_manager.service_manager_list.topLevelItem(0) + #print(song_to_expand) + self.service_manager.service_manager_list.setCurrentItem(song_to_expand) + #print(self.service_manager.service_manager_list.currentItem()) + #print(self.service_manager.service_manager_list.topLevelItemCount()) + + # WHEN Pressing the right arrow key + #QtTest.QTest.keyPress(self.service_manager.service_manager_list, QtCore.Qt.Key_Right) + + event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress,QtCore.Qt.Key_Right,QtCore.Qt.NoModifier) + ServiceManagerList.keyPressEvent(self.service_manager,event) + + # THEN Should be expanded + selected_index = self.service_manager.service_manager_list.currentIndex() + above_selection_index = self.service_manager.service_manager_list.indexAbove(selected_index) + self.assertTrue(self.service_manager.service_manager_list.isExpanded(above_selection_index), 'Item should have been expanded') \ No newline at end of file