Remove the hacks for asking the X server for screenshots and use gtk.Widget.get_snapshot() instead.
This commit is contained in:
committed by
Tomeu Vizoso
parent
1fd893f86e
commit
44cabc891b
@@ -469,20 +469,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()
|
||||
self.shared_activity = None
|
||||
self._share_id = None
|
||||
self._join_id = None
|
||||
self._preview = _sugarext.Preview()
|
||||
self._updating_jobject = False
|
||||
self._closing = False
|
||||
self._quit_requested = False
|
||||
@@ -721,10 +713,15 @@ class Activity(Window, gtk.Container):
|
||||
self._jobject = None
|
||||
|
||||
def _get_preview(self):
|
||||
pixbuf = self._preview.get_pixbuf()
|
||||
if pixbuf is None:
|
||||
return None
|
||||
|
||||
if self.canvas is None or not hasattr(self.canvas, 'get_snapshot'):
|
||||
return None
|
||||
pixmap = self.canvas.get_snapshot((-1, -1, 0, 0))
|
||||
|
||||
width, height = pixmap.get_size()
|
||||
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, 0, 8, width, height)
|
||||
pixbuf = pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(),
|
||||
0, 0, 0, 0, width, height)
|
||||
pixbuf = pixbuf.scale_simple(style.zoom(300), style.zoom(225),
|
||||
gtk.gdk.INTERP_BILINEAR)
|
||||
|
||||
@@ -735,8 +732,6 @@ class Activity(Window, gtk.Container):
|
||||
pixbuf.save_to_callback(save_func, 'png', user_data=preview_data)
|
||||
preview_data = ''.join(preview_data)
|
||||
|
||||
self._preview.clear()
|
||||
|
||||
return preview_data
|
||||
|
||||
def _get_buddies(self):
|
||||
@@ -750,10 +745,6 @@ class Activity(Window, gtk.Container):
|
||||
else:
|
||||
return {}
|
||||
|
||||
def take_screenshot(self):
|
||||
if self.canvas:
|
||||
self._preview.take_screenshot(self.canvas)
|
||||
|
||||
def save(self):
|
||||
"""Request that the activity is saved to the Journal.
|
||||
|
||||
@@ -779,7 +770,7 @@ class Activity(Window, gtk.Container):
|
||||
self.metadata['buddies'] = cjson.encode(self._get_buddies())
|
||||
|
||||
preview = self._get_preview()
|
||||
if self._preview:
|
||||
if preview is not None:
|
||||
self.metadata['preview'] = dbus.ByteArray(preview)
|
||||
|
||||
try:
|
||||
@@ -810,8 +801,6 @@ 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
|
||||
|
||||
@@ -974,9 +963,6 @@ 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
|
||||
|
||||
@@ -995,15 +981,6 @@ 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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user