def load_screen_settings(self): """ Loads the screen size and the monitor number from the settings. """ # Add the screen settings to the settings dict. This has to be done here due to cyclic dependency. # Do not do this anywhere else. screen_settings = { 'core/x position': self.current['size'].x(), 'core/y position': self.current['size'].y(), 'core/monitor': self.display_count - 1, 'core/height': self.current['size'].height(), 'core/width': self.current['size'].width() } Settings.extend_default_settings(screen_settings) settings = Settings() settings.beginGroup('core') monitor = settings.value('monitor') self.set_current_display(monitor) self.display = settings.value('display on monitor') override_display = settings.value('override position') x = settings.value('x position') y = settings.value('y position') width = settings.value('width') height = settings.value('height') self.override['size'] = QtCore.QRect(x, y, width, height) self.override['primary'] = False settings.endGroup() if override_display: self.set_override_display() else: self.reset_current_display()
def test_extend_default_settings(self): """Test that the extend_default_settings method extends the default settings""" # GIVEN: A patched __default_settings__ dictionary with patch.dict(Settings.__default_settings__, {'test/setting 1': 1, 'test/setting 2': 2, 'test/setting 3': 3}, True): # WHEN: Calling extend_default_settings Settings.extend_default_settings({'test/setting 3': 4, 'test/extended 1': 1, 'test/extended 2': 2}) # THEN: The _default_settings__ dictionary_ should have the new keys assert Settings.__default_settings__ == {'test/setting 1': 1, 'test/setting 2': 2, 'test/setting 3': 4, 'test/extended 1': 1, 'test/extended 2': 2}
def __init__(self, name, default_settings, media_item_class=None, settings_tab_class=None, version=None): """ This is the constructor for the plugin object. This provides an easy way for descendant plugins to populate common data. This method *must* be overridden, like so:: class MyPlugin(Plugin): def __init__(self): super(MyPlugin, self).__init__('MyPlugin', version='0.1') :param name: Defaults to *None*. The name of the plugin. :param default_settings: A dict containing the plugin's settings. The value to each key is the default value to be used. :param media_item_class: The class name of the plugin's media item. :param settings_tab_class: The class name of the plugin's settings tab. :param version: Defaults to *None*, which means that the same version number is used as OpenLP's version number. """ log.debug('Plugin {plugin} initialised'.format(plugin=name)) super(Plugin, self).__init__() self.name = name self.text_strings = {} self.set_plugin_text_strings() self.name_strings = self.text_strings[StringContent.Name] self.settings_section = self.name self.icon = None self.media_item_class = media_item_class self.settings_tab_class = settings_tab_class self.settings_tab = None self.media_item = None self.weight = 0 self.status = PluginStatus.Inactive # Add the default status to the default settings. default_settings[name + '/status'] = PluginStatus.Inactive default_settings[name + '/last directory'] = None # Append a setting for files in the mediamanager (note not all plugins # which have a mediamanager need this). if media_item_class is not None: default_settings['{name}/{name} files'.format(name=name)] = [] # Add settings to the dict of all settings. Settings.extend_default_settings(default_settings) Registry().register_function( '{name}_add_service_item'.format(name=self.name), self.process_add_service_event) Registry().register_function( '{name}_config_updated'.format(name=self.name), self.config_update) self._setup(version)
def load_screen_settings(self): """ Loads the screen size and the screen number from the settings. """ # Add the screen settings to the settings dict. This has to be done here due to cyclic dependency. # Do not do this anywhere else. screen_settings = {'core/screens': '{}'} Settings.extend_default_settings(screen_settings) screen_settings = Settings().value('core/screens') if screen_settings: for number, screen_dict in screen_settings.items(): # Sometimes this loads as a string instead of an int number = int(number) if self.has_screen(number): self[number].update(screen_dict) else: self.screens.append(Screen.from_dict(screen_dict)) else: self[len(self) - 1].is_display = True
def test_add_action_different_context(self): """ ActionList test - Tests the add_action method. The actions have the different parent, the same shortcuts and both have the QtCore.Qt.WidgetShortcut shortcut context set. """ # GIVEN: Two actions with the same shortcuts. parent = QtCore.QObject() action3 = QtWidgets.QAction(parent) action3.setObjectName('action3') action3.setShortcutContext(QtCore.Qt.WidgetShortcut) second_parent = QtCore.QObject() action_with_same_shortcuts3 = QtWidgets.QAction(second_parent) action_with_same_shortcuts3.setObjectName( 'action_with_same_shortcuts3') action_with_same_shortcuts3.setShortcutContext( QtCore.Qt.WidgetShortcut) # Add default shortcuts to Settings class. default_shortcuts = { 'shortcuts/action3': [ QtGui.QKeySequence(QtCore.Qt.Key_E), QtGui.QKeySequence(QtCore.Qt.Key_F) ], 'shortcuts/action_with_same_shortcuts3': [ QtGui.QKeySequence(QtCore.Qt.Key_E), QtGui.QKeySequence(QtCore.Qt.Key_F) ] } Settings.extend_default_settings(default_shortcuts) # WHEN: Add the two actions to the action list. self.action_list.add_action(action3, 'example_category2') self.action_list.add_action(action_with_same_shortcuts3, 'example_category2') # Remove the actions again. self.action_list.remove_action(action3, 'example_category2') self.action_list.remove_action(action_with_same_shortcuts3, 'example_category2') # THEN: Both action should keep their shortcuts. assert len(action3.shortcuts() ) == 2, 'The action should have two shortcut assigned.' assert len(action_with_same_shortcuts3.shortcuts() ) == 2, 'The action should have two shortcuts assigned.'
def test_settings_override_with_group(self): """Test the Settings creation and its override usage - with groups""" # GIVEN: an override for the settings screen_settings = { 'test/extend': 'very wide', } Settings.extend_default_settings(screen_settings) # WHEN reading a setting for the first time settings = Settings() settings.beginGroup('test') extend = settings.value('extend') # THEN the default value is returned assert 'very wide' == extend, 'The default value defined should be returned' # WHEN a new value is saved into config Settings().setValue('test/extend', 'very short') # THEN the new value is returned when re-read assert 'very short' == Settings().value('test/extend'), 'The saved value should be returned'
def test_add_action_different_parent(self): """ ActionList test - Tests the add_action method. The actions have the different parent, the same shortcuts and both have the QtCore.Qt.WindowShortcut shortcut context set. """ # GIVEN: Two actions with the same shortcuts. parent = QtCore.QObject() action2 = QtWidgets.QAction(parent) action2.setObjectName('action2') second_parent = QtCore.QObject() action_with_same_shortcuts2 = QtWidgets.QAction(second_parent) action_with_same_shortcuts2.setObjectName( 'action_with_same_shortcuts2') # Add default shortcuts to Settings class. default_shortcuts = { 'shortcuts/action2': [ QtGui.QKeySequence(QtCore.Qt.Key_C), QtGui.QKeySequence(QtCore.Qt.Key_D) ], 'shortcuts/action_with_same_shortcuts2': [ QtGui.QKeySequence(QtCore.Qt.Key_D), QtGui.QKeySequence(QtCore.Qt.Key_C) ] } Settings.extend_default_settings(default_shortcuts) # WHEN: Add the two actions to the action list. self.action_list.add_action(action2, 'example_category') self.action_list.add_action(action_with_same_shortcuts2, 'example_category') # Remove the actions again. self.action_list.remove_action(action2, 'example_category') self.action_list.remove_action(action_with_same_shortcuts2, 'example_category') # THEN: As both actions have the same shortcuts, they should be removed from one action. assert len(action2.shortcuts() ) == 2, 'The action should have two shortcut assigned.' assert len(action_with_same_shortcuts2.shortcuts() ) == 0, 'The action should not have a shortcut assigned.'