Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@sugarlabs.org>2010-11-09 14:00:26 (GMT)
committer Gonzalo Odiard <godiard@sugarlabs.org>2010-11-09 14:00:26 (GMT)
commit3a191f54252fcc907225a511da35a6aaa8908f2a (patch)
tree9d7b66c5c6ad739389373119c1f785bf437e8e5e
parent045a4e0e63d97c212c4a266c112dfd0b6a55579f (diff)
fix paste images in write - olpc #2507 and olpc #7186
Now you can copy a image from Paint, Browse or Write and paste in Write The patch implement take from the clipboard the different types of contents
-rw-r--r--toolbar.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/toolbar.py b/toolbar.py
index 5625adc..e1d4b63 100644
--- a/toolbar.py
+++ b/toolbar.py
@@ -37,6 +37,9 @@ from sugar.graphics.menuitem import MenuItem
from sugar.datastore import datastore
from sugar import mime
import sugar.profile
+import os
+import tempfile
+from urlparse import urlparse
import dbus
@@ -174,7 +177,29 @@ class WriteEditToolbar(EditToolbar):
self._abiword_canvas.copy()
def _paste_cb(self, button):
- self._abiword_canvas.paste()
+ clipBoard = gtk.Clipboard()
+
+ if clipBoard.wait_is_image_available():
+ pixbuf_sel = clipBoard.wait_for_image()
+ size = int(pixbuf_sel.get_width()), int(pixbuf_sel.get_height())
+ activity = self._abiword_canvas.get_toplevel()
+ temp_path = os.path.join(activity.get_activity_root(), 'instance')
+ if not os.path.exists(temp_path):
+ os.makedirs(temp_path)
+ fd, file_path = tempfile.mkstemp(dir=temp_path, suffix='.jpg')
+ os.close(fd)
+ logging.error('tempfile is %s' % file_path)
+ pixbuf_sel.save(file_path, 'jpeg')
+ self._abiword_canvas.insert_image(file_path, False)
+
+ elif clipBoard.wait_is_uris_available():
+ selection = clipBoard.wait_for_contents('text/uri-list')
+ if selection != None:
+ for uri in selection.get_uris():
+ self._abiword_canvas.insert_image(urlparse(uri).path,
+ False)
+ else:
+ self._abiword_canvas.paste()
def _can_undo_cb(self, canvas, can_undo):
self.undo.set_sensitive(can_undo)