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 clock"): 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) self.set_canvas(self.time_label) self.time_label.show() [...] # 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).""" logging.debug('unmap') self._set_may_freeze(False) 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', self._unmap_cb) window.connect('visibility-notify-event', self._visibility_cb) window.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK) [...] def _set_may_freeze(self, may_freeze): self._hide_cursor(may_freeze) self.may_freeze = may_freeze if may_freeze: self._schedule_freeze() else: self._set_dcon_freeze(False) 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). Sascha -- http://sascha.silbe.org/ http://www.infra-silbe.de/
signature.asc
Description: PGP signature
_______________________________________________ Sugar-devel mailing list Sugar-devel@lists.sugarlabs.org http://lists.sugarlabs.org/listinfo/sugar-devel