Commits

Erik Grinaker committed 024524a

improved stock icon loading

  • Participants
  • Parent commits 44c2308

Comments (0)

Files changed (2)

File src/lib/ui.py

 		self.theme.connect("changed", self.__cb_theme_changed)
 
 
-	def __init_icons(self);
+	def __init_icons(self):
 		"Loads stock icons"
 
 		for id, icon, sizes in STOCK_ICONS:
-			self.load_stock_icon(id, icon sizes)
+			self.create_stock_icon(id, icon, sizes)
 
 
 	def __init_items(self):
 		self.__init_items()
 
 
+	def create_stock_icon(self, id, icon, sizes):
+		"Creates a stock icon from a different stock icon"
+
+		iconset = gtk.IconSet()
+		self.add(id, iconset)
+
+		if self.theme.has_icon(icon) == False:
+			return
+
+		for size in sizes:
+			pixbuf = self.get_icon_pixbuf(icon, gtk.icon_size_lookup(size)[0])
+
+			if pixbuf == None:
+				continue
+
+			source = gtk.IconSource()
+			source.set_pixbuf(pixbuf)
+			source.set_size(size)
+			source.set_size_wildcarded(False)
+
+			iconset.add_source(source)
+
+
 	def create_stock_item(self, id, name, icon = None):
 		"Creates a stock item"
 
 			pass
 
 		elif gtk.stock_lookup(icon) is not None:
-			iconset = self.parent.get_style().lookup_icon_set(icon)
-			self.add(id, iconset)
+			self.add(id, self.parent.get_style().lookup_icon_set(icon))
 
 		else:
-			self.load_stock_icon(id, icon, ( gtk.ICON_SIZE_SMALL_TOOLBAR, gtk.ICON_SIZE_LARGE_TOOLBAR, gtk.ICON_SIZE_MENU, gtk.ICON_SIZE_BUTTON, gtk.ICON_SIZE_DIALOG, ICON_SIZE_LABEL, ICON_SIZE_HEADLINE ))
-
-
-	def load_icon(self, id, size):
-		"Loads an icon"
-
-		if self.theme.has_icon(id):
-			try:
-				pixbuf = self.theme.load_icon(id, size, 0)
-
-			except gobject.GError:
-				return None
-
-		else:
+			self.create_stock_icon(id, icon, ( gtk.ICON_SIZE_SMALL_TOOLBAR, gtk.ICON_SIZE_LARGE_TOOLBAR, gtk.ICON_SIZE_MENU, gtk.ICON_SIZE_BUTTON, gtk.ICON_SIZE_DIALOG, ICON_SIZE_LABEL, ICON_SIZE_HEADLINE ))
+
+
+	def get_icon_pixbuf(self, id, size):
+		"Loads an icon as a pixbuf"
+
+		if self.theme.has_icon(id) == False:
 			return None
 
-		return pixbuf
-
-
-	def load_stock_icon(self, id, icon, sizes):
-		"Registers a stock icon"
-
-		iconset = gtk.IconSet()
-
-		if self.theme.has_icon(icon):
-			for size in dict.fromkeys(sizes).keys():
-				pixelsize = gtk.icon_size_lookup(size)[0]
-
-				source = gtk.IconSource()
-				source.set_size(size)
-				source.set_size_wildcarded(False)
-
-				pixbuf = self.load_icon(icon, pixelsize)
-
-				if pixbuf != None:
-					source.set_pixbuf(pixbuf)
-
-				iconset.add_source(source)
-
-		self.add(id, iconset)
+		try:
+			return self.theme.load_icon(id, size, 0)
+
+		except gobject.GError:
+			return None
 
 
 

File src/revelation.in

 		gtk.about_dialog_set_email_hook(lambda d,l: gnome.url_show("mailto:" + l))
 
 		# set window icons
-		pixbufs = [ self.items.load_icon("revelation", size) for size in ( 48, 32, 24, 16) ]
+		pixbufs = [ self.items.get_icon_pixbuf("revelation", size) for size in ( 48, 32, 24, 16) ]
 		pixbufs = [ pixbuf for pixbuf in pixbufs if pixbuf != None ]
 
 		if len(pixbufs) > 0: