當前位置: 首頁>>代碼示例>>Python>>正文


Python Settings.get_default_value方法代碼示例

本文整理匯總了Python中openlp.core.common.Settings.get_default_value方法的典型用法代碼示例。如果您正苦於以下問題:Python Settings.get_default_value方法的具體用法?Python Settings.get_default_value怎麽用?Python Settings.get_default_value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在openlp.core.common.Settings的用法示例。


在下文中一共展示了Settings.get_default_value方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_action

# 需要導入模塊: from openlp.core.common import Settings [as 別名]
# 或者: from openlp.core.common.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!

        :param action: The action to add (QAction). **Note**, the action must not have an empty ``objectName``.
        :param 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.
        :param 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.default_shortcuts = 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.warning('Shortcut "{shortcut}" is removed from "{action}" because another '
                            'action already uses this shortcut.'.format(shortcut=shortcuts[1],
                                                                        action=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.warning('Shortcut "{shortcut}" is removed from "{action}" '
                        'because another action already uses this shortcut.'.format(shortcut=shortcuts[0],
                                                                                    action=action.objectName()))
            shortcuts.remove(shortcuts[0])
        action.setShortcuts([QtGui.QKeySequence(shortcut) for shortcut in shortcuts])
開發者ID:imkernel,項目名稱:openlp,代碼行數:61,代碼來源:actions.py


注:本文中的openlp.core.common.Settings.get_default_value方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。