Add tests for new function

This commit is contained in:
Tim Bentley 2014-01-04 11:50:27 +00:00
parent 4c7fa599c6
commit 5eba575618
4 changed files with 113 additions and 2 deletions

View File

@ -72,6 +72,11 @@ WIDE_MENU = [
'desktop_screen_button'
]
NON_TEXT_MENU = [
'blank_screen_button',
'desktop_screen_button'
]
class DisplayController(QtGui.QWidget):
"""
@ -116,6 +121,9 @@ class SlideController(DisplayController):
self.screen_size_changed()
def initialise(self):
"""
Initialise the UI elements of the controller
"""
self.screens = ScreenList()
try:
self.ratio = self.screens.current['size'].width() / self.screens.current['size'].height()
@ -442,6 +450,8 @@ class SlideController(DisplayController):
def set_live_hot_keys(self, parent=None):
"""
Set the live hotkeys
:param parent: The parent UI object for actions to be added to.
"""
self.previous_service = create_action(parent, 'previousService',
text=translate('OpenLP.SlideController', 'Previous Service'),
@ -469,6 +479,8 @@ class SlideController(DisplayController):
def toggle_display(self, action):
"""
Toggle the display settings triggered from remote messages.
:param action: The blank action to be processed.
"""
if action == 'blank' or action == 'hide':
self.on_blank_display(True)
@ -544,6 +556,8 @@ class SlideController(DisplayController):
def __add_actions_to_widget(self, widget):
"""
Add actions to the widget specified by `widget`
:param widget: The UI widget for the actions
"""
widget.addActions([
self.previous_item, self.next_item,
@ -574,6 +588,8 @@ class SlideController(DisplayController):
def on_controller_size_changed(self, width):
"""
Change layout of display control buttons on controller size change
:param width: the new width of the display
"""
if self.is_live:
# Space used by the toolbar.
@ -581,12 +597,24 @@ class SlideController(DisplayController):
# Add the threshold to prevent flickering.
if width > used_space + HIDE_MENU_THRESHOLD and self.hide_menu.isVisible():
self.toolbar.set_widget_visible(NARROW_MENU, False)
self.toolbar.set_widget_visible(WIDE_MENU)
self.set_blank_menu()
# Take away a threshold to prevent flickering.
elif width < used_space - HIDE_MENU_THRESHOLD and not self.hide_menu.isVisible():
self.toolbar.set_widget_visible(WIDE_MENU, False)
self.set_blank_menu(False)
self.toolbar.set_widget_visible(NARROW_MENU)
def set_blank_menu(self, visible=True):
"""
Set the correct menu type dependent on the service item type
:param visible: Do I need to hide the menu?
"""
self.toolbar.set_widget_visible(WIDE_MENU, False)
if self.service_item and self.service_item.is_text():
self.toolbar.set_widget_visible(WIDE_MENU, visible)
else:
self.toolbar.set_widget_visible(NON_TEXT_MENU, visible)
def on_song_bar_handler(self):
"""
Some song handler
@ -612,6 +640,8 @@ class SlideController(DisplayController):
def enable_tool_bar(self, item):
"""
Allows the toolbars to be reconfigured based on Controller Type and ServiceItem Type
:param item: current service item being processed
"""
if self.is_live:
self.enable_live_tool_bar(item)
@ -621,6 +651,8 @@ class SlideController(DisplayController):
def enable_live_tool_bar(self, item):
"""
Allows the live toolbar to be customised
:param item: The current service item
"""
# Work-around for OS X, hide and then show the toolbar
# See bug #791050
@ -643,6 +675,7 @@ class SlideController(DisplayController):
self.mediabar.show()
self.previous_item.setVisible(not item.is_media())
self.next_item.setVisible(not item.is_media())
self.set_blank_menu()
# Work-around for OS X, hide and then show the toolbar
# See bug #791050
self.toolbar.show()

View File

@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2014 Raoul Snyman #
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
Package to test the openlp.core.ui.slidecontroller package.
"""
from unittest import TestCase
from openlp.core.ui import SlideController
from tests.interfaces import MagicMock, patch
class TestSlideController(TestCase):
def initial_slide_controller_test(self):
"""
Test the initial slide controller state .
"""
# GIVEN: A new slideController instance.
slide_controller = SlideController(None)
# WHEN: No SlideItem has been added yet.
# THEN: The count of items should be zero.
self.assertEqual(slide_controller.is_live, False, 'The base slide controller should not be a live controller')
def toggle_blank_test(self):
"""
Test the setting of the display blank icons by display type.
"""
# GIVEN: A new slideController instance.
slide_controller = SlideController(None)
service_item = MagicMock()
toolbar = MagicMock()
toolbar.set_widget_visible = self.dummy_widget_visible
slide_controller.toolbar = toolbar
slide_controller.service_item = service_item
# WHEN a text based service item is used
slide_controller.service_item.is_text = MagicMock(return_value=True)
slide_controller.set_blank_menu()
# THEN: then call set up the toolbar to blank the display screen.
self.assertEqual(len(self.test_widget), 3, 'There should be three icons to display on the screen')
# WHEN a non text based service item is used
slide_controller.service_item.is_text = MagicMock(return_value=False)
slide_controller.set_blank_menu()
# THEN: then call set up the toolbar to blank the display screen.
self.assertEqual(len(self.test_widget), 2, 'There should be only two icons to display on the screen')
def dummy_widget_visible(self, widget, visible=True):
self.test_widget = widget