[Sugar-devel] [PATCH v2 sugar] Frame: show application-set icon for non-Sugar windows

Sascha Silbe sascha-pgp at silbe.org
Sun Sep 19 08:43:01 EDT 2010


Display the _NET_WM_ICON content instead of a generic icon for non-Sugar
applications.

Because the sugar.graphics.Icon API is based on file names, we need to create
a temporary file to store the icon.
A future patch could either enhance sugar.graphics.Icon to accept
pixbufs or rework ActivityButton to use something different to show the icon.

Tested on XO-1.5 running Debian Squeeze. Updating the icon took << 0.1s
(0.018s, 0.005s and 0.026s) with /tmp on tmpfs.

Signed-off-by: Sascha Silbe <sascha-pgp at silbe.org>

---
 src/jarabe/frame/activitiestray.py |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

v1->v2: fix race condition causing application-set icon not to be shown
        on fast systems

diff --git a/src/jarabe/frame/activitiestray.py b/src/jarabe/frame/activitiestray.py
index 6bd2a1b..6508953 100644
--- a/src/jarabe/frame/activitiestray.py
+++ b/src/jarabe/frame/activitiestray.py
@@ -37,6 +37,7 @@ from sugar.graphics.menuitem import MenuItem
 from sugar.datastore import datastore
 from sugar import mime
 from sugar import env
+from sugar import util

 from jarabe.model import shell
 from jarabe.model import invites
@@ -67,6 +68,12 @@ class ActivityButton(RadioToolButton):
             self._icon.props.file = home_activity.get_icon_path()
         else:
             self._icon.props.icon_name = 'image-missing'
+            window = home_activity.get_window()
+            if window is not None:
+                window.connect('icon-changed', self._icon_changed_cb)
+                if window.get_icon():
+                    self._update_icon(window)
+
         self.set_icon_widget(self._icon)
         self._icon.show()

@@ -97,6 +104,22 @@ class ActivityButton(RadioToolButton):
         else:
             self._icon.props.pulsing = False

+    def _icon_changed_cb(self, window):
+        gobject.idle_add(self._update_icon, window)
+
+    def _update_icon(self, window):
+        logging.debug('_update_icon: start')
+        pixbuf = window.get_icon()
+        if pixbuf is None:
+            return
+
+        fd, path = tempfile.mkstemp(suffix='.png')
+        os.close(fd)
+        pixbuf.save(path, 'png')
+        self._icon.props.icon_name = None
+        self._icon.props.file = util.TempFilePath(path)
+        logging.debug('_update_icon: updated icon')
+


 class InviteButton(ToolButton):
--
tg: (7fc14a7..) t/frame-show-legacy-icons (depends on: upstream/master)


More information about the Sugar-devel mailing list