Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorErik Garrison <erik@laptop.org>2008-09-17 18:25:38 (GMT)
committer Marco Pesenti Gritti <mpgritti@gmail.com>2008-09-20 10:02:50 (GMT)
commiteecf9f8e57f06716026323fb918d5b8827134d14 (patch)
tree1e3563eb6b0e4b83de02b74dee0ae5319a051fc6 /src
parent10d26a380e67b64f7336cfd3f0f170d102742a46 (diff)
Cleanup screenshot acquisition behavior in activity.py, so that we acquire
screenshots on user-initiated activity save and close. Check before saving that the window is not fully obscured, as it might be if the user initiates the close from the frame--- this would produce incorrect screenshots. The check for visibility is done by attaching a handler to the Activity class which handles visibility-notify-events from X. In the sugar repository equivalent changes remove automated screenshot acquisition from window manager navigation events (e.g. tabbing).
Diffstat (limited to 'src')
-rw-r--r--src/sugar/activity/activity.py37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/sugar/activity/activity.py b/src/sugar/activity/activity.py
index 54c361a..6571994 100644
--- a/src/sugar/activity/activity.py
+++ b/src/sugar/activity/activity.py
@@ -174,7 +174,6 @@ class ActivityToolbar(gtk.Toolbar):
self._activity.copy()
def __stop_clicked_cb(self, button):
- self._activity.take_screenshot()
self._activity.close()
def __jobject_updated_cb(self, jobject):
@@ -474,6 +473,12 @@ class Activity(Window, gtk.Container):
self.connect('realize', self.__realize_cb)
self.connect('delete-event', self.__delete_event_cb)
+ # watch visibility-notify-events to know when we can safely
+ # take a screenshot of the activity
+ self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
+ self.connect('visibility-notify-event', self.__visibility_notify_event_cb)
+ self._fully_obscured = True
+
self._active = False
self._activity_id = handle.activity_id
self._pservice = presenceservice.get_instance()
@@ -728,19 +733,12 @@ class Activity(Window, gtk.Container):
pixbuf = pixbuf.scale_simple(style.zoom(300), style.zoom(225),
gtk.gdk.INTERP_BILINEAR)
- # TODO: Find a way of taking a png out of the pixbuf without saving
- # to a temp file. Impementing gtk.gdk.Pixbuf.save_to_buffer in pygtk
- # would solve this.
- fd, file_path = tempfile.mkstemp('.png')
- os.close(fd)
+ preview_data = []
+ def save_func(buf, data):
+ data.append(buf)
- pixbuf.save(file_path, 'png')
- f = open(file_path)
- try:
- preview_data = f.read()
- finally:
- f.close()
- os.remove(file_path)
+ pixbuf.save_to_callback(save_func, 'png', user_data=preview_data)
+ preview_data = ''.join(preview_data)
self._preview.clear()
@@ -817,6 +815,8 @@ class Activity(Window, gtk.Container):
copy work that needs to be done in write_file()
"""
logging.debug('Activity.copy: %r' % self._jobject.object_id)
+ if not self._fully_obscured:
+ self.take_screenshot()
self.save()
self._jobject.object_id = None
@@ -972,6 +972,8 @@ class Activity(Window, gtk.Container):
write_file() to do any state saving instead. If the application wants
to control wether it can close, it should override can_close().
"""
+ if not self._fully_obscured:
+ self.take_screenshot()
if not self.can_close():
return
@@ -991,6 +993,15 @@ class Activity(Window, gtk.Container):
self.close()
return True
+ def __visibility_notify_event_cb(self, widget, event):
+ """Visibility state is used when deciding if we can take screenshots.
+ Currently we allow screenshots whenever the activity window is fully
+ visible or partially obscured."""
+ if event.state is gtk.gdk.VISIBILITY_FULLY_OBSCURED:
+ self._fully_obscured = True
+ else:
+ self._fully_obscured = False
+
def get_metadata(self):
"""Returns the jobject metadata or None if there is no jobject.