Re: Custom icons and Gtk::IconTheme



Yes, if you use Gtk::Stock icons, your program update automatically when the user change the theme.
But if you need a custom icon, then you need to get the icon and add it to the stock, for example:

// Create a pixbuf from a stock icon
pixbuf = icon_theme->load_icon("stock_calendar", 48, Gtk::ICON_LOOKUP_USE_BUILTIN);
// Saturate and pixelate it so it is diferent from stock_calendar
pixbuf->saturate_and_pixelate(pixbuf, 0, true);
// Add the new pixbuf as a new icon with a custom method
addStockIcon(pixbuf, "test-customicon", "test-customicon");

When the user change the theme, "stock_calendar" will be updated automatically but not "test-customicon".
Now if you run again the same code, the new pixbuf is diferent from the previous one and the widgets that were using "test-customicon" have a reference to the first version. This is why I think I have to do:

// Get the new version of stock_calendar
p = icon_theme->load_icon("stock_calendar", 48, Gtk::ICON_LOOKUP_USE_BUILTIN);
p->saturate_and_pixelate(p, 0, true);
// Replace image in pixbuf without replace the Gtk::Pixbuf
p->copy_area(0, 0, p->get_width(), p->get_height(), pixbuf, 0, 0);

In this way, I think pixbuf is the same all time and only change it's content, but I don't know if this is the correct way to do it.

2009/7/24 José Alburquerque <jaalburquerque cox net>
On Fri, 2009-07-24 at 11:36 +0200, Juan A. Moreno wrote:
> Hi,
> I'm trying to imagine how to update the custom icons in my program
> when user change the icons theme.

It's hard to know what you're trying to do, but with the programs I've
written, I don't have to do anything when a user changes themes.  I use
Gtk::Action with Gtk::Stock icons to create the Gtk::Toolbar and the
Gtk::MenuBar (see the online book[1]).  When the theme is changed, the
UI changes along without me having to do anything else.  The
GtkIconTheme docs[2] seems to suggest using stock icons if possible.

I think that if you end up using Gtk::IconTheme, you would simply have
to update the icons if the icon theme changes.  See the
gtk_icon_theme_load_icon docs[3].  I'm not an expert so I hope that
helps.

[1]
http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/chapter-menus-and-toolbars.html
[2] http://library.gnome.org/devel/gtk/2.17/GtkIconTheme.html
[3]
http://library.gnome.org/devel/gtk/2.17/GtkIconTheme.html#gtk-icon-theme-load-icon


--
José Alburquerque


--
jamf
gelide.sf.net


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