From 863f605e77212665a761496431896aeb47b0ea5e Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Fri, 20 Jul 2012 23:07:46 +0000 Subject: share Turtle shell --- diff --git a/TurtleArt/tacollaboration.py b/TurtleArt/tacollaboration.py index a025074..e9bc149 100644 --- a/TurtleArt/tacollaboration.py +++ b/TurtleArt/tacollaboration.py @@ -72,6 +72,7 @@ class Collaboration(): self._processing_methods = { 't': self._turtle_request, 'T': self._receive_turtle_dict, + 'R': self._reskin_turtle, 'f': self._move_forward, 'a': self._move_in_arc, 'r': self._rotate_turtle, @@ -291,6 +292,20 @@ class Collaboration(): self.send_event('r|%s' % (data_to_string([self._get_nick(), int(self._tw.canvas.heading)]))) + def _reskin_turtle(self, payload): + if len(payload) > 0: + [nick, [width, height, data]] = data_from_string(payload) + if nick != self._tw.nick: + 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.set_turtle(nick) + self._tw.active_turtle.set_shapes([pixbuf]) + def _draw_pixbuf(self, payload): if len(payload) > 0: [nick, [a, b, x, y, w, h, width, height, data]] =\ diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py index be44296..8442261 100644 --- a/plugins/turtle_blocks_extras/turtle_blocks_extras.py +++ b/plugins/turtle_blocks_extras/turtle_blocks_extras.py @@ -16,6 +16,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import gtk +import gobject from time import time import os @@ -31,7 +32,7 @@ from TurtleArt.taconstants import DEFAULT_SCALE, ICON_SIZE, CONSTANTS, \ MEDIA_SHAPES, SKIN_PATHS, BLOCKS_WITH_SKIN, PYTHON_SKIN, \ PREFIX_DICTIONARY, VOICES from TurtleArt.tautils import convert, round_int, debug_output, get_path, \ - data_to_string, find_group + data_to_string, find_group, image_to_base64 from TurtleArt.tajail import myfunc, myfunc_import @@ -1193,6 +1194,24 @@ bullets')) if pen_state: self.tw.canvas.setpen(True) + if self.tw.sharing(): + if self.tw.running_sugar: + tmp_path = get_path(self.tw.activity, 'instance') + else: + tmp_path = '/tmp' + tmp_file = os.path.join(get_path(self.tw.activity, 'instance'), + 'tmpfile.png') + pixbuf.save(tmp_file, 'png', {'quality': '100'}) + data = image_to_base64(tmp_file, tmp_path) + height = pixbuf.get_height() + width = pixbuf.get_width() + event = 'R|%s' % (data_to_string([self.tw.nick, + [round_int(width), + round_int(height), + data]])) + gobject.idle_add(self.tw.send_event, event) + os.remove(tmp_file) + def _prim_save_picture(self, name): """ Save canvas to file as PNG """ self.tw.save_as_image(name) -- cgit v0.9.1