Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2012-06-10 05:39:48 (GMT)
committer Walter Bender <walter.bender@gmail.com>2012-06-10 05:39:48 (GMT)
commit8940fcb3a83103bb777a76b041ae53d5df778da9 (patch)
treeb2707aa8ba0d12cca091a8ccf99ccbbb9a306064
parentc9b953d7028d76445f217393afad8e92db55977f (diff)
adding share of blocks and speak
-rw-r--r--TurtleArt/tacollaboration.py33
-rw-r--r--TurtleArtActivity.py14
-rw-r--r--icons/shareoff.svg18
-rw-r--r--icons/shareon.svg28
-rw-r--r--plugins/turtle_blocks_extras/turtle_blocks_extras.py10
5 files changed, 98 insertions, 5 deletions
diff --git a/TurtleArt/tacollaboration.py b/TurtleArt/tacollaboration.py
index 8316c7a..6663f04 100644
--- a/TurtleArt/tacollaboration.py
+++ b/TurtleArt/tacollaboration.py
@@ -1,4 +1,4 @@
-#Copyright (c) 2011, Walter Bender
+#Copyright (c) 2011-12 Walter Bender
#Copyright (c) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
#Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -22,7 +22,7 @@
from dbus.service import signal
from dbus.gobject_service import ExportedGObject
import telepathy
-
+import os
import gtk
import base64
@@ -54,7 +54,7 @@ class Collaboration():
self._setup_dispatch_table()
def setup(self):
- # TODO: hand off role of master is sharer leaves
+ # TODO: hand off role of master if sharer leaves
self.pservice = presenceservice.get_instance()
self.initiating = None # sharing (True) or joining (False)
@@ -81,7 +81,9 @@ class Collaboration():
'w': self._set_pen_width,
'p': self._set_pen_state,
'F': self._fill_polygon,
- 'P': self._draw_pixbuf
+ 'P': self._draw_pixbuf,
+ 'P': self._paste,
+ 'S': self._speak
}
def _shared_cb(self, activity):
@@ -112,6 +114,7 @@ class Collaboration():
id = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube(
SERVICE, {})
+ self._enable_share_button()
def _joined_cb(self, activity):
self._shared_activity = self._activity._shared_activity
@@ -140,6 +143,11 @@ class Collaboration():
# Joiner should request current state from sharer.
self.waiting_for_turtles = True
+ self._enable_share_button()
+
+ def _enable_share_button(self):
+ self._activity.share_button.set_icon('shareon')
+ self._activity.share_button.set_tooltip(_('Share blocks'))
def _list_tubes_reply_cb(self, tubes):
for tube_info in tubes:
@@ -376,6 +384,23 @@ class Collaboration():
poly_points[i][0], poly_points[i][1])))
self._tw.canvas.fill_polygon(shared_poly_points)
+ def _speak(self, payload):
+ if len(payload) > 0:
+ [nick, language_option, text] = data_from_string(payload)
+ if language_option == 'None':
+ language_option = ''
+ if text is not None:
+ os.system('espeak %s "%s" --stdout | aplay' % (
+ language_option, str(text)))
+
+ def _paste(self, payload):
+ if len(payload) > 0:
+ [nick, text] = data_from_string(payload)
+ if text is not None:
+ self._tw.process_data(data_from_string(text),
+ self._tw.paste_offset)
+ self._tw.paste_offset += 20
+
def _get_dictionary(self):
return {self._get_nick(): self._get_colors()}
diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py
index 63a46ab..d3b9d80 100644
--- a/TurtleArtActivity.py
+++ b/TurtleArtActivity.py
@@ -776,6 +776,9 @@ class TurtleArtActivity(activity.Activity):
def _make_load_save_buttons(self, toolbar):
''' Additional toolbar buttons for file IO '''
home = os.environ['HOME']
+ self.share_button = self._add_button('shareoff',
+ _('Sharing blocks disabled'),
+ self._share_cb, toolbar)
if self.has_toolbarbox and gtk.gdk.screen_width() < 1200:
save_load_button = self._add_button(
'save-load', _('Save/Load'), self._save_load_palette_cb,
@@ -1187,6 +1190,17 @@ in order to use the plugin.'))
clipboard.set_text(text)
self.tw.paste_offset = 20
+ def _share_cb(self, button):
+ ''' Share a stack of blocks. '''
+ if not self.tw.sharing():
+ return
+ _logger.debug('Serialize a stack and send as event.')
+ data = self.tw.assemble_data_to_save(False, False)
+ if data is not []:
+ text = data_to_string(data)
+ event = 'B|%s' % (data_to_string([self.tw.nick, text]))
+ self.tw.paste_offset = 20
+
def _paste_cb(self, button):
''' Paste from the clipboard. '''
clipboard = gtk.Clipboard()
diff --git a/icons/shareoff.svg b/icons/shareoff.svg
new file mode 100644
index 0000000..9753828
--- /dev/null
+++ b/icons/shareoff.svg
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ version="1.0"
+ width="55"
+ height="55"
+ id="svg2">
+ <path
+ d="m 1.5,25.5 0,-8 a 8,8 0 0 1 8,-8 l 8,0 0,4 20,0 0,-4 8,0 a 8,8 0 0 1 8,8 l 0,8 0,8 a 8,8 0 0 1 -8,8 l -8,0 -2,0 0,4 -16,0 0,-4 -2,0 -8,0 a 8,8 0 0 1 -8,-8 l 0,-8 z"
+ id="path2882"
+ style="fill:#404040;fill-opacity:1;stroke:none" />
+</svg>
diff --git a/icons/shareon.svg b/icons/shareon.svg
new file mode 100644
index 0000000..704193c
--- /dev/null
+++ b/icons/shareon.svg
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ version="1.0"
+ width="55"
+ height="55"
+ id="svg2">
+ <path
+ d="m 1.5,25.5 0,-8 a 8,8 0 0 1 8,-8 l 8,0 0,4 20,0 0,-4 8,0 a 8,8 0 0 1 8,8 l 0,8 0,8 a 8,8 0 0 1 -8,8 l -8,0 -2,0 0,4 -16,0 0,-4 -2,0 -8,0 a 8,8 0 0 1 -8,-8 l 0,-8 z"
+ id="path2882"
+ style="fill:#404040;fill-opacity:1;stroke:#ffffff;stroke-width:2.5;stroke-linecap:square;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <g
+ transform="matrix(0.38888889,0,0,0.38888889,16.805556,16.805556)"
+ id="zoom-neighborhood"
+ style="display:block">
+ <path
+ d="M 27.5,5 C 15.074,5 5,15.074 5,27.5 5,39.927 15.074,50 27.5,50 39.927,50 50,39.927 50,27.5 50,15.074 39.927,5 27.5,5 z m 10.104,8.904 c 2.096,0 3.795,1.699 3.795,3.794 0,2.096 -1.699,3.794 -3.795,3.794 -2.096,0 -3.794,-1.699 -3.794,-3.794 0,-2.095 1.7,-3.794 3.794,-3.794 z M 9.626,27.501 c 0,-2.099 1.7,-3.799 3.793,-3.799 2.097,0 3.796,1.7 3.796,3.799 0,2.095 -1.7,3.793 -3.796,3.793 -2.095,0 -3.793,-1.698 -3.793,-3.793 z m 7.765,13.595 c -2.093,0 -3.793,-1.695 -3.793,-3.792 0,-2.099 1.701,-3.796 3.793,-3.796 2.099,0 3.799,1.696 3.799,3.796 -0.001,2.095 -1.701,3.792 -3.799,3.792 z m 0.307,-19.901 c -2.094,0 -3.795,-1.7 -3.795,-3.799 0,-2.096 1.7,-3.795 3.795,-3.795 2.099,0 3.796,1.701 3.796,3.795 0.001,2.099 -1.696,3.799 -3.796,3.799 z m 9.801,24.179 c -2.1,0 -3.797,-1.7 -3.797,-3.794 0,-2.098 1.696,-3.797 3.797,-3.797 2.095,0 3.794,1.699 3.794,3.797 0,2.096 -1.699,3.794 -3.794,3.794 z m 0.002,-28.157 c -2.096,0 -3.795,-1.699 -3.795,-3.795 0,-2.096 1.699,-3.795 3.795,-3.795 2.097,0 3.795,1.699 3.795,3.795 0,2.096 -1.698,3.795 -3.795,3.795 z m 9.8,24.184 c -2.096,0 -3.795,-1.699 -3.795,-3.795 0,-2.096 1.699,-3.794 3.795,-3.794 2.096,0 3.794,1.698 3.794,3.794 0,2.096 -1.699,3.795 -3.794,3.795 z m 4.28,-10.103 c -2.096,0 -3.795,-1.698 -3.795,-3.795 0,-2.096 1.699,-3.793 3.799,-3.793 2.094,0 3.791,1.697 3.791,3.793 0,2.097 -1.697,3.795 -3.795,3.795 z"
+ id="zoom-neighborhood_3_"
+ style="fill:#ffffff" />
+
+</g>
+</svg>
diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py
index 55e6a8a..48ecd6e 100644
--- a/plugins/turtle_blocks_extras/turtle_blocks_extras.py
+++ b/plugins/turtle_blocks_extras/turtle_blocks_extras.py
@@ -28,7 +28,8 @@ from TurtleArt.talogo import primitive_dictionary, logoerror, \
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
+from TurtleArt.tautils import convert, round_int, debug_output, get_path, \
+ data_to_string
from TurtleArt.tajail import myfunc, myfunc_import
@@ -1188,6 +1189,13 @@ bullets'))
language_option = ''
os.system('espeak %s "%s" --stdout | aplay' % (
language_option, str(text)))
+ if self.tw.sharing():
+ if language_option == '':
+ event = 'S|%s' % (data_to_string([self.tw.nick, 'None', text]))
+ else:
+ event = 'S|%s' % (data_to_string([self.tw.nick,
+ language_option, text]))
+ self.tw.send_event(event)
def _prim_sinewave(self, pitch, amplitude, duration):
""" Create a Csound score to play a sine wave. """