[Sugar-devel] Freeing resources when switching away from activity (was: Re: [Bugs] #2413 UNSP: Hovering over the new activity toolbar activity icon so that sub toolbar appears triggers focus_out_event)

Sascha Silbe sascha-ml-reply-to-2010-3 at silbe.org
Wed Oct 6 14:51:14 EDT 2010

Excerpts from Sugar Labs Bugs's message of Wed Oct 06 18:16:49 UTC 2010:

>  I decided to keep poking at this for Physics and there does seem to be an
>  activity level fix. As per a long, long lost email from Tomeu (thanks
>  Tomeu, only took me two years to re-investigate and take action). I'm
>  connecting a callback to the visibility-notify-event and then testing if
>  data.state == gtk.gdk.VISIBILITY_FULLY_OBSCURED. Took me ages to track
>  this down, but seems to be working a treat, I'm about to test outside of
>  my VM dev environment and onto an XO-1:

FWIW, this is what I do in one of my activities (a simple "digital wall

class BigDigiClockActivity(activity.Activity):

    def __init__(self, handle):
        self.can_freeze = True
        self._freeze_scheduled = False
        self.time_label.connect('size-allocate', self._size_allocate_cb)
        self._unmap_cb_handler = None
        self.time_label.connect('unmap-event', self._unmap_cb)

    # for debug output only
    _vis_map = {
        gtk.gdk.VISIBILITY_UNOBSCURED: 'unobscured',
        gtk.gdk.VISIBILITY_PARTIAL: 'partial',
        gtk.gdk.VISIBILITY_FULLY_OBSCURED: 'fully obscured',
    def _visibility_cb(self, widget, event, *args):
        """X window has changed."""
        logging.debug('visibility = %r', self._vis_map.get(event.state, event.state))
        self._set_may_freeze(event.state == gtk.gdk.VISIBILITY_UNOBSCURED)

    def _unmap_cb(self, *args):
        """X window has been unmapped (i.e. is invisible now)."""

    def _size_allocate_cb(self, widget, allocation, *args):
        """Size for self.time_label has been (re)set.

        Recalculate font size if necessary."""
        if self._unmap_cb_handler is None:
            window = self.time_label.get_parent()
            self._unmap_cb_handler = window.connect('unmap-event',
            window.connect('visibility-notify-event', self._visibility_cb)

    def _set_may_freeze(self, may_freeze):
        self.may_freeze = may_freeze
        if may_freeze:

For other activities there might be a better match than size-allocate
for when to connect the callbacks to the window.

Perhaps we could move some of this to sugar.activity.activity.Activity
so activity authors could concentrate on the resource freeing part?
Maybe even coupled with a timer to prevent us from slowing down quick
activity switches (i.e. the user switching forth and back between two
activities in quick succession).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://lists.sugarlabs.org/private/sugar-devel/attachments/20101006/36963e2e/attachment.pgp>

More information about the Sugar-devel mailing list