Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/toolbar.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@sugarlabs.org>2010-10-28 13:22:09 (GMT)
committer Gonzalo Odiard <godiard@sugarlabs.org>2010-10-28 13:22:09 (GMT)
commitb79ed63fc6a6abd8b01e93d19ba0529e590130c9 (patch)
tree43648310aadf901f50563615f2f7111d12c37420 /toolbar.py
parent99c67b24ddbd926adcc78dae6e0d1a744b4cd1fa (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 Reviewed-by: Martin Sevior <msevior@gmail.com>
Diffstat (limited to 'toolbar.py')
-rw-r--r--toolbar.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/toolbar.py b/toolbar.py
index 6b85077..701d8be 100644
--- a/toolbar.py
+++ b/toolbar.py
@@ -21,6 +21,9 @@ import logging
import abiword
import gtk
+import os
+import tempfile
+from urlparse import urlparse
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.toolcombobox import ToolComboBox
@@ -53,7 +56,7 @@ class EditToolbar(gtk.Toolbar):
paste = PasteButton()
paste.props.accelerator = '<Ctrl>V'
- paste.connect('clicked', lambda button: pc.abiword_canvas.paste())
+ paste.connect('clicked', self.__paste_button_cb)
self.insert(paste, -1)
paste.show()
@@ -122,6 +125,31 @@ class EditToolbar(gtk.Toolbar):
self._findprev.set_sensitive(False)
self._findnext.set_sensitive(False)
+ def __paste_button_cb(self, button):
+ 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 _search_entry_activated_cb(self, entry):
logger.debug('_search_entry_activated_cb')
if not self._search_entry.props.text: