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


Python UnwrapObject.getPref方法代码示例

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


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

示例1: test_serialize_parent

# 需要导入模块: from xpcom.server import UnwrapObject [as 别名]
# 或者: from xpcom.server.UnwrapObject import getPref [as 别名]
    def test_serialize_parent(self):
        """Test that serializing/unserializing prefs will still have parent set
        """
        base = Cc["@activestate.com/koPreferenceRoot;1"].createInstance()
        child = Cc["@activestate.com/koPreferenceSet;1"].createInstance()
        root = Cc["@activestate.com/koPreferenceRoot;1"].createInstance()

        def serializePrefSet(prefset):
            path = tempfile.mktemp(suffix=".xml")
            prefset.serializeToFile(path)
            try:
                result = (Cc["@activestate.com/koPreferenceSetObjectFactory;1"]
                            .getService()
                            .deserializeFile(path))
            finally:
                os.remove(path)
                try:
                    os.remove(path + "c")
                except OSError as ex:
                    import errno
                    if ex.errno != errno.ENONET:
                        raise
            try:
                result.QueryInterface(Ci.koIPreferenceRoot)
            except COMException as ex:
                if ex.errno == Cr.NS_ERROR_NO_INTERFACE:
                    self.fail("Unserialized from file but not a root")
                raise
            def check_for_shadow_prefs(pref):
                for name, (child, typ) in pref.prefs.items():
                    if typ != "object":
                        continue
                    child = UnwrapObject(child)
                    self.assertFalse(getattr(child, "_is_shadow", False),
                                     "Child %s is a shadow pref" % (name,))
                    check_for_shadow_prefs(child)
            check_for_shadow_prefs(UnwrapObject(result))
            return result

        root.inheritFrom = base
        base.setPref("child", child)

        base.getPref("child").setLong("long", 68)
        self.assertEquals(root.getPref("child").getLong("long"),
                          base.getPref("child").getLong("long"))
        uroot = UnwrapObject(root)
        self.assertTrue(uroot.getPref("child")._is_shadow)
        # Once root.child is assigned a value, child becomes unshadowed.
        root.getPref("child").setDouble("double", 1.23456)
        self.assertFalse(base.getPref("child").hasDoublePref("double"))
        self.assertTrue(root.getPref("child").hasPref("double"))
        self.assertTrue(root.getPref("child").hasPrefHere("double"))
        self.assertFalse(uroot.getPref("child")._is_shadow)

        base = serializePrefSet(base)
        root = serializePrefSet(root)
        root.inheritFrom = base  # reset inheritFrom after serialization

        self.assertTrue(root.hasPrefHere("child"))
        self.assertAlmostEquals(root.getPref("child").getDouble("double"),
                                1.23456)
        base.getPref("child").setLong("long", 42)
        self.assertTrue(root.hasPrefHere("child"))
        long_value = root.getPref("child").getLong("long")
        self.assertEquals(long_value, 68,
                          "child pref lost its base pref, expected 42, got %r"
                          % (long_value,))
开发者ID:ChaHwa,项目名称:KomodoEdit,代码行数:69,代码来源:test_koPrefs.py

示例2: applyDocumentSettingsToView

# 需要导入模块: from xpcom.server import UnwrapObject [as 别名]
# 或者: from xpcom.server.UnwrapObject import getPref [as 别名]
    def applyDocumentSettingsToView(self, scintilla):
        scimoz = scintilla.scimoz
        # assumption: we are given a 'virgin' view, and a fully
        # capable document -- if it doesn't know something, it can figure it out.
        languageOb = self.koDoc.languageObj
        koDoc = self.koDoc
        prefs = koDoc.prefs
        try:
            # Unwrap prefs, as it will be faster to work outside of XPCOM.
            prefs = UnwrapObject(prefs)
        except:
            pass
        lexer = koDoc.lexer
        if lexer is None:
            lexer = languageOb.getLanguageService(components.interfaces.koILexerLanguageService)
        lexer.setCurrent(scimoz)
        self._applyPrefs(prefs, scimoz)
        
        if prefs.hasLongPref('anchor'):
            scimoz.currentPos = scimoz.anchor = prefs.getLongPref('anchor')

        if prefs.hasLongPref('currentPos'):
            scimoz.currentPos = prefs.getLongPref('currentPos')

        if prefs.hasPrefHere('indentWidth'):
            scimoz.indent = prefs.getLongPref('indentWidth')
        else:
            scimoz.indent = koDoc.indentWidth

        if prefs.hasPrefHere('editUseAlternateFaceType'):
            useAlternate = prefs.getBooleanPref('editUseAlternateFaceType')
        else:
            useAlternate = 0
        scintilla.alternateFaceType = useAlternate
        self._updateEdge(prefs)
            
        if prefs.hasPrefHere('useTabs'):
            scimoz.useTabs = prefs.getBooleanPref('useTabs')
        else:
            scimoz.useTabs = koDoc.useTabs

        if prefs.hasPrefHere('tabWidth'):
            scimoz.tabWidth = prefs.getLongPref('tabWidth')
        else:
            scimoz.tabWidth = koDoc.tabWidth

        slop = prefs.getLongPref('ySlop')
        scimoz.setYCaretPolicy(scimoz.CARET_SLOP | scimoz.CARET_STRICT | scimoz.CARET_EVEN, slop)
        scimoz.setVisiblePolicy(scimoz.VISIBLE_SLOP | scimoz.VISIBLE_STRICT, slop)

        if prefs.hasLongPref('firstVisibleLine'):
            scimoz.lineScroll(0, prefs.getLongPref('firstVisibleLine'))

        # scrollWidth is disabled on OS X - see bug 88586.
        if sys.platform != "darwin":
            if prefs.hasLongPref('scrollWidth'):
                scimoz.scrollWidth = prefs.getLongPref("scrollWidth")
            else:
                log.warn('should set default scroll width?')

        if prefs.getBooleanPref('scrollWidthTracking'):
            scimoz.scrollWidthTracking = prefs.getBooleanPref("scrollWidthTracking")

        if prefs.hasLongPref('xOffset'):
            scimoz.xOffset = prefs.getLongPref('xOffset')
        else:
            scimoz.xOffset = 0

        if languageOb.variableIndicators:
            scimoz.wordChars = _letters + languageOb.variableIndicators
        else:
            # Do this for cases where we change languages.
            scimoz.setCharsDefault()
        
        # restore fold points if the user has checked that pref off.
        # We don't do it by default because the colourise(.., -1) call below
        # can be quite slow.
        # Bug 93190: prefs are boolean for foldPoints,
        # but get the actual foldPoints off the document prefs
        if prefs.getBooleanPref("editRestoreFoldPoints") and \
                prefs.hasPref('foldPoints') and \
                scimoz.getPropertyInt("fold"):
            foldPoints = prefs.getPref("foldPoints")
            if foldPoints.length:
                # restyle the whole document to get folding right
                # Fixes bug 45621
                scimoz.colourise(0, -1)
                for i in range(foldPoints.length):
                    scimoz.toggleFold(foldPoints.getLongPref(i));

        # restore the bookmarks
        # Bug 93190: use doc prefs, stay away from project prefs here
        if prefs.hasPref("bookmarks"):
            bookmarks = prefs.getPref("bookmarks")
            for i in range(bookmarks.length):
                scimoz.markerAdd(bookmarks.getLongPref(i), MARKNUM_BOOKMARK)
开发者ID:Acidburn0zzz,项目名称:KomodoEdit,代码行数:98,代码来源:koDocumentSettingsManager.p.py


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