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

Sascha Silbe sascha-pgp at silbe.org
Thu Sep 23 14:42:19 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 |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

v1->v2: fix race condition causing application-set icon not to be shown
        on fast systems
v2->v3: remove idle task, use __* for callback name, workaround for temp
        file leak

diff --git a/src/jarabe/frame/activitiestray.py b/src/jarabe/frame/activitiestray.py
index 6bd2a1b..07e834f 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.__icon_changed_cb(window)
+
         self.set_icon_widget(self._icon)
         self._icon.show()

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

+    def __icon_changed_cb(self, window):
+        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)


 class InviteButton(ToolButton):
@@ -241,6 +258,10 @@ class ActivitiesTray(HTray):
         button = self._buttons[home_activity]
         self.remove_item(button)
         del self._buttons[home_activity]
+        # FIXME: workaround for leaking temporary files because the file name
+        # (TempFilePath instance) doesn't get garbage-collected. See also
+        # SL#2360.
+        button._icon.props.file = None

     def _activate_activity(self, home_activity):
         button = self._buttons[home_activity]
--
tg: (7fc14a7..) t/frame-show-legacy-icons (depends on: upstream/master)


More information about the Sugar-devel mailing list