From 02d35937fac46d197bbd67ceef87ab9225a68591 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Mon, 21 May 2012 16:49:37 +0000 Subject: using notify::active for suspend/resume --- (limited to 'TurtleArtActivity.py') diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py index 5503482..24ed3f6 100644 --- a/TurtleArtActivity.py +++ b/TurtleArtActivity.py @@ -82,7 +82,7 @@ class TurtleArtActivity(activity.Activity): _logger.error(str(e)) self._check_ver_change(get_path(activity, 'data')) - self._setup_visibility_handler() + self.connect("notify::active", self._notify_active_cb) self.has_toolbarbox = HAS_TOOLBARBOX _logger.debug('_setup_toolbar') @@ -503,14 +503,6 @@ class TurtleArtActivity(activity.Activity): tmpfile = None return tmpfile - def __visibility_notify_cb(self, window, event): - ''' Callback method for when the activity's visibility changes. ''' - if event.state == gtk.gdk.VISIBILITY_FULLY_OBSCURED: - self.tw.background_plugins() - elif event.state in \ - [gtk.gdk.VISIBILITY_UNOBSCURED, gtk.gdk.VISIBILITY_PARTIAL]: - self.tw.foreground_plugins() - def _keep_clicked_cb(self, button): ''' Keep-button clicked. ''' self.jobject_new_patch() @@ -937,10 +929,18 @@ class TurtleArtActivity(activity.Activity): ''' Resync xy position (and orientation) of my turtle. ''' self._collaboration.send_my_xy() - def _setup_visibility_handler(self): - ''' Notify me when the visibility state changes. ''' - self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK) - self.connect('visibility-notify-event', self.__visibility_notify_cb) + def _notify_active_cb(self, widget, event): + ''' Sugar notify us that the activity is becoming active or + inactive. Notify plugins. ''' + if self.props.active: + _logger.debug('going to foreground') + self.tw.foreground_plugins() + else: + # If we go to background, stop media playing. + if self.tw.gst_available: + from TurtleArt.tagplay import stop_media + stop_media(self.tw.lc) + self.tw.background_plugins() def can_close(self): ''' Override activity class can_close inorder to notify plugins ''' -- cgit v0.9.1