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


Python Delegator.setdelegate方法代码示例

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


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

示例1: test_mydel

# 需要导入模块: from idlelib.Delegator import Delegator [as 别名]
# 或者: from idlelib.Delegator.Delegator import setdelegate [as 别名]
    def test_mydel(self):
        # Test a simple use scenario.

        # Initialize an int delegator.
        mydel = Delegator(int)
        self.assertIs(mydel.delegate, int)
        self.assertEqual(mydel._Delegator__cache, set())
        # Trying to access a non-attribute of int fails.
        self.assertRaises(AttributeError, mydel.__getattr__, 'xyz')

        # Add real int attribute 'bit_length' by accessing it.
        bl = mydel.bit_length
        self.assertIs(bl, int.bit_length)
        self.assertIs(mydel.__dict__['bit_length'], int.bit_length)
        self.assertEqual(mydel._Delegator__cache, {'bit_length'})

        # Add attribute 'numerator'.
        mydel.numerator
        self.assertEqual(mydel._Delegator__cache, {'bit_length', 'numerator'})

        # Delete 'numerator'.
        del mydel.numerator
        self.assertNotIn('numerator', mydel.__dict__)
        # The current implementation leaves  it in the name cache.
        # self.assertIn('numerator', mydel._Delegator__cache)
        # However, this is not required and not part of the specification

        # Change delegate to float, first resetting the attributes.
        mydel.setdelegate(float)  # calls resetcache
        self.assertNotIn('bit_length', mydel.__dict__)
        self.assertEqual(mydel._Delegator__cache, set())
        self.assertIs(mydel.delegate, float)
开发者ID:AndreLouisCaron,项目名称:cpython,代码行数:34,代码来源:test_delegator.py

示例2: test_mydel

# 需要导入模块: from idlelib.Delegator import Delegator [as 别名]
# 或者: from idlelib.Delegator.Delegator import setdelegate [as 别名]
    def test_mydel(self):
        # test a simple use scenario

        # initialize
        mydel = Delegator(int)
        self.assertIs(mydel.delegate, int)
        self.assertEqual(mydel._Delegator__cache, set())

        # add an attribute:
        self.assertRaises(AttributeError, mydel.__getattr__, "xyz")
        bl = mydel.bit_length
        self.assertEqual(bl, int.bit_length)
        self.assertEqual(mydel.__dict__["bit_length"], int.bit_length)
        self.assertEqual(mydel._Delegator__cache, {"bit_length"})

        # add a second attribute
        mydel.numerator
        self.assertEqual(mydel._Delegator__cache, {"bit_length", "numerator"})

        # delete the second (which, however, leaves it in the name cache)
        del mydel.numerator
        self.assertNotIn("numerator", mydel.__dict__)
        self.assertIn("numerator", mydel._Delegator__cache)

        # reset by calling .setdelegate, which calls .resetcache
        mydel.setdelegate(float)
        self.assertIs(mydel.delegate, float)
        self.assertNotIn("bit_length", mydel.__dict__)
        self.assertEqual(mydel._Delegator__cache, set())
开发者ID:cimarieta,项目名称:usp,代码行数:31,代码来源:test_delegator.py

示例3: setdelegate

# 需要导入模块: from idlelib.Delegator import Delegator [as 别名]
# 或者: from idlelib.Delegator.Delegator import setdelegate [as 别名]
 def setdelegate(self, delegate):
     if self.delegate is not None:
         self.unbind("<<toggle-auto-coloring>>")
     Delegator.setdelegate(self, delegate)
     if delegate is not None:
         self.config_colors()
         self.bind("<<toggle-auto-coloring>>", self.toggle_colorize_event)
         self.notify_range("1.0", "end")
开发者ID:AndyPanda95,项目名称:python-for-android,代码行数:10,代码来源:ColorDelegator.py

示例4: setdelegate

# 需要导入模块: from idlelib.Delegator import Delegator [as 别名]
# 或者: from idlelib.Delegator.Delegator import setdelegate [as 别名]
 def setdelegate(self, delegate):
     if self.delegate is not None:
         self.unbind("<<undo>>")
         self.unbind("<<redo>>")
         self.unbind("<<dump-undo-state>>")
     Delegator.setdelegate(self, delegate)
     if delegate is not None:
         self.bind("<<undo>>", self.undo_event)
         self.bind("<<redo>>", self.redo_event)
         self.bind("<<dump-undo-state>>", self.dump_event)
开发者ID:billtsay,项目名称:win-demo-opcua,代码行数:12,代码来源:UndoDelegator.py

示例5: setdelegate

# 需要导入模块: from idlelib.Delegator import Delegator [as 别名]
# 或者: from idlelib.Delegator.Delegator import setdelegate [as 别名]
 def setdelegate(self, delegate):
     if self.delegate is not None:
         self.unbind("<<toggle-auto-coloring>>")
     Delegator.setdelegate(self, delegate)
     if delegate is not None:
         self.config_colors()
         self.bind("<<toggle-auto-coloring>>", self.toggle_colorize_event)
         self.notify_range("1.0", "end")
     else:
         # No delegate - stop any colorizing
         self.stop_colorizing = True
         self.allow_colorizing = False
开发者ID:rsk0315,项目名称:papyrus,代码行数:14,代码来源:ColorDelegator.py

示例6: setdelegate

# 需要导入模块: from idlelib.Delegator import Delegator [as 别名]
# 或者: from idlelib.Delegator.Delegator import setdelegate [as 别名]
 def setdelegate(self, delegate):
     if self.delegate is not None:
         self.unbind('<<toggle-auto-coloring>>')
     Delegator.setdelegate(self, delegate)
     if delegate is not None:
         self.config_colors()
         self.bind('<<toggle-auto-coloring>>', self.toggle_colorize_event)
         self.notify_range('1.0', 'end')
     else:
         self.stop_colorizing = True
         self.allow_colorizing = False
     return
开发者ID:webiumsk,项目名称:WOT-0.9.14-CT,代码行数:14,代码来源:colordelegator.py

示例7: test_mydel

# 需要导入模块: from idlelib.Delegator import Delegator [as 别名]
# 或者: from idlelib.Delegator.Delegator import setdelegate [as 别名]
 def test_mydel(self):
     mydel = Delegator(int)
     self.assertIs(mydel.delegate, int)
     self.assertEqual(mydel._Delegator__cache, set())
     self.assertRaises(AttributeError, mydel.__getattr__, 'xyz')
     bl = mydel.bit_length
     self.assertIs(bl, int.bit_length)
     self.assertIs(mydel.__dict__['bit_length'], int.bit_length)
     self.assertEqual(mydel._Delegator__cache, {'bit_length'})
     mydel.numerator
     self.assertEqual(mydel._Delegator__cache, {'bit_length', 'numerator'})
     del mydel.numerator
     self.assertNotIn('numerator', mydel.__dict__)
     self.assertIn('numerator', mydel._Delegator__cache)
     mydel.setdelegate(float)
     self.assertIs(mydel.delegate, float)
     self.assertNotIn('bit_length', mydel.__dict__)
     self.assertEqual(mydel._Delegator__cache, set())
开发者ID:aevitas,项目名称:wotsdk,代码行数:20,代码来源:idle_testtest_delegator.py


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