From e059c631054d8e941ff27bd0c606e7b80d205bca Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sun, 06 Feb 2011 15:16:04 +0000 Subject: adding sharing of pixbufs --- diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.py index ac9e36e..a4dbb64 100644 --- a/TurtleArt/tacanvas.py +++ b/TurtleArt/tacanvas.py @@ -24,6 +24,7 @@ import gtk from math import sin, cos, pi import pango import cairo +import base64 from sprites import Sprite from tasprite_factory import SVG @@ -402,7 +403,7 @@ class TurtleGraphics: round_int(self.gray)])) self._send_event(event, share) - def settextcolor(self, c): + def settextcolor(self, c): # depreciated """ Set the text color """ try: self.tcolor = c @@ -487,7 +488,7 @@ class TurtleGraphics: event = "p|%s" % (data_to_string([self._get_my_nick(), bool])) self._send_event(event, share) - def draw_pixbuf(self, pixbuf, a, b, x, y, w, h, path): + def draw_pixbuf(self, pixbuf, a, b, x, y, w, h, path, share=True): """ Draw a pixbuf """ w *= self.tw.coord_scale h *= self.tw.coord_scale @@ -501,6 +502,21 @@ class TurtleGraphics: else: self.tw.svg_string += self.svg.image(x - self.width / 2, y, w, h, path) + if self.tw.sharing(): + data = pixbuf.get_pixels() + 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), path, + height, width, stride, bits_per_sample, + has_alpha, colorspace, + base64.standard_b64encode(str(data))]])) + self._send_event(event, share) def draw_text(self, label, x, y, size, w, share=True): """ Draw text """ @@ -666,5 +682,5 @@ class TurtleGraphics: return if self.tw.sharing(): - print "Sending: %s" % entry + # print "Sending: %s" % entry self.tw.send_event(entry) diff --git a/TurtleArt/tacollaboration.py b/TurtleArt/tacollaboration.py index 9081edc..0383e6b 100644 --- a/TurtleArt/tacollaboration.py +++ b/TurtleArt/tacollaboration.py @@ -23,6 +23,10 @@ from dbus.service import signal from dbus.gobject_service import ExportedGObject import logging import telepathy + +import gtk +import base64 + from TurtleArt.tautils import data_to_string, data_from_string try: @@ -75,7 +79,8 @@ class Collaboration(): 'g' : self._set_pen_gray_level, 's' : self._set_pen_shade, 'w' : self._set_pen_width, - 'p' : self._set_pen_state + 'p' : self._set_pen_state, + 'P' : self._draw_pixbuf } def _shared_cb(self, activity): @@ -218,6 +223,17 @@ class Collaboration(): self._tw.canvas.set_turtle(nick, colors) self.waiting_for_turtles = False + def _draw_pixbuf(self, payload): + if len(payload) > 0: + [nick, [a, b, x, y, w, h, path, width, height, stride, + bits_per_sample, has_alpha, colorspace, data]] =\ + data_from_string(payload) + if nick != self._tw.nick: + self._tw.canvas.draw_pixbuf(gtk.gdk.pixbuf_new_from_data( + base64.standard_b64decode(data), colorspace, has_alpha, + bits_per_sample, width, height, stride), a, b, x, y, w, + h, path, False) + def _move_forward(self, payload): if len(payload) > 0: [nick, x] = data_from_string(payload) -- cgit v0.9.1