self.__init_ui()
def __init_ui(self):
- self.set_icon_name(Gtk.STOCK_ABOUT)
+ # set_icon_name() cannot fallback any stock ids to the real files.
+ self.set_icon_name('help-about')
sw = Gtk.ScrolledWindow()
sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
renderer.set_property("visible", True)
renderer.set_property("sensitive", True)
pixbuf = load_icon(engine.get_icon(), Gtk.IconSize.LARGE_TOOLBAR)
- if pixbuf == None:
- pixbuf = load_icon("ibus-engine", Gtk.IconSize.LARGE_TOOLBAR)
- if pixbuf == None:
- pixbuf = load_icon(Gtk.STOCK_MISSING_IMAGE,
- Gtk.IconSize.LARGE_TOOLBAR)
renderer.set_property("pixbuf", pixbuf)
def __name_cell_data_cb(self, celllayout, renderer, model, iter, data):
icon_size = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR)[0]
pixbuf = load_icon(engine.get_icon(), Gtk.IconSize.LARGE_TOOLBAR)
-
- if pixbuf == None:
- pixbuf = load_icon("ibus-engine", Gtk.IconSize.LARGE_TOOLBAR)
- if pixbuf == None:
- pixbuf = load_icon(Gtk.STOCK_MISSING_IMAGE,
- Gtk.IconSize.LARGE_TOOLBAR)
-
renderer.set_property("pixbuf", pixbuf)
def __name_cell_data_cb(self, celllayout, renderer, model, it, data):
icon_cache = {}
-def load_icon(icon, size):
- if (icon, size) in icon_cache:
- return icon_cache[(icon, size)]
+# load_icon:
+# @icon_name_or_path: Can be a name or path but not stock id
+# because gtk_icon_theme_load_icon() cannot fallback the stock id to
+# a real file name against gtk_image_new_from_stock().
+# @size: #GtkIconSize
+def load_icon(icon_name_or_path, size):
+ if (icon_name_or_path, size) in icon_cache:
+ return icon_cache[(icon_name_or_path, size)]
icon_size = Gtk.icon_size_lookup(size)
if icon_size[0]:
pixbuf = None
try:
- pixbuf = GdkPixbuf.Pixbuf.new_from_file(icon)
+ pixbuf = GdkPixbuf.Pixbuf.new_from_file(icon_name_or_path)
w, h = pixbuf.get_width(), pixbuf.get_height()
rate = max(w, h) / float(icon_size)
w = int(w / rate)
if pixbuf == None:
try:
theme = Gtk.IconTheme.get_default()
- pixbuf = theme.load_icon(icon, icon_size, 0)
+ pixbuf = theme.load_icon(icon_name_or_path, icon_size, 0)
except:
# import traceback
# traceback.print_exc()
pass
- icon_cache[(icon, size)] = pixbuf
+ if pixbuf == None:
+ try:
+ theme = Gtk.IconTheme.get_default()
+ pixbuf = theme.load_icon('ibus-engine', icon_size, 0)
+ except:
+ # import traceback
+ # traceback.print_exc()
+ pass
+ if pixbuf == None:
+ try:
+ theme = Gtk.IconTheme.get_default()
+ pixbuf = theme.load_icon('image-missing', icon_size, 0)
+ except:
+ # import traceback
+ # traceback.print_exc()
+ pass
+ icon_cache[(icon_name_or_path, size)] = pixbuf
return pixbuf
*/
class IconWidget: Gtk.Image {
- public IconWidget(string icon, int size) {
+ /**
+ * IconWidget:
+ * @icon_name_or_path: Can be a name or path but not stock id
+ * because gtk_icon_theme_load_icon() cannot fallback the
+ * stock id to a real file name against
+ * gtk_image_new_from_stock().
+ * @size: #Gtk.IconSize
+ */
+ public IconWidget(string icon_name_or_path, Gtk.IconSize size) {
Gdk.Pixbuf pixbuf = null;
+ int fixed_width, fixed_height;
+ Gtk.icon_size_lookup(size, out fixed_width, out fixed_height);
+
try {
- if (icon[0] == '/') {
- pixbuf = new Gdk.Pixbuf.from_file(icon);
+ if (icon_name_or_path[0] == '/') {
+ pixbuf = new Gdk.Pixbuf.from_file(icon_name_or_path);
} else {
var theme = Gtk.IconTheme.get_default();
- pixbuf = theme.load_icon(icon, size, 0);
+ pixbuf = theme.load_icon(icon_name_or_path, fixed_width, 0);
}
} catch (GLib.Error e) {
try {
var theme = Gtk.IconTheme.get_default();
- pixbuf = theme.load_icon(Gtk.Stock.MISSING_IMAGE, size, 0);
- } catch (GLib.Error e) {}
+ pixbuf = theme.load_icon("ibus-engine", fixed_width, 0);
+ } catch (GLib.Error e) {
+ /* "gtk-missing-image.png" is the symlink of
+ * "image-missing.png" and included in
+ * gnome-icon-theme-legacy package in fedora.
+ * gtk_image_set_from_stock() can fallback the stock name
+ * to the real name instead of gtk_image_set_from_icon_name()
+ * or gtk_icon_theme_load_icon() and
+ * could remove gnome-icon-theme-legacy.
+ */
+ set_from_stock(Gtk.Stock.MISSING_IMAGE, size);
+ return;
+ }
}
if (pixbuf == null)
return;
float width = (float)pixbuf.get_width();
float height = (float)pixbuf.get_height();
- float scale = size / (width > height ? width : height);
+ float scale = fixed_width / (width > height ? width : height);
width *= scale;
height *= scale;
m_ime_menu.append(new Gtk.SeparatorMenuItem());
- int width, height;
- Gtk.icon_size_lookup(Gtk.IconSize.MENU, out width, out height);
-
// Append IMEs
foreach (var engine in m_engines) {
var language = engine.get_language();
var item = new Gtk.ImageMenuItem.with_label(
"%s - %s".printf (IBus.get_language_name(language), longname));
if (engine.get_icon() != "") {
- var icon = new IconWidget(engine.get_icon(), width);
+ var icon = new IconWidget(engine.get_icon(), Gtk.IconSize.MENU);
item.set_image(icon);
}
// Make a copy of engine to workaround a bug in vala.
if (icon_name[0] == '/')
m_status_icon.set_from_file(icon_name);
- else
- m_status_icon.set_from_icon_name(icon_name);
+ else {
+ var theme = Gtk.IconTheme.get_default();
+ if (theme.lookup_icon(icon_name, 48, 0) != null) {
+ m_status_icon.set_from_icon_name(icon_name);
+ } else {
+ m_status_icon.set_from_icon_name("ibus-engine");
+ }
+ }
if (engine == null)
return;
}
private void set_icon(string icon) {
- int width, height;
- Gtk.icon_size_lookup(Gtk.IconSize.MENU, out width, out height);
- set_image(new IconWidget(icon, width));
+ set_image(new IconWidget(icon, Gtk.IconSize.MENU));
}
public override void activate() {
public extern const bool USE_SYMBOL_ICON;
private const int DEFAULT_FONT_SIZE = 16;
private const int DESC_LABEL_MAX_LEN = 20;
- private const int ICON_SIZE = 48;
private class IBusEngineButton : Gtk.Button {
public IBusEngineButton(IBus.EngineDesc engine) {
add(align);
if (!USE_SYMBOL_ICON) {
- IconWidget icon = new IconWidget(engine.get_icon(), ICON_SIZE);
+ IconWidget icon = new IconWidget(engine.get_icon(),
+ Gtk.IconSize.DIALOG);
align.add(icon);
} else {
var language = engine.get_language();