Skip to content

Commit

Permalink
Add image preview to clipboard
Browse files Browse the repository at this point in the history
Fixes #4614
  • Loading branch information
edudev committed Dec 13, 2013
1 parent 3015082 commit f0dbc5d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/jarabe/frame/clipboard.py
Expand Up @@ -25,6 +25,7 @@
from gi.repository import Gdk

from sugar3 import mime
from sugar3.graphics.objectchooser import get_preview_pixbuf

from jarabe.frame.clipboardobject import ClipboardObject, Format

Expand Down Expand Up @@ -140,6 +141,12 @@ def _process_object(self, cb_object):
cb_object.get_id(), 'text/plain',
data=formats['UTF8_STRING'].get_data(), on_disk=False)

if 'image/png' in formats.keys():
pixbuf = get_preview_pixbuf(formats['image/png'].get_data())
self.add_object_format(
cb_object.get_id(), 'image/x-pixbuf',
data=pixbuf, on_disk=False)

def get_object(self, object_id):
logging.debug('Clipboard.get_object')
return self._objects[object_id]
Expand Down
13 changes: 10 additions & 3 deletions src/jarabe/frame/clipboardmenu.py
Expand Up @@ -23,6 +23,7 @@
from gi.repository import GLib

from gi.repository import Gtk
from gi.repository import GdkPixbuf

from sugar3.graphics.palette import Palette
from sugar3.graphics.menuitem import MenuItem
Expand Down Expand Up @@ -146,12 +147,18 @@ def _object_state_changed_cb(self, cb_service, cb_object):
def _update(self):
name = self._cb_object.get_name()
self.props.primary_text = GLib.markup_escape_text(name)
preview = self._cb_object.get_preview()
if preview:
self.props.secondary_text = GLib.markup_escape_text(preview)
self._update_preview()
self._update_items_visibility()
self._update_open_submenu()

def _update_preview(self):
preview = self._cb_object.get_preview()
if isinstance(preview, str):
self.props.secondary_text = GLib.markup_escape_text(preview)
elif isinstance(preview, GdkPixbuf.Pixbuf):
self.props.secondary_text = GLib.markup_escape_text(_('Image'))
self.set_pixbuf(preview)

def _open_item_activate_cb(self, menu_item):
logging.debug('_open_item_activate_cb')
percent = self._cb_object.get_percent()
Expand Down
5 changes: 5 additions & 0 deletions src/jarabe/frame/clipboardobject.py
Expand Up @@ -77,6 +77,11 @@ def get_preview(self):
for mime_type in ['text/plain']:
if mime_type in self._formats:
return self._formats[mime_type].get_data()

for mime_type in ['image/x-pixbuf']:
if mime_type in self._formats:
return self._formats[mime_type].get_data()

return ''

def is_bundle(self):
Expand Down

0 comments on commit f0dbc5d

Please sign in to comment.