[kupfer] obj.base: For Actions, use Action's icon name as last fallback



commit 5e9fd7f8242ae3a3d11b1a668119441991591593
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Tue Jan 12 22:56:27 2010 +0100

    obj.base: For Actions, use Action's icon name as last fallback
    
    Unify KupferObject.get_icon and .get_pixbuf to do the same thing.
    get_pixbuf is kept as is, since it is used more frequently and avoids
    disk accesses (by not asking if icons are good/files exist).
    
    We make sure that for actions that don't find their icons, we use the
    default action icon. Other objects unchanged.

 kupfer/icons.py    |    3 +++
 kupfer/obj/base.py |   26 ++++++++++++++++----------
 2 files changed, 19 insertions(+), 10 deletions(-)
---
diff --git a/kupfer/icons.py b/kupfer/icons.py
index 546bc3c..b5a7a6e 100644
--- a/kupfer/icons.py
+++ b/kupfer/icons.py
@@ -284,3 +284,6 @@ def get_good_name_for_icon_names(names):
 		if _default_theme.has_icon(name):
 			return name
 	return None
+
+def get_gicon_for_names(*names):
+	return ThemedIcon(names)
diff --git a/kupfer/obj/base.py b/kupfer/obj/base.py
index 61ca5a7..dc86a6c 100644
--- a/kupfer/obj/base.py
+++ b/kupfer/obj/base.py
@@ -106,15 +106,15 @@ class KupferObject (object):
 		The methods are tried in that order.
 		"""
 		gicon = self.get_gicon()
-		if gicon:
-			pbuf = icons.get_icon_for_gicon(gicon, icon_size)
-			if pbuf:
-				return pbuf
+		pbuf = gicon and icons.get_icon_for_gicon(gicon, icon_size)
+		if pbuf:
+			return pbuf
 		icon_name = self.get_icon_name()
-		if icon_name:
-			icon = icons.get_icon_for_name(icon_name, icon_size)
-			if icon: return icon
-		return icons.get_icon_for_name(KupferObject.get_icon_name(self), icon_size)
+		icon = icon_name and icons.get_icon_for_name(icon_name, icon_size)
+		if icon:
+			return icon
+		fallback_class = Action if isinstance(self, Action) else KupferObject
+		return icons.get_icon_for_name(fallback_class.get_icon_name(self), icon_size)
 
 	def get_icon(self):
 		"""
@@ -124,8 +124,14 @@ class KupferObject (object):
 		if they make sense.
 		The methods are tried in that order.
 		"""
-		return icons.get_gicon_with_fallbacks(self.get_gicon(),
-				(self.get_icon_name(), KupferObject.get_icon_name(self)))
+		gicon = self.get_gicon()
+		if gicon and icons.is_good(gicon):
+			return gicon
+		icon_name = self.get_icon_name()
+		if icon_name and icons.get_good_name_for_icon_names((icon_name, )):
+			return icons.get_gicon_for_names(icon_name)
+		fallback_class = Action if isinstance(self, Action) else KupferObject
+		return icons.get_gicon_for_names(fallback_class.get_icon_name(self))
 
 	def get_gicon(self):
 		"""Return GIcon, if there is one"""



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