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


Python WeakValueDictionary.update方法代码示例

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


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

示例1: FontTexture

# 需要导入模块: from weakref import WeakValueDictionary [as 别名]
# 或者: from weakref.WeakValueDictionary import update [as 别名]
class FontTexture(Texture):
    """
    A texture object that contains a font as well as a cache of coloured
    variants.
    """
    __slots__ = ("cache", "glyph_size")
    def __init__(self, surface, blocks):
        Texture.__init__(self, surface, blocks)
        self.cache = WeakValueDictionary()
        self.glyph_size = self.blocks[0][0].size
    def get_color(self, color):
        """
        Retrieves a cached colour entry for a textbox sprite to use, making one
        and storing it if it isn't already in the cache.
        """
        if color not in self.cache:
            colored_surface = self.surface.copy()
            colored_surface.fill(color, special_flags=pygame.BLEND_MULT)
            self.cache.update({color:colored_surface})
            return colored_surface
        else:
            return self.cache[color]
开发者ID:dungnv53,项目名称:Hittie,代码行数:24,代码来源:video.py


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