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


Python UnwrapObject.addListener方法代码示例

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


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

示例1: test_11_python_interface

# 需要导入模块: from xpcom.server import UnwrapObject [as 别名]
# 或者: from xpcom.server.UnwrapObject import addListener [as 别名]
    def test_11_python_interface(self):
        """Test the more Python API"""
        self.assertEquals(self.nm.notificationCount, 0)
        nm = UnwrapObject(self.nm)
        kwargs = { "iconURL": "icon URL",
                   "severity": Ci.koINotification.SEVERITY_WARNING,
                   "description": "description",
                   "details": "details",
                   "maxProgress": 10,
                   "progress": 5 }
        notif = nm.add("summary", ["tags"], "notif-ident", **kwargs)
        try:
            self.assertEquals(notif, self._wrap(notif)) # should already be wrapped
            notif.QueryInterface(Ci.koINotification) # should implement this
            notif.QueryInterface(Ci.koINotificationProgress) # due to maxProgress
            notif.QueryInterface(Ci.koINotificationText) # due to details
            self.assertEquals(notif.summary, "summary")
            self.assertEquals(notif.getTags(), ["tags"])
            self.assertEquals(notif.identifier, "notif-ident")
            self.assertEquals(self.nm.notificationCount, 1) # added one notification

            notif2 = nm.add("modified-summary", [], "notif-ident")
            self.assertEquals(notif, notif2) # no context, same identifier
            self.assertEquals(notif.summary, "modified-summary") # got the new one
            self.assertEquals(notif.getTags(), ["tags"]) # kept the old one

            for k, v in kwargs.items():
                self.assertEquals(getattr(notif, k), v)
            updates = { "summary": "new summary",
                        "details": "new details",
                        "progress": 2 }
            nm.update(notif, **updates)
            for k, v in updates.items():
                self.assertEquals(getattr(notif, k), v)
            self.assertRaises(COMException,
                              nm.update, notif, progress=20)

            # check listeners get hooked up correctly
            called = set()
            def listener(aNotification, aOldIndex, aNewIndex, aReason):
                self.assertEquals(aNotification, notif)
                self.assertEquals(aOldIndex, 0)
                self.assertEquals(aNewIndex, 0)
                self.assertEquals(aReason, Ci.koINotificationListener.REASON_UPDATED)
                called.add(True)
            nm.addListener(listener)
            notif.progress = 9
            self._waitForCompletion()
            self.assertTrue(called, "expected listener to be called due to progress change")
            nm.removeListener(listener)
            called.discard(True)
            notif.progress = 10
            self._waitForCompletion()
            self.assertFalse(called, "did not expect listener to be called because it was removed")

            # test python iterable
            self.assertEquals(len(nm), 1)
            self.assertEquals(nm[0], notif)
            self.assertEquals([x for x in nm], [notif])
            self.assertTrue(notif in nm)
            self.assertEquals(nm.count(notif), 1)
            self.assertEquals(nm.index(notif), 0)

        finally:
            nm.remove(notif)
            self.assertEquals(self.nm.notificationCount, 0)
开发者ID:ball6847,项目名称:openkomodo,代码行数:68,代码来源:test_koNotificationManager.py


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