[kupfer] asciiunicodeiconset: Use a weakref cache



commit dbc7a7b14daf41185c84bc5e4ae7e04f96271474
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sun Apr 3 17:03:50 2011 +0200

    asciiunicodeiconset: Use a weakref cache
    
    A weak value dict allows re-using pixbufs when we have them in the
    icon cache and otherwise we don't keep anything extra around.

 kupfer/plugin/asciiunicodeiconset.py |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
---
diff --git a/kupfer/plugin/asciiunicodeiconset.py b/kupfer/plugin/asciiunicodeiconset.py
index 010375e..18caa57 100644
--- a/kupfer/plugin/asciiunicodeiconset.py
+++ b/kupfer/plugin/asciiunicodeiconset.py
@@ -9,6 +9,7 @@ __version__ = ""
 __author__ = "Ulrik Sverdrup"
 
 import io
+import weakref
 
 import cairo
 import gtk
@@ -33,7 +34,7 @@ def text_color():
 	return (1.0*c.red/0xffff, 1.0*c.green/0xffff, 1.0*c.blue/0xffff)
 
 class AsciiIconRenderer (object):
-	glyph_pixbuf_cache = {}
+	glyph_pixbuf_cache = weakref.WeakValueDictionary()
 	def __init__(self):
 		settings = gtk.settings_get_default()
 		settings.connect("notify::gtk-color-scheme", self._theme_change)
@@ -62,7 +63,7 @@ class AsciiIconRenderer (object):
 		return None
 
 class UnicodeIconRenderer (object):
-	glyph_pixbuf_cache = {}
+	glyph_pixbuf_cache = weakref.WeakValueDictionary()
 	@classmethod
 	def pixbuf_for_name(cls, icon_name, size):
 		"""Return pixbuf at @size or None"""



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]