- use QActionGroup instead of Checkboxes (Bug #1103906 'Auto Play Slides menu should use radioboxes')

bzr-revno: 2227
Fixes: https://launchpad.net/bugs/1103906
This commit is contained in:
Andreas Preikschat 2013-04-05 11:04:38 +02:00
commit 131b46edef
2 changed files with 56 additions and 11 deletions

View File

@ -234,18 +234,22 @@ class ServiceManagerDialog(object):
icon=u':/general/general_edit.png', triggers=self.create_custom) icon=u':/general/general_edit.png', triggers=self.create_custom)
self.menu.addSeparator() self.menu.addSeparator()
# Add AutoPlay menu actions # Add AutoPlay menu actions
self.auto_play_slides_group = QtGui.QMenu(translate('OpenLP.ServiceManager', '&Auto play slides')) self.auto_play_slides_menu = QtGui.QMenu(translate('OpenLP.ServiceManager', '&Auto play slides'))
self.menu.addMenu(self.auto_play_slides_group) self.menu.addMenu(self.auto_play_slides_menu)
self.auto_play_slides_loop = create_widget_action(self.auto_play_slides_group, auto_play_slides_group = QtGui.QActionGroup(self.auto_play_slides_menu)
auto_play_slides_group.setExclusive(True)
self.auto_play_slides_loop = create_widget_action(self.auto_play_slides_menu,
text=translate('OpenLP.ServiceManager', 'Auto play slides &Loop'), text=translate('OpenLP.ServiceManager', 'Auto play slides &Loop'),
checked=False, triggers=self.toggle_auto_play_slides_loop) checked=False, triggers=self.toggle_auto_play_slides_loop)
self.auto_play_slides_once = create_widget_action(self.auto_play_slides_group, auto_play_slides_group.addAction(self.auto_play_slides_loop)
self.auto_play_slides_once = create_widget_action(self.auto_play_slides_menu,
text=translate('OpenLP.ServiceManager', 'Auto play slides &Once'), text=translate('OpenLP.ServiceManager', 'Auto play slides &Once'),
checked=False, triggers=self.toggle_auto_play_slides_once) checked=False, triggers=self.toggle_auto_play_slides_once)
self.auto_play_slides_group.addSeparator() auto_play_slides_group.addAction(self.auto_play_slides_once)
self.timed_slide_interval = create_widget_action(self.auto_play_slides_group, self.auto_play_slides_menu.addSeparator()
self.timed_slide_interval = create_widget_action(self.auto_play_slides_menu,
text=translate('OpenLP.ServiceManager', '&Delay between slides'), text=translate('OpenLP.ServiceManager', '&Delay between slides'),
checked=False, triggers=self.on_timed_slide_interval) triggers=self.on_timed_slide_interval)
self.menu.addSeparator() self.menu.addSeparator()
self.preview_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', 'Show &Preview'), self.preview_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', 'Show &Preview'),
icon=u':/general/general_preview.png', triggers=self.make_preview) icon=u':/general/general_preview.png', triggers=self.make_preview)
@ -786,7 +790,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
self.notes_action.setVisible(True) self.notes_action.setVisible(True)
if service_item[u'service_item'].is_capable(ItemCapabilities.CanLoop) and \ if service_item[u'service_item'].is_capable(ItemCapabilities.CanLoop) and \
len(service_item[u'service_item'].get_frames()) > 1: len(service_item[u'service_item'].get_frames()) > 1:
self.auto_play_slides_group.menuAction().setVisible(True) self.auto_play_slides_menu.menuAction().setVisible(True)
self.auto_play_slides_once.setChecked(service_item[u'service_item'].auto_play_slides_once) self.auto_play_slides_once.setChecked(service_item[u'service_item'].auto_play_slides_once)
self.auto_play_slides_loop.setChecked(service_item[u'service_item'].auto_play_slides_loop) self.auto_play_slides_loop.setChecked(service_item[u'service_item'].auto_play_slides_loop)
self.timed_slide_interval.setChecked(service_item[u'service_item'].timed_slide_interval > 0) self.timed_slide_interval.setChecked(service_item[u'service_item'].timed_slide_interval > 0)
@ -798,7 +802,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
translate('OpenLP.ServiceManager', '&Delay between slides') + delay_suffix) translate('OpenLP.ServiceManager', '&Delay between slides') + delay_suffix)
# TODO for future: make group explains itself more visually # TODO for future: make group explains itself more visually
else: else:
self.auto_play_slides_group.menuAction().setVisible(False) self.auto_play_slides_menu.menuAction().setVisible(False)
if service_item[u'service_item'].is_capable(ItemCapabilities.HasVariableStartTime): if service_item[u'service_item'].is_capable(ItemCapabilities.HasVariableStartTime):
self.time_action.setVisible(True) self.time_action.setVisible(True)
if service_item[u'service_item'].is_capable(ItemCapabilities.CanAutoStartForLive): if service_item[u'service_item'].is_capable(ItemCapabilities.CanAutoStartForLive):

View File

@ -3,11 +3,11 @@
""" """
from unittest import TestCase from unittest import TestCase
from mock import MagicMock, patch from mock import MagicMock, Mock, patch
from PyQt4 import QtGui from PyQt4 import QtGui
from openlp.core.lib import Registry, ScreenList from openlp.core.lib import Registry, ScreenList, ServiceItem
from openlp.core.ui.mainwindow import MainWindow from openlp.core.ui.mainwindow import MainWindow
@ -42,3 +42,44 @@ class TestServiceManager(TestCase):
# THEN the count of items should be zero # THEN the count of items should be zero
self.assertEqual(self.service_manager.service_manager_list.topLevelItemCount(), 0, self.assertEqual(self.service_manager.service_manager_list.topLevelItemCount(), 0,
u'The service manager list should be empty ') u'The service manager list should be empty ')
def context_menu_test(self):
"""
Test the context_menu() method.
"""
# GIVEN: A service item added
with patch(u'PyQt4.QtGui.QTreeWidget.itemAt') as mocked_item_at_method, \
patch(u'PyQt4.QtGui.QWidget.mapToGlobal') as mocked_map_to_global, \
patch(u'PyQt4.QtGui.QMenu.exec_') as mocked_exec:
mocked_item = MagicMock()
mocked_item.parent.return_value = None
mocked_item_at_method.return_value = mocked_item
# We want 1 to be returned for the position
mocked_item.data.return_value = 1
# A service item without capabilities.
service_item = ServiceItem()
self.service_manager.service_items = [{u'service_item': service_item}]
q_point = None
# Mocked actions.
self.service_manager.edit_action.setVisible = Mock()
self.service_manager.create_custom_action.setVisible = Mock()
self.service_manager.maintain_action.setVisible = Mock()
self.service_manager.notes_action.setVisible = Mock()
self.service_manager.time_action.setVisible = Mock()
self.service_manager.auto_start_action.setVisible = Mock()
# WHEN: Show the context menu.
self.service_manager.context_menu(q_point)
# THEN: The following actions should be not visible.
self.service_manager.edit_action.setVisible.assert_called_once_with(False), \
u'The action should be set invisible.'
self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
u'The action should be set invisible.'
self.service_manager.maintain_action.setVisible.assert_called_once_with(False), \
u'The action should be set invisible.'
self.service_manager.notes_action.setVisible.assert_called_with(True), u'The action should be set visible.'
self.service_manager.time_action.setVisible.assert_called_once_with(False), \
u'The action should be set invisible.'
self.service_manager.auto_start_action.setVisible.assert_called_once_with(False), \
u'The action should be set invisible.'