[PATCH] rework image handling

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

 



The attached:

1) cleans up/simplifies readImageFromFile, removing options no longer used
2) introduces a readIconFromTheme, which pulls icons from the system theme
3) uses readIconFromTheme, where available, using XDG standard names

Comments?

Bill
Index: gui.py
===================================================================
RCS file: /usr/local/CVS/anaconda/gui.py,v
retrieving revision 1.496
diff -u -r1.496 gui.py
--- gui.py	2 Aug 2007 15:49:42 -0000	1.496
+++ gui.py	15 Sep 2007 03:11:49 -0000
@@ -422,7 +422,7 @@
 
     return (xml, w)
 
-def findPixmap(file):
+def readImageFromFile(file, image = None):
     for dir in ("/mnt/source/RHupdates/pixmaps/",
                  "/mnt/source/RHupdates/",
                  "/tmp/updates/pixmaps/", "/tmp/updates/",
@@ -432,57 +432,16 @@
                  "/usr/share/anaconda/", ""):
         fn = dir + file
         if os.access(fn, os.R_OK):
-            return fn
+            if image:
+                image.set_from_file(fn)
+                return image
+            else:
+                return gtk.image_new_from_file(fn)
+    log.error("unable to load %s" %(file,))
     return None
-
-def getPixbuf(file):
-    fn = findPixmap(file)
-    if not fn:
-        log.error("unable to load %s" %(file,))
-        return None
-
-    try:
-        pixbuf = gtk.gdk.pixbuf_new_from_file(fn)
-    except RuntimeError, msg:
-        log.error("unable to read %s: %s" %(file, msg))
-        pixbuf = None
-    
-    return pixbuf
-
-def readImageFromFile(file, width = None, height = None, dither = None,
-                      image = None):
-    pixbuf = getPixbuf(file)
-    if pixbuf is None:
-        log.warning("can't find pixmap %s" %(file,))
-        return None
-
-    if (width is not None and height is not None
-        and height != pixbuf.get_height()
-        and width != pixbuf.get_width()):
-        pixbuf = pixbuf.scale_simple(width, height,
-                                     gtk.gdk.INTERP_BILINEAR)
-
-    if image is None:
-        p = gtk.Image()
-    else:
-        p = image
-    if dither:
-        (pixmap, mask) = pixbuf.render_pixmap_and_mask()
-        pixmap.draw_pixbuf(gtk.gdk.GC(pixmap), pixbuf, 0, 0, 0, 0,
-                           pixbuf.get_width(), pixbuf.get_height(),
-                           gtk.gdk.RGB_DITHER_MAX, 0, 0)
-        p = gtk.Image()
-        p.set_from_pixmap(pixmap, mask)
-    else:
-        source = gtk.IconSource()
-        source.set_pixbuf(pixbuf)
-        source.set_size(gtk.ICON_SIZE_DIALOG)
-        source.set_size_wildcarded(False)
-        iconset = gtk.IconSet()
-        iconset.add_source(source)
-        p.set_from_icon_set(iconset, gtk.ICON_SIZE_DIALOG)
-
-    return p
+                
+def readIconFromTheme(file, size = gtk.ICON_SIZE_DIALOG):
+    return gtk.image_new_from_icon_name(file, size)
 
 class WaitWindow:
     def __init__(self, title, text, parent = None):
@@ -664,9 +623,7 @@
         info.set_text(exceptionText)
 
         infoImage.clear()
-        img = findPixmap("exception.png")
-        if os.path.exists(img):
-            infoImage.set_from_file(img)
+        infoImage.set_from_icon_name("face-crying", gtk.ICON_SIZE_DIALOG)
 
         # Add the brief traceback message to the upper text view.
         textbuf = gtk.TextBuffer()
@@ -1197,8 +1154,7 @@
         
         # FIXME: doesn't handle the lowres case
         i = self.mainxml.get_widget("headerImage")        
-        p = readImageFromFile("anaconda_header.png",
-                              dither = False, image = i)
+        p = readImageFromFile("anaconda_header.png", image = i)
         if p is None:
             print _("Unable to load title bar")
         if (gtk.gdk.screen_height() < 600) or \
Index: iw/account_gui.py
===================================================================
RCS file: /usr/local/CVS/anaconda/iw/account_gui.py,v
retrieving revision 1.69
diff -u -r1.69 account_gui.py
--- iw/account_gui.py	16 Mar 2007 19:07:54 -0000	1.69
+++ iw/account_gui.py	15 Sep 2007 03:11:49 -0000
@@ -100,7 +100,7 @@
         box.set_border_width(5)
 
         hbox = gtk.HBox()
-        pix = gui.readImageFromFile ("root-password.png")
+        pix = gui.readIconFromTheme("security-high")
         if pix:
             hbox.pack_start (pix, False)
 
Index: iw/language_gui.py
===================================================================
RCS file: /usr/local/CVS/anaconda/iw/language_gui.py,v
retrieving revision 1.45
diff -u -r1.45 language_gui.py
--- iw/language_gui.py	28 Nov 2006 19:17:29 -0000	1.45
+++ iw/language_gui.py	15 Sep 2007 03:11:49 -0000
@@ -58,7 +58,7 @@
         mainBox = gtk.VBox (False, 10)
 
         hbox = gtk.HBox(False, 5)
-        pix = gui.readImageFromFile ("gnome-globe.png")
+        pix = gui.readIconFromTheme("applications-internet")
         if pix:
             a = gtk.Alignment ()
             a.add (pix)
Index: iw/mouse_gui.py
===================================================================
RCS file: /usr/local/CVS/anaconda/iw/mouse_gui.py,v
retrieving revision 1.38
diff -u -r1.38 mouse_gui.py
--- iw/mouse_gui.py	16 May 2006 16:01:32 -0000	1.38
+++ iw/mouse_gui.py	15 Sep 2007 03:11:49 -0000
@@ -240,7 +240,7 @@
 
         # top header, includes graphic and instructions
         hbox = gtk.HBox(False, 5)
-        pix = gui.readImageFromFile ("gnome-mouse.png")
+        pix = gui.readIconFromTheme("input-mouse")
         if pix:
             a = gtk.Alignment()
             a.add(pix)
Index: iw/welcome_gui.py
===================================================================
RCS file: /usr/local/CVS/anaconda/iw/welcome_gui.py,v
retrieving revision 1.27
diff -u -r1.27 welcome_gui.py
--- iw/welcome_gui.py	23 Mar 2007 21:34:18 -0000	1.27
+++ iw/welcome_gui.py	15 Sep 2007 03:11:49 -0000
@@ -34,7 +34,7 @@
         else:
             width = 500
             height = 258
-        pix = gui.readImageFromFile("splash.png", width, height, dither=False)
+        pix = gui.readImageFromFile("splash.png")
         box = gtk.EventBox ()
         box.add (pix)
         return box

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux