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).
This commit is contained in:
parent
c613b9cf5e
commit
c1f6d9843d
@ -174,7 +174,6 @@ class ActivityToolbar(gtk.Toolbar):
|
|||||||
self._activity.copy()
|
self._activity.copy()
|
||||||
|
|
||||||
def __stop_clicked_cb(self, button):
|
def __stop_clicked_cb(self, button):
|
||||||
self._activity.take_screenshot()
|
|
||||||
self._activity.close()
|
self._activity.close()
|
||||||
|
|
||||||
def __jobject_updated_cb(self, jobject):
|
def __jobject_updated_cb(self, jobject):
|
||||||
@ -467,6 +466,12 @@ class Activity(Window, gtk.Container):
|
|||||||
self.connect('realize', self.__realize_cb)
|
self.connect('realize', self.__realize_cb)
|
||||||
self.connect('delete-event', self.__delete_event_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._active = False
|
||||||
self._activity_id = handle.activity_id
|
self._activity_id = handle.activity_id
|
||||||
self._pservice = presenceservice.get_instance()
|
self._pservice = presenceservice.get_instance()
|
||||||
@ -724,19 +729,12 @@ class Activity(Window, gtk.Container):
|
|||||||
pixbuf = pixbuf.scale_simple(style.zoom(300), style.zoom(225),
|
pixbuf = pixbuf.scale_simple(style.zoom(300), style.zoom(225),
|
||||||
gtk.gdk.INTERP_BILINEAR)
|
gtk.gdk.INTERP_BILINEAR)
|
||||||
|
|
||||||
# TODO: Find a way of taking a png out of the pixbuf without saving
|
preview_data = []
|
||||||
# to a temp file. Impementing gtk.gdk.Pixbuf.save_to_buffer in pygtk
|
def save_func(buf, data):
|
||||||
# would solve this.
|
data.append(buf)
|
||||||
fd, file_path = tempfile.mkstemp('.png')
|
|
||||||
os.close(fd)
|
|
||||||
|
|
||||||
pixbuf.save(file_path, 'png')
|
pixbuf.save_to_callback(save_func, 'png', user_data=preview_data)
|
||||||
f = open(file_path)
|
preview_data = ''.join(preview_data)
|
||||||
try:
|
|
||||||
preview_data = f.read()
|
|
||||||
finally:
|
|
||||||
f.close()
|
|
||||||
os.remove(file_path)
|
|
||||||
|
|
||||||
self._preview.clear()
|
self._preview.clear()
|
||||||
|
|
||||||
@ -813,6 +811,8 @@ class Activity(Window, gtk.Container):
|
|||||||
copy work that needs to be done in write_file()
|
copy work that needs to be done in write_file()
|
||||||
"""
|
"""
|
||||||
logging.debug('Activity.copy: %r' % self._jobject.object_id)
|
logging.debug('Activity.copy: %r' % self._jobject.object_id)
|
||||||
|
if not self._fully_obscured:
|
||||||
|
self.take_screenshot()
|
||||||
self.save()
|
self.save()
|
||||||
self._jobject.object_id = None
|
self._jobject.object_id = None
|
||||||
|
|
||||||
@ -968,6 +968,8 @@ class Activity(Window, gtk.Container):
|
|||||||
write_file() to do any state saving instead. If the application wants
|
write_file() to do any state saving instead. If the application wants
|
||||||
to control wether it can close, it should override can_close().
|
to control wether it can close, it should override can_close().
|
||||||
"""
|
"""
|
||||||
|
if not self._fully_obscured:
|
||||||
|
self.take_screenshot()
|
||||||
|
|
||||||
if not self.can_close():
|
if not self.can_close():
|
||||||
return
|
return
|
||||||
@ -987,6 +989,15 @@ class Activity(Window, gtk.Container):
|
|||||||
self.close()
|
self.close()
|
||||||
return True
|
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):
|
def get_metadata(self):
|
||||||
"""Returns the jobject metadata or None if there is no jobject.
|
"""Returns the jobject metadata or None if there is no jobject.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user