本文整理汇总了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]