Commits

Ronny Pfannschmidt committed f5d5fce

add icon name cached properties patch

Comments (0)

Files changed (2)

language-iconname-cachedproperty

+# HG changeset patch
+# Parent 6684d2791c6a7c567cc7f8a9215e7100f0bfda19
+
+diff --git a/pida/utils/languages.py b/pida/utils/languages.py
+--- a/pida/utils/languages.py
++++ b/pida/utils/languages.py
+@@ -9,6 +9,7 @@ List of general Language classes.
+ """
+ from .addtypes import Enumeration
+ from .path import get_line_from_file
++from .descriptors import cached_property
+ 
+ import itertools
+ 
+@@ -178,12 +179,9 @@ class OutlineItem(InitObject):
+     def get_markup(self):
+         return '<b>%s</b>' % self.name
+ 
+-    def _get_icon_name(self):
+-        return getattr(self, '_icon_name_set', 
+-                                    LANG_IMAGE_MAP.get(self.type, ''))
+-    def _set_icon_name(self, value):
+-        self._icon_name_set = value
+-    icon_name = property(_get_icon_name, _set_icon_name)
++    @cached_property
++    def icon_name(self):
++        return LANG_IMAGE_MAP.get(self.type, '')
+ 
+     #XXX: these 2 hacks need tests!!!
+     @property
+@@ -221,13 +219,9 @@ class Definition(InitObject):
+             where = " line %s " % self.line
+         return '<Definition %s%s>' % (self.file_name, where)
+ 
+-    def _get_icon_name(self):
+-        return getattr(self, '_icon_name_set', 
+-                                    LANG_IMAGE_MAP.get(self.type, ''))
+-    def _set_icon_name(self, value):
+-        self._icon_name_set = value
+-
+-    icon_name = property(_get_icon_name, _set_icon_name)
++    @cached_property
++    def icon_name(self):
++        return LANG_IMAGE_MAP.get(self.type, '')
+ 
+     def _get_signature(self):
+         if self.line is None and self.offset is None:
 kill-outliner-types-enum
 kill-most-language-enum-definitions
 validator-markip-format-cleanup
+language-iconname-cachedproperty
 pypath-for-options
 core-pdbus-pyxml-introspect #+dbus
 pida-remote-cleanup