• The method above gives me an icon with an emblem on top, but the emblem is smaller than expected and not positioned with an offset like most file browsers. It's very difficult to see at this size compared to other apps. Larger sizes aren't as much a problem, but most people will be seeing the icons at the 16x16 size.

    Can't seem to find a way to specify the emblem size or offset.

    And can't figure out why it's different than Xfdesktop or Thunar, which I believe use the same method.

    If anyone could give me some ideas I'd really appreciate it.


    Attached image is a comparison of my method (Top icon) and Thunar (Bottom icon) using two different themes.

  • The difference I think is because Thunar uses a custom icon renderer which also draws emblems, see here.

    Xfdesktop also does its own tricks to draw emblems over pixbufs.

  • @andreldm

    Thanks very much for the help!

    I kind of used the Xfdesktop method, and it seems to have worked nicely! I guess the Gio.EmblemedIcon method doesn't allow for scaling or positioning the emblem. And on top of that, Thunar and Xfdesktop have the emblem on an offset which you can't do without expanding the image size. So to do that I had to use GdkPixbuf composite.

    I made a new slightly larger empty/transparent icon, overlayed the regular icon, then scaling and offsetting the emblem then overlaying the emblem. The extra room let me have the emblem off to the side like Thunar and Xfdesktop.

    That means that instead of a 16x16px icon I have a 22x22px icon but the Gtk CellRendererPixbuf doesn't seem to care and it looks just the same.

    So thanks again very much! I was having a hard time figuring that out!

    Here's what I came up with. Maybe it can help someone else out. And if anyone else has any input or ways I could make it better I'd really appreciate that too!

    import gi
    gi.require_version("Gtk", "3.0")  # noqa
    from gi.repository import Gtk, Gio, GLib, GdkPixbuf
    theme = Gtk.IconTheme.get_default()
    new_icon = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace(0), True, 8, 22, 22)
    icon_pixbuf = theme.load_icon('audio-x-wav', 16, 0)
    GdkPixbuf.Pixbuf.composite(icon_pixbuf, new_icon, 3, 3, 16, 16, 3.0, 3.0,
                               1.0, 1.0, GdkPixbuf.InterpType.NEAREST, 255)
    emblem_pixbuf = theme.load_icon('emblem-symbolic-link', 16, 0)
    scaled = GdkPixbuf.Pixbuf.scale_simple(emblem_pixbuf, 12, 12,
    GdkPixbuf.Pixbuf.composite(scaled, new_icon, 10, 10, 12, 12, 10.0, 10.0,
                               1.0, 1.0, GdkPixbuf.InterpType.NEAREST, 255)
    img = Gtk.Image.new_from_pixbuf(new_icon)
    loc = '/home/new_icon16.png'
    GdkPixbuf.Pixbuf.savev(new_icon, loc, 'png', [], [])
    win = Gtk.Window()
    win.set_size_request(150, 150)
    win.connect("destroy", Gtk.main_quit)


    First is OP Emblemed method, Second is Thunar, Third is this new Composite method

    Edited by newhoa
  • We are the best event planners in chennai and we work in all types of events.Like Special event planning services, Event Designs,Workshops / Seminars training,Conference and venue sourcing services,Event Coordination. Event management services in chennai

0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment