def setUp(self): """ Create the UI """ Registry.create() self.registry = Registry() self.setup_application() # Mock cursor busy/normal methods. self.app.set_busy_cursor = MagicMock() self.app.set_normal_cursor = MagicMock() self.app.args = [] Registry().register('application', self.app) # 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.QtGui.QToolBox') as mocked_q_tool_box_class, \ patch('openlp.core.ui.mainwindow.QtGui.QMainWindow.addDockWidget') as mocked_add_dock_method, \ patch('openlp.core.ui.mainwindow.ServiceManager') as mocked_service_manager, \ 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()
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.QtGui.QToolBox" ) as mocked_q_tool_box_class, patch( "openlp.core.ui.mainwindow.QtGui.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 test_registry_service(self): """ Test the registry creation and its usage """ # GIVEN: A new registry Registry.create() # WHEN: I add a component it should save it mock_1 = MagicMock() Registry().register('test1', mock_1) # THEN: we should be able retrieve the saved component assert Registry().get('test1') == mock_1, 'The saved service can be retrieved and matches' # WHEN: I add a component for the second time I am mad. # THEN and I will get an exception with self.assertRaises(KeyError) as context: Registry().register('test1', mock_1) self.assertEqual(context.exception.args[0], 'Duplicate service exception test1', 'KeyError exception should have been thrown for duplicate service') # WHEN I try to get back a non existent component # THEN I will get an exception temp = Registry().get('test2') self.assertEqual(temp, None, 'None should have been returned for missing service') # WHEN I try to replace a component I should be allowed Registry().remove('test1') # THEN I will get an exception temp = Registry().get('test1') self.assertEqual(temp, None, 'None should have been returned for deleted service')
def setUp(self): """ Set up the Registry """ Registry.create() Registry().register('service_list', MagicMock()) Registry().register('application', MagicMock())
def test_registry_function(self): """ Test the registry function creation and their usages """ # GIVEN: An existing registry register a function Registry.create() Registry().register_function('test1', self.dummy_function_1) # WHEN: I execute the function return_value = Registry().execute('test1') # THEN: I expect then function to have been called and a return given self.assertEqual(return_value[0], 'function_1', 'A return value is provided and matches') # WHEN: I execute the a function with the same reference and execute the function Registry().register_function('test1', self.dummy_function_1) return_value = Registry().execute('test1') # THEN: I expect then function to have been called and a return given self.assertEqual(return_value, ['function_1', 'function_1'], 'A return value list is provided and matches') # WHEN: I execute the a 2nd function with the different reference and execute the function Registry().register_function('test2', self.dummy_function_2) return_value = Registry().execute('test2') # THEN: I expect then function to have been called and a return given self.assertEqual(return_value[0], 'function_2', 'A return value is provided and matches')
def test_build_html_video(self, MockedSettings, Mocked_build_html): # GIVEN: Mocked display display = MagicMock() mocked_media_controller = MagicMock() Registry.create() Registry().register('media_controller', mocked_media_controller) main_display = MainDisplay(display) main_display.frame = MagicMock() mocked_settings = MagicMock() mocked_settings.value.return_value = False MockedSettings.return_value = mocked_settings main_display.shake_web_view = MagicMock() service_item = MagicMock() service_item.theme_data = MagicMock() service_item.theme_data.background_type = 'video' service_item.theme_data.theme_name = 'name' service_item.theme_data.background_filename = 'background_filename' mocked_plugin = MagicMock() display.plugin_manager = PluginManager() display.plugin_manager.plugins = [mocked_plugin] main_display.web_view = MagicMock() # WHEN: build_html is called with a normal service item and a video theme. main_display.build_html(service_item) # THEN: the following should had not been called self.assertEquals(main_display.web_view.setHtml.call_count, 1, 'setHTML should be called once') self.assertEquals(main_display.media_controller.video.call_count, 1, 'Media Controller video should have been called once')
def setUp(self): """ Create the registry """ self.setup_application() Registry.create() self.build_settings()
def setUp(self): """ Set up the environment for testing bible parse reference """ self.build_settings() Registry.create() Registry().register('service_list', MagicMock()) Registry().register('application', MagicMock()) bible_settings = { 'bibles/proxy name': '', 'bibles/db type': 'sqlite', 'bibles/book name language': LanguageSelection.Bible, 'bibles/verse separator': '', 'bibles/range separator': '', 'bibles/list separator': '', 'bibles/end separator': '', } Settings().extend_default_settings(bible_settings) with patch('openlp.core.common.applocation.Settings') as mocked_class, \ patch('openlp.core.common.AppLocation.get_section_data_path') as mocked_get_section_data_path, \ patch('openlp.core.common.AppLocation.get_files') as mocked_get_files: # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_files() mocked_settings = mocked_class.return_value mocked_settings.contains.return_value = False mocked_get_files.return_value = ["tests.sqlite"] mocked_get_section_data_path.return_value = TEST_RESOURCES_PATH + "/bibles" self.manager = BibleManager(MagicMock())
def setUp(self): """ Create the UI """ self.build_settings() self.setup_application() Registry.create() self.theme_manager = ThemeManager()
def setUp(self): """ Some pre-test setup required. """ Registry.create() self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) self.combo = HistoryComboBox(self.main_window)
def setUp(self): """ Set up the Registry """ Registry.create() mocked_renderer = MagicMock() mocked_renderer.format_slide.return_value = [VERSE] Registry().register('renderer', mocked_renderer) Registry().register('image_manager', MagicMock())
def setUp(self): self.setup_application() self.app.setApplicationVersion('0.0') # Set up a fake "set_normal_cursor" method since we're not dealing with an actual OpenLP application object self.app.set_normal_cursor = lambda: None self.app.process_events = lambda: None Registry.create() Registry().register('application', self.app) self.tempfile = os.path.join(tempfile.gettempdir(), 'testfile')
def setUp(self): """ Create the UI """ Registry.create() self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register("main_window", self.main_window) self.form = ShortcutListForm()
def setUp(self): """ Create the UI """ Registry.create() self.setup_application() self.main_window = QtWidgets.QMainWindow() Registry().register('main_window', self.main_window) self.form = AuthorsForm()
def setUp(self): """ Create the UI """ Registry.create() self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) self.form = servicenoteform.ServiceNoteForm()
def setUp(self): """ Create the UI """ Registry.create() self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register("main_window", self.main_window) self.form = EditCustomSlideForm()
def setUp(self): """ Create the UI """ Registry.create() self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) self.form = TopicsForm()
def setUp(self): """ Create the UI """ Registry.create() self.setup_application() self.main_window = QtWidgets.QMainWindow() Registry().register('main_window', self.main_window) bibleimportform.PYSWORD_AVAILABLE = False self.form = bibleimportform.BibleImportForm(self.main_window, MagicMock(), MagicMock())
def setUp(self): """ Set up the components need for all tests. """ Registry.create() Registry().register('service_manager', MagicMock()) Registry().register('main_window', MagicMock()) with patch('openlp.plugins.presentations.lib.mediaitem.MediaManagerItem._setup'), \ patch('openlp.plugins.presentations.lib.mediaitem.PresentationMediaItem.setup_item'): self.media_item = PresentationMediaItem(None, MagicMock, MagicMock())
def setUp(self): """ Create the UI """ Registry.create() self.setup_application() self.main_window = QtWidgets.QMainWindow() Registry().register('main_window', self.main_window) Registry().register('theme_manager', MagicMock()) self.form = EditSongForm(MagicMock(), self.main_window, MagicMock())
def setUp(self): """ Create the UI """ Registry.create() self.setup_application() ScreenList.create(self.app.desktop()) self.image_manager = ImageManager() self.lock = Lock() self.sleep_time = 0.1
def setUp(self): """ Create the UI """ Registry.create() self.setup_application() self.build_settings() Settings().extend_default_settings(__default_settings__) self.service_manager = ServiceManager() self.router = HttpRouter()
def setUp(self): """ Set up the components need for all tests """ # Mocked out desktop object self.desktop = MagicMock() self.desktop.primaryScreen.return_value = SCREEN['primary'] self.desktop.screenCount.return_value = SCREEN['number'] self.desktop.screenGeometry.return_value = SCREEN['size'] self.screens = ScreenList.create(self.desktop) Registry.create()
def setUp(self): """ Create the UI """ Registry.create() self.setup_application() self.main_window = QtWidgets.QMainWindow() Registry().register('main_window', self.main_window) media_item = MagicMock() manager = MagicMock() self.form = EditCustomForm(media_item, self.main_window, manager)
def setUp(self): self.mocked_main_window = MagicMock() Registry.create() Registry().register('application', MagicMock()) Registry().register('service_list', MagicMock()) Registry().register('main_window', self.mocked_main_window) Registry().register('live_controller', MagicMock()) mocked_plugin = MagicMock() with patch('openlp.plugins.images.lib.mediaitem.MediaManagerItem._setup'), \ patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.setup_item'): self.media_item = ImageMediaItem(None, mocked_plugin) self.media_item.settings_section = 'images'
def test_registry_mixin_present(self): """ Test the registry creation and its usage """ # GIVEN: A new registry Registry.create() # WHEN: I create a new class mock_2 = Test2() # THEN: The following bootstrap methods should be present self.assertEqual(len(Registry().functions_list), 2), 'The bootstrap functions should be in the dict.'
def setUp(self): """ Create the UI. """ Registry.create() self.setup_application() self.main_window = QtWidgets.QMainWindow() self.image = QtGui.QImage(1, 1, QtGui.QImage.Format_RGB32) self.image_manager = MagicMock() self.image_manager.get_image.return_value = self.image Registry().register('image_manager', self.image_manager) self.preview_widget = ListPreviewWidget(self.main_window, 2)
def setUp(self): """ Set up the components need for all tests. """ Registry.create() Registry().register('service_list', MagicMock()) Registry().register('main_window', MagicMock()) with patch('openlp.plugins.songs.forms.editsongform.EditSongForm.__init__', return_value=None): self.edit_song_form = EditSongForm(None, MagicMock(), MagicMock()) self.setup_application() self.build_settings() QtCore.QLocale.setDefault(QtCore.QLocale('en_GB'))
def setUp(self): """ Create the UI """ Registry.create() Registry().register('settings_form', MagicMock()) self.setup_application() self.build_settings() Settings().extend_default_settings(__default_settings__) self.parent = QtWidgets.QMainWindow() self.form = ImageTab(self.parent, 'Images', None, None) self.form.settings_form.register_post_process = MagicMock()
def setUp(self): """ Create the UI """ Registry.create() self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) self.search_edit = SearchEdit(self.main_window) # To complete set up we have to set the search types. self.search_edit.set_search_types(SEARCH_TYPES)
def unblank(self): """ Instruct the controller to unblank the presentation. """ log.debug('Live = {live}, unblank'.format(live=self.is_live)) self.hide_mode = None if not self.doc: return if not self.is_live: return if not self.activate(): return self.doc.unblank_screen() Registry().execute('live_display_hide', HideMode.Screen)
def serve_thumbnail_with_valid_params_test(self): """ Test the serve_thumbnail routine with valid params """ # GIVEN: Mocked send_header, send_response, end_headers and wfile self.router.send_response = MagicMock() self.router.send_header = MagicMock() self.router.end_headers = MagicMock() self.router.wfile = MagicMock() mocked_image_manager = MagicMock() Registry.create() Registry().register('image_manager', mocked_image_manager) file_name = 'another%20test/slide1.png' full_path = os.path.normpath(os.path.join('thumbnails', file_name)) width = 120 height = 90 with patch('openlp.core.lib.os.path.exists') as mocked_exists, \ patch('builtins.open', mock_open(read_data='123')), \ patch('openlp.plugins.remotes.lib.httprouter.AppLocation') as mocked_location, \ patch('openlp.plugins.remotes.lib.httprouter.image_to_byte') as mocked_image_to_byte: mocked_exists.return_value = True mocked_image_to_byte.return_value = '123' mocked_location.get_section_data_path.return_value = '' # WHEN: pass good controller and filename self.router.serve_thumbnail('presentations', '{0}x{1}'.format(width, height), file_name) # THEN: a file should be returned self.assertEqual(self.router.send_header.call_count, 1, 'One header') self.assertEqual(self.router.send_response.call_count, 1, 'Send response called once') self.assertEqual(self.router.end_headers.call_count, 1, 'end_headers called once') mocked_exists.assert_called_with(urllib.parse.unquote(full_path)) self.assertEqual(mocked_image_to_byte.call_count, 1, 'Called once') mocked_image_manager.assert_called_any(os.path.normpath('thumbnails\\another test'), 'slide1.png', None, '120x90') mocked_image_manager.assert_called_any(os.path.normpath('thumbnails\\another test'), 'slide1.png', '120x90')
def on_quick_search_button_general_test(self): """ Test that general things, which should be called on all Quick searches are called. """ # GIVEN: self.application as self.app, all the required functions Registry.create() Registry().register('application', self.app) self.media_item.quickSearchButton = MagicMock() self.app.process_events = MagicMock() self.media_item.quickVersionComboBox = MagicMock() self.media_item.quickVersionComboBox.currentText = MagicMock() self.media_item.quickSecondComboBox = MagicMock() self.media_item.quickSecondComboBox.currentText = MagicMock() self.media_item.quick_search_edit = MagicMock() self.media_item.quick_search_edit.text = MagicMock() self.media_item.quickLockButton = MagicMock() self.media_item.list_view = MagicMock() self.media_item.search_results = MagicMock() self.media_item.display_results = MagicMock() self.media_item.check_search_result = MagicMock() self.app.set_normal_cursor = MagicMock() # WHEN: on_quick_search_button is called self.media_item.on_quick_search_button() # THEN: Search should had been started and finalized properly self.assertEqual(1, self.app.process_events.call_count, 'Normal cursor should had been called once') self.assertEqual(1, self.media_item.quickVersionComboBox.currentText.call_count, 'Should had been called once') self.assertEqual(1, self.media_item.quickSecondComboBox.currentText.call_count, 'Should had been called once') self.assertEqual(1, self.media_item.quick_search_edit.text.call_count, 'Text edit Should had been called once') self.assertEqual(1, self.media_item.quickLockButton.isChecked.call_count, 'Lock Should had been called once') self.assertEqual(1, self.media_item.display_results.call_count, 'Display results Should had been called once') self.assertEqual(2, self.media_item.quickSearchButton.setEnabled.call_count, 'Disable and Enable the button') self.assertEqual(1, self.media_item.check_search_result.call_count, 'Check results Should had been called once') self.assertEqual(1, self.app.set_normal_cursor.call_count, 'Normal cursor should had been called once')
def setUp(self): """ Create the UI """ Registry.create() self.setup_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) # Mock VLC so we don't actually use it self.vlc_patcher = patch( 'openlp.plugins.media.forms.mediaclipselectorform.vlc') self.vlc_patcher.start() Registry().register('application', self.app) # Mock the media item self.mock_media_item = MagicMock() # create form to test self.form = MediaClipSelectorForm(self.mock_media_item, self.main_window, None) mock_media_state_wait = MagicMock() mock_media_state_wait.return_value = True self.form.media_state_wait = mock_media_state_wait self.form.application.set_busy_cursor = MagicMock() self.form.application.set_normal_cursor = MagicMock() self.form.find_optical_devices = MagicMock()
def initialise(self): log.info('SongUsage Initialising') super(SongUsagePlugin, self).initialise() Registry().register_function('slidecontroller_live_started', self.display_song_usage) Registry().register_function('print_service_started', self.print_song_usage) self.song_usage_active = Settings().value(self.settings_section + '/active') # Set the button and checkbox state self.set_button_state() action_list = ActionList.get_instance() action_list.add_action(self.song_usage_status, translate('SongUsagePlugin', 'Song Usage')) action_list.add_action(self.song_usage_delete, translate('SongUsagePlugin', 'Song Usage')) action_list.add_action(self.song_usage_report, translate('SongUsagePlugin', 'Song Usage')) self.song_usage_delete_form = SongUsageDeleteForm( self.manager, self.main_window) self.song_usage_detail_form = SongUsageDetailForm( self, self.main_window) self.song_usage_menu.menuAction().setVisible(True) self.song_usage_active_button.show()
def __init__(self, plugin): """ Instantiate the wizard, and run any extra setup we need to. :param plugin: The songs plugin. """ self.duplicate_song_list = [] self.review_current_count = 0 self.review_total_count = 0 # Used to interrupt ongoing searches when cancel is clicked. self.break_search = False super(DuplicateSongRemovalForm, self).__init__(Registry().get('main_window'), plugin, 'duplicateSongRemovalWizard', ':/wizards/wizard_duplicateremoval.bmp', False) self.setMinimumWidth(730)
def poll_slidenumber(self, is_live, hide_mode): """ Check the current slide number """ if not self.is_active(): return if not hide_mode: current = self.get_slide_number() if current == self.slide_number: return self.slide_number = current if is_live: prefix = 'live' else: prefix = 'preview' Registry().execute('slidecontroller_{prefix}_change'.format(prefix=prefix), self.slide_number - 1)
def show_display(self): """ Show the stored layers so the screen reappears as it was originally. Make the stored images None to release memory. """ if self.screens.display_count == 1: # Only make visible if setting enabled. if not Settings().value('core/display on monitor'): return self.frame.evaluateJavaScript('show_blank("show");') if self.isHidden(): self.setVisible(True) self.hide_mode = None # Trigger actions when display is active again. if self.is_live: Registry().execute('live_display_active')
def set_defaults(self): """ Set up display at start of theme edit. """ self.restart() self.web = 'http://openlp.org/files/frw/' self.cancel_button.clicked.connect(self.on_cancel_button_clicked) self.no_internet_finish_button.clicked.connect(self.on_no_internet_finish_button_clicked) self.no_internet_cancel_button.clicked.connect(self.on_no_internet_cancel_button_clicked) self.currentIdChanged.connect(self.on_current_id_changed) Registry().register_function('config_screen_changed', self.update_screen_list_combo) self.no_internet_finish_button.setVisible(False) self.no_internet_cancel_button.setVisible(False) # Check if this is a re-run of the wizard. self.has_run_wizard = Settings().value('core/has run wizard') check_directory_exists(os.path.join(gettempdir(), 'openlp'))
def test_registry_working_flags(self): """ Test the registry working flags creation and its usage """ # GIVEN: A new registry Registry.create() # WHEN: I add a working flag it should save it my_data = 'Lamas' my_data2 = 'More Lamas' Registry().set_flag('test1', my_data) # THEN: we should be able retrieve the saved component temp = Registry().get_flag('test1') self.assertEquals(temp, my_data, 'The value should have been saved') # WHEN: I add a component for the second time I am not mad. # THEN and I will not get an exception Registry().set_flag('test1', my_data2) temp = Registry().get_flag('test1') self.assertEquals(temp, my_data2, 'The value should have been updated') # WHEN I try to get back a non existent Working Flag # THEN I will get an exception with self.assertRaises(KeyError) as context1: temp = Registry().get_flag('test2') self.assertEqual( context1.exception.args[0], 'Working Flag test2 not found in list', 'KeyError exception should have been thrown for missing working flag' ) # WHEN I try to replace a working flag I should be allowed Registry().remove_flag('test1') # THEN I will get an exception with self.assertRaises(KeyError) as context: temp = Registry().get_flag('test1') self.assertEqual( context.exception.args[0], 'Working Flag test1 not found in list', 'KeyError exception should have been thrown for duplicate working flag' )
def start_presentation(self): """ Starts a presentation from the beginning. """ log.debug('start_presentation') # SlideShowWindow measures its size/position by points, not pixels # https://technet.microsoft.com/en-us/library/dn528846.aspx try: dpi = win32ui.GetActiveWindow().GetDC().GetDeviceCaps(88) except win32ui.error: try: dpi = win32ui.GetForegroundWindow().GetDC().GetDeviceCaps( 88) except win32ui.error: dpi = 96 size = ScreenList().current['size'] ppt_window = None try: ppt_window = self.presentation.SlideShowSettings.Run() except (AttributeError, pywintypes.com_error) as e: log.exception('Caught exception while in start_presentation') log.exception(e) trace_error_handler(log) self.show_error_msg() if ppt_window and not Settings().value( 'presentations/powerpoint control window'): try: ppt_window.Top = size.y() * 72 / dpi ppt_window.Height = size.height() * 72 / dpi ppt_window.Left = size.x() * 72 / dpi ppt_window.Width = size.width() * 72 / dpi except AttributeError as e: log.exception('AttributeError while in start_presentation') log.exception(e) # Find the presentation window and save the handle for later self.presentation_hwnd = None if ppt_window: log.debug('main display size: y={y:d}, height={height:d}, ' 'x={x:d}, width={width:d}'.format( y=size.y(), height=size.height(), x=size.x(), width=size.width())) win32gui.EnumWindows(self._window_enum_callback, size) # Make sure powerpoint doesn't steal focus, unless we're on a single screen setup if len(ScreenList().screen_list) > 1: Registry().get('main_window').activateWindow()
def on_edit_author_button_clicked(self): """ Edit an author. """ author_id = self._get_current_item_id(self.authors_list_widget) if author_id == -1: return author = self.manager.get_object(Author, author_id) self.author_form.auto_display_name = False self.author_form.first_name_edit.setText(author.first_name) self.author_form.last_name_edit.setText(author.last_name) self.author_form.display_edit.setText(author.display_name) # Save the author's first and last name as well as the display name # for the case that they have to be restored. temp_first_name = author.first_name temp_last_name = author.last_name temp_display_name = author.display_name if self.author_form.exec(False): author.first_name = self.author_form.first_name_edit.text() author.last_name = self.author_form.last_name_edit.text() author.display_name = self.author_form.display_edit.text() if self.check_author_exists(author, True): if self.manager.save_object(author): self.reset_authors() if not self.from_song_edit: Registry().execute('songs_load_list') else: critical_error_message_box( message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.')) elif critical_error_message_box(message=translate( 'SongsPlugin.SongMaintenanceForm', 'The author %s already exists. Would you like to make songs with ' 'author %s use the existing author %s?') % (author.display_name, temp_display_name, author.display_name), parent=self, question=True) == \ QtWidgets.QMessageBox.Yes: self._merge_objects(author, self.merge_authors, self.reset_authors) else: # We restore the author's old first and last name as well as # his display name. author.first_name = temp_first_name author.last_name = temp_last_name author.display_name = temp_display_name critical_error_message_box(message=translate( 'SongsPlugin.SongMaintenanceForm', 'Could not save your modified author, because the author already exists.' ))
def __init__(self, plugin): """ Initialise the alert form """ self.manager = plugin.manager self.plugin = plugin self.item_id = None super(AlertForm, self).__init__(Registry().get('main_window')) self.setupUi(self) self.display_button.clicked.connect(self.on_display_clicked) self.display_close_button.clicked.connect(self.on_display_close_clicked) self.alert_text_edit.textChanged.connect(self.on_text_changed) self.new_button.clicked.connect(self.on_new_click) self.save_button.clicked.connect(self.on_save_all) self.alert_list_widget.doubleClicked.connect(self.on_double_click) self.alert_list_widget.clicked.connect(self.on_single_click) self.alert_list_widget.currentRowChanged.connect(self.on_current_row_changed)
def setup_item(self): """ Do some additional setup. """ self.images_go_live.connect(self.go_live_remote) self.images_add_to_service.connect(self.add_to_service_remote) self.quick_preview_allowed = True self.has_search = True self.manager = self.plugin.manager self.choose_group_form = ChooseGroupForm(self) self.add_group_form = AddGroupForm(self) self.fill_groups_combobox(self.choose_group_form.group_combobox) self.fill_groups_combobox(self.add_group_form.parent_group_combobox) Registry().register_function('live_theme_changed', self.live_theme_changed) # Allow DnD from the desktop. self.list_view.activateDnD()
def initialise(self): """ Initialise the plugin """ log.info('Songs Initialising') super(SongsPlugin, self).initialise() self.songselect_form = SongSelectForm(Registry().get('main_window'), self, self.manager) self.songselect_form.initialise() self.song_import_item.setVisible(True) self.song_export_item.setVisible(True) self.tools_reindex_item.setVisible(True) self.tools_find_duplicates.setVisible(True) action_list = ActionList.get_instance() action_list.add_action(self.song_import_item, UiStrings().Import) action_list.add_action(self.song_export_item, UiStrings().Export) action_list.add_action(self.tools_reindex_item, UiStrings().Tools) action_list.add_action(self.tools_find_duplicates, UiStrings().Tools)
def add_slide(self, item_title, html_details, theme_name): custom_slide = CustomSlide() custom_slide.title = item_title sxml = CustomXMLBuilder() slide_content = '' if html_details is None: slide_content = item_title else: # we need non-html here, but the input is html slide_content = self._process_details(html_details) sxml.add_verse_to_lyrics('custom', str(1), slide_content) custom_slide.text = str(sxml.extract_xml(), 'utf-8') custom_slide.credits = 'pco' custom_slide.theme_name = theme_name custom = Registry().get('custom') custom_db_manager = custom.plugin.db_manager custom_db_manager.save_object(custom_slide) return custom_slide.id
def close_presentation(self): """ Close presentation and clean up objects. This is triggered by a new object being added to SlideController or OpenLP being shut down. """ log.debug('ClosePresentation') if self.presentation: try: self.presentation.Close() except (AttributeError, pywintypes.com_error) as e: log.exception('Caught exception while closing powerpoint presentation') log.exception(e) trace_error_handler(log) self.presentation = None self.controller.remove_doc(self) # Make sure powerpoint doesn't steal focus, unless we're on a single screen setup if len(ScreenList().screen_list) > 1: Registry().get('main_window').activateWindow()
def __init__(self, media_item, parent, manager): """ Constructor """ super(EditCustomForm, self).__init__(parent) self.manager = manager self.media_item = media_item self.setupUi(self) # Create other objects and forms. self.edit_slide_form = EditCustomSlideForm(self) # Connecting signals and slots self.preview_button.clicked.connect(self.on_preview_button_clicked) self.add_button.clicked.connect(self.on_add_button_clicked) self.edit_button.clicked.connect(self.on_edit_button_clicked) self.edit_all_button.clicked.connect(self.on_edit_all_button_clicked) self.slide_list_view.currentRowChanged.connect( self.on_current_row_changed) self.slide_list_view.doubleClicked.connect(self.on_edit_button_clicked) Registry().register_function('theme_update_list', self.load_themes)
def __init__(self): """ Initialise the renderer. """ super(Renderer, self).__init__(None) # Need live behaviour if this is also working as a pseudo MainDisplay. self.screens = ScreenList() self.theme_level = ThemeLevel.Global self.global_theme_name = '' self.service_theme_name = '' self.item_theme_name = '' self.force_page = False self._theme_dimensions = {} self._calculate_default() self.web = QtWebKitWidgets.QWebView() self.web.setVisible(False) self.web_frame = self.web.page().mainFrame() Registry().register_function('theme_update_global', self.set_global_theme)
def media_blank(self, msg): """ Blank the related video Widget :param msg: First element is the boolean for Live indication Second element is the hide mode """ is_live = msg[1] hide_mode = msg[2] if not is_live: return Registry().execute('live_display_hide', hide_mode) display = self._define_display(self.live_controller) if self.live_controller.controller_type in self.current_media_players and \ self.current_media_players[self.live_controller.controller_type].get_live_state() == MediaState.Playing: self.current_media_players[ self.live_controller.controller_type].pause(display) self.current_media_players[ self.live_controller.controller_type].set_visible( display, False)
def blank(self, hide_mode): """ Instruct the controller to blank the presentation. """ log.debug('Live = %s, blank' % self.is_live) self.hide_mode = hide_mode if not self.doc: return if not self.is_live: return if hide_mode == HideMode.Theme: if not self.doc.is_loaded(): return if not self.doc.is_active(): return Registry().execute('live_display_hide', HideMode.Theme) elif hide_mode == HideMode.Blank: if not self.activate(): return self.doc.blank_screen()
def test_get_application_on_windows(self, mocked_is_win): """ Set that getting the application object on Windows happens dynamically """ # GIVEN an Empty Registry and we're on Windows mocked_is_win.return_value = True mock_application = MagicMock() reg_props = RegistryProperties() registry = Registry() # WHEN the application is accessed with patch.object(registry, 'get') as mocked_get: mocked_get.return_value = mock_application actual_application = reg_props.application # THEN the application should be the mock object, and the correct function should have been called self.assertEqual(mock_application, actual_application, 'The application value should match') mocked_is_win.assert_called_with() mocked_get.assert_called_with('application')
def critical_error_message_box(title=None, message=None, parent=None, question=False): """ Provides a standard critical message box for errors that OpenLP displays to users. :param title: The title for the message box. :param message: The message to display to the user. :param parent: The parent UI element to attach the dialog to. :param question: Should this message box question the user. """ if question: return QtWidgets.QMessageBox.critical( parent, UiStrings().Error, message, QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)) return Registry().get('main_window').error_message( title if title else UiStrings().Error, message)
def css_changed_test(self): """ Test that when the CSS changes, the plugins are looped over and given an opportunity to update the CSS """ # GIVEN: A mocked list of plugins, a mocked display and a MainDisplay mocked_songs_plugin = MagicMock() mocked_bibles_plugin = MagicMock() mocked_plugin_manager = MagicMock() mocked_plugin_manager.plugins = [mocked_songs_plugin, mocked_bibles_plugin] Registry().register('plugin_manager', mocked_plugin_manager) display = MagicMock() main_display = MainDisplay(display) # This is set up dynamically, so we need to mock it out for now main_display.frame = MagicMock() # WHEN: The css_changed() method is triggered main_display.css_changed() # THEN: The plugins should have each been given an opportunity to add their bit to the CSS mocked_songs_plugin.refresh_css.assert_called_with(main_display.frame) mocked_bibles_plugin.refresh_css.assert_called_with(main_display.frame)
def on_preview_click(self, keep_focus=False): """ Preview an item by building a service item then adding that service item to the preview slide controller. :param keep_focus: Do we keep focus (False) """ if not self.list_view.selectedIndexes() and not self.remote_triggered: QtWidgets.QMessageBox.information( self, UiStrings().NISp, translate('OpenLP.MediaManagerItem', 'You must select one or more items to preview.')) else: log.debug('%s Preview requested' % self.plugin.name) Registry().set_flag('has doubleclick added item to service', False) service_item = self.build_service_item() if service_item: service_item.from_plugin = True self.preview_controller.add_service_item(service_item) if not keep_focus: self.preview_controller.preview_widget.setFocus()
def _setup(self): """ Run some initial setup. This method is separate from __init__ in order to mock it out in tests. """ self.hide() self.whitespace = re.compile(r'[\W_]+', re.UNICODE) visible_title = self.plugin.get_string(StringContent.VisibleName) self.title = str(visible_title['title']) Registry().register(self.plugin.name, self) self.settings_section = self.plugin.name self.toolbar = None self.remote_triggered = None self.single_service_item = True self.quick_preview_allowed = False self.has_search = False self.page_layout = QtWidgets.QVBoxLayout(self) self.page_layout.setSpacing(0) self.page_layout.setContentsMargins(0, 0, 0, 0) self.required_icons() self.setupUi() self.retranslateUi() self.auto_select_id = -1
def load_presentation(self): """ Called when a presentation is added to the SlideController. Opens the PowerPoint file using the process created earlier. """ log.debug('load_presentation') try: if not self.controller.process: self.controller.start_process() self.controller.process.Presentations.Open(os.path.normpath(self.file_path), False, False, False) self.presentation = self.controller.process.Presentations(self.controller.process.Presentations.Count) self.create_thumbnails() self.create_titles_and_notes() # Make sure powerpoint doesn't steal focus, unless we're on a single screen setup if len(ScreenList().screen_list) > 1: Registry().get('main_window').activateWindow() return True except (AttributeError, pywintypes.com_error) as e: log.exception('Exception caught while loading Powerpoint presentation') log.exception(e) trace_error_handler(log) return False
def show_display(self): """ Show the stored layers so the screen reappears as it was originally. Make the stored images None to release memory. """ if self.screens.display_count == 1: # Only make visible if setting enabled. if not Settings().value('core/display on monitor'): return self.frame.evaluateJavaScript('show_blank("show");') # Check if setting for hiding logo on startup is enabled. # If it is, display should remain hidden, otherwise logo is shown. (from def setup) if self.isHidden( ) and not Settings().value('core/logo hide on startup'): self.setVisible(True) self.hide_mode = None # Trigger actions when display is active again. if self.is_live: Registry().execute('live_display_active') # Workaround for bug #1531319, should not be needed with PyQt 5.6. if is_win(): self.shake_web_view()
def media_unblank(self, msg): """ Unblank the related video Widget :param msg: First element is not relevant in this context Second element is the boolean for Live indication """ Registry().execute('live_display_show') is_live = msg[1] if not is_live: return display = self._define_display(self.live_controller) if self.live_controller.controller_type in self.current_media_players and \ self.current_media_players[self.live_controller.controller_type].state != MediaState.Playing: if self.current_media_players[ self.live_controller.controller_type].play(display): self.current_media_players[ self.live_controller.controller_type].set_visible( display, True) # Start Timer for ui updates if not self.timer.isActive(): self.timer.start()