From 0f6ec143612b29306e20b0512a8b1ea3b2cb7662 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Mon, 07 Feb 2011 14:05:17 +0000 Subject: trying base64 for draw_pixbuf sharing --- (limited to 'TurtleArt') diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.py index 8f12f61..952fc25 100644 --- a/TurtleArt/tacanvas.py +++ b/TurtleArt/tacanvas.py @@ -501,21 +501,22 @@ class TurtleGraphics: y, w, h, path, image_to_base64(pixbuf, get_path(self.tw.activity, 'instance'))) else: + # Outside of Sugar, we save a path self.tw.svg_string += self.svg.image(x - self.width / 2, y, w, h, path) if self.tw.sharing(): - data = pixbuf.get_pixels() + if self.tw.running_sugar: + tmp_path = get_path(self.tw.activity, 'instance') + else: + tmp_path = '/tmp' + data = image_to_base64(pixbuf, tmp_path) height = pixbuf.get_height() width = pixbuf.get_width() - stride = pixbuf.get_rowstride() - bits_per_sample = pixbuf.get_bits_per_sample() - has_alpha = pixbuf.get_has_alpha() - colorspace = pixbuf.get_colorspace() event = "P|%s" % (data_to_string([self._get_my_nick(), [round_int(a), round_int(b), round_int(x), round_int(y), round_int(w), round_int(h), - width, height, stride, bits_per_sample, - has_alpha, colorspace, data]])) + round_int(width), round_int(height), + data]])) self._send_event(event, share) def draw_text(self, label, x, y, size, w, share=True): diff --git a/TurtleArt/tacollaboration.py b/TurtleArt/tacollaboration.py index 0bebe67..83ce835 100644 --- a/TurtleArt/tacollaboration.py +++ b/TurtleArt/tacollaboration.py @@ -225,13 +225,18 @@ class Collaboration(): def _draw_pixbuf(self, payload): if len(payload) > 0: - [nick, [a, b, x, y, w, h, width, height, stride, - bits_per_sample, has_alpha, colorspace, data]] =\ - data_from_string(payload) + [nick, [a, b, x, y, w, h, width, height, data]] =\ + data_from_string(payload) if nick != self._tw.nick: - self._tw.canvas.draw_pixbuf(gtk.gdk.pixbuf_new_from_data( - data, colorspace, has_alpha, bits_per_sample, width, - height, stride), a, b, x, y, w, h, None, False) + if self.tw.running_sugar: + tmp_path = get_path(self.tw.activity, 'instance') + else: + tmp_path = '/tmp' + file_name = base64_to_image(data, tmp_path) + pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(file_name, + width, height) + self._tw.canvas.draw_pixbuf(pixbuf, a, b, x, y, w, h, + file_name, False) def _move_forward(self, payload): if len(payload) > 0: diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py index db2ef4b..2b7b230 100644 --- a/TurtleArt/tautils.py +++ b/TurtleArt/tautils.py @@ -296,6 +296,7 @@ def image_to_base64(pixbuf, path_name): file_handle = open(base64, 'r') data = file_handle.read() file_handle.close() + print 'image to base64:' + file_name return data @@ -308,6 +309,7 @@ def base64_to_image(data, path_name): file_name = os.path.join(path_name, 'imagetmp.png') cmd = "base64 -d <" + base64 + ">" + file_name subprocess.check_call(cmd, shell=True) + print 'base64 to image:' + file_name return file_name -- cgit v0.9.1