本文整理汇总了Python中openlp.core.common.Registry.context_menu方法的典型用法代码示例。如果您正苦于以下问题:Python Registry.context_menu方法的具体用法?Python Registry.context_menu怎么用?Python Registry.context_menu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openlp.core.common.Registry
的用法示例。
在下文中一共展示了Registry.context_menu方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestServiceManager
# 需要导入模块: from openlp.core.common import Registry [as 别名]
# 或者: from openlp.core.common.Registry import context_menu [as 别名]
class TestServiceManager(TestCase, TestMixin):
def setUp(self):
"""
Create the UI
"""
Registry.create()
self.setup_application()
ScreenList.create(self.app.desktop())
Registry().register('application', MagicMock())
# Mock classes and methods used by mainwindow.
with patch('openlp.core.ui.mainwindow.SettingsForm') as mocked_settings_form, \
patch('openlp.core.ui.mainwindow.ImageManager') as mocked_image_manager, \
patch('openlp.core.ui.mainwindow.LiveController') as mocked_live_controller, \
patch('openlp.core.ui.mainwindow.PreviewController') as mocked_preview_controller, \
patch('openlp.core.ui.mainwindow.OpenLPDockWidget') as mocked_dock_widget, \
patch('openlp.core.ui.mainwindow.QtWidgets.QToolBox') as mocked_q_tool_box_class, \
patch('openlp.core.ui.mainwindow.QtWidgets.QMainWindow.addDockWidget') as mocked_add_dock_method, \
patch('openlp.core.ui.mainwindow.ThemeManager') as mocked_theme_manager, \
patch('openlp.core.ui.mainwindow.ProjectorManager') as mocked_projector_manager, \
patch('openlp.core.ui.mainwindow.Renderer') as mocked_renderer:
self.main_window = MainWindow()
self.service_manager = Registry().get('service_manager')
def tearDown(self):
"""
Delete all the C++ objects at the end so that we don't have a segfault
"""
del self.main_window
def test_basic_service_manager(self):
"""
Test the Service Manager UI Functionality
"""
# GIVEN: A New Service Manager instance
# WHEN I have set up the display
self.service_manager.setup_ui(self.service_manager)
# THEN the count of items should be zero
self.assertEqual(self.service_manager.service_manager_list.topLevelItemCount(), 0,
'The service manager list should be empty ')
def test_default_context_menu(self):
"""
Test the context_menu() method with a default service item
"""
# GIVEN: A service item added
self.service_manager.setup_ui(self.service_manager)
with patch('PyQt5.QtWidgets.QTreeWidget.itemAt') as mocked_item_at_method, \
patch('PyQt5.QtWidgets.QWidget.mapToGlobal'), \
patch('PyQt5.QtWidgets.QMenu.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 = [{'service_item': service_item}]
q_point = None
# Mocked actions.
self.service_manager.edit_action.setVisible = MagicMock()
self.service_manager.create_custom_action.setVisible = MagicMock()
self.service_manager.maintain_action.setVisible = MagicMock()
self.service_manager.notes_action.setVisible = MagicMock()
self.service_manager.time_action.setVisible = MagicMock()
self.service_manager.auto_start_action.setVisible = MagicMock()
# 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), \
'The action should be set invisible.'
self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
'The action should be set invisible.'
self.service_manager.maintain_action.setVisible.assert_called_once_with(False), \
'The action should be set invisible.'
self.service_manager.notes_action.setVisible.assert_called_with(True), 'The action should be set visible.'
self.service_manager.time_action.setVisible.assert_called_once_with(False), \
'The action should be set invisible.'
self.service_manager.auto_start_action.setVisible.assert_called_once_with(False), \
'The action should be set invisible.'
def test_edit_context_menu(self):
"""
Test the context_menu() method with a edit service item
"""
# GIVEN: A service item added
self.service_manager.setup_ui(self.service_manager)
with patch('PyQt5.QtWidgets.QTreeWidget.itemAt') as mocked_item_at_method, \
patch('PyQt5.QtWidgets.QWidget.mapToGlobal'), \
patch('PyQt5.QtWidgets.QMenu.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()
#.........这里部分代码省略.........