当前位置: 首页>>代码示例>>Python>>正文


Python Settings.get_default_value方法代码示例

本文整理汇总了Python中openlp.core.lib.Settings.get_default_value方法的典型用法代码示例。如果您正苦于以下问题:Python Settings.get_default_value方法的具体用法?Python Settings.get_default_value怎么用?Python Settings.get_default_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openlp.core.lib.Settings的用法示例。


在下文中一共展示了Settings.get_default_value方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_action

# 需要导入模块: from openlp.core.lib import Settings [as 别名]
# 或者: from openlp.core.lib.Settings import get_default_value [as 别名]
    def add_action(self, action, category=None, weight=None):
        """
        Add an action to the list of actions.

        **Note**: The action's objectName must be set when you want to add it!

        ``action``
            The action to add (QAction). **Note**, the action must not have an empty ``objectName``.

        ``category``
            The category this action belongs to. The category has to be a python string. . **Note**, if the category
            is ``None``, the category and its actions are being hidden in the shortcut dialog. However, if they are
            added, it is possible to avoid assigning shortcuts twice, which is important.

        ``weight``
            The weight specifies how important a category is. However, this only has an impact on the order the
            categories are displayed.
        """
        if category not in self.categories:
            self.categories.append(category)
        settings = Settings()
        settings.beginGroup('shortcuts')
        # Get the default shortcut from the config.
        action.defaultShortcuts = settings.get_default_value(action.objectName())
        if weight is None:
            self.categories[category].actions.append(action)
        else:
            self.categories[category].actions.add(action, weight)
        # Load the shortcut from the config.
        shortcuts = settings.value(action.objectName())
        settings.endGroup()
        if not shortcuts:
            action.setShortcuts([])
            return
        # We have to do this to ensure that the loaded shortcut list e. g. STRG+O (German) is converted to CTRL+O,
        # which is only done when we convert the strings in this way (QKeySequencet -> uncode).
        shortcuts = list(map(QtGui.QKeySequence.toString, list(map(QtGui.QKeySequence, shortcuts))))
        # Check the alternate shortcut first, to avoid problems when the alternate shortcut becomes the primary shortcut
        #  after removing the (initial) primary shortcut due to conflicts.
        if len(shortcuts) == 2:
            existing_actions = ActionList.shortcut_map.get(shortcuts[1], [])
            # Check for conflicts with other actions considering the shortcut context.
            if self._is_shortcut_available(existing_actions, action):
                actions = ActionList.shortcut_map.get(shortcuts[1], [])
                actions.append(action)
                ActionList.shortcut_map[shortcuts[1]] = actions
            else:
                log.warn('Shortcut "%s" is removed from "%s" because another action already uses this shortcut.' %
                    (shortcuts[1], action.objectName()))
                shortcuts.remove(shortcuts[1])
        # Check the primary shortcut.
        existing_actions = ActionList.shortcut_map.get(shortcuts[0], [])
        # Check for conflicts with other actions considering the shortcut context.
        if self._is_shortcut_available(existing_actions, action):
            actions = ActionList.shortcut_map.get(shortcuts[0], [])
            actions.append(action)
            ActionList.shortcut_map[shortcuts[0]] = actions
        else:
            log.warn('Shortcut "%s" is removed from "%s" because another action already uses this shortcut.' %
                (shortcuts[0], action.objectName()))
            shortcuts.remove(shortcuts[0])
        action.setShortcuts([QtGui.QKeySequence(shortcut) for shortcut in shortcuts])
开发者ID:marmyshev,项目名称:bug_1117098,代码行数:64,代码来源:actions.py


注:本文中的openlp.core.lib.Settings.get_default_value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。