From 68cc9379e29ab9c6e729ccadebd36af9151ae946 Mon Sep 17 00:00:00 2001
From: Rafal Luzynski <digitalfreak@lingonborough.com>
Date: Wed, 21 Oct 2015 02:01:12 +0200
Subject: [PATCH] Show HiDPI icons on HiDPI screens
Closes #115
Signed-off-by: Jakub Filak <jfilak@redhat.com>
Closes #141
---
src/gnome_abrt/tools.py | 21 +++++++++++++++++----
src/gnome_abrt/views.py | 9 ++++++---
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/src/gnome_abrt/tools.py b/src/gnome_abrt/tools.py
index a7361a0..61d4585 100644
--- a/src/gnome_abrt/tools.py
+++ b/src/gnome_abrt/tools.py
@@ -23,6 +23,8 @@ import logging
from gi.repository import GLib
#pylint: disable=E0611
from gi.repository import Gtk
+#pylint: disable=E0611
+from gi.repository import Gdk
from gnome_abrt.l10n import _
from gnome_abrt.l10n import ngettext
@@ -69,21 +71,22 @@ def smart_truncate(content, length=100, suffix='...'):
return content[:length].rsplit(' ', 1)[0] + suffix
-def load_icon(name=None, gicon=None):
+def load_icon(name=None, gicon=None, scale=1):
theme = Gtk.IconTheme.get_default()
icon = None
if not gicon is None and name is None:
name = gicon.to_string()
- icon = theme.lookup_by_gicon(gicon, 128,
+ icon = theme.lookup_by_gicon_for_scale(gicon, 128, scale,
Gtk.IconLookupFlags.FORCE_SIZE)
elif not name is None and gicon is None:
- icon = theme.lookup_icon(name, 128,
+ icon = theme.lookup_icon_for_scale(name, 128, scale,
Gtk.IconLookupFlags.FORCE_SIZE
| Gtk.IconLookupFlags.FORCE_SYMBOLIC)
else:
logging.error("BUG: invalid arguments in load_icon():" \
- "name={0}, gicon={1}".format(str(name), str(gicon)))
+ "name={0}, gicon={1}, scale={2}"
+ .format(str(name), str(gicon), str(scale)))
return None
if icon is None:
@@ -98,3 +101,13 @@ def load_icon(name=None, gicon=None):
.format(name, str(ex)))
return None
+
+
+def set_icon_from_pixbuf_with_scale(icon, pixbuf, scale=1):
+ if scale == 1 or scale is None or pixbuf is None:
+ icon.set_from_pixbuf(pixbuf)
+ return None
+
+ surface = Gdk.cairo_surface_create_from_pixbuf(pixbuf, scale, None)
+ icon.set_from_surface(surface)
+ return None
diff --git a/src/gnome_abrt/views.py b/src/gnome_abrt/views.py
index 5b03602..8cf7e26 100644
--- a/src/gnome_abrt/views.py
+++ b/src/gnome_abrt/views.py
@@ -41,6 +41,7 @@ import gnome_abrt.errors as errors
import gnome_abrt.desktop as desktop
from gnome_abrt import GNOME_ABRT_UI_DIR
from gnome_abrt.tools import fancydate, smart_truncate, load_icon
+from gnome_abrt.tools import set_icon_from_pixbuf_with_scale
from gnome_abrt.l10n import _, GETTEXT_PROGNAME
@@ -836,14 +837,16 @@ class OopsWindow(Gtk.ApplicationWindow):
problem['date'].strftime(config.get_configuration()['D_T_FMT']))
icon_buf = None
+ scale = self._builder.img_app_icon.get_scale_factor()
if app.icon:
- icon_buf = load_icon(gicon=app.icon)
+ icon_buf = load_icon(gicon=app.icon, scale=scale)
if icon_buf is None:
- icon_buf = load_icon(name="system-run-symbolic")
+ icon_buf = load_icon(name="system-run-symbolic", scale=scale)
# icon_buf can be None and if it is None, no icon will be displayed
- self._builder.img_app_icon.set_from_pixbuf(icon_buf)
+ set_icon_from_pixbuf_with_scale(self._builder.img_app_icon,
+ icon_buf, scale)
self._builder.lbl_reported_value.show()
self._builder.lbl_reported.set_text(_("Reported"))
--
2.4.3